Skip to content

Commit e32ce93

Browse files
SMODS.DrawStep Card.draw modularization (#480)
* Card.draw API * Remove test code * Remove duplicate sticker draw * Update src/card_draw.lua Co-authored-by: WilsontheWolf <git@shorty.systems> * Conditions and ignore keys * Respect shininess * Add soul_pos.draw * These went missing for some reason * Undo shiny orange stake * Swap hologram and soul_pos.draw --------- Co-authored-by: WilsontheWolf <git@shorty.systems>
1 parent e105f33 commit e32ce93

8 files changed

Lines changed: 462 additions & 223 deletions

File tree

lovely/atlas.toml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,3 @@ payload = '''
3939
_atlas = G.ASSET_ATLAS[_smods_atlas] or _atlas
4040
end'''
4141

42-
## Hide floating ? from undiscovered types
43-
# Card:draw()
44-
[[patches]]
45-
[patches.pattern]
46-
target = 'card.lua'
47-
pattern = '''shared_sprite:draw_shader('dissolve', nil, nil, nil, self.children.center, scale_mod, rotate_mod)'''
48-
position = 'at'
49-
match_indent = true
50-
payload = '''
51-
if (self.config.center.undiscovered and not self.config.center.undiscovered.no_overlay) or not( SMODS.UndiscoveredSprites[self.ability.set] and SMODS.UndiscoveredSprites[self.ability.set].no_overlay) then
52-
shared_sprite:draw_shader('dissolve', nil, nil, nil, self.children.center, scale_mod, rotate_mod)
53-
else
54-
if SMODS.UndiscoveredSprites[self.ability.set] and SMODS.UndiscoveredSprites[self.ability.set].overlay_sprite then
55-
SMODS.UndiscoveredSprites[self.ability.set].overlay_sprite:draw_shader('dissolve', nil, nil, nil, self.children.center, scale_mod, rotate_mod)
56-
end
57-
end'''

lovely/center.toml

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -466,47 +466,6 @@ payload = '''
466466
end
467467
'''
468468

469-
# Card:draw()
470-
[[patches]]
471-
[patches.pattern]
472-
target = 'card.lua'
473-
pattern = '--If the card has any edition/seal, add that here'
474-
position = 'before'
475-
match_indent = true
476-
payload = '''
477-
local center = self.config.center
478-
if center.draw and type(center.draw) == 'function' then
479-
center:draw(self, layer)
480-
end
481-
if center.set == 'Default' or center.set == 'Enhanced' and not center.replace_base_card then
482-
if not center.no_suit then
483-
local suit = SMODS.Suits[self.base.suit] or {}
484-
if suit.draw and type(suit.draw) == 'function' then
485-
suit:draw(self, layer)
486-
end
487-
end
488-
if not center.no_rank then
489-
local rank = SMODS.Ranks[self.base.value] or {}
490-
if rank.draw and type(rank.draw) == 'function' then
491-
rank:draw(self, layer)
492-
end
493-
end
494-
end
495-
'''
496-
497-
[[patches]]
498-
[patches.pattern]
499-
target = 'card.lua'
500-
pattern = 'if self.seal then'
501-
position = 'at'
502-
match_indent = true
503-
payload = '''
504-
local seal = G.P_SEALS[self.seal or {}] or {}
505-
if type(seal.draw) == 'function' then
506-
seal:draw(self, layer)
507-
elseif self.seal then
508-
'''
509-
510469
# no_blueprint check
511470
[[patches]]
512471
[patches.pattern]

lovely/edition.toml

Lines changed: 0 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -93,114 +93,6 @@ for _, v in ipairs(G.P_CENTER_POOLS.Edition) do
9393
G.BADGE_COL[v.key:sub(3)] = v.badge_colour
9494
end'''
9595

96-
# Limit ARGS.send_to_shader[1] to wiggle between 0 and 2 instead of growing infinitely
97-
# this makes shaders responsiveness on tilt reliable over time
98-
# Card:draw()
99-
[[patches]]
100-
[patches.regex]
101-
target = "card.lua"
102-
pattern = '''
103-
G\.TIMERS\.REAL/\(28\)'''
104-
position = "at"
105-
payload = '''math.sin(G.TIMERS.REAL/28) + 1'''
106-
107-
# Allow editions to not draw shadow
108-
# Card:draw()
109-
[[patches]]
110-
[patches.regex]
111-
target = "card.lua"
112-
pattern = '''
113-
self\.ability\.effect ~= 'Glass Card' and not self\.greyed'''
114-
position = "after"
115-
payload = ''' and self:should_draw_shadow() '''
116-
117-
# If shader modifies shape of card, this will stop "back" layer of the card being rendered.
118-
# Card:draw()
119-
[[patches]]
120-
[patches.pattern]
121-
target = "card.lua"
122-
pattern = '''
123-
elseif not self.greyed then'''
124-
position = "before"
125-
payload = '''
126-
elseif not self:should_draw_base_shader() then
127-
-- Don't render base dissolve shader.
128-
'''
129-
match_indent = true
130-
131-
# If shader modifies shape of card, this will stop "back" layer of the card being rendered.
132-
# spectral cards and booster packs only.
133-
# Card:draw()
134-
[[patches]]
135-
[patches.pattern]
136-
target = "card.lua"
137-
pattern = '''
138-
if self.ability.set == 'Booster' or self.ability.set == 'Spectral' then'''
139-
position = "at"
140-
payload = '''
141-
if (self.ability.set == 'Booster' or self.ability.set == 'Spectral') and self:should_draw_base_shader() then'''
142-
match_indent = true
143-
144-
# If shader modifies shape of card, this will stop "back" layer of the card being rendered.
145-
# invisible joker and vouchers.
146-
# Card:draw()
147-
[[patches]]
148-
[patches.pattern]
149-
target = "card.lua"
150-
pattern = '''
151-
self.children.center:draw_shader('voucher', nil, self.ARGS.send_to_shader)'''
152-
position = "at"
153-
payload = '''
154-
if self:should_draw_base_shader() then
155-
self.children.center:draw_shader('voucher', nil, self.ARGS.send_to_shader)
156-
end'''
157-
match_indent = true
158-
159-
# Inject shaders applying to cards
160-
# Card:draw()
161-
[[patches]]
162-
[patches.regex]
163-
target = "card.lua"
164-
pattern = '''
165-
(?<indent>[\t ]*)if self\.edition and self\.editi[A-z\.\:\n\t _(',)~=]*me', nil, self.ARGS.send_to_shader\)
166-
[\t ]*end
167-
[\t ]*end'''
168-
position = "at"
169-
payload = '''
170-
if self.edition then
171-
for k, v in pairs(G.P_CENTER_POOLS.Edition) do
172-
if self.edition[v.key:sub(3)] and v.shader then
173-
if type(v.draw) == 'function' then
174-
v:draw(self, layer)
175-
else
176-
self.children.center:draw_shader(v.shader, nil, self.ARGS.send_to_shader)
177-
if self.children.front and self.ability.effect ~= 'Stone Card' and not self.config.center.replace_base_card then
178-
self.children.front:draw_shader(v.shader, nil, self.ARGS.send_to_shader)
179-
end
180-
end
181-
end
182-
end
183-
end'''
184-
line_prepend = "$indent"
185-
186-
# Inject shaders applying to floating sprites
187-
[[patches]]
188-
[patches.pattern]
189-
target = "card.lua"
190-
pattern = "self.children.floating_sprite:draw_shader('dissolve', nil, nil, nil, self.children.center, scale_mod, rotate_mod)"
191-
position = "after"
192-
payload = '''
193-
if self.edition then
194-
for k, v in pairs(G.P_CENTER_POOLS.Edition) do
195-
if v.apply_to_float then
196-
if self.edition[v.key:sub(3)] then
197-
self.children.floating_sprite:draw_shader(v.shader, nil, nil, nil, self.children.center, scale_mod, rotate_mod)
198-
end
199-
end
200-
end
201-
end'''
202-
match_indent = true
203-
20496
# Remove prefix from shader key when calling send()
20597
[[patches]]
20698
[patches.pattern]

lovely/enhancement.toml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,6 @@ payload = """if not SMODS.has_no_suit(scoring_hand[i]) then
142142
G.GAME.cards_played[scoring_hand[i].base.value].suits[scoring_hand[i].base.suit] = true
143143
end"""
144144

145-
146-
## replace_base_card
147-
# Determines whether to draw the base card's front or not
148-
# Card:draw()
149-
[[patches]]
150-
[patches.pattern]
151-
target = "card.lua"
152-
pattern = "if self.children.front and self.ability.effect ~= 'Stone Card' then"
153-
match_indent = true
154-
position = "at"
155-
payload = "if self.children.front and (self.ability.delayed or (self.ability.effect ~= 'Stone Card' and not self.config.center.replace_base_card)) then"
156145
# Add the delayed property to sprites that are delayed
157146
[[patches]]
158147
[patches.pattern]

lovely/fixes.toml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -465,31 +465,6 @@ pattern = "for _, v in pairs(G.I.SPRITE) do"
465465
position = "at"
466466
payload = 'for k, v in pairs(G.I.SPRITE) do'
467467

468-
##
469-
## Card:draw() - improved mod compatibility
470-
##
471-
# Add option for sprites to not be drawn
472-
[[patches]]
473-
[patches.pattern]
474-
target = "card.lua"
475-
match_indent = true
476-
pattern = '''
477-
if k ~= 'focused_ui' and k ~= "front" and k ~= "back" and k ~= "soul_parts" and k ~= "center" and k ~= 'floating_sprite' and k~= "shadow" and k~= "use_button" and k ~= 'buy_button' and k ~= 'buy_and_use_button' and k~= "debuff" and k ~= 'price' and k~= 'particles' and k ~= 'h_popup' then v:draw() end'''
478-
position = "at"
479-
payload = '''
480-
if not v.custom_draw and k ~= 'focused_ui' and k ~= "front" and k ~= "back" and k ~= "soul_parts" and k ~= "center" and k ~= 'floating_sprite' and k~= "shadow" and k~= "use_button" and k ~= 'buy_button' and k ~= 'buy_and_use_button' and k~= "debuff" and k ~= 'price' and k~= 'particles' and k ~= 'h_popup' then v:draw() end'''
481-
482-
# This check is not necessary?
483-
[[patches]]
484-
[patches.pattern]
485-
target = "card.lua"
486-
match_indent = true
487-
pattern = '''
488-
if self.edition or self.seal or self.ability.eternal or self.ability.rental or self.ability.perishable or self.sticker or ((self.sticker_run and self.sticker_run ~= 'NONE') and G.SETTINGS.run_stake_stickers) or (self.ability.set == 'Spectral') or self.debuff or self.greyed or (self.ability.name == 'The Soul') or (self.ability.set == 'Voucher') or (self.ability.set == 'Booster') or self.config.center.soul_pos or self.config.center.demo then'''
489-
position = "at"
490-
payload = '''
491-
if true then'''
492-
493468
## Make vanilla enhancement jokers work with extra enhancements
494469

495470
# Steel Joker

lovely/sticker.toml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,6 @@ position = "at"
8888
match_indent = true
8989
payload = '''if G.GAME.modifiers.enable_rentals_in_shop and pseudorandom((area == G.pack_cards and 'packssjr' or 'ssjr')..G.GAME.round_resets.ante) > 0.7 and not SMODS.Stickers["rental"].should_apply then'''
9090

91-
# Card:draw()
92-
[[patches]]
93-
[patches.pattern]
94-
target = "card.lua"
95-
pattern = '''if self.ability.name == 'The Soul' and (self.config.center.discovered or self.bypass_discovery_center) then'''
96-
match_indent = true
97-
position = "before"
98-
payload = '''
99-
for k, v in pairs(SMODS.Stickers) do
100-
if self.ability[v.key] then
101-
if v and v.draw and type(v.draw) == 'function' then
102-
v:draw(self, layer)
103-
else
104-
G.shared_stickers[v.key].role.draw_major = self
105-
G.shared_stickers[v.key]:draw_shader('dissolve', nil, nil, nil, self.children.center)
106-
G.shared_stickers[v.key]:draw_shader('voucher', nil, self.ARGS.send_to_shader, nil, self.children.center)
107-
end
108-
end
109-
end
110-
'''
111-
11291
# get_badge_colour()
11392
[[patches]]
11493
[patches.pattern]

0 commit comments

Comments
 (0)