Changes

Jump to navigation Jump to search
→‎How do I make my mod work crossplatform?: expand asset name normalization, remove 3.13.0-beta tag (now available in 3.12.6)
Line 213: Line 213:  
string modFolder = this.Helper.DirectoryPath;
 
string modFolder = this.Helper.DirectoryPath;
 
</syntaxhighlight></li>
 
</syntaxhighlight></li>
<li>{{SMAPI upcoming|3.13.0|content=An ''asset name'' identifies an asset you can load through a content API like <code><nowiki>Game1.content.Load<T>("asset name")</nowiki></code>, like <code>Characters/Abigail</code>. This is ''not'' a file path, and the asset name format on Windows does ''not'' match the path format. When comparing asset names, make sure you use <code>PathUtilities.NormalizePath("some/path")</code> instead of path helpers.}}</li>
+
<li>An ''asset name'' identifies an asset you can load through a content API like <code><nowiki>Game1.content.Load<T>("asset name")</nowiki></code>. This is ''not'' a file path, and the asset name format doesn't always match the file path format. When comparing asset names, make sure you use <code>PathUtilities.NormalizeAssetName("some/path")</code> instead of path helpers.
 +
 
 +
<syntaxhighlight lang="c#">
 +
// ✘ Don't do this! It won't work on Windows.
 +
bool isAbigail = (asset.Name == Path.Combine("Characters", "Abigail"));
 +
bool isAbigail2 = (asset.Name == PathUtilities.NormalizePath("Characters", "Abigail"));
 +
 
 +
// ✓ This is OK
 +
bool isAbigail = (asset.Name == PathUtilities.NormalizeAssetName("Characters", "Abigail"));
 +
</syntaxhighlight>
 +
 
 +
Note that there's no need to normalize asset names you pass into SMAPI APIs, which normalize them automatically (though it doesn't hurt to do it anyway):
 +
<syntaxhighlight lang="c#">
 +
// ✓ This is OK
 +
helper.Content.Load<Texture2D>("Characters/Abigail");
 +
helper.Content.Load<Texture2D>(@"Characters\Abigail");
 +
</syntaxhighlight>
 +
</li>
 
</ol>
 
</ol>
  
translators
8,446

edits

Navigation menu