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

# Turn Jimbo into Jolly Joker
[[patches]]
[patches.pattern]
target = "card_character.lua"
pattern = 'self.children.card.states.visible = false'
position = "before"
payload = "self.children.card:set_ability(G.P_CENTERS.j_jolly)"
match_indent = true

[[patches]]
[patches.pattern]
target = "card_character.lua"
pattern = 'colours = {G.C.RED, G.C.BLUE, G.C.ORANGE},'
position = "at"
payload = 'colours = {G.C.CRY_EXOTIC, G.C.BLUE, G.C.CRY_JOLLY},'
match_indent = true

# Make profiles all start with a prefix
[[patches]]
[patches.pattern]
target = "game.lua"
pattern = 'self:load_profile(G.SETTINGS.profile or 1)'
position = "before"
payload = '''Cryptid.profile_prefix = Jen and "J" or "M"
if type(G.SETTINGS.profile) ~= "string" or G.SETTINGS.profile:sub(1, #Cryptid.profile_prefix) ~= Cryptid.profile_prefix then
    G.SETTINGS.profile = Cryptid.profile_prefix .. "1"
end
for i = 1, 3 do
    G.PROFILES[Cryptid.profile_prefix .. i] = {}
end'''
match_indent = true

# Remove the builtin "P" prefix
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = 'profile_data.name = profile_data.name or ("P".._profile)'
position = "at"
payload = 'profile_data.name = profile_data.name or (_profile)'
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = 'G.PROFILES[G.SETTINGS.profile].name = "P"..G.SETTINGS.profile'
position = "at"
payload = 'G.PROFILES[G.SETTINGS.profile].name = G.SETTINGS.profile'
match_indent = true

# Pre-load all profiles in selection menu
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = 'for i = 1, 3 do'
position = "after"
payload = 'i = Cryptid.profile_prefix .. i'
match_indent = true

# Gameset sprite in profile screen
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '{n=G.UIT.C, config={align = "cl", minw = rwidth}, nodes={{n=G.UIT.T, config={text = tostring(profile_data.career_stats.c_wins),colour = G.C.RED, shadow = true, scale = 1*scale}}}}'
position = "after"
payload = ',{n=G.UIT.C, config={align = "cl", minw = rwidth}, nodes={{n=G.UIT.O, config={object = Cryptid.gameset_sprite(1, _profile)}}}}'
match_indent = true

# Gameset sprite in deck select
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '{n=G.UIT.C, config={align = "cm", minw = 2.5}, nodes={}}'
position = "at"
payload = '{n=G.UIT.C, config={align = "cm", minw = 0.2}, nodes={}},{n=G.UIT.C, config={align = "cl", minw = rwidth}, nodes={{n=G.UIT.O, config={object = Cryptid.gameset_sprite()}}}}'
match_indent = true

# Gameset sprite in win screen
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = '{n=G.UIT.R, config={align = "cm", minh = 0.4, minw = 0.1}, nodes={}},'
position = "at"
payload = '{n=G.UIT.R, config={align = "cm", minh = 0.1, minw = 0.1}, nodes={}},'
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = 'not show_win_cta and {n=G.UIT.R, config={align = "cm", minh = 0.2, minw = 0.1}, nodes={}} or nil,'
position = "at"
payload = 'not show_win_cta and {n=G.UIT.R, config={align = "cm", minh = 0.1, minw = 0.1}, nodes={}} or nil,'
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = "not show_win_cta and UIBox_button({button = 'go_to_menu', label = {localize('b_main_menu')}, minw = 2.5, maxw = 2.5, minh = 1, focus_args = {nav = 'wide'}}) or nil,"
position = "after"
payload = '{n=G.UIT.R, config={align = "cm", minw = rwidth}, nodes={{n=G.UIT.O, config={object = Cryptid.gameset_sprite()}}}},'
match_indent = true

# Gameset sprite in lose screen
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = "show_lose_cta and"
position = "before"
payload = '{n=G.UIT.R, config={align = "cm"}, nodes={{n=G.UIT.C, config={align = "cm", minw = rwidth}, nodes={{n=G.UIT.O, config={object = Cryptid.gameset_sprite()}}}},'
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = "{n=G.UIT.T, config={text = localize('b_main_menu'), scale = 0.5, colour = G.C.UI.TEXT_LIGHT}}"
position = "after"
payload = '}}'
match_indent = true

[[patches]]
[patches.regex]
target = "functions/UI_definitions.lua"
pattern = '''\{n=G\.UIT\.R, config=\{align = "cm", padding = 0\.1\}, nodes=\{\s+\{n=G\.UIT\.R, config=\{id = 'from_game_over','''
position = "at"
payload = '''{n=G.UIT.C, config={align = "cm", padding = 0.1}, nodes={
{n=G.UIT.R, config={id = 'from_game_over','''

# Disabled UI
# Show disabled tooltip
[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "local info_queue = {}"
position = "after"
payload = '''if _c.cry_disabled or (_c.force_gameset and _c.force_gameset == 'disabled') then
    if _c.cry_disabled then
        if _c.cry_disabled.type == "card_dependency" then
            local name = Cryptid.get_center(_c.cry_disabled.key) and localize{type = 'name_text', set = Cryptid.get_center(_c.cry_disabled.key).set, key = _c.cry_disabled.key} or _c.cry_disabled.key
            info_queue[#info_queue+1] = {key = 'disabled_card_dependency', set = 'Other', specific_vars = {name}}
        elseif _c.cry_disabled.type == "mod_dependency" then
            local name = Cryptid.cross_mod_names[_c.cry_disabled.key] or _c.cry_disabled.key
            info_queue[#info_queue+1] = {key = 'disabled_mod_dependency', set = 'Other', specific_vars = {name}}
        elseif _c.cry_disabled.type == "mod_conflict" then
            local name = SMODS.Mods[_c.cry_disabled.key].name
            info_queue[#info_queue+1] = {key = 'disabled_mod_conflict', set = 'Other', specific_vars = {name}}
        else
            if not (_c.force_gameset and _c.force_gameset ~= 'disabled') then
                info_queue[#info_queue+1] = {key = 'disabled', set = 'Other'}
            end
        end
    else
        info_queue[#info_queue+1] = {key = 'disabled', set = 'Other'}
    end
end'''
match_indent = true

# replace rarity badge with gameset
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = "card_type = (debuffed and AUT.card_type ~= 'Enhanced') and localize('k_debuffed') or card_type"
position = "after"
payload = '''
if AUT.card_type == "Back" then
    card_type = localize('b_deck')
end
if AUT.card_type == "Tag" then
    card_type = localize('b_tag')
end
if AUT.card_type == "Blind" then
    card_type = localize('b_blind')
end
if AUT.card_type == "Content Set" then
    card_type = localize('k_content_set')
end
if card.gameset_select then
    card_type = localize('cry_gameset_'..card.config.center.force_gameset)
    if card_type == "ERROR" then
        card_type = localize('cry_gameset_custom')
    end
end
if not card.gameset_select and card.config.center and card.config.center.cry_disabled then
    card_type = localize('cry_gameset_disabled')
end
'''
match_indent = true

# Descriptions for Backs and Blinds in gameset UI
[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "elseif _c.set == 'Tag' then"
position = "before"
payload = "elseif _c.set == 'Back' or _c.set == 'Blind' then localize{type = 'descriptions', key = _c.key, set = _c.set, nodes = desc_nodes, vars = specific_vars or {}}"
match_indent = true