From 198a908c01fe2c8dd2f79aa9b8b5c57b38f9c365 Mon Sep 17 00:00:00 2001 From: Joshua Navarro Date: Wed, 9 Jan 2019 11:41:40 -0800 Subject: [PATCH] Figured some weird serialization issues. Now to recreate the data after a save... --- .../Furniture/ChairMultiTiledObject.cs | 8 ++-- .../Objects/Furniture/ChairTileComponent.cs | 2 +- .../Framework/Objects/MultiTiledComponent.cs | 47 ++++++++++++++++++- .../Framework/Objects/MultiTiledObject.cs | 36 +++++++------- 4 files changed, 68 insertions(+), 25 deletions(-) diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs index 1636c6e2..5681ab7c 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairMultiTiledObject.cs @@ -31,7 +31,7 @@ namespace Revitalize.Framework.Objects.Furniture } - public ChairMultiTiledObject(BasicItemInformation Info,Vector2 TilePosition,Dictionary Objects) : base(Info, TilePosition, Objects) { + public ChairMultiTiledObject(BasicItemInformation Info,Vector2 TilePosition,Dictionary Objects) : base(Info, TilePosition, Objects) { } @@ -42,11 +42,11 @@ namespace Revitalize.Framework.Objects.Furniture public override void rotate() { Revitalize.ModCore.log("Rotate!"); - foreach(KeyValuePair pair in this.objects) + foreach(KeyValuePair pair in this.objects) { - pair.Value.rotate(); + (pair.Value as ChairTileComponent).rotate(); } - foreach (KeyValuePair pair in this.objects) + foreach (KeyValuePair pair in this.objects) { (pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation(); } diff --git a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs index 5f0bdd3a..fa39aaac 100644 --- a/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/Furniture/ChairTileComponent.cs @@ -69,7 +69,7 @@ namespace Revitalize.Framework.Objects.Furniture if (this.CanSitHere) { Revitalize.ModCore.playerInfo.sittingInfo.sit(this.containerObject, this.TileLocation*Game1.tileSize); - foreach(KeyValuePairpair in this.containerObject.objects) + foreach(KeyValuePair pair in this.containerObject.objects) { (pair.Value as ChairTileComponent).checkForSpecialUpSittingAnimation(); } diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs index f8cf8833..0a000769 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledComponent.cs @@ -109,11 +109,29 @@ namespace Revitalize.Framework.Objects { //instead of using this.offsetkey.x use get additional save data function and store offset key there - if (this.offsetKey.X == 0 && this.offsetKey.Y == 0) + Vector2 offsetKey = new Vector2(Convert.ToInt32(additionalSaveData["offsetKeyX"]), Convert.ToInt32(additionalSaveData["offsetKeyY"])); + + if (offsetKey.X == 0 && offsetKey.Y == 0) { Revitalize.ModCore.log(recreateParentId(additionalSaveData["id"]) + ".Object"); - var obj=(Revitalize.ModCore.customObjects[recreateParentId(additionalSaveData["id"])+".Object"].getOne()); + CustomObject obj=(CustomObject)(Revitalize.ModCore.customObjects[recreateParentId(additionalSaveData["id"])+".Object"].getOne()); obj.Stack =Convert.ToInt32( additionalSaveData["stack"]); + + string saveLocation = additionalSaveData["GameLocationName"]; + + + Enums.Direction facingDirection = (Enums.Direction)Convert.ToInt32(additionalSaveData["Rotation"]); + while (obj.info.facingDirection != facingDirection) + { + obj.rotate(); + } + + if (!string.IsNullOrEmpty(saveLocation)) + { + obj.placementAction(Game1.getLocationFromName(saveLocation), (int)(replacement as Chest).TileLocation.X, (int)(replacement as Chest).TileLocation.Y); + return null; + } + return (ICustomObject)obj; BasicItemInformation data = Revitalize.ModCore.customObjects[additionalSaveData["id"]].info; return new MultiTiledComponent(data, (replacement as Chest).TileLocation) @@ -129,6 +147,31 @@ namespace Revitalize.Framework.Objects } } + public override Dictionary getAdditionalSaveData() + { + Dictionary saveData= base.getAdditionalSaveData(); + saveData.Add("offsetKeyX", this.offsetKey.X.ToString()); + saveData.Add("offsetKeyY", this.offsetKey.Y.ToString()); + string saveLocation = ""; + if (this.location == null) + { + saveLocation = ""; + } + else + { + if (!string.IsNullOrEmpty(this.location.uniqueName.Value)) saveLocation = this.location.uniqueName.Value; + else + { + saveLocation = this.location.Name; + } + } + saveData.Add("GameLocationName", saveLocation); + saveData.Add("Rotation", ((int)this.info.facingDirection).ToString()); + + return saveData; + + } + protected string recreateParentId(string id) { StringBuilder b = new StringBuilder(); diff --git a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs index 38a6dab5..75c0b9e7 100644 --- a/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs +++ b/GeneralMods/Revitalize/Framework/Objects/MultiTiledObject.cs @@ -9,7 +9,7 @@ namespace Revitalize.Framework.Objects { public class MultiTiledObject : CustomObject { - public Dictionary objects; + public Dictionary objects; public Dictionary offSets; private int width; @@ -31,28 +31,28 @@ namespace Revitalize.Framework.Objects public MultiTiledObject() { - this.objects = new Dictionary(); + this.objects = new Dictionary(); this.offSets = new Dictionary(); } public MultiTiledObject(BasicItemInformation info) : base(info) { - this.objects = new Dictionary(); + this.objects = new Dictionary(); this.offSets = new Dictionary(); } public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation) : base(info, TileLocation) { - this.objects = new Dictionary(); + this.objects = new Dictionary(); this.offSets = new Dictionary(); } - public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary ObjectsList) + public MultiTiledObject(BasicItemInformation info, Vector2 TileLocation, Dictionary ObjectsList) : base(info, TileLocation) { - this.objects = new Dictionary(); + this.objects = new Dictionary(); this.offSets = new Dictionary(); foreach (var v in ObjectsList) { @@ -87,13 +87,13 @@ namespace Revitalize.Framework.Objects public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1) { - foreach (KeyValuePair pair in this.objects) + foreach (KeyValuePair pair in this.objects) pair.Value.draw(spriteBatch, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, alpha); } public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1) { - foreach (KeyValuePair pair in this.objects) + foreach (KeyValuePair pair in this.objects) pair.Value.draw(spriteBatch, xNonTile + (int)pair.Key.X * Game1.tileSize, yNonTile + (int)pair.Key.Y * Game1.tileSize, layerDepth, alpha); //base.draw(spriteBatch, xNonTile, yNonTile, layerDepth, alpha); @@ -101,14 +101,14 @@ namespace Revitalize.Framework.Objects public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber, Color c, bool drawShadow) { - foreach (KeyValuePair pair in this.objects) + foreach (KeyValuePair pair in this.objects) pair.Value.drawInMenu(spriteBatch, location + (pair.Key * 16), 1.0f, transparency, layerDepth, drawStackNumber, c, drawShadow); //base.drawInMenu(spriteBatch, location, scaleSize, transparency, layerDepth, drawStackNumber, c, drawShadow); } public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, Farmer f) { - foreach (KeyValuePair pair in this.objects) + foreach (KeyValuePair pair in this.objects) pair.Value.drawWhenHeld(spriteBatch, objectPosition + (pair.Key * Game1.tileSize), f); //base.drawWhenHeld(spriteBatch, objectPosition, f); } @@ -121,8 +121,8 @@ namespace Revitalize.Framework.Objects bool canPickUp = this.removeAndAddToPlayersInventory(); if (canPickUp) { - foreach (KeyValuePair pair in this.objects) - pair.Value.removeFromLocation(pair.Value.location, pair.Key); + foreach (KeyValuePair pair in this.objects) + (pair.Value as MultiTiledComponent).removeFromLocation((pair.Value as MultiTiledComponent).location, pair.Key); this.location = null; } else @@ -142,7 +142,7 @@ namespace Revitalize.Framework.Objects public override bool placementAction(GameLocation location, int x, int y, Farmer who = null) { - foreach (KeyValuePair pair in this.objects) + foreach (KeyValuePair pair in this.objects) { pair.Value.placementAction(location, x + (int)pair.Key.X * Game1.tileSize, y + (int)pair.Key.Y * Game1.tileSize, who); ModCore.log(pair.Value.TileLocation); @@ -154,7 +154,7 @@ namespace Revitalize.Framework.Objects public override bool canBePlacedHere(GameLocation l, Vector2 tile) { - foreach (KeyValuePair pair in this.objects) + foreach (KeyValuePair pair in this.objects) { if (!pair.Value.canBePlacedHere(l, tile + pair.Key)) return false; @@ -200,12 +200,12 @@ namespace Revitalize.Framework.Objects public void setAllAnimationsToDefault() { - foreach(KeyValuePair pair in this.objects) + foreach(KeyValuePair pair in this.objects) { - string animationKey = pair.Value.generateDefaultRotationalAnimationKey(); - if (pair.Value.animationManager.animations.ContainsKey(animationKey)) + string animationKey = (pair.Value as MultiTiledComponent) .generateDefaultRotationalAnimationKey(); + if ((pair.Value as MultiTiledComponent).animationManager.animations.ContainsKey(animationKey)) { - pair.Value.animationManager.setAnimation(animationKey); + (pair.Value as MultiTiledComponent).animationManager.setAnimation(animationKey); } } }