diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-04-01 00:33:35 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-04-01 00:33:35 -0400 |
commit | 6ad8ca932eb697a76dd9df43d6ae93c7ca4b2af5 (patch) | |
tree | 56b1762408d705016e43cbb5b61d2439af99098b | |
parent | 1d3c99cc25f6c0d504fd5e43ea71ef327b6e9066 (diff) | |
download | SMAPI-6ad8ca932eb697a76dd9df43d6ae93c7ca4b2af5.tar.gz SMAPI-6ad8ca932eb697a76dd9df43d6ae93c7ca4b2af5.tar.bz2 SMAPI-6ad8ca932eb697a76dd9df43d6ae93c7ca4b2af5.zip |
keep old XNB file extension behavior for backwards compatibility (#766)
-rw-r--r-- | src/SMAPI.sln.DotSettings | 1 | ||||
-rw-r--r-- | src/SMAPI/Framework/ContentManagers/BaseContentManager.cs | 22 | ||||
-rw-r--r-- | src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 15 | ||||
-rw-r--r-- | src/SMAPI/Metadata/CoreAssetPropagator.cs | 2 |
4 files changed, 23 insertions, 17 deletions
diff --git a/src/SMAPI.sln.DotSettings b/src/SMAPI.sln.DotSettings index 71cd7b82..b85185d5 100644 --- a/src/SMAPI.sln.DotSettings +++ b/src/SMAPI.sln.DotSettings @@ -53,6 +53,7 @@ <s:Boolean x:Key="/Default/UserDictionary/Words/=Pathoschild/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=premultiplied/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=premultiply/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/UserDictionary/Words/=Prenormalize/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=prerelease/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=pufferchick/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=rewriter/@EntryIndexedValue">True</s:Boolean> diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs index f41a9354..2d921cc3 100644 --- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs @@ -104,20 +104,21 @@ namespace StardewModdingAPI.Framework.ContentManagers /// <inheritdoc /> [Obsolete("This method is implemented for the base game and should not be used directly. To load an asset from the underlying content manager directly, use " + nameof(BaseContentManager.RawLoad) + " instead.")] - public override T LoadBase<T>(string assetName) + public sealed override T LoadBase<T>(string assetName) { return this.Load<T>(assetName, LanguageCode.en); } /// <inheritdoc /> - public override T Load<T>(string assetName) + public sealed override T Load<T>(string assetName) { return this.Load<T>(assetName, this.Language); } /// <inheritdoc /> - public override T Load<T>(string assetName, LanguageCode language) + public sealed override T Load<T>(string assetName, LanguageCode language) { + assetName = this.PrenormalizeRawAssetName(assetName); IAssetName parsedName = this.Coordinator.ParseAssetName(assetName); return this.LoadLocalized<T>(parsedName, language, useCache: true); } @@ -276,6 +277,21 @@ namespace StardewModdingAPI.Framework.ContentManagers /********* ** Private methods *********/ + /// <summary>Apply initial normalization to a raw asset name before it's parsed.</summary> + /// <param name="assetName">The asset name to normalize.</param> + private string PrenormalizeRawAssetName(string assetName) + { + // trim + assetName = assetName?.Trim(); + + // For legacy reasons, mods can pass .xnb file extensions to the content pipeline which + // are then stripped. This will be re-added as needed when reading from raw files. + if (assetName?.EndsWith(".xnb") == true) + assetName = assetName[..^".xnb".Length]; + + return assetName; + } + /// <summary>Normalize path separators in a file path. For asset keys, see <see cref="AssertAndNormalizeAssetName"/> instead.</summary> /// <param name="path">The file path to normalize.</param> [Pure] diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index 2a5a3f16..63b40d66 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -32,9 +32,6 @@ namespace StardewModdingAPI.Framework.ContentManagers /// <summary>The game content manager used for map tilesheets not provided by the mod.</summary> private readonly IContentManager GameContentManager; - /// <summary>The language code for language-agnostic mod assets.</summary> - private readonly LanguageCode DefaultLanguage = Constants.DefaultLanguage; - /// <summary>If a map tilesheet's image source has no file extensions, the file extensions to check for in the local mod folder.</summary> private readonly string[] LocalTilesheetExtensions = { ".png", ".xnb" }; @@ -76,12 +73,6 @@ namespace StardewModdingAPI.Framework.ContentManagers } /// <inheritdoc /> - public override T Load<T>(string assetName) - { - return this.Load<T>(assetName, this.DefaultLanguage); - } - - /// <inheritdoc /> public override T LoadExact<T>(IAssetName assetName, bool useCache) { // disable caching @@ -222,14 +213,14 @@ namespace StardewModdingAPI.Framework.ContentManagers private FileInfo GetModFile(string path) { // try exact match - FileInfo file = new FileInfo(Path.Combine(this.FullRootDirectory, path)); + FileInfo file = new(Path.Combine(this.FullRootDirectory, path)); // try with default extension - if (!file.Exists && file.Extension == string.Empty) + if (!file.Exists) { foreach (string extension in this.LocalTilesheetExtensions) { - FileInfo result = new FileInfo(file.FullName + extension); + FileInfo result = new(file.FullName + extension); if (result.Exists) { file = result; diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 832148aa..424abc18 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -95,8 +95,6 @@ namespace StardewModdingAPI.Metadata .Distinct() .ToDictionary(name => name, _ => false); - this.Monitor.Log($"Propagating: {propagatedAssets.Keys.OrderBy(p => p.Name, StringComparer.OrdinalIgnoreCase)}", LogLevel.Alert); - // group into optimized lists var buckets = assets.GroupBy(p => { |