From d2173bb24bf5b65c1a2deeaebc6fde63a3beb396 Mon Sep 17 00:00:00 2001 From: Joshua Navarro Date: Sat, 12 Jan 2019 18:12:14 -0800 Subject: [PATCH] Got chairs to save as well! --- .../Furniture/ChairMultiTiledObject.cs | 42 +++++++++++++--- .../Objects/Furniture/ChairTileComponent.cs | 50 +++++++++++++++---- .../Furniture/FurnitureTileComponent.cs | 8 ++- .../Framework/Objects/MultiTiledObject.cs | 3 -- GeneralMods/Revitalize/ModCore.cs | 15 +++++- 5 files changed, 94 insertions(+), 24 deletions(-) diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs index 72664884..74465c07 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs @@ -65,19 +65,49 @@ namespace Revitalize.Framework.Objects.Furniture return new ChairMultiTiledObject(this.info, this.TileLocation, objs); } + public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) { - BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]]; - - Dictionary objs = new Dictionary(); - foreach (var pair in this.objects) + ChairMultiTiledObject obj = (ChairMultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); + if (obj == null) { - objs.Add(pair.Key, (MultiTiledComponent)pair.Value); + return null; } - return new ChairMultiTiledObject(data, (replacement as Chest).TileLocation, objs); + Dictionary guids = new Dictionary(); + + foreach (KeyValuePair pair in obj.childrenGuids) + { + guids.Add(pair.Key, pair.Value); + } + + foreach (KeyValuePair pair in guids) + { + obj.childrenGuids.Remove(pair.Key); + //Revitalize.ModCore.log("DESERIALIZE: " + pair.Value.ToString()); + ChairTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); + component.InitNetFields(); + + obj.addComponent(pair.Key, component); + + + } + obj.InitNetFields(); + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["GUID"])) + { + Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["GUID"], obj); + return obj; + } + else + { + return Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]]; + } + + } + public override bool canBePlacedHere(GameLocation l, Vector2 tile) { return base.canBePlacedHere(l, tile); diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs index fa39aaac..d7db3f34 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs @@ -16,6 +16,8 @@ namespace Revitalize.Framework.Objects.Furniture /// public class ChairTileComponent:FurnitureTileComponent { + public ChairInformation furnitureInfo; + /// /// Checks if the player can sit "on" this component. /// @@ -32,14 +34,14 @@ namespace Revitalize.Framework.Objects.Furniture } - public ChairTileComponent(BasicItemInformation Info,ChairInformation FurnitureInfo) : base(Info,FurnitureInfo) + public ChairTileComponent(BasicItemInformation Info,ChairInformation FurnitureInfo) : base(Info) { - + this.furnitureInfo = FurnitureInfo; } - public ChairTileComponent(BasicItemInformation Info,Vector2 TileLocation, ChairInformation FurnitureInfo) : base(Info, TileLocation,FurnitureInfo) + public ChairTileComponent(BasicItemInformation Info,Vector2 TileLocation, ChairInformation FurnitureInfo) : base(Info, TileLocation) { - + this.furnitureInfo = FurnitureInfo; } @@ -89,14 +91,44 @@ namespace Revitalize.Framework.Objects.Furniture public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) { - BasicItemInformation data = (BasicItemInformation)CustomObjectData.collection[additionalSaveData["id"]]; - return new ChairTileComponent(data, (replacement as Chest).TileLocation,(ChairInformation)this.furnitureInfo) + //instead of using this.offsetkey.x use get additional save data function and store offset key there + + Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"])); + ChairTileComponent self = Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); + if (self == null) { - containerObject = this.containerObject, - offsetKey = this.offsetKey - }; + return null; + } + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(additionalSaveData["ParentGUID"])) + { + //Get new container + ChairMultiTiledObject obj = (ChairMultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["ParentGUID"]); + self.containerObject = obj; + obj.addComponent(offsetKey, self); + //Revitalize.ModCore.log("ADD IN AN OBJECT!!!!"); + Revitalize.ModCore.ObjectGroups.Add(additionalSaveData["ParentGUID"], obj); + } + else + { + self.containerObject = Revitalize.ModCore.ObjectGroups[additionalSaveData["ParentGUID"]]; + Revitalize.ModCore.ObjectGroups[additionalSaveData["GUID"]].addComponent(offsetKey, self); + //Revitalize.ModCore.log("READD AN OBJECT!!!!"); + } + + return (ICustomObject)self; } + public override Dictionary getAdditionalSaveData() + { + Dictionary saveData = base.getAdditionalSaveData(); + Revitalize.ModCore.Serializer.SerializeGUID(this.containerObject.childrenGuids[this.offsetKey].ToString(), this); + + return saveData; + + } + + /// ///Used to manage graphics for chairs that need to deal with special "layering" for transparent chair backs. Otherwise the player would be hidden. /// diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/FurnitureTileComponent.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/FurnitureTileComponent.cs index af8c419b..7c5661c2 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/FurnitureTileComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/FurnitureTileComponent.cs @@ -11,7 +11,6 @@ namespace Revitalize.Framework.Objects.Furniture { public class FurnitureTileComponent:MultiTiledComponent { - public FurnitureInformation furnitureInfo; public FurnitureTileComponent():base() @@ -19,14 +18,13 @@ namespace Revitalize.Framework.Objects.Furniture } - public FurnitureTileComponent(BasicItemInformation itemInfo,FurnitureInformation furnitureInfo):base(itemInfo) + public FurnitureTileComponent(BasicItemInformation itemInfo):base(itemInfo) { - this.furnitureInfo = furnitureInfo; } - public FurnitureTileComponent(BasicItemInformation itemInfo,Vector2 TileLocation ,FurnitureInformation furnitureInfo) : base(itemInfo,TileLocation) + public FurnitureTileComponent(BasicItemInformation itemInfo,Vector2 TileLocation) : base(itemInfo,TileLocation) { - this.furnitureInfo = furnitureInfo; + } } diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs index 4159304a..eba0c40b 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs @@ -208,9 +208,6 @@ namespace Revitalize.Framework.Objects public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) { - - - MultiTiledObject obj = (MultiTiledObject)Revitalize.ModCore.Serializer.DeserializeGUID(additionalSaveData["GUID"]); if (obj == null) { diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index d22a842b..2005c364 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -249,6 +249,7 @@ namespace Revitalize oakChair.addComponent(new Vector2(0, 1), chairBottom); customObjects.Add("Omegasis.BigTiledTest", bigObject); + customObjects.Add("Omegasis.Revitalize.Furniture.Chairs.OakChair",oakChair); } private void createDirectories() @@ -285,7 +286,8 @@ namespace Revitalize { throw new Exception("Can't run Revitalize in multiplayer due to lack of current support!"); } - Game1.player.addItemToInventory(customObjects["Omegasis.BigTiledTest"].getOne()); + //Game1.player.addItemToInventory(customObjects["Omegasis.BigTiledTest"].getOne()); + Game1.player.addItemToInventory(getObjectFromPool("Omegasis.Revitalize.Furniture.Chairs.OakChair")); /* StardewValley.Tools.Axe axe = new StardewValley.Tools.Axe(); @@ -296,6 +298,17 @@ namespace Revitalize } + public Item getObjectFromPool(string objName) + { + if (customObjects.ContainsKey(objName)) + { + return customObjects[objName]; + } + else + { + throw new Exception("Object Key name not found: " + objName); + } + } public static void log(object message)