diff --git a/GeneralMods/SaveAnywhere/Framework/NewSaveMenu.cs b/GeneralMods/SaveAnywhere/Framework/NewSaveMenu.cs
new file mode 100644
index 00000000..38180dd1
--- /dev/null
+++ b/GeneralMods/SaveAnywhere/Framework/NewSaveMenu.cs
@@ -0,0 +1,7 @@
+using StardewValley.Menus;
+
+namespace Omegasis.SaveAnywhere.Framework
+{
+ /// A marker subclass to detect when a custom save is in progress.
+ internal class NewSaveGameMenu : SaveGameMenu { }
+}
diff --git a/GeneralMods/SaveAnywhere/Framework/SaveManager.cs b/GeneralMods/SaveAnywhere/Framework/SaveManager.cs
index 5a70a922..4fa3c957 100644
--- a/GeneralMods/SaveAnywhere/Framework/SaveManager.cs
+++ b/GeneralMods/SaveAnywhere/Framework/SaveManager.cs
@@ -71,11 +71,17 @@ namespace Omegasis.SaveAnywhere.Framework
// perform passive save
if (this.WaitingToSave && Game1.activeClickableMenu == null)
{
- Game1.activeClickableMenu = new SaveGameMenu();
+ Game1.activeClickableMenu = new NewSaveGameMenu();
this.WaitingToSave = false;
}
}
+ /// Clear saved data.
+ public void ClearData()
+ {
+ Directory.Delete(this.SavePath, recursive: true);
+ }
+
/// Save all game data.
public void SaveGameAndPositions()
{
@@ -89,7 +95,7 @@ namespace Omegasis.SaveAnywhere.Framework
this.WaitingToSave = true;
}
else
- Game1.activeClickableMenu = new SaveGameMenu();
+ Game1.activeClickableMenu = new NewSaveGameMenu();
// save custom data
Directory.CreateDirectory(this.SaveAnimalsPath);
diff --git a/GeneralMods/SaveAnywhere/README.md b/GeneralMods/SaveAnywhere/README.md
index a6728e4d..8471ae15 100644
--- a/GeneralMods/SaveAnywhere/README.md
+++ b/GeneralMods/SaveAnywhere/README.md
@@ -37,4 +37,5 @@ Press `K` to save anywhere. Edit `Save_Anywhere_Config.txt` to configure the key
2.5:
* Updated for SMAPI 2.0.
+* Fixed issue where reloading after a sleep save restored some data from your last non-sleep save.
* Internal refactoring.
diff --git a/GeneralMods/SaveAnywhere/SaveAnywhere.cs b/GeneralMods/SaveAnywhere/SaveAnywhere.cs
index d5fe131c..a2c18754 100644
--- a/GeneralMods/SaveAnywhere/SaveAnywhere.cs
+++ b/GeneralMods/SaveAnywhere/SaveAnywhere.cs
@@ -27,6 +27,8 @@ namespace Omegasis.SaveAnywhere
/// Whether villager schedules should be reset now.
private bool ShouldResetSchedules;
+ /// Whether we're performing a non-vanilla save (i.e. not by sleeping in bed).
+ private bool IsCustomSaving;
/*********
@@ -39,6 +41,8 @@ namespace Omegasis.SaveAnywhere
this.ConfigUtilities = new ConfigUtilities(this.Helper.DirectoryPath);
SaveEvents.AfterLoad += this.SaveEvents_AfterLoad;
+ SaveEvents.AfterSave += this.SaveEvents_AfterSave;
+ MenuEvents.MenuChanged += this.MenuEvents_MenuChanged;
ControlEvents.KeyPressed += this.ControlEvents_KeyPressed;
GameEvents.UpdateTick += this.GameEvents_UpdateTick;
TimeEvents.AfterDayStarted += this.TimeEvents_AfterDayStarted;
@@ -54,6 +58,7 @@ namespace Omegasis.SaveAnywhere
private void SaveEvents_AfterLoad(object sender, EventArgs e)
{
// reset state
+ this.IsCustomSaving = false;
this.ShouldResetSchedules = false;
// load config
@@ -65,6 +70,24 @@ namespace Omegasis.SaveAnywhere
this.SaveManager.LoadPositions();
}
+ /// The method invoked after the player finishes saving.
+ /// The event sender.
+ /// The event data.
+ private void SaveEvents_AfterSave(object sender, EventArgs e)
+ {
+ // clear custom data after a normal save (to avoid restoring old state)
+ if (!this.IsCustomSaving)
+ this.SaveManager.ClearData();
+ }
+
+ /// The method invoked after a menu is opened or changed.
+ /// The event sender.
+ /// The event data.
+ private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
+ {
+ this.IsCustomSaving = e.NewMenu != null && (e.NewMenu is NewSaveGameMenu || e.NewMenu is NewSaveGameMenu);
+ }
+
/// The method invoked when the game updates (roughly 60 times per second).
/// The event sender.
/// The event data.
diff --git a/GeneralMods/SaveAnywhere/SaveAnywhere.csproj b/GeneralMods/SaveAnywhere/SaveAnywhere.csproj
index f3c289bb..f11c21ba 100644
--- a/GeneralMods/SaveAnywhere/SaveAnywhere.csproj
+++ b/GeneralMods/SaveAnywhere/SaveAnywhere.csproj
@@ -37,6 +37,7 @@
Properties\GlobalAssemblyInfo.cs
+