From 68bfaa38c932b3c5d555f02d423b10277e881d68 Mon Sep 17 00:00:00 2001 From: JoshuaNavarro Date: Sun, 22 Sep 2019 11:49:25 -0700 Subject: [PATCH] Fixed tools serialization. Also made modded tools able to be trashed. --- .../Objects/Items/Tools/AxeExtended.cs | 61 ++++++++++++------- .../Framework/Objects/Items/Tools/Chainsaw.cs | 51 +++++++++++++--- .../Objects/Items/Tools/HoeExtended.cs | 61 ++++++++++++------- .../Objects/Items/Tools/MiningDrill.cs | 23 ++++++- .../Objects/Items/Tools/PickaxeExtended.cs | 56 ++++++++++++----- .../Items/Tools/WateringCanExtended.cs | 61 ++++++++++++------- 6 files changed, 221 insertions(+), 92 deletions(-) diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs index ec68f1a9..fdc621a2 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/AxeExtended.cs @@ -10,12 +10,13 @@ using PyTK.CustomElementHandler; using Revitalize.Framework.Objects.Interfaces; using Revitalize.Framework.Utilities; using StardewValley; +using StardewValley.Objects; using StardewValley.Tools; using StardustCore.UIUtilities; namespace Revitalize.Framework.Objects.Items.Tools { - public class AxeExtended: StardewValley.Tools.Axe, ISaveElement, IItemInfo + public class AxeExtended: StardewValley.Tools.Axe, ISaveElement, IItemInfo,ICustomObject { public BasicItemInformation info; public Texture2DExtended workingTexture; @@ -194,15 +195,6 @@ namespace Revitalize.Framework.Objects.Items.Tools //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, color, drawShadow); } - public Dictionary getAdditionalSaveData() - { - Dictionary serializedInfo = new Dictionary(); - serializedInfo.Add("id", this.ItemInfo); - serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); - Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); - return serializedInfo; - } - public override bool beginUsing(GameLocation location, int x, int y, Farmer who) { this.updateInfo(); @@ -247,17 +239,6 @@ namespace Revitalize.Framework.Objects.Items.Tools return new AxeExtended(this.info.Copy(), this.UpgradeLevel, this.workingTexture.Copy()); } - public virtual object getReplacement() - { - return new StardewValley.Tools.Axe { UpgradeLevel = this.UpgradeLevel }; - } - - public virtual void rebuild(Dictionary additionalSaveData, object replacement) - { - this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); - this.upgradeLevel.Value = (replacement as Axe).UpgradeLevel; - } - /// /// Updates the info on the item. @@ -301,5 +282,43 @@ namespace Revitalize.Framework.Objects.Items.Tools return false; } } + public virtual ICustomObject recreate(Dictionary additionalSaveData, object replacement) + { + AxeExtended p = Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); + return p; + } + public virtual Dictionary getAdditionalSaveData() + { + Dictionary serializedInfo = new Dictionary(); + serializedInfo.Add("id", this.ItemInfo); + serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); + serializedInfo.Add("GUID", this.guid.ToString()); + serializedInfo.Add("Level", this.UpgradeLevel.ToString()); + Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); + return serializedInfo; + } + + public virtual object getReplacement() + { + Chest c = new Chest(true); + c.playerChoiceColor.Value = Color.Magenta; + c.TileLocation = new Vector2(0, 0); + return c; + } + + public virtual void rebuild(Dictionary additionalSaveData, object replacement) + { + //ModCore.log("REBULD THE PICKAXE!!!!!!!"); + this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); + this.UpgradeLevel = Convert.ToInt32(additionalSaveData["Level"]); + //this.upgradeLevel.Value = (replacement as Pickaxe).UpgradeLevel; + + } + + public override bool canBeTrashed() + { + return base.canBeTrashed(); + } + } } diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/Chainsaw.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/Chainsaw.cs index d55b89d0..effaf242 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/Chainsaw.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/Chainsaw.cs @@ -7,9 +7,11 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Netcode; using Newtonsoft.Json; +using PyTK.CustomElementHandler; using Revitalize.Framework.Energy; using Revitalize.Framework.Utilities; using StardewValley; +using StardewValley.Objects; using StardewValley.Tools; using StardustCore.UIUtilities; using xTile.ObjectModel; @@ -234,16 +236,6 @@ namespace Revitalize.Framework.Objects.Items.Tools return new Chainsaw(this.info.Copy(), this.UpgradeLevel, this.workingTexture.Copy()); } - public override object getReplacement() - { - return new StardewValley.Tools.Axe { UpgradeLevel = this.UpgradeLevel }; - } - - public override void rebuild(Dictionary additionalSaveData, object replacement) - { - this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); - this.upgradeLevel.Value = (replacement as Axe).UpgradeLevel; - } private int getEnergyConsumptionRate() { @@ -259,5 +251,44 @@ namespace Revitalize.Framework.Objects.Items.Tools { this.info.EnergyManager = Manager; } + + + public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) + { + Chainsaw p = Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); + return p; + } + public override Dictionary getAdditionalSaveData() + { + Dictionary serializedInfo = new Dictionary(); + serializedInfo.Add("id", this.ItemInfo); + serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); + serializedInfo.Add("GUID", this.guid.ToString()); + serializedInfo.Add("Level", this.UpgradeLevel.ToString()); + Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); + return serializedInfo; + } + + public override object getReplacement() + { + Chest c = new Chest(true); + c.playerChoiceColor.Value = Color.Magenta; + c.TileLocation = new Vector2(0, 0); + return c; + } + + public override void rebuild(Dictionary additionalSaveData, object replacement) + { + //ModCore.log("REBULD THE PICKAXE!!!!!!!"); + this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); + this.UpgradeLevel = Convert.ToInt32(additionalSaveData["Level"]); + //this.upgradeLevel.Value = (replacement as Pickaxe).UpgradeLevel; + + } + + public override bool canBeTrashed() + { + return base.canBeTrashed(); + } } } diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/HoeExtended.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/HoeExtended.cs index c1137f4f..3320b97e 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/HoeExtended.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/HoeExtended.cs @@ -10,12 +10,13 @@ using PyTK.CustomElementHandler; using Revitalize.Framework.Objects.Interfaces; using Revitalize.Framework.Utilities; using StardewValley; +using StardewValley.Objects; using StardewValley.Tools; using StardustCore.UIUtilities; namespace Revitalize.Framework.Objects.Items.Tools { - public class HoeExtended: StardewValley.Tools.Hoe, ISaveElement, IItemInfo + public class HoeExtended: StardewValley.Tools.Hoe, ISaveElement, IItemInfo,ICustomObject { public BasicItemInformation info; public Texture2DExtended workingTexture; @@ -194,15 +195,6 @@ namespace Revitalize.Framework.Objects.Items.Tools //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, color, drawShadow); } - public Dictionary getAdditionalSaveData() - { - Dictionary serializedInfo = new Dictionary(); - serializedInfo.Add("id", this.ItemInfo); - serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); - Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); - return serializedInfo; - } - public override bool beginUsing(GameLocation location, int x, int y, Farmer who) { this.updateInfo(); @@ -247,17 +239,6 @@ namespace Revitalize.Framework.Objects.Items.Tools return new HoeExtended(this.info.Copy(), this.UpgradeLevel, this.workingTexture.Copy()); } - public object getReplacement() - { - return new StardewValley.Tools.Hoe { UpgradeLevel = this.UpgradeLevel }; - } - - public void rebuild(Dictionary additionalSaveData, object replacement) - { - this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); - this.upgradeLevel.Value = (replacement as Hoe).UpgradeLevel; - } - /// /// Updates the info on the item. @@ -301,5 +282,43 @@ namespace Revitalize.Framework.Objects.Items.Tools return false; } } + + + public virtual ICustomObject recreate(Dictionary additionalSaveData, object replacement) + { + HoeExtended p = Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); + return p; + } + public Dictionary getAdditionalSaveData() + { + Dictionary serializedInfo = new Dictionary(); + serializedInfo.Add("id", this.ItemInfo); + serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); + serializedInfo.Add("GUID", this.guid.ToString()); + serializedInfo.Add("Level", this.UpgradeLevel.ToString()); + Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); + return serializedInfo; + } + + public virtual object getReplacement() + { + Chest c = new Chest(true); + c.playerChoiceColor.Value = Color.Magenta; + c.TileLocation = new Vector2(0, 0); + return c; + } + + public virtual void rebuild(Dictionary additionalSaveData, object replacement) + { + //ModCore.log("REBULD THE PICKAXE!!!!!!!"); + this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); + this.UpgradeLevel = Convert.ToInt32(additionalSaveData["Level"]); + //this.upgradeLevel.Value = (replacement as Pickaxe).UpgradeLevel; + + } + public override bool canBeTrashed() + { + return base.canBeTrashed(); + } } } diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/MiningDrill.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/MiningDrill.cs index b2bead1e..9da0a860 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/MiningDrill.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/MiningDrill.cs @@ -7,9 +7,11 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Netcode; using Newtonsoft.Json; +using PyTK.CustomElementHandler; using Revitalize.Framework.Energy; using Revitalize.Framework.Utilities; using StardewValley; +using StardewValley.Objects; using StardewValley.Tools; using StardustCore.UIUtilities; @@ -362,13 +364,25 @@ namespace Revitalize.Framework.Objects.Items.Tools public override object getReplacement() { - return new StardewValley.Tools.Pickaxe { UpgradeLevel = this.UpgradeLevel }; + Chest c = new Chest(true); + c.playerChoiceColor.Value = Color.Magenta; + c.TileLocation = new Vector2(0, 0); + return c; } public override void rebuild(Dictionary additionalSaveData, object replacement) { + //ModCore.log("REBULD THE PICKAXE!!!!!!!"); this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); - this.upgradeLevel.Value = (replacement as Pickaxe).UpgradeLevel; + this.UpgradeLevel = Convert.ToInt32(additionalSaveData["Level"]); + //this.upgradeLevel.Value = (replacement as Pickaxe).UpgradeLevel; + + } + + public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) + { + MiningDrill p = Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); + return p; } @@ -386,5 +400,10 @@ namespace Revitalize.Framework.Objects.Items.Tools { this.info.EnergyManager = Manager; } + + public override bool canBeTrashed() + { + return base.canBeTrashed(); + } } } diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/PickaxeExtended.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/PickaxeExtended.cs index ce5e53d6..791c8a6a 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/PickaxeExtended.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/PickaxeExtended.cs @@ -11,12 +11,13 @@ using Revitalize.Framework.Hacks; using Revitalize.Framework.Objects.Interfaces; using Revitalize.Framework.Utilities; using StardewValley; +using StardewValley.Objects; using StardewValley.Tools; using StardustCore.UIUtilities; namespace Revitalize.Framework.Objects.Items.Tools { - public class PickaxeExtended:StardewValley.Tools.Pickaxe, ISaveElement,IItemInfo + public class PickaxeExtended:StardewValley.Tools.Pickaxe, ISaveElement,IItemInfo, ICustomObject { public BasicItemInformation info; public Texture2DExtended workingTexture; @@ -195,14 +196,6 @@ namespace Revitalize.Framework.Objects.Items.Tools //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, color, drawShadow); } - public Dictionary getAdditionalSaveData() - { - Dictionary serializedInfo = new Dictionary(); - serializedInfo.Add("id", this.ItemInfo); - serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); - Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); - return serializedInfo; - } public override bool beginUsing(GameLocation location, int x, int y, Farmer who) { @@ -248,15 +241,11 @@ namespace Revitalize.Framework.Objects.Items.Tools return new PickaxeExtended(this.info.Copy(), this.UpgradeLevel,this.workingTexture.Copy()); } - public virtual object getReplacement() - { - return new StardewValley.Tools.Pickaxe { UpgradeLevel = this.UpgradeLevel }; - } - public virtual void rebuild(Dictionary additionalSaveData, object replacement) + + public override bool canBeTrashed() { - this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); - this.upgradeLevel.Value = (replacement as Pickaxe).UpgradeLevel; + return true; } @@ -302,5 +291,40 @@ namespace Revitalize.Framework.Objects.Items.Tools return false; } } + + public virtual ICustomObject recreate(Dictionary additionalSaveData, object replacement) + { + PickaxeExtended p = Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); + return p; + } + + + public Dictionary getAdditionalSaveData() + { + Dictionary serializedInfo = new Dictionary(); + serializedInfo.Add("id", this.ItemInfo); + serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); + serializedInfo.Add("GUID", this.guid.ToString()); + serializedInfo.Add("Level", this.UpgradeLevel.ToString()); + Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); + return serializedInfo; + } + + public virtual object getReplacement() + { + Chest c = new Chest(true); + c.playerChoiceColor.Value = Color.Magenta; + c.TileLocation = new Vector2(0, 0); + return c; + } + + public virtual void rebuild(Dictionary additionalSaveData, object replacement) + { + //ModCore.log("REBULD THE PICKAXE!!!!!!!"); + this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); + this.UpgradeLevel = Convert.ToInt32(additionalSaveData["Level"]); + //this.upgradeLevel.Value = (replacement as Pickaxe).UpgradeLevel; + + } } } diff --git a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/WateringCanExtended.cs b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/WateringCanExtended.cs index c9f2534f..b573b220 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Items/Tools/WateringCanExtended.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Items/Tools/WateringCanExtended.cs @@ -10,12 +10,13 @@ using PyTK.CustomElementHandler; using Revitalize.Framework.Objects.Interfaces; using Revitalize.Framework.Utilities; using StardewValley; +using StardewValley.Objects; using StardewValley.Tools; using StardustCore.UIUtilities; namespace Revitalize.Framework.Objects.Items.Tools { - public class WateringCanExtended:StardewValley.Tools.WateringCan, ISaveElement, IItemInfo + public class WateringCanExtended:StardewValley.Tools.WateringCan, ISaveElement, IItemInfo, ICustomObject { public BasicItemInformation info; public Texture2DExtended workingTexture; @@ -195,15 +196,6 @@ namespace Revitalize.Framework.Objects.Items.Tools //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, color, drawShadow); } - public Dictionary getAdditionalSaveData() - { - Dictionary serializedInfo = new Dictionary(); - serializedInfo.Add("id", this.ItemInfo); - serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); - Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); - return serializedInfo; - } - public override bool beginUsing(GameLocation location, int x, int y, Farmer who) { this.updateInfo(); @@ -248,18 +240,6 @@ namespace Revitalize.Framework.Objects.Items.Tools return new WateringCanExtended(this.info.Copy(), this.UpgradeLevel, this.workingTexture.Copy(),this.waterCanMax); } - public object getReplacement() - { - return new StardewValley.Tools.WateringCan { UpgradeLevel = this.UpgradeLevel, waterCanMax=this.waterCanMax }; - } - - public void rebuild(Dictionary additionalSaveData, object replacement) - { - this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); - this.upgradeLevel.Value = (replacement as WateringCan).UpgradeLevel; - } - - /// /// Updates the info on the item. /// @@ -302,5 +282,42 @@ namespace Revitalize.Framework.Objects.Items.Tools return false; } } + + public virtual ICustomObject recreate(Dictionary additionalSaveData, object replacement) + { + WateringCanExtended p = Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); + return p; + } + public Dictionary getAdditionalSaveData() + { + Dictionary serializedInfo = new Dictionary(); + serializedInfo.Add("id", this.ItemInfo); + serializedInfo.Add("ItemInfo", Revitalize.ModCore.Serializer.ToJSONString(this.info)); + serializedInfo.Add("GUID", this.guid.ToString()); + serializedInfo.Add("Level", this.UpgradeLevel.ToString()); + Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); + return serializedInfo; + } + + public virtual object getReplacement() + { + Chest c = new Chest(true); + c.playerChoiceColor.Value = Color.Magenta; + c.TileLocation = new Vector2(0, 0); + return c; + } + + public virtual void rebuild(Dictionary additionalSaveData, object replacement) + { + //ModCore.log("REBULD THE PICKAXE!!!!!!!"); + this.info = ModCore.Serializer.DeserializeFromJSONString(additionalSaveData["ItemInfo"]); + this.UpgradeLevel = Convert.ToInt32(additionalSaveData["Level"]); + //this.upgradeLevel.Value = (replacement as Pickaxe).UpgradeLevel; + + } + public override bool canBeTrashed() + { + return base.canBeTrashed(); + } } }