[manifest]
version = "1.0.0"
dump_lua = true
priority = -10

# Add starting params
[[patches]]
[patches.pattern]
target = 'functions/misc_functions.lua'
match_indent = true
position = 'before'
pattern = '''
consumable_slots = 2,
'''
payload = '''
play_limit = 5,
discard_limit = 5,
no_limit = '',
'''
# Reset visual indicators
[[patches]]
[patches.pattern]
target = 'game.lua'
match_indent = true
position = 'after'
pattern = '''
self.GAME = saveTable and saveTable.GAME or self:init_game_object()
'''
payload = '''
SMODS.update_hand_limit_text(true, true)
'''


# Change hand limit
[[patches]]
[patches.pattern]
target = 'functions/button_callbacks.lua'
match_indent = true
position = 'at'
pattern = '''
if #G.hand.highlighted <= 0 or G.GAME.blind.block_play or #G.hand.highlighted > 5 then 
'''
payload = '''
if #G.hand.highlighted <= 0 or G.GAME.blind.block_play or #G.hand.highlighted > math.max(G.GAME.starting_params.play_limit, 1) then 
'''

# Change discard limit
[[patches]]
[patches.pattern]
target = 'functions/button_callbacks.lua'
match_indent = true
position = 'at'
pattern = '''
if G.GAME.current_round.discards_left <= 0 or #G.hand.highlighted <= 0 then 
'''
payload = '''
if G.GAME.current_round.discards_left <= 0 or #G.hand.highlighted <= 0 or #G.hand.highlighted > math.max(G.GAME.starting_params.discard_limit, 0) then 
'''

# Add play limit indicator to UI
[[patches]]
[patches.pattern]
target = 'functions/UI_definitions.lua'
match_indent = true
position = 'after'
pattern = '''
{n=G.UIT.R, config={align = "bcm", padding = 0}, nodes={
    {n=G.UIT.T, config={text = localize('b_play_hand'), scale = text_scale, colour = G.C.UI.TEXT_LIGHT, focus_args = {button = 'x', orientation = 'bm'}, func = 'set_button_pip'}}
}},
'''
payload = '''
{n=G.UIT.R, config={align = "bcm", padding = 0}, nodes = {
    {n=G.UIT.T, config={ref_table = SMODS.hand_limit_strings, ref_value = 'play', scale = text_scale * 0.65, colour = G.C.UI.TEXT_LIGHT}}
}},
'''
# Add discard limit indicator to UI
[[patches]]
[patches.pattern]
target = 'functions/UI_definitions.lua'
match_indent = true
position = 'at'
pattern = '''
{n=G.UIT.R, config={align = "cm", padding = 0}, nodes={
    {n=G.UIT.T, config={text = localize('b_discard'), scale = text_scale, colour = G.C.UI.TEXT_LIGHT, focus_args = {button = 'y', orientation = 'bm'}, func = 'set_button_pip'}}
}}'''
payload = '''
{n=G.UIT.R, config={align = "cm", padding = 0}, nodes={
    {n=G.UIT.T, config={text = localize('b_discard'), scale = text_scale, colour = G.C.UI.TEXT_LIGHT, focus_args = {button = 'y', orientation = 'bm'}, func = 'set_button_pip'}}
}},
{n=G.UIT.R, config={align = "cm", padding = 0}, nodes={
    {n=G.UIT.T, config={ref_table = SMODS.hand_limit_strings, ref_value = 'discard', scale = text_scale * 0.65, colour = G.C.UI.TEXT_LIGHT}}
}},
'''
