summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ContentManagers
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-03-26 17:37:01 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-03-26 17:37:01 -0400
commit3a9ea66a20136400d3268ea2e314eacd40d06231 (patch)
tree5e006a17a15588de322bf9bb33d0412fda9ae457 /src/SMAPI/Framework/ContentManagers
parent8d704153762fa73416a3ccb44ee71032952802eb (diff)
downloadSMAPI-3a9ea66a20136400d3268ea2e314eacd40d06231.tar.gz
SMAPI-3a9ea66a20136400d3268ea2e314eacd40d06231.tar.bz2
SMAPI-3a9ea66a20136400d3268ea2e314eacd40d06231.zip
update asset propagation for new content API (#766)
Diffstat (limited to 'src/SMAPI/Framework/ContentManagers')
-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
3 files changed, 5 insertions, 38 deletions
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();
}
}