From ddd9c0a80450fb161c1ff02cce94d4783a9f3bbc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 29 Apr 2017 23:38:45 -0400 Subject: let mods specify .xnb file extension explicitly (#257) --- src/StardewModdingAPI/Framework/ContentHelper.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/StardewModdingAPI') 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(key); + return this.ContentManager.Load(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."); } + /// Strip the .xnb extension from an asset key, since it's assumed by the underlying content manager. + /// The asset key. + private string StripXnbExtension(string key) + { + if (key.EndsWith(".xnb", StringComparison.InvariantCultureIgnoreCase)) + return key.Substring(0, key.Length - 4); + return key; + } + /// Get a directory path relative to a given root. /// The root path from which the path should be relative. /// The target file path. -- cgit