Changes

Jump to navigation Jump to search
→‎Edit the game's assets: + replace a map file
Line 155: Line 155:  
}
 
}
 
</source>
 
</source>
 +
 +
===Replace a map file===
 +
{{SMAPI upcoming|2.6}}
 +
You can use <tt>IAssetLoader</tt> to load custom maps too. When you load an unpacked <tt>.tbin</tt> map file, and an unpacked tilesheet is present in the mod folder (relative to the map file), SMAPI will automatically link the map to that file and handle loading it too. If the tilesheet name starts with a season and underscore, SMAPI patches the game's seasonal logic to seasonalise it too.
 +
 +
For example, let's say you have a mod with this structure:
 +
<pre>
 +
ExampleMapMod.dll
 +
manifest.json
 +
assets/
 +
  Farm.tbin
 +
  fall_customTilesheet.png
 +
  spring_customTilesheet.png
 +
  summer_customTilesheet.png
 +
  winter_customTilesheet.png
 +
</pre>
 +
 +
You can load the custom map like this:
 +
 +
<source lang="c#">
 +
public class ModEntry : Mod, IAssetLoader
 +
{
 +
    /// <summary>Get whether this instance can load the initial version of the given asset.</summary>
 +
    /// <param name="asset">Basic metadata about the asset being loaded.</param>
 +
    public bool CanLoad<T>(IAssetInfo asset)
 +
    {
 +
        return asset.AssetNameEquals("Maps/Farm");
 +
    }
 +
 +
    /// <summary>Load a matched asset.</summary>
 +
    /// <param name="asset">Basic metadata about the asset being loaded.</param>
 +
    public T Load<T>(IAssetInfo asset)
 +
    {
 +
        return this.Helper.Content.Load<T>("assets/Farm.tbin");
 +
    }
 +
}
 +
</source>
 +
 +
That's it! SMAPI will detect a reference to <tt>spring_customTilesheet.png</tt>, find the file relative to the map file, and load it too. When the season changes in-game, SMAPI will automatically switch it to <tt>summer_customTilesheet.png</tt>, etc. The other tilesheet references will be left untouched (since there's no local file), and use the Content files.
    
===Add a new asset===
 
===Add a new asset===
translators
8,437

edits

Navigation menu