summaryrefslogtreecommitdiff
path: root/src/SMAPI/Metadata
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-07-01 17:37:19 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-07-01 17:37:19 -0400
commitd8ee422405614a9b5d56ae0f42a003835fc57a8c (patch)
tree0b5dbc6f14ce3d9ea5c0553cdafcc037a3eaaefd /src/SMAPI/Metadata
parenteb8ba0576a4e7dc7f6c7963a268297834f501d16 (diff)
downloadSMAPI-d8ee422405614a9b5d56ae0f42a003835fc57a8c.tar.gz
SMAPI-d8ee422405614a9b5d56ae0f42a003835fc57a8c.tar.bz2
SMAPI-d8ee422405614a9b5d56ae0f42a003835fc57a8c.zip
add support for reloading NPC schedules through the content API
Diffstat (limited to 'src/SMAPI/Metadata')
-rw-r--r--src/SMAPI/Metadata/CoreAssetPropagator.cs38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/SMAPI/Metadata/CoreAssetPropagator.cs b/src/SMAPI/Metadata/CoreAssetPropagator.cs
index 7ca0bd82..12abeb10 100644
--- a/src/SMAPI/Metadata/CoreAssetPropagator.cs
+++ b/src/SMAPI/Metadata/CoreAssetPropagator.cs
@@ -325,6 +325,10 @@ namespace StardewModdingAPI.Metadata
if (this.IsInFolder(key, "Portraits"))
return this.ReloadNpcPortraits(content, key);
+ // dynamic data
+ if (this.IsInFolder(key, "Characters\\schedules"))
+ return this.ReloadNpcSchedules(content, key);
+
return false;
}
@@ -333,7 +337,7 @@ namespace StardewModdingAPI.Metadata
** Private methods
*********/
/****
- ** Reload methods
+ ** Reload texture methods
****/
/// <summary>Reload the sprites for matching pets or horses.</summary>
/// <typeparam name="TAnimal">The animal type.</typeparam>
@@ -502,6 +506,38 @@ namespace StardewModdingAPI.Metadata
}
/****
+ ** Reload data methods
+ ****/
+ /// <summary>Reload the schedules 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 assets were reloaded.</returns>
+ private bool ReloadNpcSchedules(LocalizedContentManager content, string key)
+ {
+ // get NPCs
+ string name = Path.GetFileName(key);
+ NPC[] villagers = this.GetCharacters().Where(npc => npc.Name == name && npc.isVillager()).ToArray();
+ if (!villagers.Any())
+ return false;
+
+ // update schedule
+ foreach (NPC villager in villagers)
+ {
+ // reload schedule
+ villager.Schedule = villager.getSchedule(Game1.dayOfMonth);
+
+ // switch to new schedule if needed
+ int lastScheduleTime = villager.Schedule.Keys.Where(p => p <= Game1.timeOfDay).OrderByDescending(p => p).FirstOrDefault();
+ if (lastScheduleTime != 0)
+ {
+ this.Reflection.GetField<int>(villager, "scheduleTimeToTry").SetValue(this.Reflection.GetField<int>(typeof(NPC), "NO_TRY").GetValue()); // use time that's passed in to checkSchedule
+ villager.checkSchedule(lastScheduleTime);
+ }
+ }
+ return true;
+ }
+
+ /****
** Helpers
****/
/// <summary>Reload the texture for an animated sprite.</summary>