From 064346594d2239b1dceb9ddbc78e147c555d63d7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 24 May 2022 18:12:06 -0400 Subject: fix split-screen error when a mod provides a localized asset in one screen but not another --- src/SMAPI/Framework/ContentCoordinator.cs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/SMAPI/Framework/ContentCoordinator.cs') diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index fc61b44b..cfeb35c8 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -15,8 +15,8 @@ using StardewModdingAPI.Framework.Utilities; using StardewModdingAPI.Internal; using StardewModdingAPI.Metadata; using StardewModdingAPI.Toolkit.Serialization; -using StardewModdingAPI.Toolkit.Utilities; using StardewModdingAPI.Toolkit.Utilities.PathLookups; +using StardewModdingAPI.Utilities; using StardewValley; using StardewValley.GameData; using xTile; @@ -110,6 +110,10 @@ namespace StardewModdingAPI.Framework /// The absolute path to the . public string FullRootDirectory { get; } + /// A lookup which tracks whether each given asset name has a localized form. + /// This is a per-screen equivalent to the base game's field, since mods may provide different assets per-screen. + public PerScreen> LocalizedAssetNames { get; } = new(() => new()); + /********* ** Public methods @@ -245,6 +249,9 @@ namespace StardewModdingAPI.Framework { this.VanillaContentManager.Unload(); }); + + // forget localized flags (to match the logic in Game1.TranslateFields, which is called on language change) + this.LocalizedAssetNames.Value.Clear(); } /// Clean up when the player is returning to the title screen. @@ -275,6 +282,10 @@ namespace StardewModdingAPI.Framework // their changes, the assets won't be found in the cache so no changes will be propagated. if (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.en) this.InvalidateCache((contentManager, _, _) => contentManager is GameContentManager); + + // clear the localized assets lookup (to match the logic in Game1.CleanupReturningToTitle) + foreach ((_, Dictionary localizedAssets) in this.LocalizedAssetNames.GetActiveValues()) + localizedAssets.Clear(); } /// Parse a raw asset name. @@ -411,12 +422,15 @@ namespace StardewModdingAPI.Framework // A mod might provide a localized variant of a normally non-localized asset (like // `Maps/MovieTheater.fr-FR`). When the asset is invalidated, we need to recheck // whether the asset is localized in case it stops providing it. - foreach (IAssetName assetName in invalidatedAssets.Keys) { - LocalizedContentManager.localizedAssetNames.Remove(assetName.Name); + Dictionary localizedAssetNames = this.LocalizedAssetNames.Value; + foreach (IAssetName assetName in invalidatedAssets.Keys) + { + localizedAssetNames.Remove(assetName.Name); - if (LocalizedContentManager.localizedAssetNames.TryGetValue(assetName.BaseName, out string? targetForBaseKey) && targetForBaseKey == assetName.Name) - LocalizedContentManager.localizedAssetNames.Remove(assetName.BaseName); + if (localizedAssetNames.TryGetValue(assetName.BaseName, out string? targetForBaseKey) && targetForBaseKey == assetName.Name) + localizedAssetNames.Remove(assetName.BaseName); + } } // special case: maps may be loaded through a temporary content manager that's removed while the map is still in use. -- cgit