sf2.assets
Assets are the pictures, models, sounds and binary files your mod ships. These functions turn a file path or core asset ID into a handle you pass to other definitions, and replace core assets with your own. Get sf2 with local sf2 = require("sf2").
sf2.assets.sprite
Section titled “sf2.assets.sprite”Get a sprite handle for icons, portraits, location images and arena artwork.
Signature: sf2.assets.sprite(reference)
Parameters
| Parameter | Type | Required |
|---|---|---|
reference |
string |
Required |
Returns: A sprite handle. A missing or non-sprite asset is an error.
When: Usually during registration.
local icon = sf2.assets.sprite("sprites/weapon") -- assets/sprites/weapon.assetSee the reskin guide for the sprite file format. A PNG texture ID is not a sprite ID.
sf2.assets.model
Section titled “sf2.assets.model”Get a model handle for equipment, from the core game or your own mod.
Signature: sf2.assets.model(reference)
Parameters
| Parameter | Type | Required |
|---|---|---|
reference |
string |
Required |
Returns: A model handle. The asset must exist and be a model.
When: Usually during registration.
local model = sf2.assets.model("core:gamedata/models/mdl_weapon_katana_ritual")A core model is the easiest start. Your own model goes at assets/models/<name>.xml (or gzipped .modelz) and has the ID models/<name>. The model, equipment category and combat subtype must fit together. See the characters guide for warrior bodies and skins.
sf2.assets.audio
Section titled “sf2.assets.audio”Get an audio handle for music, move sounds, screen effects or sf2.audio.try_play.
Signature: sf2.assets.audio(reference)
Parameters
| Parameter | Type | Required |
|---|---|---|
reference |
string |
Required |
Returns: An audio handle. A missing or non-audio asset is an error.
When: During registration.
local music = sf2.assets.audio("audio/arena") -- assets/audio/arena.oggUse Ogg Vorbis (.ogg) or 16-bit PCM .wav; MP3, M4A and FLAC are not supported. The handle has no play methods: attach it to a music field, a sound action or a screen effect, or pass it to sf2.audio.try_play.
sf2.assets.binary
Section titled “sf2.assets.binary”Get a binary handle for an animation file used by sf2.moves.register.
Signature: sf2.assets.binary(reference)
Parameters
| Parameter | Type | Required |
|---|---|---|
reference |
string |
Required |
Returns: A binary handle.
When: During registration.
local animation = sf2.assets.binary("animations/opening")The game’s own animation clips work too: pass "core:gamedata/animations/binary/<clip>", such as sf2.assets.binary("core:gamedata/animations/binary/air_punch"), instead of shipping a copy of a clip the game already has. The clip names are the .bytes files the base moves use, without the extension.
See the moves guide. To swap an existing asset for yours, see sf2.assets.replace.
sf2.assets.exists
Section titled “sf2.assets.exists”Check whether an asset ID is available, for example to support an optional file.
Signature: sf2.assets.exists(reference)
Parameters
| Parameter | Type | Required |
|---|---|---|
reference |
string |
Required |
Returns: true if the asset is listed, otherwise false. It does not check type or contents.
When: Entrypoint or a callback.
if sf2.assets.exists("sprites/optional_badge") then sf2.log.info("Optional badge found")endsf2.assets.replace
Section titled “sf2.assets.replace”Redirect an existing asset to one your mod owns, swap one sound that moves play, or swap a music track.
Signature: sf2.assets.replace { target, replacement }, sf2.assets.replace { sound, replacement, subtypes?, setting?, choice? } or sf2.assets.replace { music, replacement, setting?, choice? }
Parameters
| Parameter | Type | Required |
|---|---|---|
definition |
AssetReplacement|MoveSoundReplacement|MusicReplacement |
Required |
Fields of AssetReplacement
| Field | Type | Required | Meaning |
|---|---|---|---|
target |
string|SpriteHandle|ModelHandle|AudioHandle|BinaryHandle |
Required | The asset to replace, as a qualified reference such as core:sprites/icon, or a handle. |
replacement |
string|SpriteHandle|ModelHandle|AudioHandle|BinaryHandle |
Required | The asset to show or play instead (a reference or a handle). |
Fields of MoveSoundReplacement
| Field | Type | Required | Meaning |
|---|---|---|---|
sound |
string |
Required | Sound name a move plays, such as snd_swish_sword1. |
replacement |
AudioHandle|string |
Required | Audio handle or built-in sound name. |
subtypes |
string[] |
Optional | 1-16 case-sensitive weapon subtype names, such as “Knives”. Default: every fighter. |
setting |
SettingHandle|SettingChoiceHandle |
Optional | A switch that turns the swap on or off, or a choice setting together with choice. Default: always on. |
choice |
string |
Optional | With a choice setting: the id of the choice the swap applies to. |
Fields of MusicReplacement
| Field | Type | Required | Meaning |
|---|---|---|---|
music |
string |
Required | The file name of a built-in track as stages and fights give it, such as “fight10_black_warrior” or “menu”. Letter case does not matter; other names for the song do not match. |
replacement |
AudioHandle |
Required | Audio handle: your own track, or a core:gamedata/music/<track> handle. |
setting |
SettingHandle|SettingChoiceHandle |
Optional | A switch that turns the swap on or off, or a choice setting together with choice. Default: always on. |
choice |
string |
Optional | With a choice setting: the id of the choice the swap applies to. |
Returns: nil.
When: Entrypoint. Restart after enabling or disabling the mod.
sf2.assets.replace { target = "core:ui/skills/skillsench02.enchantmentfrenzy", replacement = "sprites/my_frenzy",}Both assets must be the same kind (sprite, texture, model or audio), and the target must belong to a mod you depend on. Two replacements of one target conflict. You cannot replace XML or text, delete assets, or swap a whole animation. See the reskin guide for finding target IDs.
Replacing a move sound
Section titled “Replacing a move sound”Give sound instead of target to change a one-shot move sound, optionally only for some weapons and only while a setting is on.
local old_knives = sf2.settings.toggle { id = "old_knife_sounds", label = "Old knife sounds" }sf2.assets.replace { sound = "snd_swish_sword1", replacement = sf2.assets.audio("core:gamedata/sounds/swish_sword1"), subtypes = { "Knives", "Daggers" }, setting = old_knives,}Matching follows the equipped weapon and is exact ("Knives" does not match "ButcherKnives"). Looping, scripted, music, UI and screen-effect sounds are not affected. Overlapping swaps of one sound with the same setting (and choice) conflict, as do two mods swapping the same sound for overlapping subtypes. setting may also be a choice, as for music below.
Replacing a music track
Section titled “Replacing a music track”Give music instead of target to play another track wherever the game would play a built-in one: in fights, on the map and in menus. Add setting to make it a player’s choice.
local remastered = sf2.settings.toggle { id = "remastered_music", label = "Remastered music", default = false }sf2.assets.replace { music = "fight10_black_warrior", replacement = sf2.assets.audio("audio/black_warrior_remastered"), setting = remastered,}music(required) is the file name of the track, exactly as stages and fights give it, such as"fight10_black_warrior", or"menu"for the theme of the dojo, map, shop and multiplayer lobby. Letter case does not matter. Another name for the same song is a different track:"black_warrior"matches nothing, and"the_black_warrior"(a second copy of the song) matches only fights that play that file. The audio catalog lists most built-in tracks.replacement(required) is a handle fromsf2.assets.audio: your own file, or another built-in track ascore:gamedata/music/<track>.settingis optional. Without it the swap is always on. It is a switch fromsf2.settings.toggle(the swap plays while it is on), or a choice fromsf2.settings.choicetogether withchoice, theidof the choice the swap plays for. A changed setting applies from the next track that starts.- A track your mod (or another) gives a fight as an audio handle, through
musiconsf2.battles.registerorsf2.battles.patch, is not a built-in track and is not swapped. - A mod may swap up to 64 tracks. Swapping the same track twice with the same
setting(andchoice) is an error, and two mods swapping the same track conflict: the second fails to load.
To let the player pick one of several versions of a track, give each version its own choice. A choice with no swap, such as "normal" here, keeps the game’s own track:
local theme = sf2.settings.choice { id = "menu_theme", label = "Menu theme", choices = { { id = "normal", label = "Normal" }, { id = "remastered", label = "Remastered" } },}sf2.assets.replace { music = "menu", replacement = sf2.assets.audio("audio/menu_remastered"), setting = theme, choice = "remastered",}Menu, versus and loading screens
Section titled “Menu, versus and loading screens”Some UI sprites can be targeted by their exact core resource name:
| Target | Where it shows |
|---|---|
core:ui/atlases/MenuButtons.Dojo_normal |
A menu button. |
core:ui/fullscreen/VS_Fon_left.img, VS_Fon_right.img |
Versus-screen background panels. |
core:ui/fullscreen/loading_left.img, loading_right.img |
Loader into and out of fights. |
core:ui/fullscreen/menu_loading_left.img, menu_loading_right.img |
Loader between dojo, shop, profile and map (falls back to loading_*). |
core:ui/fullscreen/startLoading_left.img, startLoading_right.img |
Loader when a save is first entered. |
core:ui/fullscreen/act_left.img, act_right.img |
Act screens (sf2.story.play_sequence); fall back to loading_*. |
Each screen is a left and right panel; one wide PNG can supply both through two sprites with complementary rect crops. The picture is scaled to cover the screen and centered, so keep important parts near the middle. The loader draws core:textures/logos/logo.left and logo.right on top; replace them with a transparent sprite to hide the logo.