diff options
-rw-r--r-- | docs/release-notes.md | 3 | ||||
-rw-r--r-- | src/SMAPI/Metadata/CoreAssetPropagator.cs | 34 |
2 files changed, 35 insertions, 2 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index 3f955e78..49bc2eab 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -25,11 +25,12 @@ These changes have not been released yet. * Fixed outdoor tilesheets being seasonalised when added to an indoor location. * For modders: + * Mods are now loaded much earlier in the game launch. This lets mods intercept any content asset, but the game is not fully initialised when `Entry` is called (use the `GameLaunched` event if you need to run code when the game is initialised). * Added support for content pack translations. * Added `IContentPack.HasFile` method. * Added `Context.IsGameLaunched` field. - * Mods are now loaded much earlier in the game launch. This lets mods intercept any content asset, but the game is not fully initialised when `Entry` is called (use the `GameLaunched` event if you need to run code when the game is initialised). * Added separate `LogNetworkTraffic` option to make verbose logging less overwhelmingly verbose. + * Added asset propagation for critter textures. * The installer now recognises custom game paths stored in `stardewvalley.targets`, if any. * When a mod is incompatible, the trace logs now list all detected issues instead of the first one. * Removed all deprecated APIs. diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 9e84c67f..b000d503 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -316,8 +316,12 @@ namespace StardewModdingAPI.Metadata return true; /**** - ** Content\Critters + ** Content\TileSheets ****/ + case "tilesheets\\critters": // Critter constructor + this.ReloadCritterTextures(content, key); + return true; + case "tilesheets\\crops": // Game1.LoadContent Game1.cropSpriteSheet = content.Load<Texture2D>(key); return true; @@ -562,6 +566,34 @@ namespace StardewModdingAPI.Metadata return false; } + /// <summary>Reload critter textures.</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 the number of reloaded assets.</returns> + private int ReloadCritterTextures(LocalizedContentManager content, string key) + { + // get critters + Critter[] critters = + ( + from location in this.GetLocations() + let locCritters = this.Reflection.GetField<List<Critter>>(location, "critters").GetValue() + where locCritters != null + from Critter critter in locCritters + where this.GetNormalisedPath(critter.sprite.textureName) == key + select critter + ) + .ToArray(); + if (!critters.Any()) + return 0; + + // update sprites + Texture2D texture = content.Load<Texture2D>(key); + foreach (var entry in critters) + this.SetSpriteTexture(entry.sprite, texture); + + return critters.Length; + } + /// <summary>Reload the sprites for a fence type.</summary> /// <param name="key">The asset key to reload.</param> /// <returns>Returns whether any textures were reloaded.</returns> |