-
Notifications
You must be signed in to change notification settings - Fork 13
Examples
This page will have some examples of Sleeves and how to use them in other mods. You can also check out the source code to see how the 15 base sleeves are implemented, or other mods that have implemented Sleeves, such as SDM_0's implementation.
Reminder to use
if CardSleeves then
-- sleeve code
endA Sleeve with no effects.
CardSleeves.Sleeve {
key = "example",
atlas = "sleeve_atlas", -- you will need to create an atlas yourself
pos = { x = 0, y = 0 },
loc_txt = {
name = "Example Sleeve",
text = { "Does nothing" }
}
}If you'd like to use CardSleeve's default sprites as placeholders, add prefix_config = {atlas=false} and point the atlas to "casl_sleeve_atlas".
CardSleeves.Sleeve {
prefix_config = {atlas=false},
atlas = "casl_sleeve_atlas",
pos = { x = 1, y = 3 },
...
}Assuming the mod name is test:
CardSleeves.Sleeve {
key = "example",
...
}return {
descriptions = {
Sleeve = {
sleeve_test_example = { -- "sleeve_" + mod prefix + "_" + sleeve original key
name = "Example Sleeve",
text = { "Does nothing" }
}
}
}
}This sleeve actually has an effect and description.
CardSleeves.Sleeve {
key = "example",
atlas = "sleeve_atlas",
pos = { x = 1, y = 0 },
config = { hands = 1 },
loc_txt = {
name = "Example Sleeve",
text = { "{C:blue}+#1#{} hand", "every round" }
},
loc_vars = function(self)
return { vars = { self.config.hands } }
end,
}This Sleeve normally gives +1 hand, but when combined with the blue deck gives +2 discards instead.
This will require a separate localization file! Again assuming the mod name is test.
CardSleeves.Sleeve {
key = "example",
...,
loc_vars = function(self)
local key, vars
if self.get_current_deck_key() == "b_blue" then
key = self.key .. "_alt"
self.config = { discards = 2 }
vars = { self.config.discards }
else
key = self.key
self.config = { hands = 1 }
vars = { self.config.hands }
end
return { key = key, vars = vars }
end,
}return {
descriptions = {
Sleeve = {
sleeve_test_example = {
name = "Purple Sleeve",
text = { "{C:blue}+#1#{} hand", "every round" }
},
sleeve_test_example_alt = {
name = "Purple Sleeve",
text = { "{C:red}+#1#{} discards", "every round" }
},
}
}
}If you create a Sleeve with a custom :apply(sleeve) method, the original no longer gets called, so call it if you need to.
CardSleeves.Sleeve {
...,
config = { joker_slot = 2, win_ante = 10 },
apply = function(self, sleeve)
-- base apply does not support setting the win_ante, so we have to do it ourselves
G.GAME.win_ante = sleeve.config.win_ante
-- pick one of the 2 next options to change joker slots
-- option A: call base apply to apply the +2 joker slots:
CardSleeves.Sleeve.apply(self, sleeve)
-- option B: apply the +2 joker slots yourself
G.GAME.starting_params.joker_slots = G.GAME.starting_params.joker_slots + sleeve.config.joker_slot
end
}The Sleeve calculate method supports all the standard deck contexts, and some custom CardSleeves contexts. Sleeves do not save their config/ability when exiting the run, so don't try to scale a sleeve property by saving it to the config/ability table.
This Sleeve retriggers every scored card once.
CardSleeves.Sleeve {
key = "example",
...,
config = { repetitions = 1 },
calculate = function(self, sleeve, context)
if context.cardarea == G.play and context.repetition and not context.repetition_only then
return {
repetitions = sleeve.config.repetitions,
message = localize('k_again_ex'),
message_card = context.other_card
}
end
end
}Sleeves can be locked (like any other center) so the player cannot use them until unlocked. Discovering Sleeves does not exist, and they are always "discovered" by default. Using unlock all or the in-game CardSleeves config option allows the player to bypass all unlock conditions.
A basic locked Sleeve using unlock_condition. This Sleeve unlocks after beating the green deck on gold stake.
CardSleeves.Sleeve {
...,
unlocked = false,
unlock_condition = {deck = "b_green", stake = "stake_gold"},
}A custom locked Sleeve by re-implementing check_for_unlock and locked_loc_vars. Make sure to define an entry in the Sleeve localization set.
CardSleeves.Sleeve {
...,
unlocked = false,
unlock_condition = { type = "ante_up", ante = 12 }
check_for_unlock = function(self, args)
-- see function check_for_unlock(args) at functions/common_events.lua:1163 in the base-game for more unlock types
if args.type == self.unlock_condition.type and args.ante >= self.unlock_condition.ante then
return true
end
end,
locked_loc_vars = function(self, info_queue, card)
-- very similar to loc_vars
local key = "sleeve_locked_ante"
--[[ Localization key:
-- Define this key "globally" under the `Sleeve` set, not as sub-entry of your specific sleeve.
-- For an example, look at the `sleeve_locked` entry as used by CardSleeves in the localization files. Do NOT overwrite the `sleeve_locked` key.
--]]
local vars = { self.unlock_condition.ante }
return { key = key, vars = vars }
end
}If a deck has an "independent" apply or calculate, you might be able to simply reference it while creating the Sleeve for it instead of having to copy-paste the effect. Obviously does not work if you would like your sleeve to have a unique deck+sleeve effect. Assuming mod name is test.
local example_back = SMODS.Back {
key = "example",
pos = {x = 0, y = 4},
loc_txt = {
name = "Example Deck",
text = { "Adds loads of cards at every final scoring step" }
},
calculate = function(self, back, context)
if context.context == "final_scoring_step" then
for k, v in pairs(G.P_CARDS) do
local s, r = string.sub(k, 1, 1), string.sub(k, 3, 3)
card_from_control({s=s, r=r}) -- add to deck function in base balatro
end
end
end
}
CardSleeves.Sleeve {
...,
-- The example deck's calculate does not use config values or similar, and can just be referenced here
calculate = example_back.calculate -- or SMODS.Back.obj_table["b_test_example"].calculate
}In case you'd like to modify the effects of one of the default sleeves.
local red_sleeve = CardSleeves.Sleeve:get_obj("sleeve_casl_red")
red_sleeve.config.discards = 10Some sleeves reset their own config constantly depending on the selected deck. You will need to hook into loc_vars to change this behavior. You might also need to change the description (modify the returned key and create a localization for it) depending on the amount of changes you make.
local zodiac_sleeve = CardSleeves.Sleeve:get_obj("sleeve_casl_zodiac")
-- doesn't work!
zodiac_sleeve.config = { vouchers = {'v_tarot_merchant', 'v_planet_merchant', 'v_magic_trick' } }
-- we will need to hook loc_vars
local zodiac_sleeve_loc_vars_ref = zodiac_sleeve.loc_vars
zodiac_sleeve.loc_vars = function(self)
if self.get_current_deck_key() == "b_zodiac" then
return zodiac_sleeve_loc_vars_ref(self)
else
self.config = { vouchers = {'v_tarot_merchant', 'v_planet_merchant', 'v_magic_trick' } }
local key, vars = self.key, {}
for _, voucher in pairs(self.config.vouchers) do
vars[#vars+1] = localize{type = 'name_text', key = voucher, set = 'Voucher'}
end
return { key = key, vars = vars}
end
end