diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-01-21 02:14:28 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-01-21 02:14:28 -0500 |
commit | d76476ca687a4936cc610380e2b3902db137bced (patch) | |
tree | c83550f3a86bad69471c72125d2d448d19abd17b /src/SMAPI/Framework | |
parent | b3318af7d0e40462563e6d98c0c15fac48bb6770 (diff) | |
download | SMAPI-d76476ca687a4936cc610380e2b3902db137bced.tar.gz SMAPI-d76476ca687a4936cc610380e2b3902db137bced.tar.bz2 SMAPI-d76476ca687a4936cc610380e2b3902db137bced.zip |
add before/after save creation events (#429)
This supports mods like Custom Farm Types that need to intercept the very first save, which doesn't raise the normal save events since the world isn't fully initialised yet.
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r-- | src/SMAPI/Framework/SGame.cs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 2eb2da99..e82ee778 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -51,6 +51,9 @@ namespace StardewModdingAPI.Framework /// <summary>Whether the game is saving and SMAPI has already raised <see cref="SaveEvents.BeforeSave"/>.</summary> private bool IsBetweenSaveEvents; + /// <summary>Whether the game is creating the save file and SMAPI has already raised <see cref="SaveEvents.BeforeCreate"/>.</summary> + private bool IsBetweenCreateEvents; + /**** ** Game state ****/ @@ -246,6 +249,14 @@ namespace StardewModdingAPI.Framework // opened (since the save hasn't started yet), but all other events should be suppressed. if (Context.IsSaving) { + // raise before-create + if (!Context.IsWorldReady && !this.IsBetweenCreateEvents) + { + this.IsBetweenCreateEvents = true; + this.Monitor.Log("Context: before save creation.", LogLevel.Trace); + SaveEvents.InvokeBeforeCreate(this.Monitor); + } + // raise before-save if (Context.IsWorldReady && !this.IsBetweenSaveEvents) { @@ -258,6 +269,13 @@ namespace StardewModdingAPI.Framework base.Update(gameTime); return; } + if (this.IsBetweenCreateEvents) + { + // raise after-create + this.IsBetweenCreateEvents = false; + this.Monitor.Log($"Context: after save creation, starting {Game1.currentSeason} {Game1.dayOfMonth} Y{Game1.year}.", LogLevel.Trace); + SaveEvents.InvokeAfterCreated(this.Monitor); + } if (this.IsBetweenSaveEvents) { // raise after-save |