diff options
-rw-r--r-- | release-notes.md | 6 | ||||
-rw-r--r-- | src/StardewModdingAPI/Inheritance/SGame.cs | 23 |
2 files changed, 17 insertions, 12 deletions
diff --git a/release-notes.md b/release-notes.md index 6945a71a..4e91ee2e 100644 --- a/release-notes.md +++ b/release-notes.md @@ -1,5 +1,11 @@ # Release notes +## 1.7 +See [log](https://github.com/Pathoschild/SMAPI/compare/1.6...1.7). + +For mod developers: +* Fixed `PlayerEvents.LoadedGame` and `SaveEvents.AfterLoad` being fired before the world finishes initialising. + ## 1.6 See [log](https://github.com/Pathoschild/SMAPI/compare/1.5...1.6). diff --git a/src/StardewModdingAPI/Inheritance/SGame.cs b/src/StardewModdingAPI/Inheritance/SGame.cs index 8e87bac6..28c2aa42 100644 --- a/src/StardewModdingAPI/Inheritance/SGame.cs +++ b/src/StardewModdingAPI/Inheritance/SGame.cs @@ -24,8 +24,9 @@ namespace StardewModdingAPI.Inheritance /********* ** Properties *********/ - /// <summary>Whether to raise <see cref="PlayerEvents.LoadedGame"/> on the next tick.</summary> - private bool FireLoadedGameEvent; + /// <summary>The number of ticks until SMAPI should notify mods when <see cref="Game1.hasLoadedGame"/> is set.</summary> + /// <remarks>Skipping a few frames ensures the game finishes initialising the world before mods try to change it.</remarks> + private int AfterLoadTimer = 5; /// <summary>The debug messages to add to the next debug output.</summary> internal static Queue<string> DebugMessageQueue { get; private set; } @@ -1028,17 +1029,15 @@ namespace StardewModdingAPI.Inheritance this.PreviousYearOfGame = Game1.year; } - // raise player loaded save (in the following tick to let the game finish updating first) - if (this.FireLoadedGameEvent) + // raise save loaded + if (Game1.hasLoadedGame && this.AfterLoadTimer >= 0) { - SaveEvents.InvokeAfterLoad(this.Monitor); - PlayerEvents.InvokeLoadedGame(this.Monitor, new EventArgsLoadedGameChanged(Game1.hasLoadedGame)); - this.FireLoadedGameEvent = false; - } - if (Game1.hasLoadedGame != this.PreviouslyLoadedGame) - { - this.FireLoadedGameEvent = true; - this.PreviouslyLoadedGame = Game1.hasLoadedGame; + if (this.AfterLoadTimer == 0) + { + SaveEvents.InvokeAfterLoad(this.Monitor); + PlayerEvents.InvokeLoadedGame(this.Monitor, new EventArgsLoadedGameChanged(Game1.hasLoadedGame)); + } + this.AfterLoadTimer--; } // raise mine level changed |