Skip to content

Instantly share code, notes, and snippets.

@morerokk
Created May 30, 2024 13:39
Show Gist options
  • Save morerokk/26e5379679fcf5c3858252eba39f5994 to your computer and use it in GitHub Desktop.
Save morerokk/26e5379679fcf5c3858252eba39f5994 to your computer and use it in GitHub Desktop.
WIP version of the Double Decker deck for Balatro. Steamodded 0.9.8 required. May not work in Steamodded 1.0.0 yet.
--- STEAMODDED HEADER
--- MOD_NAME: Double Decker
--- MOD_ID: DoubleDecker
--- MOD_AUTHOR: [Rokk]
--- MOD_DESCRIPTION: Adds a double-stacked deck to the game.
----------------------------------------------
------------MOD CODE -------------------------
-- Helper function to set a card's back sprite
local function set_card_back_sprite(card, desired_back)
card.params.bypass_back = G.P_CENTERS[desired_back].pos
card.children.back = Sprite(card.T.x, card.T.y, card.T.w, card.T.h, G.ASSET_ATLAS["centers"], card.params.bypass_back)
card.children.back.states.hover = card.states.hover
card.children.back.states.click = card.states.click
card.children.back.states.drag = card.states.drag
card.children.back.states.collide.can = false
card.children.back:set_role({major = card, role_type = 'Glued', draw_major = card})
end
-- Add deck's booster effect variable and apply double card effect
local Back_apply_to_run_orig = Back.apply_to_run
function Back.apply_to_run(arg_56_0)
local result = Back_apply_to_run_orig(arg_56_0)
if arg_56_0.effect.config.extra_booster_selections then
G.GAME.starting_params.extra_booster_selections = arg_56_0.effect.config.extra_booster_selections
end
if arg_56_0.effect.config.double_playing_cards then
G.E_MANAGER:add_event(Event({
func = function()
-- Iterate over the initial deck, and deal an extra red-backed copy into the deck.
local initial_deck_size = #G.playing_cards
for i = initial_deck_size, 1, -1 do
-- Add copy and change its back to red card
-- The game makes copying a card and adding it to the deck A LOT harder than it should be.
-- Increment a global variable that governs deck size, copy the card, change its back sprite, and manually put it in the deck
G.playing_card = initial_deck_size + i
local copied_card = copy_card(G.playing_cards[i], nil, 1, G.playing_card)
set_card_back_sprite(copied_card, 'b_red')
G.deck:emplace(copied_card)
G.playing_cards[G.playing_card] = copied_card
end
return true
end
}))
end
return result
end
-- Apply the deck's "extra booster pick" effect to opened booster packs
local card_open_orig = Card.open
function Card:open()
-- Before calling the original function, add 1 to booster pack choices if the Double Deck is selected
-- After the original function is called, set it back to the original value to prevent extra choices from accumulating infinitely
-- Only apply to boosters and only apply if the player is using the Double Deck
if self.ability.set ~= "Booster" or not G.GAME.starting_params.extra_booster_selections then
return card_open_orig(self)
end
-- Add extra selection
local old_choose = self.config.center.config.choose
self.config.center.config.choose = self.config.center.config.choose or 1
self.config.center.config.choose = math.min(self.config.center.config.choose + G.GAME.starting_params.extra_booster_selections, self.ability.extra)
-- Call original function to open the pack
local result = card_open_orig(self)
-- Restore old selection amount
self.config.center.config.choose = old_choose
return result
end
-- Add deck definition to the game using Steamodded
-- Note: x and y refer to the location of the deck's back texture in the atlas, and this is 0-indexed which is unusual for Lua
local deck_double = SMODS.Deck:new("DoubleDeck", "double", {double_playing_cards = true, extra_booster_selections = 1, discards = 1}, {x = 0, y = 2},
{
name = "Double Decker",
text = {
"Start with {C:attention}104{} cards",
"{C:attention}+1{} discard",
"Choose an extra card",
"in {C:attention}Booster Packs{}"
},
}
)
deck_double:register()
----------------------------------------------
------------MOD CODE END----------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment