Skip to content

Commit 31d104b

Browse files
authored
feat: add conditionals for cycling dynatext content (#1273)
* Create dynatext_conditionals.toml * fix: don't show the first string when condition can't be met
1 parent 0957303 commit 31d104b

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

lovely/dynatext_conditionals.toml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[manifest]
2+
version = "1.0.0"
3+
dump_lua = true
4+
priority = -10
5+
6+
### allows conditional dynatext messages
7+
8+
# store conditionals
9+
[[patches]]
10+
[patches.pattern]
11+
target = 'engine/text.lua'
12+
pattern = '''
13+
if self.strings[k].H > self.config.H then self.config.H = self.strings[k].H; self.strings[k].H_offset = 0 end'''
14+
position = 'after'
15+
payload = '''
16+
if first_pass and type(mem_v) == "table" and mem_v.condition then
17+
self.strings[k].condition = mem_v.condition
18+
end
19+
'''
20+
match_indent = true
21+
22+
[[patches]]
23+
[patches.pattern]
24+
target = 'engine/text.lua'
25+
pattern = ''' for k, v in ipairs(self.config.string) do'''
26+
position = 'after'
27+
payload = '''
28+
local mem_v = v
29+
'''
30+
match_indent = true
31+
32+
# check conditionals
33+
[[patches]]
34+
[patches.pattern]
35+
target = 'engine/text.lua'
36+
pattern = '''self.focused_string = (self.config.random_element and math.random(1, #self.strings)) or self.focused_string == #self.strings and 1 or self.focused_string+1'''
37+
position = 'at'
38+
payload = '''
39+
while true do
40+
self.focused_string = (self.config.random_element and math.random(1, #self.strings)) or self.focused_string == #self.strings and 1 or self.focused_string+1
41+
if type(self.strings[self.focused_string]) ~= 'table' or not self.strings[self.focused_string].condition then break
42+
elseif self.strings[self.focused_string].condition() then break end
43+
end
44+
'''
45+
match_indent = true
46+
47+
# Check condition for the initial string
48+
[[patches]]
49+
[patches.pattern]
50+
target = 'engine/text.lua'
51+
pattern = '''for k, v in ipairs(self.strings) do'''
52+
position = 'before'
53+
payload = '''
54+
if first_pass and type(self.strings[self.focused_string]) == 'table' and
55+
type(self.strings[self.focused_string].condition) == 'function' and not self.strings[self.focused_string].condition() then
56+
while true do
57+
self.focused_string = (self.config.random_element and math.random(1, #self.strings)) or self.focused_string == #self.strings and 1 or self.focused_string+1
58+
if type(self.strings[self.focused_string]) ~= 'table' or not self.strings[self.focused_string].condition then break
59+
elseif self.strings[self.focused_string].condition() then break end
60+
end
61+
end
62+
63+
'''
64+
match_indent = true

0 commit comments

Comments
 (0)