From 924c3a5d3fe6bfad483834112883156bdf202b57 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 25 Nov 2018 15:19:12 -0500 Subject: add support for propagating NPCDisposition asset changes --- docs/release-notes.md | 3 ++- src/SMAPI/Metadata/CoreAssetPropagator.cs | 33 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index c2b58cd2..cfcaf65c 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -6,7 +6,8 @@ * Fixed Console Commands' handling of tool upgrade levels for item commands. * For modders: - * Reloading a map asset will now automatically update affected locations. + * Reloading a map asset will now update affected locations. + * Reloading the `Data\NPCDispositions` asset will now update affected NPCs. * Fixed newlines in most manifest fields not being ignored. * For the web UI: diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs index 841e6d64..8083b4b1 100644 --- a/src/SMAPI/Metadata/CoreAssetPropagator.cs +++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using StardewModdingAPI.Framework.Reflection; using StardewValley; @@ -163,6 +164,9 @@ namespace StardewModdingAPI.Metadata case "data\\craftingrecipes": // CraftingRecipe.InitShared return CraftingRecipe.craftingRecipes = content.Load>(key); + case "data\\npcdispositions": // NPC constructor + return this.ReloadNpcDispositions(content, key); + case "data\\npcgifttastes": // Game1.loadContent return Game1.NPCGiftTastes = content.Load>(key); @@ -482,6 +486,35 @@ namespace StardewModdingAPI.Metadata return true; } + /// Reload the disposition data for matching NPCs. + /// The content manager through which to reload the asset. + /// The asset key to reload. + /// Returns whether any NPCs were affected. + private bool ReloadNpcDispositions(LocalizedContentManager content, string key) + { + IDictionary dispositions = content.Load>(key); + foreach (NPC character in this.GetCharacters()) + { + if (!character.isVillager() || !dispositions.ContainsKey(character.Name)) + continue; + + NPC clone = new NPC(null, Vector2.Zero, 0, character.Name); + character.Age = clone.Age; + character.Manners = clone.Manners; + character.SocialAnxiety = clone.SocialAnxiety; + character.Optimism = clone.Optimism; + character.Gender = clone.Gender; + character.datable.Value = clone.datable.Value; + character.homeRegion = clone.homeRegion; + character.Birthday_Season = clone.Birthday_Season; + character.Birthday_Day = clone.Birthday_Day; + character.id = clone.id; + character.displayName = clone.displayName; + } + + return true; + } + /// Reload the sprites for matching NPCs. /// The content manager through which to reload the asset. /// The asset key to reload. -- cgit