summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ContentCoordinator.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-05-27 18:09:04 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-05-27 18:09:04 -0400
commit0209e70695b6d12692d4de554ce1fc9d65ca4715 (patch)
tree011867d845ee3cf2a88f306504a4bdd6fe414ed6 /src/SMAPI/Framework/ContentCoordinator.cs
parent2ab2182645179129997eac3fccb63f6f0683dbe1 (diff)
parente4cd7c8eb09fa50802ce4eb9dbe4683ce61f7a5d (diff)
downloadSMAPI-0209e70695b6d12692d4de554ce1fc9d65ca4715.tar.gz
SMAPI-0209e70695b6d12692d4de554ce1fc9d65ca4715.tar.bz2
SMAPI-0209e70695b6d12692d4de554ce1fc9d65ca4715.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/ContentCoordinator.cs')
-rw-r--r--src/SMAPI/Framework/ContentCoordinator.cs24
1 files changed, 19 insertions, 5 deletions
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
/// <summary>The absolute path to the <see cref="ContentManager.RootDirectory"/>.</summary>
public string FullRootDirectory { get; }
+ /// <summary>A lookup which tracks whether each given asset name has a localized form.</summary>
+ /// <remarks>This is a per-screen equivalent to the base game's <see cref="LocalizedContentManager.localizedAssetNames"/> field, since mods may provide different assets per-screen.</remarks>
+ public PerScreen<Dictionary<string, string>> 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();
}
/// <summary>Clean up when the player is returning to the title screen.</summary>
@@ -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<string, string> localizedAssets) in this.LocalizedAssetNames.GetActiveValues())
+ localizedAssets.Clear();
}
/// <summary>Parse a raw asset name.</summary>
@@ -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<string, string> 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.