SMODS.Sound({key = "e_jumbo", path = "e_jumbo.ogg"})
SMODS.Shader({key = "polygloss", path = "polygloss.fs"})
SMODS.Sound({key = "e_polygloss", path = "e_polygloss.ogg"})

local function resize(card, mod, force_save)
    if force_save or not card.origsize then
        card.origsize = {w = card.T.w, h = card.T.h}
    end

    card:hard_set_T(card.T.x, card.T.y, card.T.w * mod, card.T.h * mod)
    remove_all(card.children)
    card.children = {}
    card.children.shadow = Moveable(0, 0, 0, 0)
    card:set_sprites(card.config.center, card.base.id and card.config.card)

    if card.area and
        ((G.shop_jokers and card.area == G.shop_jokers) or
        (G.shop_booster and card.area == G.shop_booster) or
        (G.shop_vouchers and card.area == G.shop_vouchers)) then
        create_shop_card_ui(card)
    end
end

SMODS.Edition({
    key = "polygloss",
    loc_txt = {
        name = "Polygloss",
        label = "Polygloss",
        text = {
            "{C:chips}+#1#{}, {X:chips,C:white}x#2#{} & {X:chips,C:dark_edition}^#3#{} Chips",
            "{C:mult}+#4#{}, {X:mult,C:white}x#5#{} & {X:mult,C:dark_edition}^#6#{} Mult",
            "Generates {C:money}+$#7#",
        }
    },
    config = {chips = 1, mult = 1, x_chips = 1.1, x_mult = 1.1, e_chips = 1.01, e_mult = 1.01, p_dollars = 1},
    sound = {
        sound = "jane_e_polygloss",
        per = 1.2,
        vol = 0.4
    },
    weight = 8,
    extra_cost = 2,
    in_shop = true,
    shader = "polygloss",
    apply_to_float = false,
    loc_vars = function(self)
        return {vars = {
            self.config.chips,
            self.config.x_chips,
            self.config.e_chips,
            self.config.mult,
            self.config.x_mult,
            self.config.e_mult,
            self.config.p_dollars
        }}
    end,
    calculate = function(_, card, context)
        if context.pre_joker then
            return {
                mult = card.edition.mult,
                chips = card.edition.chips,
            }
        elseif context.post_joker then
            return {
                e_mult = card.edition.e_mult,
                x_mult = card.edition.x_mult,
                e_chips = card.edition.e_chips,
                x_chips = card.edition.x_chips,
                p_dollars = card.edition.p_dollars,
            }
        elseif context.main_scoring and context.cardarea == G.play then
            return {
                mult = card.edition.mult,
                chips = card.edition.chips,
                e_mult = card.edition.e_mult,
                x_mult = card.edition.x_mult,
                e_chips = card.edition.e_chips,
                x_chips = card.edition.x_chips,
                p_dollars = card.edition.p_dollars,
            }
        end
    end,
})

local jumbo_modifier = Cryptid and 100 or 2

SMODS.Edition({
    key = "jumbo",
    loc_txt = {
        name = "Jumbo",
        label = "Jumbo",
        text = {
            "All card values are",
            "{C:attention}multiplied{} by {C:attention}up to " .. jumbo_modifier,
            "{C:inactive}(If possible)",
            "{C:inactive,E:1,s:0.7}Whoa, it's huge!!{}"
        }
    },
    on_apply = function(card)
        G.E_MANAGER:add_event(Event({
            blocking = false,
            blockable = false,
            func = function()
                resize(card, Jane.config.wee_sizemod)
                return true
            end
        }))

        local obj = card:gc()

        if obj.set == "Booster" or obj.jumbo_mod then
            jumbo_modifier = obj.jumbo_mod or 10
        end

        if card.added_to_deck then
            card:remove_from_deck()
        end

        Jane.misprintize(card, {min = jumbo_modifier, max = jumbo_modifier}, nil, true)

        if card.added_to_deck then
            card:add_to_deck()
        end
    end,
    on_remove = function(card)
        G.E_MANAGER:add_event(Event({
            blocking = false,
            blockable = false,
            func = function()
                resize(card, 1 / Jane.config.wee_sizemod)
                return true
            end
        }))

        local was_added = card.added_to_deck

        if was_added then
            card:remove_from_deck()
        end

        Jane.misprintize(card, {min = 1 / jumbo_modifier, max = 1 / jumbo_modifier}, nil, true)

        if was_added then
            card:add_to_deck()
        end
    end,
    config = {twos_scored = 0},
    sound = {
        sound = "jane_e_jumbo",
        per = 1,
        vol = 0.5
    },
    weight = 0.8,
    in_shop = true,
    shader = false,
    extra_cost = 12,
    apply_to_float = false,
    get_weight = function(self)
        return G.GAME.edition_rate * self.weight
    end,
})
