Skip to content

Commit

Permalink
feat(examples): add kinetic_text_tags and glitch_tag
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Sep 2, 2024
1 parent 435adad commit 546a97a
Show file tree
Hide file tree
Showing 15 changed files with 982 additions and 0 deletions.
103 changes: 103 additions & 0 deletions game/examples/glitch_tag.rpy
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Kinetic Text Tags Ren'Py Module
# 2021 Daniel Westfall <[email protected]>
#
# http://twitter.com/sodara9
# I'd appreciate being given credit if you do end up using it! :D Would really
# make my day to know I helped some people out!
# Really hope this can help the community create some really neat ways to spice
# up their dialogue!
# http://opensource.org/licenses/mit-license.php
# Forum Post: https://lemmasoft.renai.us/forums/viewtopic.php?f=51&t=60527&sid=75b4eb1aa5212a33cbfe9b0354e5376b
# GitHub: https://github.com/SoDaRa/Kinetic-Text-Tags
# itch.io: https://wattson.itch.io/kinetic-text-tags

# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


init python:
class GlitchText(renpy.Displayable,str):
def __init__(self, child, amount, **kwargs):
super(GlitchText, self).__init__(**kwargs)
if isinstance(child, (str, unicode)):
self.child = Text(child)
else:
self.child = child
self.amount = amount

def __new__(cls, child, amount, **kwargs):
if isinstance(child, (str, unicode)):
return str.__new__(cls, child)

def render(self, width, height, st, at):
child_render = renpy.render(self.child, width, height, st, at)

self.width, self.height = child_render.get_size()
render = renpy.Render(self.width, self.height)
y = 0
while y < self.height:
glitch_occurs = renpy.random.random() * 100 < self.amount
if glitch_occurs:
curr_height = renpy.random.randint(-10,10)
else:
curr_height = renpy.random.randint(0,10)
curr_offset = renpy.random.randint(-10,10)
curr_surface = child_render.subsurface((0,y,self.width,curr_height))
if glitch_occurs:
render.subpixel_blit(curr_surface, (curr_offset, y))
else:
render.subpixel_blit(curr_surface, (0, y))
if curr_height > 0:
y += curr_height
else:
y -= curr_height
renpy.redraw(self,0)
return render

# Argument is the percertage of the time it'll apply a random offset to a randomly sized slice.
# offset_percent: (Float between 0.0-100.0) Percentage chance a random block of the render will be offset.
# 0 will cause it to never occur. 100 will cause an offset on every line.
# Example: {glitch=59.94}Text{/glitch}
def glitch_tag(tag, argument, contents):
new_list = [ ]
if argument == "":
argument = 10.0
else:
argument = float(argument)
my_style = DispTextStyle()
for kind,text in contents:
if kind == renpy.TEXT_TEXT:
char_disp = GlitchText(my_style.apply_style(text), argument)
new_list.append((renpy.TEXT_DISPLAYABLE, char_disp))
new_list.append((renpy.TEXT_TAG, "alt"))
new_list.append((renpy.TEXT_TEXT, text))
new_list.append((renpy.TEXT_TAG, "/alt"))
elif kind == renpy.TEXT_TAG:
if text.find("image") != -1:
tag, _, value = text.partition("=")
my_img = renpy.displayable(value)
img_disp = GlitchText(my_img, argument)
new_list.append((renpy.TEXT_DISPLAYABLE, img_disp))
elif not my_style.add_tags(text):
new_list.append((kind, text))
else:
new_list.append((kind,text))
return new_list

config.custom_text_tags["glitch"] = glitch_tag
Loading

0 comments on commit 546a97a

Please sign in to comment.