summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ContentCoordinator.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-04-27 16:30:41 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-04-27 16:30:41 -0400
commitdf6e745c6b842290338317ed1d3e969ee222998c (patch)
tree4b8b28ddd7d8b9fe381bc7902f7c19187a61d4be /src/SMAPI/Framework/ContentCoordinator.cs
parentd0dad43e243864eb8bfdf46c853c5c7fba7c55ed (diff)
parentf44151dbb47b82250955be7c25145d1774bec705 (diff)
downloadSMAPI-df6e745c6b842290338317ed1d3e969ee222998c.tar.gz
SMAPI-df6e745c6b842290338317ed1d3e969ee222998c.tar.bz2
SMAPI-df6e745c6b842290338317ed1d3e969ee222998c.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/ContentCoordinator.cs')
-rw-r--r--src/SMAPI/Framework/ContentCoordinator.cs27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs
index 0b1ccc3c..47ef30d4 100644
--- a/src/SMAPI/Framework/ContentCoordinator.cs
+++ b/src/SMAPI/Framework/ContentCoordinator.cs
@@ -14,6 +14,7 @@ using StardewModdingAPI.Metadata;
using StardewModdingAPI.Toolkit.Serialization;
using StardewModdingAPI.Toolkit.Utilities;
using StardewValley;
+using xTile;
namespace StardewModdingAPI.Framework
{
@@ -228,16 +229,32 @@ namespace StardewModdingAPI.Framework
public IEnumerable<string> InvalidateCache(Func<string, Type, bool> predicate, bool dispose = false)
{
// invalidate cache & track removed assets
- IDictionary<string, ISet<object>> removedAssets = new Dictionary<string, ISet<object>>(StringComparer.InvariantCultureIgnoreCase);
+ IDictionary<string, Type> removedAssets = new Dictionary<string, Type>(StringComparer.InvariantCultureIgnoreCase);
this.ContentManagerLock.InReadLock(() =>
{
+ // cached assets
foreach (IContentManager contentManager in this.ContentManagers)
{
foreach (var entry in contentManager.InvalidateCache(predicate, dispose))
{
- if (!removedAssets.TryGetValue(entry.Key, out ISet<object> assets))
- removedAssets[entry.Key] = assets = new HashSet<object>(new ObjectReferenceComparer<object>());
- assets.Add(entry.Value);
+ if (!removedAssets.TryGetValue(entry.Key, out Type type))
+ removedAssets[entry.Key] = entry.Value.GetType();
+ }
+ }
+
+ // special case: maps may be loaded through a temporary content manager that's removed while the map is still in use.
+ // This notably affects the town and farmhouse maps.
+ if (Game1.locations != null)
+ {
+ foreach (GameLocation location in Game1.locations)
+ {
+ if (location.map == null || string.IsNullOrWhiteSpace(location.mapPath.Value))
+ continue;
+
+ // get map path
+ string mapPath = this.MainContentManager.AssertAndNormalizeAssetName(location.mapPath.Value);
+ if (!removedAssets.ContainsKey(mapPath) && predicate(mapPath, typeof(Map)))
+ removedAssets[mapPath] = typeof(Map);
}
}
});
@@ -245,7 +262,7 @@ namespace StardewModdingAPI.Framework
// reload core game assets
if (removedAssets.Any())
{
- IDictionary<string, bool> propagated = this.CoreAssets.Propagate(this.MainContentManager, removedAssets.ToDictionary(p => p.Key, p => p.Value.First().GetType())); // use an intercepted content manager
+ IDictionary<string, bool> propagated = this.CoreAssets.Propagate(this.MainContentManager, removedAssets.ToDictionary(p => p.Key, p => p.Value)); // use an intercepted content manager
this.Monitor.Log($"Invalidated {removedAssets.Count} asset names ({string.Join(", ", removedAssets.Keys.OrderBy(p => p, StringComparer.InvariantCultureIgnoreCase))}); propagated {propagated.Count(p => p.Value)} core assets.", LogLevel.Trace);
}
else