diff options
-rw-r--r-- | src/SMAPI/Events/DayEndingEventArgs.cs | 7 | ||||
-rw-r--r-- | src/SMAPI/Events/IGameLoopEvents.cs | 3 | ||||
-rw-r--r-- | src/SMAPI/Framework/Events/EventManager.cs | 4 | ||||
-rw-r--r-- | src/SMAPI/Framework/Events/ModGameLoopEvents.cs | 7 | ||||
-rw-r--r-- | src/SMAPI/Framework/SGame.cs | 7 | ||||
-rw-r--r-- | src/SMAPI/Framework/SModHooks.cs | 34 | ||||
-rw-r--r-- | src/SMAPI/StardewModdingAPI.csproj | 1 |
7 files changed, 63 insertions, 0 deletions
diff --git a/src/SMAPI/Events/DayEndingEventArgs.cs b/src/SMAPI/Events/DayEndingEventArgs.cs new file mode 100644 index 00000000..5cb433bc --- /dev/null +++ b/src/SMAPI/Events/DayEndingEventArgs.cs @@ -0,0 +1,7 @@ +using System; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for an <see cref="IGameLoopEvents.DayEnding"/> event.</summary> + public class DayEndingEventArgs : EventArgs { } +} diff --git a/src/SMAPI/Events/IGameLoopEvents.cs b/src/SMAPI/Events/IGameLoopEvents.cs index 165aa0ce..5f531ba7 100644 --- a/src/SMAPI/Events/IGameLoopEvents.cs +++ b/src/SMAPI/Events/IGameLoopEvents.cs @@ -31,5 +31,8 @@ namespace StardewModdingAPI.Events /// <summary>Raised after the game begins a new day (including when the player loads a save).</summary> event EventHandler<DayStartedEventArgs> DayStarted; + + /// <summary>Raised before the game ends the current day. This happens before it starts setting up the next day and before <see cref="Saving"/>.</summary> + event EventHandler<DayEndingEventArgs> DayEnding; } } diff --git a/src/SMAPI/Framework/Events/EventManager.cs b/src/SMAPI/Framework/Events/EventManager.cs index 023c45de..616db7d9 100644 --- a/src/SMAPI/Framework/Events/EventManager.cs +++ b/src/SMAPI/Framework/Events/EventManager.cs @@ -41,6 +41,9 @@ namespace StardewModdingAPI.Framework.Events /// <summary>Raised after the game begins a new day, including when loading a save.</summary> public readonly ManagedEvent<DayStartedEventArgs> DayStarted; + /// <summary>Raised before the game ends the current day. This happens before it starts setting up the next day and before <see cref="Saving"/>.</summary> + public readonly ManagedEvent<DayEndingEventArgs> DayEnding; + /**** ** Input ****/ @@ -291,6 +294,7 @@ namespace StardewModdingAPI.Framework.Events this.Saved = ManageEventOf<SavedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.Saved)); this.SaveLoaded = ManageEventOf<SaveLoadedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.SaveLoaded)); this.DayStarted = ManageEventOf<DayStartedEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.DayStarted)); + this.DayEnding = ManageEventOf<DayEndingEventArgs>(nameof(IModEvents.GameLoop), nameof(IGameLoopEvents.DayEnding)); this.ButtonPressed = ManageEventOf<ButtonPressedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonPressed)); this.ButtonReleased = ManageEventOf<ButtonReleasedEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.ButtonReleased)); diff --git a/src/SMAPI/Framework/Events/ModGameLoopEvents.cs b/src/SMAPI/Framework/Events/ModGameLoopEvents.cs index cf7e54aa..d1def91b 100644 --- a/src/SMAPI/Framework/Events/ModGameLoopEvents.cs +++ b/src/SMAPI/Framework/Events/ModGameLoopEvents.cs @@ -72,6 +72,13 @@ namespace StardewModdingAPI.Framework.Events remove => this.EventManager.DayStarted.Remove(value); } + /// <summary>Raised before the game ends the current day. This happens before it starts setting up the next day and before <see cref="IGameLoopEvents.Saving"/>.</summary> + public event EventHandler<DayEndingEventArgs> DayEnding + { + add => this.EventManager.DayEnding.Add(value); + remove => this.EventManager.DayEnding.Remove(value); + } + /********* ** Public methods diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index ef851afc..bd266ce1 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -151,6 +151,7 @@ namespace StardewModdingAPI.Framework this.OnGameExiting = onGameExiting; Game1.input = new SInputState(); Game1.multiplayer = new SMultiplayer(monitor, eventManager); + Game1.hooks = new SModHooks(this.OnNewDayAfterFade); // init observables Game1.locations = new ObservableCollection<GameLocation>(); @@ -182,6 +183,12 @@ namespace StardewModdingAPI.Framework /**** ** Intercepted methods & events ****/ + /// <summary>A callback invoked before <see cref="Game1.newDayAfterFade"/> runs.</summary> + protected void OnNewDayAfterFade() + { + this.Events.DayEnding.RaiseEmpty(); + } + /// <summary>Constructor a content manager to read XNB files.</summary> /// <param name="serviceProvider">The service provider to use to locate services.</param> /// <param name="rootDirectory">The root directory to search for content.</param> diff --git a/src/SMAPI/Framework/SModHooks.cs b/src/SMAPI/Framework/SModHooks.cs new file mode 100644 index 00000000..9f0201c8 --- /dev/null +++ b/src/SMAPI/Framework/SModHooks.cs @@ -0,0 +1,34 @@ +using System; +using StardewValley; + +namespace StardewModdingAPI.Framework +{ + /// <summary>Invokes callbacks for mod hooks provided by the game.</summary> + internal class SModHooks : ModHooks + { + /********* + ** Properties + *********/ + /// <summary>A callback to invoke before <see cref="Game1.newDayAfterFade"/> runs.</summary> + private readonly Action BeforeNewDayAfterFade; + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="beforeNewDayAfterFade">A callback to invoke before <see cref="Game1.newDayAfterFade"/> runs.</param> + public SModHooks(Action beforeNewDayAfterFade) + { + this.BeforeNewDayAfterFade = beforeNewDayAfterFade; + } + + /// <summary>A hook invoked when <see cref="Game1.newDayAfterFade"/> is called.</summary> + /// <param name="action">The vanilla <see cref="Game1.newDayAfterFade"/> logic.</param> + public override void OnGame1_NewDayAfterFade(Action action) + { + this.BeforeNewDayAfterFade?.Invoke(); + action(); + } + } +} diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 4c8f2ffa..efb85c52 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -79,6 +79,7 @@ <Compile Include="..\..\build\GlobalAssemblyInfo.cs"> <Link>Properties\GlobalAssemblyInfo.cs</Link> </Compile> + <Compile Include="Events\DayEndingEventArgs.cs" /> <Compile Include="Events\DayStartedEventArgs.cs" /> <Compile Include="Events\SaveCreatingEventArgs.cs" /> <Compile Include="Events\SavedEventArgs.cs" /> |