summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-04-29 23:38:45 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-04-29 23:38:45 -0400
commitddd9c0a80450fb161c1ff02cce94d4783a9f3bbc (patch)
tree82ea3b0a38ddd116a56c8e839db5b5f3bb526f83 /src/StardewModdingAPI
parent3cfe14d27946518c1cd631607f878f7d2f4a2cdb (diff)
downloadSMAPI-ddd9c0a80450fb161c1ff02cce94d4783a9f3bbc.tar.gz
SMAPI-ddd9c0a80450fb161c1ff02cce94d4783a9f3bbc.tar.bz2
SMAPI-ddd9c0a80450fb161c1ff02cce94d4783a9f3bbc.zip
let mods specify .xnb file extension explicitly (#257)
Diffstat (limited to 'src/StardewModdingAPI')
-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>