Skip to content

Commit 546a97a

Browse files
feat(examples): add kinetic_text_tags and glitch_tag
https://github.com/SoDaRa/Kinetic-Text-Tags
1 parent 435adad commit 546a97a

15 files changed

+982
-0
lines changed

game/examples/glitch_tag.rpy

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Kinetic Text Tags Ren'Py Module
2+
# 2021 Daniel Westfall <SoDaRa2595@gmail.com>
3+
#
4+
# http://twitter.com/sodara9
5+
# I'd appreciate being given credit if you do end up using it! :D Would really
6+
# make my day to know I helped some people out!
7+
# Really hope this can help the community create some really neat ways to spice
8+
# up their dialogue!
9+
# http://opensource.org/licenses/mit-license.php
10+
# Forum Post: https://lemmasoft.renai.us/forums/viewtopic.php?f=51&t=60527&sid=75b4eb1aa5212a33cbfe9b0354e5376b
11+
# GitHub: https://github.com/SoDaRa/Kinetic-Text-Tags
12+
# itch.io: https://wattson.itch.io/kinetic-text-tags
13+
14+
# Permission is hereby granted, free of charge, to any person
15+
# obtaining a copy of this software and associated documentation files
16+
# (the "Software"), to deal in the Software without restriction,
17+
# including without limitation the rights to use, copy, modify, merge,
18+
# publish, distribute, sublicense, and/or sell copies of the Software,
19+
# and to permit persons to whom the Software is furnished to do so,
20+
# subject to the following conditions:
21+
#
22+
# The above copyright notice and this permission notice shall be
23+
# included in all copies or substantial portions of the Software.
24+
#
25+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32+
33+
34+
init python:
35+
class GlitchText(renpy.Displayable,str):
36+
def __init__(self, child, amount, **kwargs):
37+
super(GlitchText, self).__init__(**kwargs)
38+
if isinstance(child, (str, unicode)):
39+
self.child = Text(child)
40+
else:
41+
self.child = child
42+
self.amount = amount
43+
44+
def __new__(cls, child, amount, **kwargs):
45+
if isinstance(child, (str, unicode)):
46+
return str.__new__(cls, child)
47+
48+
def render(self, width, height, st, at):
49+
child_render = renpy.render(self.child, width, height, st, at)
50+
51+
self.width, self.height = child_render.get_size()
52+
render = renpy.Render(self.width, self.height)
53+
y = 0
54+
while y < self.height:
55+
glitch_occurs = renpy.random.random() * 100 < self.amount
56+
if glitch_occurs:
57+
curr_height = renpy.random.randint(-10,10)
58+
else:
59+
curr_height = renpy.random.randint(0,10)
60+
curr_offset = renpy.random.randint(-10,10)
61+
curr_surface = child_render.subsurface((0,y,self.width,curr_height))
62+
if glitch_occurs:
63+
render.subpixel_blit(curr_surface, (curr_offset, y))
64+
else:
65+
render.subpixel_blit(curr_surface, (0, y))
66+
if curr_height > 0:
67+
y += curr_height
68+
else:
69+
y -= curr_height
70+
renpy.redraw(self,0)
71+
return render
72+
73+
# Argument is the percertage of the time it'll apply a random offset to a randomly sized slice.
74+
# offset_percent: (Float between 0.0-100.0) Percentage chance a random block of the render will be offset.
75+
# 0 will cause it to never occur. 100 will cause an offset on every line.
76+
# Example: {glitch=59.94}Text{/glitch}
77+
def glitch_tag(tag, argument, contents):
78+
new_list = [ ]
79+
if argument == "":
80+
argument = 10.0
81+
else:
82+
argument = float(argument)
83+
my_style = DispTextStyle()
84+
for kind,text in contents:
85+
if kind == renpy.TEXT_TEXT:
86+
char_disp = GlitchText(my_style.apply_style(text), argument)
87+
new_list.append((renpy.TEXT_DISPLAYABLE, char_disp))
88+
new_list.append((renpy.TEXT_TAG, "alt"))
89+
new_list.append((renpy.TEXT_TEXT, text))
90+
new_list.append((renpy.TEXT_TAG, "/alt"))
91+
elif kind == renpy.TEXT_TAG:
92+
if text.find("image") != -1:
93+
tag, _, value = text.partition("=")
94+
my_img = renpy.displayable(value)
95+
img_disp = GlitchText(my_img, argument)
96+
new_list.append((renpy.TEXT_DISPLAYABLE, img_disp))
97+
elif not my_style.add_tags(text):
98+
new_list.append((kind, text))
99+
else:
100+
new_list.append((kind,text))
101+
return new_list
102+
103+
config.custom_text_tags["glitch"] = glitch_tag

0 commit comments

Comments
 (0)