Skip to content

Commit 7bee4bc

Browse files
authored
Address all unnecessary update_hand_text calls (#1111)
1 parent 59550b5 commit 7bee4bc

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

lovely/scoring_calculation.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,33 @@ payload = '''
241241
]]
242242
'''
243243

244+
# Remove update_hand_text duplicates
245+
[[patches]]
246+
[patches.pattern]
247+
target = 'card.lua'
248+
match_indent = true
249+
position = 'at'
250+
pattern = '''
251+
update_hand_text({sound = 'button', volume = 0.7, pitch = 0.8, delay = 0.3}, {handname=localize(self.ability.consumeable.hand_type, 'poker_hands'),chips = G.GAME.hands[self.ability.consumeable.hand_type].chips, mult = G.GAME.hands[self.ability.consumeable.hand_type].mult, level=G.GAME.hands[self.ability.consumeable.hand_type].level})
252+
level_up_hand(used_tarot, self.ability.consumeable.hand_type)
253+
update_hand_text({sound = 'button', volume = 0.7, pitch = 1.1, delay = 0}, {mult = 0, chips = 0, handname = '', level = ''})
254+
'''
255+
payload = '''
256+
level_up_hand(used_tarot, self.ability.consumeable.hand_type)
257+
'''
258+
[[patches]]
259+
[patches.pattern]
260+
target = 'card.lua'
261+
match_indent = true
262+
position = 'at'
263+
pattern = '''
264+
update_hand_text({sound = 'button', volume = 0.7, pitch = 0.8, delay = 0.3}, {handname=localize(text, 'poker_hands'),chips = G.GAME.hands[text].chips, mult = G.GAME.hands[text].mult, level=G.GAME.hands[text].level})
265+
level_up_hand(context.blueprint_card or self, text, nil, 1)
266+
update_hand_text({sound = 'button', volume = 0.7, pitch = 1.1, delay = 0}, {mult = 0, chips = 0, handname = '', level = ''})
267+
'''
268+
payload = '''
269+
level_up_hand(context.blueprint_card or self, text, nil, 1)
270+
'''
244271

245272
# Face down hands
246273
[[patches]]

lsp_def/utils.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ SMODS.displaying_scoring = nil
243243
---@param instant boolean
244244
---@param amount? number
245245
-- Like level_up_hand(), but takes care of calling update_hand_text().
246-
-- Tries to avoid calling update_hand_text() if unnecessary.
246+
-- Tries to avoid calling update_hand_text() if unnecessary.\
247+
-- Smart effect is already handled inside `SMODS.upgrade_poker_hands`.
248+
-- Downgrading this to plain wrapper for backwards compat.
247249
function SMODS.smart_level_up_hand(card, hand, instant, amount) end
248250

249251
---@param _type CardAreaTypes|string

src/utils.lua

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,22 +1217,7 @@ SMODS.smart_level_up_hand = function(card, hand, instant, amount)
12171217
-- Level ups in context.before on another hand AND any level up during scoring
12181218
-- -> restore the current chips/mult
12191219
-- Level ups outside anything -> always update to empty chips/mult
1220-
local vals_after_level
1221-
if SMODS.displaying_scoring and not (SMODS.displayed_hand == hand) then
1222-
vals_after_level = copy_table(G.GAME.current_round.current_hand)
1223-
local text,disp_text,_,_,_ = G.FUNCS.get_poker_hand_info(G.play.cards)
1224-
vals_after_level.handname = disp_text or ''
1225-
vals_after_level.level = (G.GAME.hands[text] or {}).level or ''
1226-
vals_after_level.chips = number_format(hand_chips) or 0
1227-
vals_after_level.mult = number_format(mult) or 0
1228-
end
1229-
if not (instant or SMODS.displayed_hand == hand) then
1230-
update_hand_text({sound = 'button', volume = 0.7, pitch = 0.8, delay = 0.3}, {handname=localize(hand, 'poker_hands'),chips = G.GAME.hands[hand].chips, mult = G.GAME.hands[hand].mult, level=G.GAME.hands[hand].level})
1231-
end
12321220
level_up_hand(card, hand, instant, (type(amount) == 'number' or type(amount) == 'table') and amount or 1)
1233-
if not (instant or SMODS.displayed_hand == hand) then
1234-
update_hand_text({sound = 'button', volume = 0.7, pitch = 1.1, delay = 0}, vals_after_level or {mult = 0, chips = 0, handname = '', level = ''})
1235-
end
12361221
end
12371222

12381223
-- This function handles the calculation of each effect returned to evaluate play.
@@ -3271,6 +3256,7 @@ function SMODS.upgrade_poker_hands(args)
32713256
-- args.parameters
32723257
-- args.func
32733258
-- args.level_up
3259+
-- args.instant
32743260
-- args.from
32753261

32763262
local function get_keys(t)
@@ -3316,10 +3302,10 @@ function SMODS.upgrade_poker_hands(args)
33163302
update_hand_text({nopulse = nil, delay = 0}, {[name] = p.current})
33173303
end
33183304
end
3319-
for _, parameter in ipairs(args.parameters) do
3305+
for i, parameter in ipairs(args.parameters) do
33203306
G.GAME.hands[hand][parameter] = args.func(G.GAME.hands[hand][parameter], hand, parameter)
33213307
if not instant then
3322-
G.E_MANAGER:add_event(Event({trigger = 'after', delay = 0.9, func = function()
3308+
G.E_MANAGER:add_event(Event({trigger = 'after', delay = i == 1 and 0.2 or 0.9, func = function()
33233309
play_sound('tarot1')
33243310
if args.from then args.from:juice_up(0.8, 0.5) end
33253311
G.TAROT_INTERRUPT_PULSE = true

0 commit comments

Comments
 (0)