From 6805c90e2cdac734341b692298670b0beb50faa6 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 14 Mar 2021 14:17:09 -0400 Subject: add asset propagation for interior door sprites --- src/SMAPI/Metadata/CoreAssetPropagator.cs | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src') diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 8b591bc1..ae56dc9c 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -366,6 +366,8 @@ namespace StardewModdingAPI.Metadata foreach (ClickableTextureComponent button in new[] { menu.questButton, menu.zoomInButton, menu.zoomOutButton }) button.texture = Game1.mouseCursors; } + + this.ReloadDoorSprites(content, key); return true; case "loosesprites\\cursors2": // Game1.LoadContent @@ -739,6 +741,36 @@ namespace StardewModdingAPI.Metadata return critters.Length; } + /// Reload the sprites for interior doors. + /// The content manager through which to reload the asset. + /// The asset key to reload. + /// Returns whether any doors were affected. + private bool ReloadDoorSprites(LocalizedContentManager content, string key) + { + Lazy texture = new Lazy(() => content.Load(key)); + + foreach (GameLocation location in this.GetLocations()) + { + IEnumerable doors = location.interiorDoors?.Doors; + if (doors == null) + continue; + + foreach (InteriorDoor door in doors) + { + if (door?.Sprite == null) + continue; + + string textureName = this.NormalizeAssetNameIgnoringEmpty(this.Reflection.GetField(door.Sprite, "textureName").GetValue()); + if (textureName != key) + continue; + + door.Sprite.texture = texture.Value; + } + } + + return texture.IsValueCreated; + } + /// Reload the data for matching farm animals. /// Returns whether any farm animals were affected. /// Derived from the constructor. -- cgit