From fb253941dfdd370d3081c6e46707424d993b300a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 25 Nov 2018 00:07:26 -0500 Subject: add support for propagating map asset changes --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/SMAPI/Metadata') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 8487b6be..841e6d64 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -13,6 +13,7 @@ using StardewValley.Menus; using StardewValley.Objects; using StardewValley.Projectiles; using StardewValley.TerrainFeatures; +using xTile; using xTile.Tiles; namespace StardewModdingAPI.Metadata @@ -45,10 +46,11 @@ namespace StardewModdingAPI.Metadata /// Reload one of the game's core assets (if applicable). /// The content manager through which to reload the asset. /// The asset key to reload. + /// The asset type to reload. /// Returns whether an asset was reloaded. - public bool Propagate(LocalizedContentManager content, string key) + public bool Propagate(LocalizedContentManager content, string key, Type type) { - object result = this.PropagateImpl(content, key); + object result = this.PropagateImpl(content, key, type); if (result is bool b) return b; return result != null; @@ -61,9 +63,12 @@ namespace StardewModdingAPI.Metadata /// Reload one of the game's core assets (if applicable). /// The content manager through which to reload the asset. /// The asset key to reload. - /// Returns any non-null value to indicate an asset was loaded. - private object PropagateImpl(LocalizedContentManager content, string key) + /// The asset type to reload. + /// Returns whether an asset was loaded. The return value may be true or false, or a non-null value for true. + private object PropagateImpl(LocalizedContentManager content, string key, Type type) { + key = this.GetNormalisedPath(key); + /**** ** Special case: current map tilesheet ** We only need to do this for the current location, since tilesheets are reloaded when you enter a location. @@ -78,6 +83,23 @@ namespace StardewModdingAPI.Metadata } } + /**** + ** Propagate map changes + ****/ + if (type == typeof(Map)) + { + bool anyChanged = false; + foreach (GameLocation location in this.GetLocations()) + { + if (this.GetNormalisedPath(location.mapPath.Value) == key) + { + this.Reflection.GetMethod(location, "reloadMap").Invoke(); + anyChanged = true; + } + } + return anyChanged; + } + /**** ** Propagate by key ****/ -- cgit