[manifest]
version = "1.0.0"
dump_lua = true
priority = 0

[[patches]]
[patches.copy]
target = "main.lua"
position = "append"
sources = ["index.lua"]

[[patches]]
[patches.copy]
target = "main.lua"
position = "append"
sources = ["config_ui.lua"]

# Skipping Cash Out stage
[[patches]]
[patches.pattern]
target = "game.lua"
pattern = '''G.FUNCS.evaluate_round()'''
position = "after"
payload = '''
Handy.insta_cash_out.can_skip = true
'''
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = '''G.FUNCS.cash_out = function(e)'''
position = "after"
payload = '''
if Handy.insta_cash_out.is_skipped and e.config.button then return end
'''
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "game.lua"
pattern = '''G.ACC = math.min((G.ACC or 0) + dt*0.2*self.SETTINGS.GAMESPEED, 16)'''
position = "after"
payload = '''
 elseif Handy.insta_cash_out.is_skipped then G.ACC = 999 
'''
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = '''G.STATE = G.STATES.SHOP'''
position = "after"
payload = '''
Handy.insta_cash_out.is_skipped = false
Handy.insta_cash_out.can_skip = false
'''
match_indent = true
overwrite = false

# Skipping booster
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = '''G.GAME.PACK_INTERRUPT = nil'''
position = "after"
payload = '''
Handy.insta_booster_skip.is_skipped = false
'''
match_indent = true
overwrite = false

# Draw UI
[[patches]]
[patches.pattern]
target = "game.lua"
pattern = '''self.GAME = saveTable and saveTable.GAME or self:init_game_object()'''
position = "after"
payload = '''
Handy.UI.init()
'''
match_indent = true
overwrite = false

# Mouse listeners
[[patches]]
[patches.pattern]
target = "main.lua"
pattern = '''function love.mousepressed(x, y, button, touch)'''
position = "after"
payload = '''
if not touch and Handy.controller.process_mouse(button, false) then return end
'''
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "main.lua"
pattern = '''function love.mousereleased(x, y, button)'''
position = "after"
payload = '''
if Handy.controller.process_mouse(button, true) then return end
'''
match_indent = true
overwrite = false

# Key listeners
[[patches]]
[patches.pattern]
target = "main.lua"
pattern = '''function love.keypressed(key)'''
position = "after"
payload = '''
if Handy.controller.process_key(key, false) then return end
'''
match_indent = true
overwrite = false

[[patches]]
[patches.pattern]
target = "main.lua"
pattern = '''function love.keyreleased(key)'''
position = "after"
payload = '''
if Handy.controller.process_key(key, true) then return end
'''
match_indent = true
overwrite = false

# Handle card click
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''function Card:click()'''
position = "after"
payload = '''
if Handy.controller.process_card_click(self) then return end
'''
match_indent = true
overwrite = false

# Handle card hover
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''function Card:hover()'''
position = "after"
payload = '''
if Handy.controller.process_card_hover(self) then return end
'''
match_indent = true
overwrite = false

# Handle card stop hover
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''function Card:stop_hover()'''
position = "after"
payload = '''
if Handy.last_hovered_card == self then
    Handy.last_hovered_card = nil
    Handy.last_hovered_area = nil
end
'''
match_indent = true
overwrite = false


# Handle skip tag click
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '''local tag_sprite_ui = _tag:generate_UI()'''
position = "after"
payload = '''
local _handy_tag_click_target = _tag.tag_sprite
local _handy_tag_click_ref = _handy_tag_click_target.click
_handy_tag_click_target.click = function(...)
    if Handy.controller.process_tag_click(_tag) then return end
    return _handy_tag_click_ref(...)
end
'''
match_indent = true
overwrite = false


# Apply multiplier to speed
[[patches]]
[patches.pattern]
target = "game.lua"
pattern = '''self.SPEEDFACTOR = self.SPEEDFACTOR + math.max(0, math.abs(G.ACC) - 2)'''
position = "after"
payload = '''
self.SPEEDFACTOR = self.SPEEDFACTOR * Handy.speed_multiplier.get_value() or 1
'''
match_indent = true
overwrite = false

# Show deck preview
[[patches]]
[patches.regex]
target = "game.lua"
pattern = '''G.CONTROLLER.held_buttons.triggerleft'''
position = "after"
payload = '''
 or Handy.show_deck_preview.is_hold
'''
match_indent = true
overwrite = false
times = 2

# Prevent default hand deselecting
[[patches]]
[patches.pattern]
target = "engine/controller.lua"
pattern = '''if (G.play and #G.play.cards > 0) or'''
position = "after"
payload = '''
Handy.deselect_hand.should_prevent() or
'''
match_indent = true
overwrite = false

# Add ability to override chosen tab in create_tabs
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '''if v.chosen then args.current = {k = k, v = v} end'''
position = "before"
payload = '''
if Handy.override_create_tabs_chosen then v.chosen = k == Handy.override_create_tabs_chosen
elseif Handy.override_create_tabs_chosen_by_label then v.chosen = v.label == Handy.override_create_tabs_chosen_by_label end
'''
match_indent = true
overwrite = false
