Changes

Jump to navigation Jump to search
→‎Replace an asset entirely: clarify how CanLoad / Load are called
Line 133: Line 133:  
Sometimes you may need to replace an asset entirely (without changing the original file), not just edit it after it's loaded. In other words, you're providing the asset to SMAPI yourself so the original file won't be read at all. Note that two mods can't both provide the same asset.
 
Sometimes you may need to replace an asset entirely (without changing the original file), not just edit it after it's loaded. In other words, you're providing the asset to SMAPI yourself so the original file won't be read at all. Note that two mods can't both provide the same asset.
   −
You can do this by implementing <tt>IAssetLoader</tt> in your <tt>Mod</tt> class. This adds two methods: <tt>CanLoad&lt;T&gt;</tt> returns whether the mod can provide a particular asset, and <tt>Load&lt;T&gt;</tt> provides the asset data. For example, here's a mod which replaces Abigail's portraits with a custom version from its mod folder:
+
You can do this by implementing <tt>IAssetLoader</tt> in your <tt>Mod</tt> class. This adds two methods: <tt>CanLoad&lt;T&gt;</tt> returns whether the mod can provide a particular asset, and <tt>Load&lt;T&gt;</tt> provides the asset data. SMAPI will call your <tt>CanLoad&lt;T&gt;</tt> every time an asset is loaded (which may happen multiple times per asset), then call <tt>Load&lt;T&gt;</tt> if it returns true. (If multiple mods return true from <tt>CanLoad&lt;T&gt;</tt> for the same asset, SMAPI will display an error and not call <tt>Load&lt;T&gt;</tt> for any of them.)
 +
 
 +
For example, here's a mod which replaces Abigail's portraits with a custom version from its mod folder:
    
<source lang="c#">
 
<source lang="c#">
translators
8,437

edits

Navigation menu