-
Notifications
You must be signed in to change notification settings - Fork 192
Utility
Casimir Eisenach edited this page Dec 14, 2024
·
33 revisions
Steamodded provides utility functions that extend or replace vanilla functionality or provide other useful tools you may need when making your mod. This page contains information on these functions. Check out src/utils.lua if you'd like to learn more about a function's implementation.
-
inspect(table) -> string- Given an input table, outputs a shallow mapping of keys to values as a string. Gives no further information on subtables.
-
inspectDepth(table) -> string- Given an input table, recursively creates a string representation up to a depth of 5.
-
inspectFunction(func) -> string- Given an input function, outputs details on its name, source, line of definition and number of upvalues.
-
serialize(t, indent) -> string- Given an input table, creates a string containing Lua code that evaluates to the serializable part of
t. Information may be lost, and circular references are not resolved.
- Given an input table, creates a string containing Lua code that evaluates to the serializable part of
-
round_number(num_precision) -> number- Rounds the input number to a given amount of decimal places.
-
format_ui_value(value) -> string- Stringifies the input if it is not a number. Otherwise return the number as it should be displayed in the UI (e.g. scientific notation).
-
SMODS.poll_rarity(_pool_key, _rand_key) -> string|number- Generates a random rarity for the given pool (the only vanilla pool that supports rarities is
'Joker'). If_rand_keyis present, use it as a seed.
- Generates a random rarity for the given pool (the only vanilla pool that supports rarities is
-
SMODS.poll_seal(args) -> string?- Checks if a seal should be generated, and generates one according to the specified arguments if so. The following arguments are supported:
-
key- Randomness seed for the check whether to generate a seal, defaults to'stdseal'. -
mod- Multiplier to the base rate at which seals appear. -
guaranteed- If this istrue, always generate a seal. -
options- A table of possible seals to generate. Defaults to all available seals. -
type_key- Randomness seed for the roll which seal to generate.
-
SMODS.poll_enhancement(args)- Checks if an enhancement should be generated, and generates one according to the specified arguments if so. The following arguments are supported:
-
key- Randomness seed for the check whether to generate an enhancement, defaults to'std_enhance'. -
mod- Multiplier to the base rate at which enhancements appear. -
guaranteed- If this istrue, always generate an enhancement. -
options- A table of possible enhancements to generate. Defaults to all available enhancements. -
type_key- Randomness seed for the roll which enhancement to generate.
These functions facilitate specific tasks that many mods may use but may be harder to achieve when implemented individually. Some replace base game functions to create a more usable interface.
-
SMODS.juice_up_blind()- Plays a 'juice up' animation on the Blind chip.
-
SMODS.eval_this(card, effects)- Given a
Cardobject and a table that could be returned from acalculatefunction, evaluates the specified effects on this card while allowing thecalculatefunction to continue on. You'll need to use this if your joker shows multiple consecutive messages in the main calculation phase. - Supported keys in
effectsincludemult_mod, chip_mod, Xmult_mod, message, but you can extend the function to include your own effects.
- Given a
-
SMODS.change_base(card, rank, suit) -> bool- Given a
Cardrepresenting a playing card, changes the card's suit, rank, or both. Either argument may be omitted to retain the original suit or rank. - This function returns
falseif it fails. It is recommended to always wrap calls to it inassertso errors don't go unnoticed. - Examples:
assert(SMODS.change_base(card, 'Hearts'))converts a card into Hearts.assert(SMODS.change_base(card, nil, 'Ace'))converts a card into an Ace.assert(SMODS.change_base(card, 'Hearts', 'Ace'))converts a card into an Ace of Hearts.
- Given a
-
SMODS.find_card(key, count_debuffed) -> table- This function replaces
find_joker. It operates using keys instead of names, which avoids overlap between mods. - Returns an array of all jokers or consumables in the player's possession with the given key. Debuffed cards count only if
count_debuffedis true.
- This function replaces
-
SMODS.create_card(t) -> Card- This function replaces
create_card. It provides a cleaner interface to the same functionality. The argument to this function should always be a table. The following fields are supported: -
set- The card type to be generated, e.g.'Joker','Tarot','Spectral' -
area- The card area this will be emplaced into, e.g.G.jokers,G.consumeables. Default values are determined based onset. -
legendary- Set this totrueto generate a card of Legendary rarity. -
rarity- If this is specified, skip rarity polling and use this instead of a chance roll between 0 and 1.- Under vanilla conditions, values up to 0.7 indicate Common rarity, values above 0.7 and up to 0.95 indicate Uncommon rarity, and values above 0.95 indicate Rare rarity.
-
skip_materialize- If this istrue, astart_materializeanimation will not be shown. -
soulable- If this istrue, hidden Soul-type cards are allowed to replace the generated card. Usually, this is the case for cards generated for booster packs. -
key- If this is specified, generate a card with the given key instead of the random one. -
key_append- An additional RNG seeding string. This should be used to put different sources of card generation on different queues. -
no_edition- If this istrue, the generated card is guaranteed to have no randomly generated edition. -
edition,enhancement,seal- Applies the specified modifier to the card. -
stickers- This should be an array of sticker keys. Applies all specified stickers to the card.
- This function replaces
-
SMODS.debuff_card(card, debuff, source)- Allows manually setting and removing debuffs from cards.
-
sourceshould be a unique identifier string. You must use the same source to remove a previously set debuff. - If
debuffis the string'reset', remove debuffs from all sources handled by this function. - If
debuffis the string'prevent_debuff', blocks all possible debuffs on the card until removed. - If
debuffis another truthy value, set a debuff on the card. - If
debuffis a falsy values, remove this debuff.
-
SMODS.recalc_debuff(card)- Recalculates the debuff state of a card.
-
SMODS.merge_lists(...) -> table- Takes any number of 2D arrays. Flattens the input into a 1D array that contains all elements once in the order they first appear and removes any duplicates.
- This can be used to merge results from poker hand evaluation to create a combined hand.
-
SMODS.get_blind_amount(ante) -> number- Provides score requirements for higher stages of ante scaling. If you want to implement your own scaling rules, you should modify this function.
-
SMODS.stake_from_index(index) -> string- Given an index from the Stake pool, return the corresponding key, or
'error'if it doesn't exist.
- Given an index from the Stake pool, return the corresponding key, or
-
time(func, ...) -> number- Calls an input function with any given additional arguments:
func(...)and returns the time the function took to execute in milliseconds. The return value fromfuncis lost.
- Calls an input function with any given additional arguments:
These functions are used internally and may be of use to you if you're modifying Steamodded's injection process.
-
SMODS.save_d_u(o)- Saves the default discovery and unlock states of an object into a separate field for later use before they are overwritten with profile data.
-
SMODS.SAVE_UNLOCKS()- Modified from base game code. Sets discovery and unlock data according to profile state after injection.
-
SMODS.process_loc_text(ref_table, ref_value, loc_txt, key)- Saves a localization entry (usually consisting of a name and a description) into the game's dictionary, with the ability to handle a multi-language format. The
loc_txttable should either have locale indexing at the top layer or none at all. If the table holds multiple entries,keycan be used to choose a key one layer down. - Example:
SMODS.process_loc_text(G.localization.descriptions.Joker, 'my_joker_key', loc_txt)
- Saves a localization entry (usually consisting of a name and a description) into the game's dictionary, with the ability to handle a multi-language format. The
-
SMODS.handle_loc_file(path)- Given a mod's path, reads any present localization files and adds entries to the dictionary.
-
SMODS.insert_pool(pool, center, replace)- If
replaceis true orcenterhas been taken ownership of, look for an entry inpoolwith the same key and replace it. Otherwise, appendcenterto the end ofpool.
- If
-
SMODS.remove_pool(pool, key)- Find an entry in pool with this
keyand remove it if found.
- Find an entry in pool with this
-
SMODS.create_loc_dump()- Dumps localization entries created during injection into a single file, for purposes of converting to a file-based localization system.
-
SMODS.create_mod_badges(obj, badges)- UI code for adding mod badges to an object.
-
SMODS.merge_defaults(t, defaults) -> t- Starting with
t, insert any key-value pairs fromdefaultsthat don't already exist intintot. Modifiestand returns it as the result of the merge. -
nilentries are interpreted as an empty table;falseinputs count as a table where every possible key maps tofalse. Therefore,t == nilis weak and falls back to defaults, whilet == falseexplicitly ignoresdefaultsin its entirety. Due to this, this function may not always return a table. - This is used for controlling when keys should receive prefixes.
- Starting with
-
convert_save_data()- Adjusts values in save data to make the save compatible with Steamodded's way of storing deck wins by stake key instead of index.
-
SMODS.restart_game()- Restarts the game.
Game Objects
- API Documentation
- SMODS.Achievement
- SMODS.Atlas
- SMODS.Attribute
- SMODS.Blind
- SMODS.CanvasSprite
- SMODS.Center
- SMODS.Challenge
- SMODS.DeckSkin
- SMODS.DrawStep
- SMODS.DynaTextEffect
- SMODS.Font
- SMODS.Gradient
- SMODS.https
- SMODS.JimboQuip
- SMODS.Keybind
- SMODS.Language
- SMODS.ObjectType and SMODS.ConsumableType
- SMODS.PokerHand
- SMODS.Rank and SMODS.Suit
- SMODS.Rarity
- SMODS.Scoring_Parameter and SMODS.Scoring_Calculation
- SMODS.Seal
- SMODS.Shader and SMODS.ScreenShader
- SMODS.Sound
- SMODS.Stake
- SMODS.Sticker
- SMODS.Tag
Guides
- Your First Mod
- Mod Metadata
- The Mod Object
- Calculate Functions
- Perma-bonuses
- Object Weights
- Logging
- Event Manager
- Localization
- Text Styling
- UI Structure
- Utility Functions
- All About
G - Internal Documentation
Release Notes
Found an issue, or want to add something? Submit a PR to the Wiki repo.