summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/ContentCoordinator.cs5
-rw-r--r--src/SMAPI/Framework/ContentManagers/BaseContentManager.cs11
-rw-r--r--src/SMAPI/Framework/ContentManagers/GameContentManager.cs29
-rw-r--r--src/SMAPI/Framework/ContentManagers/IContentManager.cs3
4 files changed, 6 insertions, 42 deletions
diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs
index a4d29068..ee8b6893 100644
--- a/src/SMAPI/Framework/ContentCoordinator.cs
+++ b/src/SMAPI/Framework/ContentCoordinator.cs
@@ -230,12 +230,9 @@ namespace StardewModdingAPI.Framework
/// <summary>Perform any updates needed when the locale changes.</summary>
public void OnLocaleChanged()
{
- // reload affected content
+ // reset baseline cache
this.ContentManagerLock.InReadLock(() =>
{
- foreach (IContentManager contentManager in this.ContentManagers)
- contentManager.OnLocaleChanged();
-
this.VanillaContentManager.Unload();
});
}
diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
index b1ace259..1ca84792 100644
--- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
@@ -137,16 +137,18 @@ namespace StardewModdingAPI.Framework.ContentManagers
try
{
- this.LoadExact<T>(localizedName, useCache: useCache);
+ T data = this.LoadExact<T>(localizedName, useCache: useCache);
LocalizedContentManager.localizedAssetNames[assetName.Name] = localizedName.Name;
+ return data;
}
catch (ContentLoadException)
{
localizedName = new AssetName(assetName.BaseName + "_international", null, null);
try
{
- this.LoadExact<T>(localizedName, useCache: useCache);
+ T data = this.LoadExact<T>(localizedName, useCache: useCache);
LocalizedContentManager.localizedAssetNames[assetName.Name] = localizedName.Name;
+ return data;
}
catch (ContentLoadException)
{
@@ -158,7 +160,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
// use cached key
string rawName = LocalizedContentManager.localizedAssetNames[assetName.Name];
if (assetName.Name != rawName)
- assetName = this.Coordinator.ParseAssetName(assetName.Name);
+ assetName = this.Coordinator.ParseAssetName(rawName);
return this.LoadExact<T>(assetName, useCache: useCache);
}
@@ -166,9 +168,6 @@ namespace StardewModdingAPI.Framework.ContentManagers
public abstract T LoadExact<T>(IAssetName assetName, bool useCache);
/// <inheritdoc />
- public virtual void OnLocaleChanged() { }
-
- /// <inheritdoc />
[SuppressMessage("ReSharper", "ParameterOnlyUsedForPreconditionCheck.Local", Justification = "Parameter is only used for assertion checks by design.")]
public string AssertAndNormalizeAssetName(string assetName)
{
diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
index 500c0191..0fcad30a 100644
--- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
@@ -25,9 +25,6 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <summary>The assets currently being intercepted by <see cref="IAssetLoader"/> instances. This is used to prevent infinite loops when a loader loads a new asset.</summary>
private readonly ContextHash<string> AssetsBeingLoaded = new();
- /// <summary>Maps asset names to their localized form, like <c>LooseSprites\Billboard => LooseSprites\Billboard.fr-FR</c> (localized) or <c>Maps\AnimalShop => Maps\AnimalShop</c> (not localized).</summary>
- private IDictionary<string, string> LocalizedAssetNames => LocalizedContentManager.localizedAssetNames;
-
/// <summary>Whether the next load is the first for any game content manager.</summary>
private static bool IsFirstLoad = true;
@@ -140,32 +137,6 @@ namespace StardewModdingAPI.Framework.ContentManagers
}
/// <inheritdoc />
- public override void OnLocaleChanged()
- {
- base.OnLocaleChanged();
-
- // find assets for which a translatable version was loaded
- HashSet<string> removeAssetNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
- foreach (string key in this.LocalizedAssetNames.Where(p => p.Key != p.Value).Select(p => p.Key))
- {
- IAssetName assetName = this.Coordinator.ParseAssetName(key);
- removeAssetNames.Add(assetName.BaseName);
- }
-
- // invalidate translatable assets
- string[] invalidated = this
- .InvalidateCache((key, _) =>
- removeAssetNames.Contains(key)
- || removeAssetNames.Contains(this.Coordinator.ParseAssetName(key).BaseName)
- )
- .Select(p => p.Key)
- .OrderBy(p => p, StringComparer.OrdinalIgnoreCase)
- .ToArray();
- if (invalidated.Any())
- this.Monitor.Log($"Invalidated {invalidated.Length} asset names: {string.Join(", ", invalidated)} for locale change.");
- }
-
- /// <inheritdoc />
public override LocalizedContentManager CreateTemporary()
{
return this.Coordinator.CreateGameContentManager("(temporary)");
diff --git a/src/SMAPI/Framework/ContentManagers/IContentManager.cs b/src/SMAPI/Framework/ContentManagers/IContentManager.cs
index 4de9a8c3..774b20d9 100644
--- a/src/SMAPI/Framework/ContentManagers/IContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/IContentManager.cs
@@ -65,8 +65,5 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <param name="dispose">Whether to dispose invalidated assets. This should only be <c>true</c> when they're being invalidated as part of a dispose, to avoid crashing the game.</param>
/// <returns>Returns the invalidated asset names and instances.</returns>
IDictionary<string, object> InvalidateCache(Func<string, Type, bool> predicate, bool dispose = false);
-
- /// <summary>Perform any cleanup needed when the locale changes.</summary>
- void OnLocaleChanged();
}
}