Any Sprite asset can be used in a binding, and there are implicit conversions for things that often translate to sprites like Texture2D, Tuple<Texture2D, Rectangle> and ParsedItemData, but it's hard to represent the entire sprite structure with just implicit conversions, and there isn't an easy way for a mod to actually register a Sprite asset.
Plan: Use JSON data to register "sprite sheets", with a single texture reference for each, either pointing implicitly to a texture file of the same name or to an external, named game asset.
For a modded sprite sheet, the format is the same except that we omit the Texture and have two file names that differ only by extension, e.g.
assets/sprites/ui.png and
assets/sprites/ui.json
When registered through the API - which is much easier than doing a manual asset handler because only StardewUI has the actual Sprite type and knows how to convert this data - it will register a handler for both the Texture2D asset as well as the Sprite asset that points to that texture and is invalidated when the texture is invalidated.
e.g. ViewEngine.AddSprites("Mods/MyMod/Sprites", "assets/sprites") would allow all sprites in the directory to be referenced with the asset prefix, so in the example above, we could then use an asset binding @Mods/MyMod/Sprites/Cursors/BackpackTab (mod reference to vanilla texture) or @Mods/MyMod/Sprites/UI/ExampleSprite to refer to an ExampleSprite key in the assets/sprites/ui.json which uses pixels from the assets/sprites/ui.png image.
Any
Sprite
asset can be used in a binding, and there are implicit conversions for things that often translate to sprites likeTexture2D
,Tuple<Texture2D, Rectangle>
andParsedItemData
, but it's hard to represent the entire sprite structure with just implicit conversions, and there isn't an easy way for a mod to actually register aSprite
asset.Plan: Use JSON data to register "sprite sheets", with a single texture reference for each, either pointing implicitly to a texture file of the same name or to an external, named game asset.
e.g. for a vanilla sprite sheet:
For a modded sprite sheet, the format is the same except that we omit the
Texture
and have two file names that differ only by extension, e.g.assets/sprites/ui.png
andassets/sprites/ui.json
When registered through the API - which is much easier than doing a manual asset handler because only StardewUI has the actual
Sprite
type and knows how to convert this data - it will register a handler for both theTexture2D
asset as well as theSprite
asset that points to that texture and is invalidated when the texture is invalidated.e.g.
ViewEngine.AddSprites("Mods/MyMod/Sprites", "assets/sprites")
would allow all sprites in the directory to be referenced with the asset prefix, so in the example above, we could then use an asset binding@Mods/MyMod/Sprites/Cursors/BackpackTab
(mod reference to vanilla texture) or@Mods/MyMod/Sprites/UI/ExampleSprite
to refer to anExampleSprite
key in theassets/sprites/ui.json
which uses pixels from theassets/sprites/ui.png
image.