Changes

split into 'breaking changes' vs 'other changes', add raw texture data
Line 36: Line 36:  
# You can refer to the following sections on how to replace specific interfaces.
 
# You can refer to the following sections on how to replace specific interfaces.
   −
==Changes==
+
==Breaking changes==
 
===Content interception API===
 
===Content interception API===
 
The <samp>IAssetLoader</samp> and <samp>IAssetEditor</samp> interfaces no longer exist. Both have been replaced by the [[Modding:Modder Guide/APIs/Events#Content.AssetRequested|<samp>AssetRequested</samp> event]], which is used like this:
 
The <samp>IAssetLoader</samp> and <samp>IAssetEditor</samp> interfaces no longer exist. Both have been replaced by the [[Modding:Modder Guide/APIs/Events#Content.AssetRequested|<samp>AssetRequested</samp> event]], which is used like this:
Line 203: Line 203:  
| This is usually only needed for <samp>System.Configuration.ConfigurationManager.dll</samp> or <samp>System.Runtime.Caching.dll</samp>, and can probably be removed.
 
| This is usually only needed for <samp>System.Configuration.ConfigurationManager.dll</samp> or <samp>System.Runtime.Caching.dll</samp>, and can probably be removed.
 
|}
 
|}
 +
 +
==Other changes==
 +
===Raw texture data===
 +
Creating <samp>Texture2D</samp> instances is expensive and involves calls to the graphics card. When you don't need a full texture, you can now load it as <samp>IRawTextureData</samp> instead, and then pass that into SMAPI APIs that accept textures.
 +
 +
For example, you no longer need to create a <samp>Texture2D</samp> instance to apply an image overlay:
 +
<syntaxhighlight lang="c#">
 +
private void OnAssetRequested(object? sender, AssetRequestedEventArgs e)
 +
{
 +
    if (e.Name.IsEquivalentTo("Portraits/Abigail"))
 +
    {
 +
        e.Edit(asset =>
 +
        {
 +
            IRawTextureData ribbon = this.Helper.ModContent.Load<IRawTextureData>("assets/ribbon.png");
 +
            asset.AsImage().PatchImage(source: ribbon);
 +
        });
 +
    }
 +
}
 +
</syntaxhighlight>
    
[[Category:Modding]]
 
[[Category:Modding]]
translators
8,404

edits