SMAPI - Stardew Modding API

SMAPI - Stardew Modding API

971k Downloads

Improve asset management

Pathoschild opened this issue ยท 2 comments

commented

Improve how SMAPI manages content assets to make sure assets are correctly disposed and seasonal tilesheets work correctly.

To do

1.15.4-alpha

  • Rewrite content manager disposal to let individual CMs be disposed without affecting each other.
  • Fix map tilesheet fixing not accounting for seasonal variations.

1.15.4-alpha.2

  • Fix IAssetLoader instances not able to load a map tilesheet if it doesn't also exist in the content folder.
  • Make tilesheet fixing better reflect core game logic.
  • Fix tilesheets with a non-spring season prefix not being seasonalised.
commented

Done in develop for the upcoming release. This consists of two main changes:

  • Previously all content manager (CM) references in the game pointed to SMAPI's core SContentManager. These now point to individual ContentManagerShim instances, which defer loading to the single SContentManager. SMAPI keeps track of which CMs loaded each key, so when a CM is disposed SMAPI can properly dispose the assets it loaded (but only if they're not also loaded through a live CM).

  • When loading a map, the tilesheet fix logic now accounts for seasonal variations. For example, a tilesheet which references spring_outdoorTileSheet will load winter_outdoorTileSheet instead in winter. This is based on the game's own logic, but works for any tilesheet whose name begins with spring_. (If no file for the current season exists, it'll load the spring version.)

commented

Three changes in alpha 2:

  • SMAPI previously checked if the content file exists before loading it, which meant that IAssetLoaders couldn't provide custom map tilesheets. SMAPI now tries to load the content file, and only checks for existence if an error occurs.

  • The game's logic for tilesheets is a bit specialised. It boils down to this: if the location is indoors or the desert, or the image source contains 'path' or 'object', load it as-is relative to the Content folder; else load it from Content\Maps with a seasonal prefix. That logic doesn't work well in our case, mainly because we have no location metadata at that point.

    Instead, SMAPI now uses a more heuristic approach: check relative to the map file first, then relative to Content\Maps, then Content. If the image source filename contains a seasonal prefix, we try for a seasonal variation and then an exact match.

    While that doesn't exactly match the game logic, it's close enough that it's unlikely to make a difference.

  • SMAPI now performs a seasonal check if the image source has any season prefix (not just spring_).