From cf33b0228e3d4bb79f222a82fd0fd439e47b6e36 Mon Sep 17 00:00:00 2001 From: Date: Wed, 13 Sep 2017 13:53:12 -0700 Subject: [PATCH] Changed serialization manager, all objects serialize in world and inventory. Next is chests. --- .../Framework/Utilities.cs | 29 ++- .../AdditionalCropsFramework/ModCore.cs | 32 +--- .../ModularCropObject.cs | 171 +++++++++++++++++- .../AdditionalCropsFramework/ModularSeeds.cs | 160 +++++++++++++++- .../AdditionalCropsFramework/PlanterBox.cs | 71 ++++---- GeneralMods/RuneFactoryCropsMod/ModCore.cs | 4 +- .../RuneFactoryCropsMod/PlanterBox.xnb | Bin 1114 -> 1114 bytes GeneralMods/StardustCore/CoreObject.cs | 2 + GeneralMods/StardustCore/ModCore.cs | 36 +++- .../Serialization/Serialization.cs | 87 ++++++--- 10 files changed, 464 insertions(+), 128 deletions(-) diff --git a/GeneralMods/AdditionalCropsFramework/Framework/Utilities.cs b/GeneralMods/AdditionalCropsFramework/Framework/Utilities.cs index fb6944e8..7a780b08 100644 --- a/GeneralMods/AdditionalCropsFramework/Framework/Utilities.cs +++ b/GeneralMods/AdditionalCropsFramework/Framework/Utilities.cs @@ -664,7 +664,7 @@ namespace AdditionalCropsFramework else { // Game1.showRedMessage("STEP 2"); - Log.Info(vector); + // Log.Info(vector); Vector2 newVec = new Vector2(vector.X, vector.Y); // cObj.boundingBox.Inflate(32, 32); @@ -675,11 +675,11 @@ namespace AdditionalCropsFramework if (playSound == true) Game1.playSound("woodyStep"); else { - Log.AsyncG("restoring item from file"); + // Log.AsyncG("restoring item from file"); } //Log.AsyncM("Placed and object"); cObj.locationsName = location.name; - ModCore.serilaizationManager.trackedObjectList.Add(cObj); + StardustCore.ModCore.SerializationManager.trackedObjectList.Add(cObj); return true; } @@ -692,7 +692,7 @@ namespace AdditionalCropsFramework if (Game1.player.isInventoryFull() == false) { Game1.player.addItemToInventoryBool(I, false); - ModCore.serilaizationManager.trackedObjectList.Remove(I); + StardustCore.ModCore.SerializationManager.trackedObjectList.Remove(I); return true; } else @@ -753,9 +753,9 @@ namespace AdditionalCropsFramework if (state == 1) { c.dayOfCurrentPhase++; - Log.AsyncG("DaY OF CURRRENT PHASE BISCUITS!"+c.dayOfCurrentPhase); + // Log.AsyncG("DaY OF CURRRENT PHASE BISCUITS!"+c.dayOfCurrentPhase); - Log.AsyncC(c.currentPhase); + // Log.AsyncC(c.currentPhase); if (c.dayOfCurrentPhase >= c.phaseDays[c.currentPhase]) { c.currentPhase++; @@ -769,10 +769,6 @@ namespace AdditionalCropsFramework c.dayOfCurrentPhase = 0; } - foreach(var v in c.phaseDays) - { - Log.AsyncR("PHASE DAY"+v); - } while (c.currentPhase < c.phaseDays.Count - 1 && c.phaseDays.Count > 0 && c.phaseDays[c.currentPhase] <= 0) c.currentPhase = c.currentPhase + 1; if (c.rowInSpriteSheet == 23 && c.phaseToShow == -1 && c.currentPhase > 0) @@ -850,7 +846,9 @@ namespace AdditionalCropsFramework if (state == 1) { c.dayOfCurrentPhase++; - Log.AsyncG(c.dayOfCurrentPhase); + + + //c.dayOfCurrentPhase = c.fullyGrown ? c.dayOfCurrentPhase - 1 : Math.Min(c.dayOfCurrentPhase + 1, c.phaseDays.Count > 0 ? c.phaseDays[Math.Min(c.phaseDays.Count - 1, c.currentPhase)] : 0); if (c.dayOfCurrentPhase >= (c.phaseDays.Count > 0 ? c.phaseDays[Math.Min(c.phaseDays.Count - 1, c.currentPhase)] : 0) && c.currentPhase < c.phaseDays.Count - 1) { @@ -858,10 +856,6 @@ namespace AdditionalCropsFramework c.dayOfCurrentPhase = 0; } - foreach (var v in c.phaseDays) - { - Log.AsyncR(v); - } @@ -1123,7 +1117,6 @@ namespace AdditionalCropsFramework public static bool harvestModularCrop(ModularCrop c, int xTile, int yTile, int fertilizer, JunimoHarvester junimoHarvester = null) { Item I = (Item)new ModularCropObject(c.indexOfHarvest, 1, c.cropObjectTexture, c.cropObjectData); - int howMuch = 3; if (Game1.player.addItemToInventoryBool(I, false)) { @@ -1242,7 +1235,7 @@ namespace AdditionalCropsFramework ModularCropObject @object; if (!c.programColored) { - Log.AsyncG(c.indexOfHarvest); + // Log.AsyncG(c.indexOfHarvest); try { @object = new ModularCropObject(c.indexOfHarvest, 1, c.cropObjectTexture, c.cropObjectData); @@ -1250,7 +1243,7 @@ namespace AdditionalCropsFramework catch(Exception lol) { @object = new ModularCropObject(); - Log.AsyncO(lol); + // Log.AsyncO(lol); } } else diff --git a/GeneralMods/AdditionalCropsFramework/ModCore.cs b/GeneralMods/AdditionalCropsFramework/ModCore.cs index 78792d73..fe7cab38 100644 --- a/GeneralMods/AdditionalCropsFramework/ModCore.cs +++ b/GeneralMods/AdditionalCropsFramework/ModCore.cs @@ -39,7 +39,6 @@ namespace AdditionalCropsFramework public static readonly List SummerWildCrops = new List(); public static readonly List FallWildCrops = new List(); public static readonly List WinterWildCrops = new List(); - public static SerializationManager serilaizationManager; private List shippingList; @@ -49,14 +48,18 @@ namespace AdditionalCropsFramework ModHelper = helper; ModMonitor = this.Monitor; StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; - StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave; StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave; if (!Directory.Exists(Path.Combine(ModCore.ModHelper.DirectoryPath, Utilities.EntensionsFolderName))) { Directory.CreateDirectory(Path.Combine(ModCore.ModHelper.DirectoryPath, Utilities.EntensionsFolderName)); } - // StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick; + + + StardustCore.ModCore.SerializationManager.acceptedTypes.Add("AdditionalCropsFramework.PlanterBox", new SerializerDataNode(new SerializerDataNode.SerializingFunction(PlanterBox.Serialize), new SerializerDataNode.ParsingFunction(PlanterBox.ParseIntoInventory), new SerializerDataNode.WorldParsingFunction(PlanterBox.SerializeFromWorld))); //need serialize, deserialize, and world deserialize functions. + StardustCore.ModCore.SerializationManager.acceptedTypes.Add("AdditionalCropsFramework.ModularCropObject", new SerializerDataNode(new SerializerDataNode.SerializingFunction(ModularCropObject.Serialize), new SerializerDataNode.ParsingFunction(ModularCropObject.ParseIntoInventory), new SerializerDataNode.WorldParsingFunction(ModularCropObject.SerializeFromWorld))); + StardustCore.ModCore.SerializationManager.acceptedTypes.Add("AdditionalCropsFramework.ModularSeeds", new SerializerDataNode(new SerializerDataNode.SerializingFunction(ModularSeeds.Serialize), new SerializerDataNode.ParsingFunction(ModularSeeds.ParseIntoInventory), new SerializerDataNode.WorldParsingFunction(ModularSeeds.SerializeFromWorld))); + // StardewModdingAPI.Events.GameEvents.UpdateTick += GameEvents_UpdateTick; this.shippingList = new List(); } @@ -91,7 +94,7 @@ namespace AdditionalCropsFramework public void dailyUpdates() { - foreach (var v in serilaizationManager.trackedObjectList) + foreach (var v in StardustCore.ModCore.SerializationManager.trackedObjectList) { if (v is PlanterBox) { @@ -102,32 +105,15 @@ namespace AdditionalCropsFramework private void SaveEvents_AfterSave(object sender, EventArgs e) { - serilaizationManager.restoreAllModObjects(serilaizationManager.trackedObjectList); - dailyUpdates(); } - private void SaveEvents_BeforeSave(object sender, EventArgs e) - { - serilaizationManager.cleanUpInventory(); - serilaizationManager.cleanUpWorld(); - } + private void SaveEvents_AfterLoad(object sender, EventArgs e) { - string invPath = Path.Combine(ModCore.ModHelper.DirectoryPath,Game1.player.name,"PlayerInventory"); - string worldPath = Path.Combine(ModCore.ModHelper.DirectoryPath, Game1.player.name, "ObjectsInWorld"); ; - string trashPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "ModTrashFolder"); - serilaizationManager = new SerializationManager(invPath,trashPath,worldPath); - - serilaizationManager.acceptedTypes.Add("AdditionalCropsFramework.PlanterBox", new SerializerDataNode(new SerializerDataNode.SerializingFunction(PlanterBox.Serialize), new SerializerDataNode.ParsingFunction(PlanterBox.ParseIntoInventory), new SerializerDataNode.WorldParsingFunction(PlanterBox.SerializeFromWorld))); //need serialize, deserialize, and world deserialize functions. - - serilaizationManager.restoreAllModObjects(serilaizationManager.trackedObjectList); + dailyUpdates(); } - - - - } } diff --git a/GeneralMods/AdditionalCropsFramework/ModularCropObject.cs b/GeneralMods/AdditionalCropsFramework/ModularCropObject.cs index 25a5bb9d..b1f6a816 100644 --- a/GeneralMods/AdditionalCropsFramework/ModularCropObject.cs +++ b/GeneralMods/AdditionalCropsFramework/ModularCropObject.cs @@ -1,12 +1,14 @@  using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json.Linq; using StardewModdingAPI; using StardewValley; using StardewValley.Locations; using StardewValley.Menus; using StardewValley.Objects; using StardustCore; +using StardustCore.Animations; using System; using System.Collections.Generic; using System.IO; @@ -41,7 +43,7 @@ namespace AdditionalCropsFramework [XmlIgnore] public Texture2D TextureSheet; - public string dataFileName; + public new bool flipped; @@ -50,7 +52,7 @@ namespace AdditionalCropsFramework public bool lightGlowAdded; - public string texturePath; + public bool itemReadyForHarvest; @@ -66,6 +68,9 @@ namespace AdditionalCropsFramework public string cropType; + public string dataFileName; + public string texturePath; + public override string Name { get @@ -87,8 +92,8 @@ namespace AdditionalCropsFramework public ModularCropObject(int which, int initalStack, string ObjectTextureSheetName, string DataFileName) { - - if (File.Exists(ObjectTextureSheetName)) Log.AsyncC("YAY"); + this.serializationName = this.GetType().ToString(); + // if (File.Exists(ObjectTextureSheetName)) Log.AsyncC("YAY"); this.tileLocation = Vector2.Zero; this.stack = initalStack; @@ -98,13 +103,26 @@ namespace AdditionalCropsFramework } catch(Exception err) { - Log.AsyncM(err); + // Log.AsyncM(err); } texturePath = ObjectTextureSheetName; this.dataFileName = DataFileName; this.canBeSetDown = false; + // Log.AsyncG(Path.Combine(Utilities.EntensionsFolderName,DataFileName)); + // Log.AsyncC(which); + Dictionary dictionary = new Dictionary(); + + + try + { + dictionary = ModCore.ModHelper.Content.Load>(Path.Combine(Utilities.EntensionsFolderName, DataFileName)); + } + catch(Exception err) + { + // Log.AsyncC(err); + } + - Dictionary dictionary = ModCore.ModHelper.Content.Load>(Path.Combine(Utilities.EntensionsFolderName, DataFileName)); string[] array = dictionary[which].Split(new char[] { '/' @@ -139,13 +157,24 @@ namespace AdditionalCropsFramework this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 16, 16); this.sourceRect = this.defaultSourceRect; - Log.AsyncC(this.sourceRect); + + this.defaultBoundingBox = new Rectangle(0, 0, 16, 16); this.boundingBox = this.defaultBoundingBox; this.updateDrawPosition(); this.parentSheetIndex = which; - + + try + { + this.animationManager = new StardustCore.Animations.AnimationManager(this.TextureSheet, new StardustCore.Animations.Animation(this.defaultSourceRect, -1), AnimationManager.parseAnimationsFromXNB(array[3]), "default"); + this.animationManager.setAnimation("Default", 0); + //Log.AsyncC("Using animation manager"); + } + catch (Exception errr) + { + this.animationManager = new StardustCore.Animations.AnimationManager(this.TextureSheet, new StardustCore.Animations.Animation(this.defaultSourceRect, -1)); + } } public override string getDescription() @@ -1254,8 +1283,132 @@ namespace AdditionalCropsFramework } - + public static new void Serialize(Item I) + { + StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.playerInventoryPath, I.Name + ".json"), (ModularCropObject)I); + } + + public static Item ParseIntoInventory(string s) + { + // PlanterBox p = new PlanterBox(); + // return p; + + + + dynamic obj = JObject.Parse(s); + + ModularCropObject d = new ModularCropObject(); + + d.dataFileName= obj.dataFileName; + d.price = obj.price; + d.Decoration_type = obj.Decoration_type; + d.rotations = obj.rotations; + d.currentRotation = obj.currentRotation; + string s1 = Convert.ToString(obj.sourceRect); + d.sourceRect = Utilities.parseRectFromJson(s1); + string s2 = Convert.ToString(obj.defaultSourceRect); + d.defaultSourceRect = Utilities.parseRectFromJson(s2); + string s3 = Convert.ToString(obj.defaultBoundingBox); + d.defaultBoundingBox = Utilities.parseRectFromJson(s3); + d.description = obj.description; + d.flipped = obj.flipped; + d.flaggedForPickUp = obj.flaggedForPickUp; + d.tileLocation = obj.tileLocation; + d.parentSheetIndex = obj.parentSheetIndex; + d.owner = obj.owner; + d.name = obj.name; + d.type = obj.type; + d.canBeSetDown = obj.canBeSetDown; + d.canBeGrabbed = obj.canBeGrabbed; + d.isHoedirt = obj.isHoedirt; + d.isSpawnedObject = obj.isSpawnedObject; + d.questItem = obj.questItem; + d.isOn = obj.isOn; + d.fragility = obj.fragility; + d.edibility = obj.edibility; + d.stack = obj.stack; + d.quality = obj.quality; + d.bigCraftable = obj.bigCraftable; + d.setOutdoors = obj.setOutdoors; + d.setIndoors = obj.setIndoors; + d.readyForHarvest = obj.readyForHarvest; + d.showNextIndex = obj.showNextIndex; + d.hasBeenPickedUpByFarmer = obj.hasBeenPickedUpByFarmer; + d.isRecipe = obj.isRecipe; + d.isLamp = obj.isLamp; + d.heldObject = obj.heldObject; + d.minutesUntilReady = obj.minutesUntilReady; + string s4 = Convert.ToString(obj.boundingBox); + d.boundingBox = Utilities.parseRectFromJson(s4); + d.scale = obj.scale; + d.lightSource = obj.lightSource; + d.shakeTimer = obj.shakeTimer; + d.internalSound = obj.internalSound; + d.specialVariable = obj.specialVariable; + d.category = obj.category; + d.specialItem = obj.specialItem; + d.hasBeenInInventory = obj.hasBeenInInventory; + + + string t = obj.texturePath; + d.TextureSheet = ModCore.ModHelper.Content.Load(Path.Combine(Utilities.EntensionsFolderName, t)); + d.texturePath = t; + d.itemReadyForHarvest = obj.itemReadyForHarvest; + d.lightsOn = obj.lightsOn; + d.lightColor = obj.lightColor; + d.thisType = obj.thisType; + d.removable = obj.removable; + d.locationsName = obj.locationsName; + d.cropType = obj.cropType; + d.drawColor = obj.drawColor; + d.serializationName = obj.serializationName; + //ANIMATIONS + var q = obj.animationManager; + dynamic obj1 = q; + + ModularCropObject dummy = new ModularCropObject(d.parentSheetIndex, d.stack, d.texturePath, d.dataFileName); + d.animationManager = dummy.animationManager; + try + { + string name = Convert.ToString(obj1.currentAnimationName); + int frame = Convert.ToInt32(obj1.currentAnimationListIndex); + bool f = d.animationManager.setAnimation(name, frame); + bool f2; + if (f == false) + { + f2 = d.animationManager.setAnimation(name, 0); + if (f2 == false) d.animationManager.currentAnimation = d.animationManager.defaultDrawFrame; + } + } + catch(Exception err) + { + + } + + try + { + return d; + } + catch (Exception e) + { + // Log.AsyncM(e); + return null; + } + + //return base.ParseIntoInventory(); + } + + public static void SerializeFromWorld(Item I) + { + // ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, (c as CoreObject).thisLocation.name, c.Name + ".json"), (PlanterBox)c); + StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.objectsInWorldPath, I.Name + ".json"), (ModularCropObject)I); + } + + + + + } } diff --git a/GeneralMods/AdditionalCropsFramework/ModularSeeds.cs b/GeneralMods/AdditionalCropsFramework/ModularSeeds.cs index 9a099e88..0f80bcd7 100644 --- a/GeneralMods/AdditionalCropsFramework/ModularSeeds.cs +++ b/GeneralMods/AdditionalCropsFramework/ModularSeeds.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Xml.Serialization; using System.IO; +using Newtonsoft.Json.Linq; namespace AdditionalCropsFramework { @@ -52,6 +53,7 @@ namespace AdditionalCropsFramework TextureSheet = ModCore.ModHelper.Content.Load(Path.Combine(Utilities.EntensionsFolderName, ObjectSpriteSheet)); //Game1.content.Load("Revitalize\\CropsNSeeds\\Graphics\\seeds"); texturePath = ObjectSpriteSheet; } + this.serializationName = this.GetType().ToString(); Dictionary dictionary = ModCore.ModHelper.Content.Load>(Path.Combine(Utilities.EntensionsFolderName, ObjectDataFile));//Game1.content.Load>("Revitalize\\CropsNSeeds\\Data\\seeds"); dataFilePath = ObjectDataFile; cropDataFilePath = AssociatedCropDataFile; @@ -60,9 +62,6 @@ namespace AdditionalCropsFramework cropObjectDataFilePath = AssociatedCropObjectDataFile; cropObjectTextureFilePath = AssociatedCropObjectTexture; - Log.AsyncC(cropDataFilePath); - Log.AsyncG(cropTextureFilePath); - //Log.AsyncC(which); string[] array = dictionary[which].Split(new char[] @@ -395,10 +394,6 @@ namespace AdditionalCropsFramework return this.stack; } - public override int addToStack(int amount) - { - return 1; - } private float getScaleSize() { @@ -446,6 +441,15 @@ namespace AdditionalCropsFramework { //spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(this.defaultSourceRect), Color.White * transparency, 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * this.getScaleSize() * scaleSize, SpriteEffects.None, layerDepth); spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Rectangle?(this.defaultSourceRect), Color.White * transparency, 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height / 2)), 1f * this.getScaleSize() * scaleSize * 1.5f, SpriteEffects.None, layerDepth); + + + if (drawStackNumber && this.maximumStackSize() > 1 && ((double)scaleSize > 0.3 && this.Stack != int.MaxValue) && this.Stack > 1) + Utility.drawTinyDigits(this.stack, spriteBatch, location + new Vector2((float)(Game1.tileSize - Utility.getWidthOfTinyDigitString(this.stack, 3f * scaleSize)) + 3f * scaleSize, (float)((double)Game1.tileSize - 18.0 * (double)scaleSize + 2.0)), 3f * scaleSize, 1f, Color.White); + if (drawStackNumber && this.quality > 0) + { + float num = this.quality < 4 ? 0.0f : (float)((Math.Cos((double)Game1.currentGameTime.TotalGameTime.Milliseconds * Math.PI / 512.0) + 1.0) * 0.0500000007450581); + spriteBatch.Draw(Game1.mouseCursors, location + new Vector2(12f, (float)(Game1.tileSize - 12) + num), new Microsoft.Xna.Framework.Rectangle?(this.quality < 4 ? new Microsoft.Xna.Framework.Rectangle(338 + (this.quality - 1) * 8, 400, 8, 8) : new Microsoft.Xna.Framework.Rectangle(346, 392, 8, 8)), Color.White * transparency, 0.0f, new Vector2(4f, 4f), (float)(3.0 * (double)scaleSize * (1.0 + (double)num)), SpriteEffects.None, layerDepth); + } } public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) @@ -503,13 +507,13 @@ namespace AdditionalCropsFramework public override int maximumStackSize() { - return base.maximumStackSize(); + return 999; } public ModularCrop parseCropInfo(int seedIndex) { ModularCrop c = new ModularCrop(); - Log.AsyncC(this.cropDataFilePath); + // Log.AsyncC(this.cropDataFilePath); Dictionary dictionary = ModCore.ModHelper.Content.Load>(Path.Combine(Utilities.EntensionsFolderName, this.cropDataFilePath)); //Game1.content.Load>("Data\\Crops"); if (dictionary.ContainsKey(seedIndex)) @@ -576,5 +580,143 @@ namespace AdditionalCropsFramework return c; } + + + public static new void Serialize(Item I) + { + StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.playerInventoryPath, I.Name + ".json"), (ModularSeeds)I); + } + + public static Item ParseIntoInventory(string s) + { + // PlanterBox p = new PlanterBox(); + // return p; + + + + dynamic obj = JObject.Parse(s); + + ModularSeeds d = new ModularSeeds(); + + d.dataFilePath = obj.dataFilePath; + d.cropDataFilePath = obj.cropDataFilePath; + d.cropObjectDataFilePath = obj.cropObjectDataFilePath; + + + + d.texturePath = obj.texturePath; + d.cropTextureFilePath = obj.cropTextureFilePath; + d.cropObjectTextureFilePath = obj.cropObjectTextureFilePath; + + d.price = obj.price; + d.Decoration_type = obj.Decoration_type; + d.rotations = obj.rotations; + d.currentRotation = obj.currentRotation; + string s1 = Convert.ToString(obj.sourceRect); + d.sourceRect = Utilities.parseRectFromJson(s1); + string s2 = Convert.ToString(obj.defaultSourceRect); + d.defaultSourceRect = Utilities.parseRectFromJson(s2); + string s3 = Convert.ToString(obj.defaultBoundingBox); + d.defaultBoundingBox = Utilities.parseRectFromJson(s3); + d.description = obj.description; + d.flipped = obj.flipped; + d.flaggedForPickUp = obj.flaggedForPickUp; + d.tileLocation = obj.tileLocation; + d.parentSheetIndex = obj.parentSheetIndex; + d.owner = obj.owner; + d.name = obj.name; + d.type = obj.type; + d.canBeSetDown = obj.canBeSetDown; + d.canBeGrabbed = obj.canBeGrabbed; + d.isHoedirt = obj.isHoedirt; + d.isSpawnedObject = obj.isSpawnedObject; + d.questItem = obj.questItem; + d.isOn = obj.isOn; + d.fragility = obj.fragility; + d.edibility = obj.edibility; + d.stack = obj.stack; + d.quality = obj.quality; + d.bigCraftable = obj.bigCraftable; + d.setOutdoors = obj.setOutdoors; + d.setIndoors = obj.setIndoors; + d.readyForHarvest = obj.readyForHarvest; + d.showNextIndex = obj.showNextIndex; + d.hasBeenPickedUpByFarmer = obj.hasBeenPickedUpByFarmer; + d.isRecipe = obj.isRecipe; + d.isLamp = obj.isLamp; + d.heldObject = obj.heldObject; + d.minutesUntilReady = obj.minutesUntilReady; + string s4 = Convert.ToString(obj.boundingBox); + d.boundingBox = Utilities.parseRectFromJson(s4); + d.scale = obj.scale; + d.lightSource = obj.lightSource; + d.shakeTimer = obj.shakeTimer; + d.internalSound = obj.internalSound; + d.specialVariable = obj.specialVariable; + d.category = obj.category; + d.specialItem = obj.specialItem; + d.hasBeenInInventory = obj.hasBeenInInventory; + + + string t = obj.texturePath; + d.TextureSheet = ModCore.ModHelper.Content.Load(Path.Combine(Utilities.EntensionsFolderName, t)); + d.texturePath = t; + d.itemReadyForHarvest = obj.itemReadyForHarvest; + d.lightsOn = obj.lightsOn; + d.lightColor = obj.lightColor; + d.thisType = obj.thisType; + d.removable = obj.removable; + d.locationsName = obj.locationsName; + + d.drawColor = obj.drawColor; + d.serializationName = obj.serializationName; + + /* + //ANIMATIONS + var q = obj.animationManager; + dynamic obj1 = q; + string name = Convert.ToString(obj1.currentAnimationName); + int frame = Convert.ToInt32(obj1.currentAnimationListIndex); + PlanterBox dummy = new PlanterBox(d.parentSheetIndex, d.tileLocation, d.texturePath, d.dataPath, d.removable, d.IsSolid); + d.animationManager = dummy.animationManager; + bool f = d.animationManager.setAnimation(name, frame); + bool f2; + if (f == false) + { + f2 = d.animationManager.setAnimation(name, 0); + if (f2 == false) d.animationManager.currentAnimation = d.animationManager.defaultDrawFrame; + } + // Log.AsyncC(d.cropInformationString); + */ + + //ModularCrop f= j.ToObject(); + //ModularCrop f = obj.modularCrop; + + // Log.AsyncG("THIS IS CROP: " + c.indexOfHarvest); + //Log.AsyncG(cropString); + + + // d.crop = obj.crop; + // d.modularCrop = obj.modularCrop; + + + try + { + return d; + } + catch (Exception e) + { + // Log.AsyncM(e); + return null; + } + + //return base.ParseIntoInventory(); + } + + public static void SerializeFromWorld(Item I) + { + // ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, (c as CoreObject).thisLocation.name, c.Name + ".json"), (PlanterBox)c); + StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.objectsInWorldPath, I.Name + ".json"), (ModularSeeds)I); + } } } diff --git a/GeneralMods/AdditionalCropsFramework/PlanterBox.cs b/GeneralMods/AdditionalCropsFramework/PlanterBox.cs index d92d0fd6..53bf0e57 100644 --- a/GeneralMods/AdditionalCropsFramework/PlanterBox.cs +++ b/GeneralMods/AdditionalCropsFramework/PlanterBox.cs @@ -22,9 +22,6 @@ namespace AdditionalCropsFramework public class PlanterBox : CoreObject { - - public new int price; - public int Decoration_type; public int rotations; @@ -65,7 +62,6 @@ namespace AdditionalCropsFramework public string normalCropSeedName; public int normalCropSeedIndex; - public string serializationName="AdditionalCropsFramework.PlanterBox"; public override string Name { @@ -226,8 +222,8 @@ namespace AdditionalCropsFramework this.defaultSourceRect = this.sourceRect; try { - this.animationManager = new StardustCore.Animations.AnimationManager(this.TextureSheet, new StardustCore.Animations.Animation(this.defaultSourceRect, -1), AnimationManager.parseAnimationsFromXNB(array[3]), "default"); - this.animationManager.setAnimation("default", 0); + this.animationManager = new StardustCore.Animations.AnimationManager(this.TextureSheet, new StardustCore.Animations.Animation(this.defaultSourceRect, -1), AnimationManager.parseAnimationsFromXNB(array[3]), "Default"); + this.animationManager.setAnimation("Default", 0); //Log.AsyncC("Using animation manager"); } catch (Exception errr) @@ -315,21 +311,21 @@ namespace AdditionalCropsFramework } if (this.modularCrop != null) { - Log.AsyncM("HELLO MOD CROP"); + // Log.AsyncM("HELLO MOD CROP"); if (this.modularCrop.isFullyGrown() == true) { - Log.AsyncM("FULL BLOW"); + // Log.AsyncM("FULL BLOW"); bool f = Utilities.harvestModularCrop(this.modularCrop, (int)this.tileLocation.X, (int)this.tileLocation.Y, 0); if (f == true) { //this.modularCrop = null; if (f == true && this.modularCrop.regrowAfterHarvest == -1) this.modularCrop = null; - Log.AsyncO("HARVEST"); + // Log.AsyncO("HARVEST"); return false; } else { - Log.AsyncC("failed to harvest crop. =/"); + // Log.AsyncC("failed to harvest crop. =/"); } } } @@ -357,9 +353,9 @@ namespace AdditionalCropsFramework public void plantModdedCrop(ModularSeeds seeds) { - if (this.modularCrop != null) return; + if (this.modularCrop != null) return; this.modularCrop = new ModularCrop(seeds.parentSheetIndex, (int)Game1.currentCursorTile.X, (int)Game1.currentCursorTile.Y, seeds.cropDataFilePath, seeds.cropTextureFilePath, seeds.cropObjectTextureFilePath, seeds.cropObjectDataFilePath); - // Game1.player.reduceActiveItemByOne(); + Game1.player.reduceActiveItemByOne(); Game1.playSound("dirtyHit"); } @@ -375,12 +371,12 @@ namespace AdditionalCropsFramework } catch(Exception e) { - Log.AsyncM(e); + // Log.AsyncM(e); } foreach (var v in this.crop.phaseDays) { - Log.AsyncC("I grow! " + v); + // Log.AsyncC("I grow! " + v); } Game1.player.reduceActiveItemByOne(); Game1.playSound("dirtyHit"); @@ -395,7 +391,7 @@ namespace AdditionalCropsFramework if (Game1.player.getToolFromName(Game1.player.CurrentItem.Name) is StardewValley.Tools.WateringCan) { this.isWatered = true; - this.animationManager.setAnimation("watered", 0); + this.animationManager.setAnimation("Watered", 0); return false; } } @@ -478,7 +474,7 @@ namespace AdditionalCropsFramework public void dayUpdate() { - Log.AsyncC("HELLO?!?!?"); + if (this.isWatered==true) { if (this.crop != null) @@ -491,14 +487,14 @@ namespace AdditionalCropsFramework { Utilities.cropNewDayModded(this.modularCrop,1, 0, (int)this.tileLocation.X, (int)this.tileLocation.Y, this.thisLocation); } - Log.AsyncC("DRINK YOUR WATER"); + this.isWatered = false; - this.animationManager.setAnimation("default", 0); + this.animationManager.setAnimation("Default", 0); } else { - Log.AsyncC("No Water Here"); - this.animationManager.setAnimation("default", 0); + + this.animationManager.setAnimation("Default", 0); } } @@ -900,7 +896,7 @@ namespace AdditionalCropsFramework public static new void Serialize(Item I) { makeCropInformationString(I); - ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.playerInventoryPath, I.Name + ".json"), (PlanterBox)I); + StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.playerInventoryPath, I.Name + ".json"), (PlanterBox)I); } public static Item ParseIntoInventory(string s) @@ -981,11 +977,11 @@ namespace AdditionalCropsFramework d.drawColor = obj.drawColor; d.normalCropSeedIndex = obj.normalCropSeedIndex; d.cropInformationString = obj.cropInformationString; - + d.serializationName = obj.serializationName; d.IsSolid = obj.IsSolid; string IsWatered = obj.isWatered; - Log.AsyncC("AM I WATERED OR NOT?!?!?: "+IsWatered); + // Log.AsyncC("AM I WATERED OR NOT?!?!?: "+IsWatered); d.isWatered = Convert.ToBoolean(IsWatered); //ANIMATIONS var q = obj.animationManager; @@ -1027,10 +1023,10 @@ namespace AdditionalCropsFramework } d.modularCrop = c; - Log.AsyncM("PARSED MODULAR CROP!"); - Log.AsyncG(cropInfo[8]); - Log.AsyncG(cropInfo[9]); - Log.AsyncG(cropInfo[10]); + // Log.AsyncM("PARSED MODULAR CROP!"); + // Log.AsyncG(cropInfo[8]); + // Log.AsyncG(cropInfo[9]); + // Log.AsyncG(cropInfo[10]); } if (cropInfo[0] == "false") //non-modular crop { @@ -1051,7 +1047,7 @@ namespace AdditionalCropsFramework } else { - Log.AsyncR("AOSIDHA(IUDGUDIUBGDLIUGDOIHDO:IHDOIHDIOHDIOP"); + } c.currentPhase = Convert.ToInt32(cropInfo[4]); @@ -1065,17 +1061,12 @@ namespace AdditionalCropsFramework { } - Log.AsyncM("PARSED Regular CROP!"); - Log.AsyncG(cropInfo[1]); - Log.AsyncG(cropInfo[2]); - Log.AsyncG(cropInfo[3]); - Log.AsyncR(c.phaseDays.Count); - Log.AsyncM("PARSED REGULAR CROP! FINISH"); - - foreach(var v in c.phaseDays) - { - Log.AsyncG("THIS IS THE FINAL COUNT DOWN " + v); - } + // Log.AsyncM("PARSED Regular CROP!"); + // Log.AsyncG(cropInfo[1]); + // Log.AsyncG(cropInfo[2]); + // Log.AsyncG(cropInfo[3]); + // Log.AsyncR(c.phaseDays.Count); + // Log.AsyncM("PARSED REGULAR CROP! FINISH"); d.crop = c; } @@ -1112,7 +1103,7 @@ namespace AdditionalCropsFramework { makeCropInformationString(I); // ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, (c as CoreObject).thisLocation.name, c.Name + ".json"), (PlanterBox)c); - ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, I.Name + ".json"), (PlanterBox)I); + StardustCore.ModCore.SerializationManager.WriteToJsonFile(Path.Combine(StardustCore.ModCore.SerializationManager.objectsInWorldPath, I.Name + ".json"), (PlanterBox)I); } public static void makeCropInformationString(Item I) diff --git a/GeneralMods/RuneFactoryCropsMod/ModCore.cs b/GeneralMods/RuneFactoryCropsMod/ModCore.cs index 7c1099f4..fefd6f65 100644 --- a/GeneralMods/RuneFactoryCropsMod/ModCore.cs +++ b/GeneralMods/RuneFactoryCropsMod/ModCore.cs @@ -26,7 +26,9 @@ namespace RuneFactoryCropsMod { List shopInventory = new List(); string ModdedCropsFolderName = "RuneFactoryCropsMod"; - shopInventory.Add((Item)new ModularSeeds(1, Path.Combine(ModdedCropsFolderName,"SeedsGraphics.xnb"), Path.Combine(ModdedCropsFolderName,"SeedsData.xnb"), Path.Combine(ModdedCropsFolderName,"CropsGraphics.xnb"), Path.Combine(ModdedCropsFolderName,"CropsData.xnb"),Path.Combine(ModdedCropsFolderName,"CropsObjectTexture.xnb"), Path.Combine(ModdedCropsFolderName,"CropsObjectData.xnb"))); + shopInventory.Add((Item)new ModularSeeds(1, Path.Combine(ModdedCropsFolderName, "SeedsGraphics.xnb"), Path.Combine(ModdedCropsFolderName, "SeedsData.xnb"), Path.Combine(ModdedCropsFolderName, "CropsGraphics.xnb"), Path.Combine(ModdedCropsFolderName, "CropsData.xnb"), Path.Combine(ModdedCropsFolderName, "CropsObjectTexture.xnb"), Path.Combine(ModdedCropsFolderName, "CropsObjectData.xnb")){ + stack = 5 + }); shopInventory.Add((Item)new PlanterBox(1, Vector2.Zero, Path.Combine(ModdedCropsFolderName, "PlanterBox.png"), Path.Combine(ModdedCropsFolderName, "PlanterBox.xnb"))); shopInventory.Add((Item)new ModularCropObject(816, 1, Path.Combine(ModdedCropsFolderName, "CropsObjectTexture.xnb"), Path.Combine(ModdedCropsFolderName, "CropsObjectData.xnb"))); Game1.activeClickableMenu = new StardewValley.Menus.ShopMenu(shopInventory); diff --git a/GeneralMods/RuneFactoryCropsMod/RuneFactoryCropsMod/PlanterBox.xnb b/GeneralMods/RuneFactoryCropsMod/RuneFactoryCropsMod/PlanterBox.xnb index 8c33fc365e47943eec5dac495cec49212124ae3e..8236dcddad015fcccc3a8dc47c66bb2cf24f6830 100644 GIT binary patch delta 1102 zcmV-U1hM#^-rn8r(B6w8jv$N(ix>z4+YTn3EmKRo zxpw+55fQi_>qmV(R(oL>MC0{}%c0B~>yzxPis7j2MER+e4(26qC#iBJs2i-;pu zAkuE{x1Fg-x!rfxHL_eu#hE3}=GGX=U?ljZzZv@f00aO40Dk~VNCu!@9S8OP2uDtP$kvf;h~ovJ-(I)|D?^*%atblDd|i2#$uzz6ewSCd zn>kV-Chf`6)L7&2ES`+D~Ef$ob!slWICEW4abv;W1ivYYcsXMdDgmv}oD9xi#) z-AyO-dAB@+HS`#r?BL+n?LWX*>;=#(UP?DeVCG*8;5Y-PH+F4oJb5vRRim7d7Zxy| zptLz(wYPv)i#y=!8elXWh99uv-5AwXNBzpa4JeJkg?~Ra6QQ*?f^p!$rS@geG?P~J zPkq%qn|B<2PKvWU&Mt2Wq{X|PMUG21Q`QV~FpSQoU9RA|Jk=rw-kl*gQVVEY%1d5ny76IQ_ztxKPV_b@MA&=%dKSW)H; z(A(lsn7VZo*+?Dd=qkt*RVzza5^z0fv^idzgnrHntR^ZamF^h0;}UPR&|7Re{Nd@y zr;Htp&50Wx(Q7g~ob^X;!u(|`OCLz9?0@N|{jDb7;pj}QGpKLYjk8Ub)Nnn-_lid9 z*;Aco&Z*L%GLUpyu~8}3pL4e=zo$(~we@7WODj~MgUnuB`COy*Y^LZNyTutvD|@zN z9i#%ZO3qfX6u9CGf(s?HXIiiQ7fF+95rW(k5KPo#)zx0;b;IIB6ZUMi&zRN@(MPG) zxQD-fePSCz!;3|&Lw6by=Pogc)&PzM1-DA`v0W9TjGQicm#VBRoyE>q00;p9qL~1=I0N5%PnQ>MkWN*W1Ha&|;MWmK!8j3-#A-x( z>m6OED$;Iuopp`uS5|Q*iF3JiMzS0UzZ5qE|NnqM0000034aLyRI9_F-XGzJ%8u;* z{we<7uy+w31H>JnY=*uN=m zzq|H^Fz?T^RYZ`{)ehr*-Tq*ChrbDa%8Ts=0A?q|6dbqUdS}PR$&VhDSv}w^y|9G| z0%n^NReu9$g}M?5iPi@Zy5R<_)i!~3?@^4jw*}~t;(u^9=0L3cM?Ovl3}at{R;sL~ ze^jU$^(l5wwEO9;bbzTK5*rUNKBesIszp!QiL3` zlQc2=l0z@QT7xXmKEm;X-Smwgyd1s>qj?%l8RK&qX)G$^syQAerhAo5;R#e$IeaFq zY?AROH23JiFTx|6C;ydlj(*C@(G{2c0i%C{;(rW!&=5SWbfMLbXfKFA#O!3>#x{k+FU`z?B<9Enp)lZ930^ zrl30$Q*^K5F)9OzBhtg5&zI0=-Fo7sk53VbfkC#3Eu+@=N)wc=YZI?>`R;(Qs> z7)J|BXeO_X;z*aJZXEqbI|3hNtxxJm{eNsW=HabS-!tgnaz{iKSy#`R1n;4(jM*j~ z>(4_{XJw}7AY-9Yv_GS6uYTu?bZSqtX)e~#=)FUEuzPSK!000000GZAsWB>pF diff --git a/GeneralMods/StardustCore/CoreObject.cs b/GeneralMods/StardustCore/CoreObject.cs index a630cb4e..3a9b7a12 100644 --- a/GeneralMods/StardustCore/CoreObject.cs +++ b/GeneralMods/StardustCore/CoreObject.cs @@ -74,6 +74,8 @@ namespace StardustCore public AnimationManager animationManager; + public string serializationName; + public override string Name { get diff --git a/GeneralMods/StardustCore/ModCore.cs b/GeneralMods/StardustCore/ModCore.cs index 09b30921..dfbb93b1 100644 --- a/GeneralMods/StardustCore/ModCore.cs +++ b/GeneralMods/StardustCore/ModCore.cs @@ -3,8 +3,10 @@ using StardewModdingAPI; using StardewValley; using StardewValley.Menus; using StardustCore.ModInfo; +using StardustCore.Serialization; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -15,15 +17,41 @@ namespace StardustCore { public static IModHelper ModHelper; public static IMonitor ModMonitor; + public static Serialization.SerializationManager SerializationManager; public override void Entry(IModHelper helper) { ModHelper = helper; ModMonitor = this.Monitor; //Unused MetaData information. Works in player inventory but not in chests. Besides who really care where an object is from anyways. Also doesn't work 100% like I intended since it only gets base mod object that this runs from, not extensions? - - // StardewModdingAPI.Events.GraphicsEvents.OnPostRenderGuiEvent += Metadata.GameEvents_UpdateTick; - // StardewModdingAPI.Events.ControlEvents.MouseChanged += ControlEvents_MouseChanged; - + + // StardewModdingAPI.Events.GraphicsEvents.OnPostRenderGuiEvent += Metadata.GameEvents_UpdateTick; + // StardewModdingAPI.Events.ControlEvents.MouseChanged += ControlEvents_MouseChanged; + string invPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "PlayerData", Game1.player.name, "PlayerInventory"); + string worldPath = Path.Combine(ModCore.ModHelper.DirectoryPath, Game1.player.name, "ObjectsInWorld"); ; + string trashPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "ModTrashFolder"); + string chestPath = Path.Combine(ModCore.ModHelper.DirectoryPath, "StorageContainers"); + SerializationManager = new SerializationManager(invPath, trashPath, worldPath,chestPath); + + StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave; + StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave; + StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; + } + + private void SaveEvents_AfterLoad(object sender, EventArgs e) + { + SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList); + } + + private void SaveEvents_AfterSave(object sender, EventArgs e) + { + SerializationManager.restoreAllModObjects(SerializationManager.trackedObjectList); + + } + + private void SaveEvents_BeforeSave(object sender, EventArgs e) + { + SerializationManager.cleanUpInventory(); + SerializationManager.cleanUpWorld(); } private void ControlEvents_MouseChanged(object sender, StardewModdingAPI.Events.EventArgsMouseStateChanged e) diff --git a/GeneralMods/StardustCore/Serialization/Serialization.cs b/GeneralMods/StardustCore/Serialization/Serialization.cs index 8dd19032..3bd23854 100644 --- a/GeneralMods/StardustCore/Serialization/Serialization.cs +++ b/GeneralMods/StardustCore/Serialization/Serialization.cs @@ -2,6 +2,7 @@ using Newtonsoft.Json.Linq; using StardewModdingAPI; using StardewValley; +using StardewValley.Buildings; using System; using System.Collections.Generic; using System.IO; @@ -22,27 +23,30 @@ namespace StardustCore.Serialization { public string objectsInWorldPath; public string playerInventoryPath; - public string SerializerTrashPath; + public string serializerTrashPath; + public string storageContainerPath; - public Dictionary acceptedTypes = new Dictionary(); - public List trackedObjectList = new List(); + + public Dictionary acceptedTypes = new Dictionary(); + public List trackedObjectList = new List(); - public SerializationManager(string PlayerInventoryPath,string SerializerTrashPath,string ObjectsInWorldPath) + public SerializationManager(string PlayerInventoryPath,string SerializerTrashPath,string ObjectsInWorldPath,string StorageContainerPath) { - this.objectsInWorldPath = ObjectsInWorldPath; - this.playerInventoryPath = PlayerInventoryPath; - this.SerializerTrashPath = SerializerTrashPath; - + objectsInWorldPath = ObjectsInWorldPath; + playerInventoryPath = PlayerInventoryPath; + serializerTrashPath = SerializerTrashPath; + storageContainerPath = StorageContainerPath; verifyAllDirectoriesExist(); } private void verifyAllDirectoriesExist() { - if (!Directory.Exists(this.playerInventoryPath)) Directory.CreateDirectory(this.playerInventoryPath); - if (!Directory.Exists(this.SerializerTrashPath)) Directory.CreateDirectory(this.SerializerTrashPath); - if (!Directory.Exists(this.objectsInWorldPath)) Directory.CreateDirectory(this.objectsInWorldPath); + if (!Directory.Exists(playerInventoryPath)) Directory.CreateDirectory(playerInventoryPath); + if (!Directory.Exists(serializerTrashPath)) Directory.CreateDirectory(serializerTrashPath); + if (!Directory.Exists(objectsInWorldPath)) Directory.CreateDirectory(objectsInWorldPath); + if (!Directory.Exists(storageContainerPath)) Directory.CreateDirectory(storageContainerPath); } public void cleanUpInventory() @@ -99,7 +103,7 @@ namespace StardustCore.Serialization } catch(Exception e) { - Log.AsyncC(e); + // Log.AsyncC(e); } List removalList = new List(); int countProcessed = 0; @@ -123,7 +127,7 @@ namespace StardustCore.Serialization if (acceptedTypes.ContainsKey(s)) { - Log.AsyncM("Object is of accepted type: " + s); + // Log.AsyncM("Object is of accepted type: " + s); SerializerDataNode t; bool works = acceptedTypes.TryGetValue(s, out t); @@ -132,7 +136,7 @@ namespace StardustCore.Serialization countProcessed++; if (d.useXML == false) { - Log.AsyncY("Saving the object"); + // Log.AsyncY("Saving the object"); t.worldObj.Invoke(d); } else @@ -175,11 +179,43 @@ namespace StardustCore.Serialization } + public static void cleanUpStorageContainers() + { + foreach (GameLocation loc in Game1.locations) + { + foreach (var obj in loc.objects) + { + if (obj.Value is StardewValley.Objects.Chest) { + foreach(var item in (obj.Value as StardewValley.Objects.Chest).items) + { + if (item is CoreObject) (obj.Value as StardewValley.Objects.Chest).items.Remove(item); + } + } + } + } + + foreach (Building building in Game1.getFarm().buildings) + { + GameLocation loc =Game1.getLocationFromName(building.nameOfIndoors,true); + Log.AsyncG("THIS IS MY BUILDING!!!!!"); + foreach (var obj in loc.objects) + { + if (obj.Value is StardewValley.Objects.Chest) + { + foreach (var item in (obj.Value as StardewValley.Objects.Chest).items) + { + if (item is CoreObject) (obj.Value as StardewValley.Objects.Chest).items.Remove(item); + } + } + } + } + } public void restoreAllModObjects(List thingsToAddBackIn) { - processDirectoryForDeserialization(this.playerInventoryPath,thingsToAddBackIn); - Log.AsyncG("DESERIALIZE???"); + processDirectoryForDeserialization(playerInventoryPath,thingsToAddBackIn); + processDirectoryForDeserialization(storageContainerPath, thingsToAddBackIn); + // Log.AsyncG("Done deserializing player inventory."); try { trackedObjectList.Clear(); //clear whatever mod objects I'm tracking @@ -261,9 +297,12 @@ namespace StardustCore.Serialization public void processDirectoryForDeserialization(string pathToFile,List thingsToAddBackIn) { string[] fileEntries = Directory.GetFiles(pathToFile); + // Log.AsyncC(pathToFile); + foreach(var fileName in fileEntries) { ProcessFileForCleanUp(fileName,thingsToAddBackIn); + // Log.AsyncG(fileName); } string[] subDirectories = Directory.GetDirectories(pathToFile); @@ -278,7 +317,7 @@ namespace StardustCore.Serialization public void ProcessFileForCleanUp(string path, List thingsToAddBackIn) { - Log.AsyncC(path); + //Log.AsyncC(path); string[] ehh = File.ReadAllLines(path); string data = ehh[0]; @@ -298,7 +337,7 @@ namespace StardustCore.Serialization a = obj.serializationName; b = a.Split(','); s = b.ElementAt(0); - Log.AsyncC(s); + // Log.AsyncC(s); } catch (Exception e) { @@ -315,7 +354,7 @@ namespace StardustCore.Serialization if ((cObj as CoreObject).thisLocation == null) { Game1.player.addItemToInventory(cObj); - Log.AsyncY("ADDED ITEM TO INVENTORY"); + // Log.AsyncY("ADDED ITEM TO INVENTORY"); return; } else @@ -350,23 +389,23 @@ namespace StardustCore.Serialization //USE JSON STYLE DESERIALIZNG if (acceptedTypes.ContainsKey(s)) { - Log.AsyncC("FUUUUU"); + //Log.AsyncC("FUUUUU"); foreach (KeyValuePair pair in acceptedTypes) { - Log.AsyncY(pair.Key); + // Log.AsyncY(pair.Key); if (pair.Key == s) { try { //parse from Json Style - Log.AsyncR("1"); + // Log.AsyncR("1"); cObj = (CoreObject)pair.Value.parse.Invoke(data); (cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName); if ((cObj as CoreObject).thisLocation == null) { Game1.player.addItemToInventory(cObj); - Log.AsyncY("ADDED ITEM TO INVENTORY"); + // Log.AsyncY("ADDED ITEM TO INVENTORY"); return; } else @@ -378,7 +417,7 @@ namespace StardustCore.Serialization } catch (Exception e) { - Log.AsyncO(e); + // Log.AsyncO(e); } } }