From 2406380495cc5176d3cbd2309e6f17080389f9af Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 26 Dec 2020 01:28:00 -0500 Subject: fix SMAPI using a cached translation when the game asks for an untranslated asset This mainly affects community center bundles in Stardew Valley 1.5, --- src/SMAPI/Framework/ContentManagers/BaseContentManager.cs | 8 +++++--- src/SMAPI/Framework/ContentManagers/GameContentManager.cs | 9 +++++---- src/SMAPI/Framework/ContentManagers/IContentManager.cs | 3 ++- src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 3 ++- 4 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src/SMAPI/Framework/ContentManagers') diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs index 6bc3a505..92264f8c 100644 --- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs @@ -169,10 +169,11 @@ namespace StardewModdingAPI.Framework.ContentManagers /// Get whether the content manager has already loaded and cached the given asset. /// The asset path relative to the loader root directory, not including the .xnb extension. - public bool IsLoaded(string assetName) + /// The language. + public bool IsLoaded(string assetName, LanguageCode language) { assetName = this.Cache.NormalizeKey(assetName); - return this.IsNormalizedKeyLoaded(assetName); + return this.IsNormalizedKeyLoaded(assetName, language); } /// Get the cached asset keys. @@ -315,7 +316,8 @@ namespace StardewModdingAPI.Framework.ContentManagers /// Get whether an asset has already been loaded. /// The normalized asset name. - protected abstract bool IsNormalizedKeyLoaded(string normalizedAssetName); + /// The language to check. + protected abstract bool IsNormalizedKeyLoaded(string normalizedAssetName, LanguageCode language); /// Get the locale codes (like ja-JP) used in asset keys. private IDictionary GetKeyLocales() diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs index 83a63986..ad8f2ef1 100644 --- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs @@ -78,7 +78,7 @@ namespace StardewModdingAPI.Framework.ContentManagers return this.Load(newAssetName, newLanguage, useCache); // get from cache - if (useCache && this.IsLoaded(assetName)) + if (useCache && this.IsLoaded(assetName, language)) return this.RawLoad(assetName, language, useCache: true); // get managed asset @@ -151,11 +151,12 @@ namespace StardewModdingAPI.Framework.ContentManagers *********/ /// Get whether an asset has already been loaded. /// The normalized asset name. - protected override bool IsNormalizedKeyLoaded(string normalizedAssetName) + /// The language to check. + protected override bool IsNormalizedKeyLoaded(string normalizedAssetName, LanguageCode language) { string cachedKey = null; bool localized = - this.Language != LocalizedContentManager.LanguageCode.en + language != LocalizedContentManager.LanguageCode.en && !this.Coordinator.IsManagedAssetKey(normalizedAssetName) && this.LocalizedAssetNames.TryGetValue(normalizedAssetName, out cachedKey); @@ -214,7 +215,7 @@ namespace StardewModdingAPI.Framework.ContentManagers private T RawLoad(string assetName, LanguageCode language, bool useCache) { // use cached key - if (this.LocalizedAssetNames.TryGetValue(assetName, out string cachedKey)) + if (language == this.Language && this.LocalizedAssetNames.TryGetValue(assetName, out string cachedKey)) return base.RawLoad(cachedKey, useCache); // try translated key diff --git a/src/SMAPI/Framework/ContentManagers/IContentManager.cs b/src/SMAPI/Framework/ContentManagers/IContentManager.cs index 8da9a777..0e7edd8f 100644 --- a/src/SMAPI/Framework/ContentManagers/IContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/IContentManager.cs @@ -58,7 +58,8 @@ namespace StardewModdingAPI.Framework.ContentManagers /// Get whether the content manager has already loaded and cached the given asset. /// The asset path relative to the loader root directory, not including the .xnb extension. - bool IsLoaded(string assetName); + /// The language. + bool IsLoaded(string assetName, LocalizedContentManager.LanguageCode language); /// Get the cached asset keys. IEnumerable GetAssetKeys(); diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index 127705ea..753ec188 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -211,7 +211,8 @@ namespace StardewModdingAPI.Framework.ContentManagers *********/ /// Get whether an asset has already been loaded. /// The normalized asset name. - protected override bool IsNormalizedKeyLoaded(string normalizedAssetName) + /// The language to check. + protected override bool IsNormalizedKeyLoaded(string normalizedAssetName, LanguageCode language) { return this.Cache.ContainsKey(normalizedAssetName); } -- cgit