summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/ContentHelper.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI/Framework/ContentHelper.cs')
-rw-r--r--src/StardewModdingAPI/Framework/ContentHelper.cs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/StardewModdingAPI/Framework/ContentHelper.cs b/src/StardewModdingAPI/Framework/ContentHelper.cs
index 4d116b54..7cf726e1 100644
--- a/src/StardewModdingAPI/Framework/ContentHelper.cs
+++ b/src/StardewModdingAPI/Framework/ContentHelper.cs
@@ -57,7 +57,7 @@ namespace StardewModdingAPI.Framework
switch (source)
{
case ContentSource.GameContent:
- return this.ContentManager.Load<T>(key);
+ return this.ContentManager.Load<T>(this.StripXnbExtension(key));
case ContentSource.ModFolder:
// find content file
@@ -117,13 +117,11 @@ namespace StardewModdingAPI.Framework
switch (source)
{
case ContentSource.GameContent:
- return this.ContentManager.NormaliseAssetName(key);
+ return this.ContentManager.NormaliseAssetName(this.StripXnbExtension(key));
case ContentSource.ModFolder:
string contentPath = Path.Combine(this.ModFolderPathFromContent, key);
- if (contentPath.EndsWith(".xnb"))
- contentPath = contentPath.Substring(0, contentPath.Length - 4);
- return this.ContentManager.NormaliseAssetName(contentPath);
+ return this.ContentManager.NormaliseAssetName(this.StripXnbExtension(contentPath));
default:
throw new NotSupportedException($"Unknown content source '{source}'.");
@@ -146,6 +144,15 @@ namespace StardewModdingAPI.Framework
throw new ArgumentException("The asset key or local path contains invalid characters.");
}
+ /// <summary>Strip the .xnb extension from an asset key, since it's assumed by the underlying content manager.</summary>
+ /// <param name="key">The asset key.</param>
+ private string StripXnbExtension(string key)
+ {
+ if (key.EndsWith(".xnb", StringComparison.InvariantCultureIgnoreCase))
+ return key.Substring(0, key.Length - 4);
+ return key;
+ }
+
/// <summary>Get a directory path relative to a given root.</summary>
/// <param name="rootPath">The root path from which the path should be relative.</param>
/// <param name="targetPath">The target file path.</param>