Changes

Jump to navigation Jump to search
→‎Advanced: + compare asset names
Line 352: Line 352:     
==Advanced==
 
==Advanced==
 +
===Compare asset names===
 +
You can't compare asset names directly because they depend on the current OS (e.g. <tt>Characters/Abigail</tt> versus <tt>Characters\Abigail</tt>) and they're case-insensitive (e.g. <tt>Characters/ABIGAIL</tt>).
 +
 +
To check for an exact match when you have an <tt>IAssetData</tt> instance (e.g. from the content API), just call <code>asset.AssetNameEquals("Characters/Abigail")</code> and SMAPI will normalize the asset names internally.
 +
 +
{{SMAPI upcoming|3.7|If you need to check manually, you should normalize directory separators and compare case-insensitively. For example:
 +
<source lang="c#">
 +
string dialoguePrefix = PathUtilities.NormalizePathSeparators(@"Characters\Dialogue\");
 +
bool isDialogue = asset.AssetName.StartsWith(dialoguePrefix, StringComparison.OrdinalIgnoreCase);
 +
</source>}}
 +
 
===Cache invalidation===
 
===Cache invalidation===
 
You can reload an asset by invalidating it from the cache. It will be reloaded next time the game requests it (and mods will have another chance to intercept it), and SMAPI will automatically update references to the asset in many cases. For example, this lets you change what clothes an NPC is wearing (by invalidating their cached sprites or portraits).
 
You can reload an asset by invalidating it from the cache. It will be reloaded next time the game requests it (and mods will have another chance to intercept it), and SMAPI will automatically update references to the asset in many cases. For example, this lets you change what clothes an NPC is wearing (by invalidating their cached sprites or portraits).
translators
8,403

edits

Navigation menu