summaryrefslogtreecommitdiff
path: root/src/SMAPI/Metadata
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-25 00:07:26 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-11-25 00:07:26 -0500
commitfb253941dfdd370d3081c6e46707424d993b300a (patch)
tree9819c0ac1ceaa8b5c6add64da01f0b366b458a75 /src/SMAPI/Metadata
parent43f11cfe51fdbb6c8fdee657ddf82d740ff6d738 (diff)
downloadSMAPI-fb253941dfdd370d3081c6e46707424d993b300a.tar.gz
SMAPI-fb253941dfdd370d3081c6e46707424d993b300a.tar.bz2
SMAPI-fb253941dfdd370d3081c6e46707424d993b300a.zip
add support for propagating map asset changes
Diffstat (limited to 'src/SMAPI/Metadata')
-rw-r--r--src/SMAPI/Metadata/CoreAssetPropagator.cs30
1 files changed, 26 insertions, 4 deletions
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
/// <summary>Reload one of the game's core assets (if applicable).</summary>
/// <param name="content">The content manager through which to reload the asset.</param>
/// <param name="key">The asset key to reload.</param>
+ /// <param name="type">The asset type to reload.</param>
/// <returns>Returns whether an asset was reloaded.</returns>
- 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
/// <summary>Reload one of the game's core assets (if applicable).</summary>
/// <param name="content">The content manager through which to reload the asset.</param>
/// <param name="key">The asset key to reload.</param>
- /// <returns>Returns any non-null value to indicate an asset was loaded.</returns>
- private object PropagateImpl(LocalizedContentManager content, string key)
+ /// <param name="type">The asset type to reload.</param>
+ /// <returns>Returns whether an asset was loaded. The return value may be true or false, or a non-null value for true.</returns>
+ 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.
@@ -79,6 +84,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
****/
Reflector reflection = this.Reflection;