summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-10-01 21:41:15 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-10-01 21:41:15 -0400
commit65997c1243a60ae15cc0b832ebcd41d96c3ea06a (patch)
tree4b55e07011ed3144d6a996821ddc1886f35de83f /src/SMAPI/Framework
parent845deb43d60147603ec31fe4ae5fd7d747556d8c (diff)
downloadSMAPI-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')
-rw-r--r--src/SMAPI/Framework/SCore.cs2
-rw-r--r--src/SMAPI/Framework/SGame.cs19
2 files changed, 20 insertions, 1 deletions
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index bd131762..bfdf1c51 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -245,7 +245,7 @@ namespace StardewModdingAPI.Framework
new DialogueErrorPatch(this.MonitorForGame, this.Reflection),
new ObjectErrorPatch(),
new LoadContextPatch(this.Reflection, this.GameInstance.OnLoadStageChanged),
- new LoadErrorPatch(this.Monitor)
+ new LoadErrorPatch(this.Monitor, this.GameInstance.OnSaveContentRemoved)
);
// add exit handler
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
*********/
{