diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-03-25 00:52:37 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-03-25 00:52:37 -0400 |
commit | 5a0e49827be92d19dfdda7bb15ca15fa8f269ecb (patch) | |
tree | dada12bffd9acd76d2361eae546a160aedc3e0cc /src/SMAPI/Metadata | |
parent | d0b96ed3c068f8b94a53a156a7c5e668f53aa2fc (diff) | |
download | SMAPI-5a0e49827be92d19dfdda7bb15ca15fa8f269ecb.tar.gz SMAPI-5a0e49827be92d19dfdda7bb15ca15fa8f269ecb.tar.bz2 SMAPI-5a0e49827be92d19dfdda7bb15ca15fa8f269ecb.zip |
update fence textures when changed through the content API (#459)
Diffstat (limited to 'src/SMAPI/Metadata')
-rw-r--r-- | src/SMAPI/Metadata/CoreAssetPropagator.cs | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 4a1d6097..1702ee26 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -333,6 +333,9 @@ namespace StardewModdingAPI.Metadata if (key.StartsWith(this.GetNormalisedPath("Characters\\Monsters\\"))) return this.ReloadNpcSprites(content, key, monster: true); + if (key.StartsWith(this.GetNormalisedPath("LooseSprites\\Fence"))) + return this.ReloadFenceTextures(content, key); + if (key.StartsWith(this.GetNormalisedPath("Portraits\\"))) return this.ReloadNpcPortraits(content, key); @@ -372,6 +375,34 @@ namespace StardewModdingAPI.Metadata return false; } + /// <summary>Reload the sprites for a fence type.</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 whether any textures were reloaded.</returns> + private bool ReloadFenceTextures(LocalizedContentManager content, string key) + { + // get fence type + if (!int.TryParse(this.GetSegments(key)[1].Substring("Fence".Length), out int fenceType)) + return false; + + // get fences + Fence[] fences = + ( + from location in this.GetLocations() + from fence in location.Objects.Values.OfType<Fence>() + where fenceType == 1 + ? fence.isGate + : fence.whichType == fenceType + select fence + ) + .ToArray(); + + // update fence textures + foreach (Fence fence in fences) + fence.reloadSprite(); + return true; + } + /// <summary>Reload the sprites for matching NPCs.</summary> /// <param name="content">The content manager through which to reload the asset.</param> /// <param name="key">The asset key to reload.</param> @@ -490,13 +521,20 @@ namespace StardewModdingAPI.Metadata } } + /// <summary>Get the segments in a path (e.g. 'a/b' is 'a' and 'b').</summary> + /// <param name="path">The path to check.</param> + private string[] GetSegments(string path) + { + if (path == null) + return new string[0]; + return path.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + } + /// <summary>Count the number of segments in a path (e.g. 'a/b' is 2).</summary> /// <param name="path">The path to check.</param> private int CountSegments(string path) { - if (path == null) - return 0; - return path.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Length; + return this.GetSegments(path).Length; } } } |