Skip to content

Commit 72b8920

Browse files
authored
Custom StatusText in update_hand_text (#1172)
1 parent fb09d91 commit 72b8920

File tree

4 files changed

+64
-7
lines changed

4 files changed

+64
-7
lines changed

lovely/poker_hand_text.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[manifest]
2+
version = "1.0.0"
3+
dump_lua = true
4+
priority = -5
5+
6+
# statustext parameter in level_up_hand
7+
[[patches]]
8+
[patches.pattern]
9+
target = 'functions/common_events.lua'
10+
pattern = 'function level_up_hand(card, hand, instant, amount)'
11+
position = 'at'
12+
match_indent = true
13+
payload = 'function level_up_hand(card, hand, instant, amount, statustext)'
14+
15+
# Allow custom StatusText values in update_hand_text
16+
[[patches]]
17+
[patches.regex]
18+
target = 'functions/common_events.lua'
19+
position = 'at'
20+
line_prepend = '$indent'
21+
pattern = '''(?<indent>[\t ]*)if vals\.StatusText[A-z0-9\n\t .~=()'\-+,<;>:{}]+config\.align\n[\t ]+\}\)\n[\t ]+end'''
22+
payload = '''
23+
if vals.StatusText then
24+
local StatusText = {
25+
text = delta,
26+
scale = 0.8,
27+
hold = 1,
28+
cover = G.hand_text_area[name].parent,
29+
cover_colour = mix_colours(parameter.colour, col, 0.1),
30+
emboss = 0.05,
31+
align = 'cm',
32+
cover_align = G.hand_text_area[name].parent.config.align
33+
}
34+
if type(vals.StatusText) == 'string' then StatusText.text = vals.StatusText
35+
elseif type(vals.StatusText) == 'table' then
36+
for k,v in pairs(vals.StatusText) do
37+
if v ~= nil then StatusText[k] = v end
38+
end
39+
end
40+
attention_text(StatusText)
41+
end
42+
'''

lovely/scoring_calculation.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ SMODS.upgrade_poker_hands({
238238
end,
239239
level_up = amount,
240240
from = card,
241-
instant = instant
241+
instant = instant,
242+
StatusText = statustext
242243
})
243244
--[[
244245
'''

lsp_def/utils.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,13 @@ function SMODS.is_active_blind(key, ignore_disabled) end
763763
---@return boolean
764764
function SMODS.challenge_is_unlocked(challenge, k) end
765765

766-
---@param args table|{hands?: table, parameters?: table, level_up?: number|boolean, func?: fun(base: number, hand: string, param: string), instant?: boolean}
766+
---@param args table|{hands?: table, parameters?: table, level_up?: number|boolean, func?: fun(base: number, hand: string, param: string), instant?: boolean, StatusText?: boolean|string|table|fun(hand: string, parameter: string)}
767767
--- This functions handles upgrading poker hands in more complex ways. You can define
768768
--- a custom `func` to modify the values in specific ways. `hands` and `parameters` can
769769
--- be limited to specific ones, or default to using all of `G.GAME.hands` and `SMODS.Scoring_Parameters`.
770770
--- Use `level_up` to control whether the level of the hand is upgraded.
771-
function SMODS.upgrade_poker_hands(args) end
771+
--- Use `StatusText` to control the text that appears when a parameter is upgraded, it can be:
772+
--- a string, which changes the displayed text, a boolean, which disables StatusText when set to `false`,
773+
--- a table, which defines the `attention_text` function settings, or a function that takes the key of
774+
--- the hand and scoring parameter being upgraded as arguments and returns a boolean, string or table
775+
function SMODS.upgrade_poker_hands(args) end

src/utils.lua

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,14 +1227,14 @@ G.FUNCS.update_suit_colours = function(suit, skin, palette_num)
12271227
G.C.SUITS[suit] = new_colour_proto
12281228
end
12291229

1230-
SMODS.smart_level_up_hand = function(card, hand, instant, amount)
1230+
SMODS.smart_level_up_hand = function(card, hand, instant, amount, statustext)
12311231
-- Cases:
12321232
-- Level ups in context.before on the played hand
12331233
-- -> direct level_up_hand(), keep displaying
12341234
-- Level ups in context.before on another hand AND any level up during scoring
12351235
-- -> restore the current chips/mult
12361236
-- Level ups outside anything -> always update to empty chips/mult
1237-
level_up_hand(card, hand, instant, (type(amount) == 'number' or type(amount) == 'table') and amount or 1)
1237+
level_up_hand(card, hand, instant, (type(amount) == 'number' or type(amount) == 'table') and amount or 1, statustext)
12381238
end
12391239

12401240
-- This function handles the calculation of each effect returned to evaluate play.
@@ -3295,6 +3295,7 @@ function SMODS.upgrade_poker_hands(args)
32953295
-- args.level_up
32963296
-- args.instant
32973297
-- args.from
3298+
-- args.StatusText
32983299

32993300
local function get_keys(t)
33003301
local keys = {}
@@ -3311,7 +3312,7 @@ function SMODS.upgrade_poker_hands(args)
33113312

33123313
if not args.func then
33133314
for _, hand in ipairs(args.hands) do
3314-
level_up_hand(args.from, hand, instant, args.level_up or 1)
3315+
level_up_hand(args.from, hand, instant, args.level_up or 1, args.StatusText)
33153316
end
33163317
return
33173318
end
@@ -3343,12 +3344,21 @@ function SMODS.upgrade_poker_hands(args)
33433344
if G.GAME.hands[hand][parameter] then
33443345
G.GAME.hands[hand][parameter] = args.func(G.GAME.hands[hand][parameter], hand, parameter)
33453346
if not instant then
3347+
local StatusText = true
3348+
if args.StatusText ~= nil then
3349+
if type(args.StatusText) == 'function' then
3350+
local NewStatusText = args.StatusText(hand, parameter)
3351+
if NewStatusText ~= nil then StatusText = NewStatusText end
3352+
else
3353+
StatusText = args.StatusText
3354+
end
3355+
end
33463356
G.E_MANAGER:add_event(Event({trigger = 'after', delay = i == 1 and 0.2 or 0.9, func = function()
33473357
play_sound('tarot1')
33483358
if args.from then args.from:juice_up(0.8, 0.5) end
33493359
G.TAROT_INTERRUPT_PULSE = true
33503360
return true end }))
3351-
update_hand_text({delay = 0}, {[parameter] = G.GAME.hands[hand][parameter], StatusText = true})
3361+
update_hand_text({delay = 0}, {[parameter] = G.GAME.hands[hand][parameter], StatusText = StatusText})
33523362
end
33533363
end
33543364
end

0 commit comments

Comments
 (0)