diff options
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r-- | src/StardewModdingAPI/Events/TimeEvents.cs | 14 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/SGame.cs | 4 |
2 files changed, 16 insertions, 2 deletions
diff --git a/src/StardewModdingAPI/Events/TimeEvents.cs b/src/StardewModdingAPI/Events/TimeEvents.cs index dedd7e77..a140a223 100644 --- a/src/StardewModdingAPI/Events/TimeEvents.cs +++ b/src/StardewModdingAPI/Events/TimeEvents.cs @@ -9,10 +9,13 @@ namespace StardewModdingAPI.Events /********* ** Events *********/ + /// <summary>Raised after the game begins a new day, including when loading a save.</summary> + public static event EventHandler AfterDayStarted; + /// <summary>Raised after the in-game clock changes.</summary> public static event EventHandler<EventArgsIntChanged> TimeOfDayChanged; - /// <summary>Raised after the day-of-month value changes, including when loading a save (unlike <see cref="OnNewDay"/>).</summary> + /// <summary>Raised after the day-of-month value changes, including when loading a save. This may happen before save; in most cases you should use <see cref="AfterDayStarted"/> instead.</summary> public static event EventHandler<EventArgsIntChanged> DayOfMonthChanged; /// <summary>Raised after the year value changes.</summary> @@ -22,13 +25,20 @@ namespace StardewModdingAPI.Events public static event EventHandler<EventArgsStringChanged> SeasonOfYearChanged; /// <summary>Raised when the player is transitioning to a new day and the game is performing its day update logic. This event is triggered twice: once after the game starts transitioning, and again after it finishes.</summary> - [Obsolete("Use " + nameof(TimeEvents) + "." + nameof(DayOfMonthChanged) + " or " + nameof(SaveEvents) + " instead")] + [Obsolete("Use " + nameof(TimeEvents) + "." + nameof(TimeEvents.AfterDayStarted) + " or " + nameof(SaveEvents) + " instead")] public static event EventHandler<EventArgsNewDay> OnNewDay; /********* ** Internal methods *********/ + /// <summary>Raise an <see cref="AfterDayStarted"/> event.</summary> + /// <param name="monitor">Encapsulates monitoring and logging.</param> + internal static void InvokeAfterDayStarted(IMonitor monitor) + { + monitor.SafelyRaisePlainEvent($"{nameof(TimeEvents)}.{nameof(TimeEvents.AfterDayStarted)}", TimeEvents.AfterDayStarted?.GetInvocationList(), null, EventArgs.Empty); + } + /// <summary>Raise a <see cref="InvokeDayOfMonthChanged"/> event.</summary> /// <param name="monitor">Encapsulates monitoring and logging.</param> /// <param name="priorTime">The previous time in military time format (e.g. 6:00pm is 1800).</param> diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs index 55e7ff1a..83af62e0 100644 --- a/src/StardewModdingAPI/Framework/SGame.cs +++ b/src/StardewModdingAPI/Framework/SGame.cs @@ -1120,6 +1120,7 @@ namespace StardewModdingAPI.Framework { SaveEvents.InvokeAfterLoad(this.Monitor); PlayerEvents.InvokeLoadedGame(this.Monitor, new EventArgsLoadedGameChanged(Game1.hasLoadedGame)); + TimeEvents.InvokeAfterDayStarted(this.Monitor); } this.AfterLoadTimer--; } @@ -1200,7 +1201,10 @@ namespace StardewModdingAPI.Framework if (newMenu is SaveGameMenu || newMenu is ShippingMenu) SaveEvents.InvokeBeforeSave(this.Monitor); else if (previousMenu is SaveGameMenu || previousMenu is ShippingMenu) + { SaveEvents.InvokeAfterSave(this.Monitor); + TimeEvents.InvokeAfterDayStarted(this.Monitor); + } // raise menu events if (newMenu != null) |