diff --git a/GeneralMods/Revitalize/Framework/Objects/Extras/ArcadeCabinetOBJ.cs b/GeneralMods/Revitalize/Framework/Objects/Extras/ArcadeCabinetOBJ.cs index a67fef37..7b8160a3 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Extras/ArcadeCabinetOBJ.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Extras/ArcadeCabinetOBJ.cs @@ -92,6 +92,33 @@ namespace Revitalize.Framework.Objects.Extras } + public override void recreate() + { + Dictionary guids = new Dictionary(); + + foreach (KeyValuePair pair in this.childrenGuids) + { + guids.Add(pair.Key, pair.Value); + } + + foreach (KeyValuePair pair in guids) + { + this.childrenGuids.Remove(pair.Key); + ArcadeCabinetTile component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); + component.InitNetFields(); + this.removeComponent(pair.Key); + this.addComponent(pair.Key, component); + + + } + this.InitNetFields(); + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString())) + { + Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this); + } + } + public override bool canBePlacedHere(GameLocation l, Vector2 tile) { diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/Bench.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/Bench.cs index 0fb9e457..9ad29549 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/Bench.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/Bench.cs @@ -105,6 +105,33 @@ namespace Revitalize.Framework.Objects.Furniture } } + public override void recreate() + { + Dictionary guids = new Dictionary(); + + foreach (KeyValuePair pair in this.childrenGuids) + { + guids.Add(pair.Key, pair.Value); + } + + foreach (KeyValuePair pair in guids) + { + this.childrenGuids.Remove(pair.Key); + ChairTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); + component.InitNetFields(); + this.removeComponent(pair.Key); + this.addComponent(pair.Key, component); + + + } + this.InitNetFields(); + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString())) + { + Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this); + } + } + } } diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs index 380fe21a..694c650f 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs @@ -108,6 +108,33 @@ namespace Revitalize.Framework.Objects.Furniture } + public override void recreate() + { + Dictionary guids = new Dictionary(); + + foreach (KeyValuePair pair in this.childrenGuids) + { + guids.Add(pair.Key, pair.Value); + } + + foreach (KeyValuePair pair in guids) + { + this.childrenGuids.Remove(pair.Key); + ChairTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); + component.InitNetFields(); + this.removeComponent(pair.Key); + this.addComponent(pair.Key, component); + + + } + this.InitNetFields(); + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString())) + { + Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this); + } + } + public override bool canBePlacedHere(GameLocation l, Vector2 tile) { diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/LampMultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/LampMultiTiledObject.cs index 2d6e425d..db17d900 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/LampMultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/LampMultiTiledObject.cs @@ -72,7 +72,7 @@ namespace Revitalize.Framework.Objects.Furniture //Revitalize.ModCore.log("DESERIALIZE: " + pair.Value.ToString()); LampTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); component.InitNetFields(); - + obj.addComponent(pair.Key, component); @@ -92,6 +92,33 @@ namespace Revitalize.Framework.Objects.Furniture } + public override void recreate() + { + Dictionary guids = new Dictionary(); + + foreach (KeyValuePair pair in this.childrenGuids) + { + guids.Add(pair.Key, pair.Value); + } + + foreach (KeyValuePair pair in guids) + { + this.childrenGuids.Remove(pair.Key); + LampTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); + component.InitNetFields(); + this.removeComponent(pair.Key); + this.addComponent(pair.Key, component); + + + } + this.InitNetFields(); + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString())) + { + Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this); + } + } + public override bool canBePlacedHere(GameLocation l, Vector2 tile) { diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/RugMultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/RugMultiTiledObject.cs index 9ec327ba..8b155f11 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/RugMultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/RugMultiTiledObject.cs @@ -94,6 +94,33 @@ namespace Revitalize.Framework.Objects.Furniture } + public override void recreate() + { + Dictionary guids = new Dictionary(); + + foreach (KeyValuePair pair in this.childrenGuids) + { + guids.Add(pair.Key, pair.Value); + } + + foreach (KeyValuePair pair in guids) + { + this.childrenGuids.Remove(pair.Key); + RugTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); + component.InitNetFields(); + this.removeComponent(pair.Key); + this.addComponent(pair.Key, component); + + + } + this.InitNetFields(); + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString())) + { + Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this); + } + } + public override bool canBePlacedHere(GameLocation l, Vector2 tile) { diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/StorageFurnitureOBJ.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/StorageFurnitureOBJ.cs index 172289ea..bca689d7 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/StorageFurnitureOBJ.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/StorageFurnitureOBJ.cs @@ -92,7 +92,32 @@ namespace Revitalize.Framework.Objects.Furniture } + public override void recreate() + { + Dictionary guids = new Dictionary(); + foreach (KeyValuePair pair in this.childrenGuids) + { + guids.Add(pair.Key, pair.Value); + } + + foreach (KeyValuePair pair in guids) + { + this.childrenGuids.Remove(pair.Key); + StorageFurnitureTile component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); + component.InitNetFields(); + this.removeComponent(pair.Key); + this.addComponent(pair.Key, component); + + + } + this.InitNetFields(); + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString())) + { + Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this); + } + } public override bool canBePlacedHere(GameLocation l, Vector2 tile) { return base.canBePlacedHere(l, tile); diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/TableMultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/TableMultiTiledObject.cs index 8b79a4be..191806d2 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/TableMultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/TableMultiTiledObject.cs @@ -93,6 +93,32 @@ namespace Revitalize.Framework.Objects.Furniture } + public override void recreate() + { + Dictionary guids = new Dictionary(); + + foreach (KeyValuePair pair in this.childrenGuids) + { + guids.Add(pair.Key, pair.Value); + } + + foreach (KeyValuePair pair in guids) + { + this.childrenGuids.Remove(pair.Key); + TableTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); + component.InitNetFields(); + this.removeComponent(pair.Key); + this.addComponent(pair.Key, component); + + + } + this.InitNetFields(); + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString())) + { + Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this); + } + } public override bool canBePlacedHere(GameLocation l, Vector2 tile) { diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs index 8fb36d62..da94978d 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs @@ -290,10 +290,9 @@ namespace Revitalize.Framework.Objects foreach (KeyValuePair pair in guids) { obj.childrenGuids.Remove(pair.Key); - //Revitalize.ModCore.log("DESERIALIZE: " + pair.Value.ToString()); MultiTiledComponent component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); component.InitNetFields(); - + obj.removeComponent(pair.Key); obj.addComponent(pair.Key, component); @@ -313,14 +312,40 @@ namespace Revitalize.Framework.Objects } + /// + /// Recreate the data from data already stored on the object. + /// + public virtual void recreate() + { + Dictionary guids = new Dictionary(); + + foreach (KeyValuePair pair in this.childrenGuids) + { + guids.Add(pair.Key, pair.Value); + } + + foreach (KeyValuePair pair in guids) + { + this.childrenGuids.Remove(pair.Key); + MultiTiledComponent component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); + component.InitNetFields(); + this.removeComponent(pair.Key); + this.addComponent(pair.Key, component); + + + } + this.InitNetFields(); + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString())) + { + Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this); + } + } + public override Dictionary getAdditionalSaveData() { Dictionary saveData = base.getAdditionalSaveData(); - - Revitalize.ModCore.log("Serialize: " + this.guid.ToString()); - saveData.Add("GUID", this.guid.ToString()); - Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this); return saveData; } diff --git a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs index 60d0a493..69cee6a6 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Resources/OreVeins/OreVeinObj.cs @@ -104,6 +104,33 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins } + public override void recreate() + { + Dictionary guids = new Dictionary(); + + foreach (KeyValuePair pair in this.childrenGuids) + { + guids.Add(pair.Key, pair.Value); + } + + foreach (KeyValuePair pair in guids) + { + this.childrenGuids.Remove(pair.Key); + OreVeinTile component = Revitalize.ModCore.Serializer.DeserializeGUID(pair.Value.ToString()); + component.InitNetFields(); + this.removeComponent(pair.Key); + this.addComponent(pair.Key, component); + + + } + this.InitNetFields(); + + if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString())) + { + Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this); + } + } + public override bool canBePlacedHere(GameLocation l, Vector2 tile) { diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 3b038854..007a3d09 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -396,6 +396,59 @@ namespace Revitalize } } + foreach(GameLocation loc in Game1.locations) + { + foreach(StardewValley.Object c in loc.Objects.Values) + { + if (c is Chest) + { + List toRemove=new List(); + List toAdd=new List(); + foreach (Item o in (c as Chest).items) + { + if (o is Chest && o.Name != "Chest") + { + ModCore.log("Found a custom object in a chest!"); + string jsonString = o.Name; + string guidName = jsonString.Split(new string[] { "GUID=" },StringSplitOptions.None)[1]; + ModCore.log(jsonString); + string type = jsonString.Split('|')[2]; + Item I=(Item)Serializer.DeserializeGUID(guidName, Type.GetType(type)); + + if(I is MultiTiledObject) + { + (I as MultiTiledObject).recreate(); + } + + toAdd.Add(I); + toRemove.Add(o); + //Item i = Serializer.DeserializeFromJSONString(jsonString); + //ModCore.log("Deserialized item is: "+i.Name); + } + } + + foreach(Item i in toRemove) + { + (c as Chest).items.Remove(i); + } + foreach(Item I in toAdd) + { + (c as Chest).items.Add(I); + } + } + else if(c is StorageFurnitureTile) + { + foreach (Item o in (c as StorageFurnitureTile).info.inventory.items) + { + if (o is Chest&& o.Name != "Chest") + { + ModCore.log("Found a custom object in a chest!"); + } + } + } + } + } + // Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.BigTiledTest")); Game1.player.addItemToInventory(ObjectManager.getChair("Omegasis.Revitalize.Furniture.Chairs.OakChair")); //Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Rugs.RugTest"));