diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-11-25 15:19:12 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2018-11-25 15:19:12 -0500 |
commit | 924c3a5d3fe6bfad483834112883156bdf202b57 (patch) | |
tree | 0eb1d2408dd2b0098e8bbd9e48804de44bfbef76 | |
parent | 0dc653e5afd0225e3c54756b89f642e127593d9a (diff) | |
download | SMAPI-924c3a5d3fe6bfad483834112883156bdf202b57.tar.gz SMAPI-924c3a5d3fe6bfad483834112883156bdf202b57.tar.bz2 SMAPI-924c3a5d3fe6bfad483834112883156bdf202b57.zip |
add support for propagating NPCDisposition asset changes
-rw-r--r-- | docs/release-notes.md | 3 | ||||
-rw-r--r-- | src/SMAPI/Metadata/CoreAssetPropagator.cs | 33 |
2 files changed, 35 insertions, 1 deletions
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<Dictionary<string, string>>(key); + case "data\\npcdispositions": // NPC constructor + return this.ReloadNpcDispositions(content, key); + case "data\\npcgifttastes": // Game1.loadContent return Game1.NPCGiftTastes = content.Load<Dictionary<string, string>>(key); @@ -482,6 +486,35 @@ namespace StardewModdingAPI.Metadata return true; } + /// <summary>Reload the disposition data 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> + /// <returns>Returns whether any NPCs were affected.</returns> + private bool ReloadNpcDispositions(LocalizedContentManager content, string key) + { + IDictionary<string, string> dispositions = content.Load<Dictionary<string, string>>(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; + } + /// <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> |