summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Inheritance/SGame.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-01-18 21:32:38 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-01-18 21:32:38 -0500
commitb3ff0045722acec9b8c12f5f13dec4f21008d6b8 (patch)
treed7168264bede3cdc4d48f0cb4912cc8c99cee870 /src/StardewModdingAPI/Inheritance/SGame.cs
parent6adf199987a506f8a65f6c1ddfad5aa9fa2a6a9f (diff)
downloadSMAPI-b3ff0045722acec9b8c12f5f13dec4f21008d6b8.tar.gz
SMAPI-b3ff0045722acec9b8c12f5f13dec4f21008d6b8.tar.bz2
SMAPI-b3ff0045722acec9b8c12f5f13dec4f21008d6b8.zip
fix PlayerEvents.LoadedGame and SaveEvents.AfterLoad being fired before the world finishes loading (#216)
Diffstat (limited to 'src/StardewModdingAPI/Inheritance/SGame.cs')
-rw-r--r--src/StardewModdingAPI/Inheritance/SGame.cs23
1 files changed, 11 insertions, 12 deletions
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