diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-10-01 21:41:15 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-10-01 21:41:15 -0400 |
commit | 65997c1243a60ae15cc0b832ebcd41d96c3ea06a (patch) | |
tree | 4b55e07011ed3144d6a996821ddc1886f35de83f /src/SMAPI/Framework/SGame.cs | |
parent | 845deb43d60147603ec31fe4ae5fd7d747556d8c (diff) | |
download | SMAPI-65997c1243a60ae15cc0b832ebcd41d96c3ea06a.tar.gz SMAPI-65997c1243a60ae15cc0b832ebcd41d96c3ea06a.tar.bz2 SMAPI-65997c1243a60ae15cc0b832ebcd41d96c3ea06a.zip |
auto-fix save data when a custom location mod is removed
Diffstat (limited to 'src/SMAPI/Framework/SGame.cs')
-rw-r--r-- | src/SMAPI/Framework/SGame.cs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 89705352..13858fc5 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -65,6 +65,9 @@ namespace StardewModdingAPI.Framework /// <remarks>Skipping a few frames ensures the game finishes initializing the world before mods try to change it.</remarks> private readonly Countdown AfterLoadTimer = new Countdown(5); + /// <summary>Whether custom content was removed from the save data to avoid a crash.</summary> + private bool IsSaveContentRemoved; + /// <summary>Whether the game is saving and SMAPI has already raised <see cref="IGameLoopEvents.Saving"/>.</summary> private bool IsBetweenSaveEvents; @@ -216,6 +219,12 @@ namespace StardewModdingAPI.Framework this.Events.ModMessageReceived.RaiseForMods(new ModMessageReceivedEventArgs(message), mod => mod != null && modIDs.Contains(mod.Manifest.UniqueID)); } + /// <summary>A callback invoked when custom content is removed from the save data to avoid a crash.</summary> + internal void OnSaveContentRemoved() + { + this.IsSaveContentRemoved = true; + } + /// <summary>A callback invoked when the game's low-level load stage changes.</summary> /// <param name="newStage">The new load stage.</param> internal void OnLoadStageChanged(LoadStage newStage) @@ -458,6 +467,16 @@ namespace StardewModdingAPI.Framework WatcherSnapshot state = this.WatcherSnapshot; /********* + ** Display in-game warnings + *********/ + // save content removed + if (this.IsSaveContentRemoved && Context.IsWorldReady) + { + this.IsSaveContentRemoved = false; + Game1.addHUDMessage(new HUDMessage(this.Translator.Get("warn.invalid-content-removed"), HUDMessage.error_type)); + } + + /********* ** Pre-update events *********/ { |