Fixed custom serialization issues for FarmHands

This commit is contained in:
2018-08-08 09:32:02 -07:00
parent 36b33af55b
commit 1888ad5fa7
1 changed files with 36 additions and 0 deletions

View File

@ -31,6 +31,8 @@ namespace StardustCore
public static Multiplayer multiplayer;
bool serverHack;
private Type lastMenuType;
public static string ContentDirectory;
public override void Entry(IModHelper helper)
{
@ -49,6 +51,8 @@ namespace StardustCore
StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave;
StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave;
StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad;
StardewModdingAPI.Events.MenuEvents.MenuChanged += MenuEvents_MenuChanged;
StardewModdingAPI.Events.MenuEvents.MenuClosed += MenuEvents_MenuClosed;
IlluminateFramework.Colors.initializeColors();
ContentDirectory = Path.Combine(ModHelper.DirectoryPath, "Content");
@ -67,6 +71,38 @@ namespace StardustCore
}
private void MenuEvents_MenuClosed(object sender, StardewModdingAPI.Events.EventArgsClickableMenuClosed e)
{
if (Game1.IsMasterGame == false)
{
if (this.lastMenuType == null)
{
return;
}
else
{
if (lastMenuType == typeof(StardewValley.Menus.SaveGameMenu) ||lastMenuType==typeof(StardewValley.Menus.ReadyCheckDialog))
{
SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList);
}
}
}
}
private void MenuEvents_MenuChanged(object sender, StardewModdingAPI.Events.EventArgsClickableMenuChanged e)
{
if (Game1.IsMasterGame == false)
{
if (Game1.activeClickableMenu.GetType() == typeof(StardewValley.Menus.ReadyCheckDialog))
{
SerializationManager.cleanUpInventory();
SerializationManager.cleanUpWorld();
SerializationManager.cleanUpStorageContainers();
}
}
lastMenuType = Game1.activeClickableMenu.GetType();
}
/// <summary>
/// Returns the value of the data snagged by reflection.
/// </summary>