From fa5970661b0aa907616533e5c38c6ea2855500a3 Mon Sep 17 00:00:00 2001 From: Date: Tue, 5 Sep 2017 04:13:42 -0700 Subject: [PATCH] Moved around soem files, made a core library mod that will include a bunch of things in the future. For the moment, a custom serializer/deserializer. Implemented it with AdditionalCrops. Needs some more work. --- .../ClassLibrary1/ClassLibrary1.sln | 0 .../ClassLibrary1/ClassLibrary1/Class1.cs | 0 .../ClassLibrary1/Properties/AssemblyInfo.cs | 0 .../ClassLibrary1/ClassLibrary1/Readme.txt | 0 .../ClassLibrary1/SoundExample.csproj | 0 .../ClassLibrary1/deploy.targets | 0 .../ClassLibrary1/ClassLibrary1/manifest.json | 0 .../ClassLibrary1/packages.config | 0 .../ClassLibrary1/deploy.targets | 0 .../AdditionalCropsFramework.csproj | 8 +- .../Framework/Utilities.cs | 31 +- .../AdditionalCropsFramework/ModCore.cs | 39 +- .../AdditionalCropsFramework/ModularCrop.cs | 4 +- .../ModularCropObject.cs | 41 +- .../AdditionalCropsFramework/ModularSeeds.cs | 2 +- .../AdditionalCropsFramework/PlanterBox.cs | 195 ++- .../AdditionalCropsFramework/packages.config | 1 + .../OmegasisCore}/OmegasisCore.sln | 0 .../OmegasisCore}/OmegasisCore.zip | Bin .../OmegasisCore/AdditionalLogs.cs | 0 .../OmegasisCore}/OmegasisCore/Logger.cs | 0 .../ClickableTextureComponentExtended.cs | 0 .../GameMenuComponentPair.cs | 0 .../TextureDataNode.cs | 0 .../MenuComponentsAndResources/Utility.cs | 0 .../OmegasisCore/Menus/ModdedGameMenu.cs | 0 .../OmegasisCore/Menus/ModdedMapPage.cs | 0 .../OmegasisCore}/OmegasisCore/ModCore.cs | 0 .../OmegasisCore}/OmegasisCore/ModInfo.cs | 0 .../OmegasisCore}/OmegasisCore/ModInfo.txt | 0 .../OmegasisCore/OmegasisCore.csproj | 0 .../OmegasisCore/Properties/AssemblyInfo.cs | 0 .../OmegasisCore/Resources/Dictionaries.cs | 0 .../OmegasisCore/Resources/Lists.cs | 0 .../OmegasisCore}/OmegasisCore/manifest.json | 0 .../OmegasisCore/packages.config | 0 .../OmegasisCoreLibrary/Class1.cs | 12 + .../OmegasisCoreLibrary.csproj | 61 + .../Properties/AssemblyInfo.cs | 36 + .../OutDatedMods/Serialization/Class1.cs | 19 + .../Serialization}/CoreObject.cs | 19 +- .../Serialization/Properties/AssemblyInfo.cs | 36 + .../Serialization/Serialization.cs | 293 ++++ .../Serialization/Serialization.csproj | 74 + .../Serialization/SerializerDataNode.cs | 27 + .../OutDatedMods/Serialization/Utilities.cs | 37 + .../OutDatedMods/Serialization/manifest.json | 14 + .../Serialization/packages.config | 5 + GeneralMods/StardewMods.sln | 6 + GeneralMods/StardustCore/CoreObject.cs | 1541 +++++++++++++++++ GeneralMods/StardustCore/ModCore.cs | 14 + .../StardustCore/Properties/AssemblyInfo.cs | 36 + .../Serialization/Serialization.cs | 417 +++++ .../Serialization/SerializerDataNode.cs | 27 + GeneralMods/StardustCore/StardustCore.csproj | 82 + GeneralMods/StardustCore/manifest.json | 14 + GeneralMods/StardustCore/packages.config | 5 + SunDrop/ReadMe.txt | 1 + 58 files changed, 3014 insertions(+), 83 deletions(-) rename {Frameworks => FrameworksExamples}/SimpleSoundManager/ClassLibrary1/ClassLibrary1.sln (100%) rename {Frameworks => FrameworksExamples}/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Class1.cs (100%) rename {Frameworks => FrameworksExamples}/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Properties/AssemblyInfo.cs (100%) rename {Frameworks => FrameworksExamples}/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Readme.txt (100%) rename {Frameworks => FrameworksExamples}/SimpleSoundManager/ClassLibrary1/ClassLibrary1/SoundExample.csproj (100%) rename {Frameworks => FrameworksExamples}/SimpleSoundManager/ClassLibrary1/ClassLibrary1/deploy.targets (100%) rename {Frameworks => FrameworksExamples}/SimpleSoundManager/ClassLibrary1/ClassLibrary1/manifest.json (100%) rename {Frameworks => FrameworksExamples}/SimpleSoundManager/ClassLibrary1/ClassLibrary1/packages.config (100%) rename {Frameworks => FrameworksExamples}/SimpleSoundManager/ClassLibrary1/deploy.targets (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore.sln (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore.zip (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/AdditionalLogs.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/Logger.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/Menus/MenuComponentsAndResources/ClickableTextureComponentExtended.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/Menus/MenuComponentsAndResources/GameMenuComponentPair.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/Menus/MenuComponentsAndResources/TextureDataNode.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/Menus/MenuComponentsAndResources/Utility.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/Menus/ModdedGameMenu.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/Menus/ModdedMapPage.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/ModCore.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/ModInfo.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/ModInfo.txt (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/OmegasisCore.csproj (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/Properties/AssemblyInfo.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/Resources/Dictionaries.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/Resources/Lists.cs (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/manifest.json (100%) rename {OmegasisCore => GeneralMods/OutDatedMods/OmegasisCore}/OmegasisCore/packages.config (100%) create mode 100644 GeneralMods/OutDatedMods/OmegasisCoreLibrary/Class1.cs create mode 100644 GeneralMods/OutDatedMods/OmegasisCoreLibrary/OmegasisCoreLibrary.csproj create mode 100644 GeneralMods/OutDatedMods/OmegasisCoreLibrary/Properties/AssemblyInfo.cs create mode 100644 GeneralMods/OutDatedMods/Serialization/Class1.cs rename GeneralMods/{AdditionalCropsFramework => OutDatedMods/Serialization}/CoreObject.cs (99%) create mode 100644 GeneralMods/OutDatedMods/Serialization/Properties/AssemblyInfo.cs create mode 100644 GeneralMods/OutDatedMods/Serialization/Serialization.cs create mode 100644 GeneralMods/OutDatedMods/Serialization/Serialization.csproj create mode 100644 GeneralMods/OutDatedMods/Serialization/SerializerDataNode.cs create mode 100644 GeneralMods/OutDatedMods/Serialization/Utilities.cs create mode 100644 GeneralMods/OutDatedMods/Serialization/manifest.json create mode 100644 GeneralMods/OutDatedMods/Serialization/packages.config create mode 100644 GeneralMods/StardustCore/CoreObject.cs create mode 100644 GeneralMods/StardustCore/ModCore.cs create mode 100644 GeneralMods/StardustCore/Properties/AssemblyInfo.cs create mode 100644 GeneralMods/StardustCore/Serialization/Serialization.cs create mode 100644 GeneralMods/StardustCore/Serialization/SerializerDataNode.cs create mode 100644 GeneralMods/StardustCore/StardustCore.csproj create mode 100644 GeneralMods/StardustCore/manifest.json create mode 100644 GeneralMods/StardustCore/packages.config create mode 100644 SunDrop/ReadMe.txt diff --git a/Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1.sln b/FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1.sln similarity index 100% rename from Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1.sln rename to FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1.sln diff --git a/Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Class1.cs b/FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Class1.cs similarity index 100% rename from Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Class1.cs rename to FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Class1.cs diff --git a/Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Properties/AssemblyInfo.cs b/FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Properties/AssemblyInfo.cs similarity index 100% rename from Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Properties/AssemblyInfo.cs rename to FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Properties/AssemblyInfo.cs diff --git a/Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Readme.txt b/FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Readme.txt similarity index 100% rename from Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Readme.txt rename to FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/Readme.txt diff --git a/Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/SoundExample.csproj b/FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/SoundExample.csproj similarity index 100% rename from Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/SoundExample.csproj rename to FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/SoundExample.csproj diff --git a/Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/deploy.targets b/FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/deploy.targets similarity index 100% rename from Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/deploy.targets rename to FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/deploy.targets diff --git a/Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/manifest.json b/FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/manifest.json similarity index 100% rename from Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/manifest.json rename to FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/manifest.json diff --git a/Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/packages.config b/FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/packages.config similarity index 100% rename from Frameworks/SimpleSoundManager/ClassLibrary1/ClassLibrary1/packages.config rename to FrameworksExamples/SimpleSoundManager/ClassLibrary1/ClassLibrary1/packages.config diff --git a/Frameworks/SimpleSoundManager/ClassLibrary1/deploy.targets b/FrameworksExamples/SimpleSoundManager/ClassLibrary1/deploy.targets similarity index 100% rename from Frameworks/SimpleSoundManager/ClassLibrary1/deploy.targets rename to FrameworksExamples/SimpleSoundManager/ClassLibrary1/deploy.targets diff --git a/GeneralMods/AdditionalCropsFramework/AdditionalCropsFramework.csproj b/GeneralMods/AdditionalCropsFramework/AdditionalCropsFramework.csproj index 0250fc69..289daffa 100644 --- a/GeneralMods/AdditionalCropsFramework/AdditionalCropsFramework.csproj +++ b/GeneralMods/AdditionalCropsFramework/AdditionalCropsFramework.csproj @@ -32,6 +32,13 @@ 4 + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + True + + + ..\StardustCore\bin\Release\StardustCore.dll + @@ -42,7 +49,6 @@ - diff --git a/GeneralMods/AdditionalCropsFramework/Framework/Utilities.cs b/GeneralMods/AdditionalCropsFramework/Framework/Utilities.cs index 4dd5e1d0..9e4645b2 100644 --- a/GeneralMods/AdditionalCropsFramework/Framework/Utilities.cs +++ b/GeneralMods/AdditionalCropsFramework/Framework/Utilities.cs @@ -1,9 +1,11 @@ -using Microsoft.Xna.Framework; +using AdditionalCropsFramework.Framework; +using Microsoft.Xna.Framework; using StardewModdingAPI; using StardewValley; using StardewValley.Locations; using StardewValley.Objects; using StardewValley.TerrainFeatures; +using StardustCore; using System; using System.Collections.Generic; using System.Linq; @@ -11,12 +13,12 @@ using System.Text; using System.Threading.Tasks; using xTile.Dimensions; -namespace AdditionalCropsFramework.Framework +namespace AdditionalCropsFramework { class Utilities { - public static List trackedTerrainFeatures= new List(); - public static List trackedObjectList = new List(); + public static List trackedTerrainFeatures= new List(); + public static List NonSolidThingsToDraw = new List(); @@ -684,7 +686,7 @@ namespace AdditionalCropsFramework.Framework } //Log.AsyncM("Placed and object"); cObj.locationsName = location.name; - trackedObjectList.Add(cObj); + ModCore.serilaizationManager.trackedObjectList.Add(cObj); return true; } @@ -697,7 +699,7 @@ namespace AdditionalCropsFramework.Framework if (Game1.player.isInventoryFull() == false) { Game1.player.addItemToInventoryBool(I, false); - trackedObjectList.Remove(I); + ModCore.serilaizationManager.trackedObjectList.Remove(I); return true; } else @@ -712,5 +714,22 @@ namespace AdditionalCropsFramework.Framework } + public static Microsoft.Xna.Framework.Rectangle parseRectFromJson(string s) + { + + + + s = s.Replace('{', ' '); + s = s.Replace('}', ' '); + s = s.Replace('^', ' '); + s = s.Replace(':', ' '); + string[] parsed = s.Split(' '); + foreach (var v in parsed) + { + //Log.AsyncY(v); + } + return new Microsoft.Xna.Framework.Rectangle(Convert.ToInt32(parsed[2]), Convert.ToInt32(parsed[4]), Convert.ToInt32(parsed[6]), Convert.ToInt32(parsed[8])); + } + } } diff --git a/GeneralMods/AdditionalCropsFramework/ModCore.cs b/GeneralMods/AdditionalCropsFramework/ModCore.cs index 9ef5bc08..b437f0a3 100644 --- a/GeneralMods/AdditionalCropsFramework/ModCore.cs +++ b/GeneralMods/AdditionalCropsFramework/ModCore.cs @@ -3,12 +3,15 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; using StardewModdingAPI; using StardewValley; +using StardustCore.Serialization; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; + namespace AdditionalCropsFramework { @@ -21,15 +24,21 @@ namespace AdditionalCropsFramework ! Add way for crops to be watered and to ensure that there is a graphical update when the crop is being watered. ! Add way to harvest crop from planterbox without removing planterbox. ! Fix invisible planterbox so that it does get removed when planting seeds on tillable soil and keep that soil as HoeDirt instead of reverting to normal. This can also be used to just make the dirt look wet. - * * */ + ! Add in Multiple layers to the Planter Boxes: SoilLayer->CropLayer->BoxLayer is the draw order. Mainly for aesthetics. Box on top, dry dirt below, and wet dirt below that. + * * * */ public class ModCore : Mod { public static IModHelper ModHelper; + + + public static readonly List SpringWildCrops = new List(); 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; + public override void Entry(IModHelper helper) @@ -37,10 +46,36 @@ namespace AdditionalCropsFramework ModHelper = helper; StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed; + StardewModdingAPI.Events.SaveEvents.AfterLoad += SaveEvents_AfterLoad; + StardewModdingAPI.Events.SaveEvents.BeforeSave += SaveEvents_BeforeSave; + StardewModdingAPI.Events.SaveEvents.AfterSave += SaveEvents_AfterSave; + + } + private void SaveEvents_AfterSave(object sender, EventArgs e) + { + serilaizationManager.restoreAllModObjects(serilaizationManager.trackedObjectList); + } + 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); + } private void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e) @@ -50,7 +85,7 @@ namespace AdditionalCropsFramework List shopInventory = new List(); shopInventory.Add((Item)new ModularSeeds(1, "SeedsGraphics", "SeedsData", "CropsGraphics", "CropsData","CropsObjectTexture","CropsObjectData")); shopInventory.Add((Item)new PlanterBox(0, Vector2.Zero)); - shopInventory.Add((Item)new PlanterBox(1, Vector2.Zero, "PlanterBox.png", "PlanterBox")); + shopInventory.Add((Item)new PlanterBox(1, Vector2.Zero, "PlanterBox.png", "PlanterBox.xnb")); Game1.activeClickableMenu = new StardewValley.Menus.ShopMenu(shopInventory); } } diff --git a/GeneralMods/AdditionalCropsFramework/ModularCrop.cs b/GeneralMods/AdditionalCropsFramework/ModularCrop.cs index 6caf62f5..1acc22cb 100644 --- a/GeneralMods/AdditionalCropsFramework/ModularCrop.cs +++ b/GeneralMods/AdditionalCropsFramework/ModularCrop.cs @@ -249,7 +249,7 @@ namespace StardewValley if (junimoHarvester != null) junimoHarvester.tryToAddItemToHut((Item)new ModularCropObject(this.indexOfHarvest, 1, this.cropObjectTexture, this.cropObjectData)); else - AdditionalCropsFramework.Framework.Utilities.createObjectDebris((Item)new ModularCropObject(this.indexOfHarvest, this.getAmountForHarvest(), this.cropObjectTexture, this.cropObjectData), xTile, yTile, xTile, yTile, -1, this.getQualityOfCrop(), 1); + AdditionalCropsFramework.Utilities.createObjectDebris((Item)new ModularCropObject(this.indexOfHarvest, this.getAmountForHarvest(), this.cropObjectTexture, this.cropObjectData), xTile, yTile, xTile, yTile, -1, this.getQualityOfCrop(), 1); //Game1.createObjectDebris(this.indexOfHarvest, xTile, yTile, -1, num2, 1f, (GameLocation)null); } @@ -309,7 +309,7 @@ namespace StardewValley for (int index = 0; index < num1 - 1; ++index) { if (junimoHarvester == null) - AdditionalCropsFramework.Framework.Utilities.createObjectDebris((Item)new ModularCropObject(this.indexOfHarvest, this.getAmountForHarvest(), this.cropObjectTexture, this.cropObjectData), xTile, yTile, xTile, yTile, -1, this.getQualityOfCrop(), 1); + AdditionalCropsFramework.Utilities.createObjectDebris((Item)new ModularCropObject(this.indexOfHarvest, this.getAmountForHarvest(), this.cropObjectTexture, this.cropObjectData), xTile, yTile, xTile, yTile, -1, this.getQualityOfCrop(), 1); else junimoHarvester.tryToAddItemToHut((Item)new ModularCropObject(this.indexOfHarvest, this.getAmountForHarvest(), this.cropObjectTexture, this.cropObjectData)); } diff --git a/GeneralMods/AdditionalCropsFramework/ModularCropObject.cs b/GeneralMods/AdditionalCropsFramework/ModularCropObject.cs index 4a69b6e2..5e2e336b 100644 --- a/GeneralMods/AdditionalCropsFramework/ModularCropObject.cs +++ b/GeneralMods/AdditionalCropsFramework/ModularCropObject.cs @@ -6,6 +6,7 @@ using StardewValley; using StardewValley.Locations; using StardewValley.Menus; using StardewValley.Objects; +using StardustCore; using System; using System.Collections.Generic; using System.Xml.Serialization; @@ -16,7 +17,7 @@ namespace AdditionalCropsFramework /// Revitalize ModularCropObject Class. This is a core class and should only be extended upon. /// /// - public class ModularCropObject : StardewValley.Object + public class ModularCropObject : CoreObject { public new int price; @@ -100,7 +101,6 @@ namespace AdditionalCropsFramework }); this.name = array[0]; - this.Decoration_type = this.getTypeNumberFromName(array[1]); this.description = "Can be placed inside your house."; this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 1, 1); if (array[2].Equals("-1")) @@ -1244,41 +1244,6 @@ namespace AdditionalCropsFramework return new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, num * Game1.tileSize, num2 * Game1.tileSize); } - private int getTypeNumberFromName(string typeName) - { - string key; - switch (key = typeName.ToLower()) - { - case "chair": - return 0; - case "bench": - return 1; - case "couch": - return 2; - case "armchair": - return 3; - case "dresser": - return 4; - case "long table": - return 5; - case "painting": - return 6; - case "lamp": - return 7; - case "decor": - return 8; - case "bookcase": - return 10; - case "table": - return 11; - case "rug": - return 12; - case "window": - return 13; - } - return 9; - } - public override int salePrice() { return this.price; @@ -1406,8 +1371,10 @@ namespace AdditionalCropsFramework public override Color getCategoryColor() { return Color.DarkBlue; + } + } } diff --git a/GeneralMods/AdditionalCropsFramework/ModularSeeds.cs b/GeneralMods/AdditionalCropsFramework/ModularSeeds.cs index 0f4e20ab..6fbe3d28 100644 --- a/GeneralMods/AdditionalCropsFramework/ModularSeeds.cs +++ b/GeneralMods/AdditionalCropsFramework/ModularSeeds.cs @@ -1,6 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; - +using StardustCore; using StardewModdingAPI; using StardewValley; using StardewValley.Locations; diff --git a/GeneralMods/AdditionalCropsFramework/PlanterBox.cs b/GeneralMods/AdditionalCropsFramework/PlanterBox.cs index ced7da70..ac6f7745 100644 --- a/GeneralMods/AdditionalCropsFramework/PlanterBox.cs +++ b/GeneralMods/AdditionalCropsFramework/PlanterBox.cs @@ -1,14 +1,16 @@ using AdditionalCropsFramework.Framework; 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 System; using System.Collections.Generic; +using System.IO; using System.Xml.Serialization; namespace AdditionalCropsFramework @@ -58,6 +60,8 @@ namespace AdditionalCropsFramework public ModularCrop modularCrop; public bool isWatered; + public string serializationName="AdditionalCropsFramework.PlanterBox"; + public override string Name { get @@ -79,6 +83,7 @@ namespace AdditionalCropsFramework public PlanterBox(int which, Vector2 tile, bool isRemovable = true, int price = 0, bool isSolid = false) { removable = isRemovable; + this.serializationName =Convert.ToString(GetType()); // this.thisType = GetType(); this.tileLocation = tile; this.InitializeBasics(0, tile); @@ -122,6 +127,7 @@ namespace AdditionalCropsFramework public PlanterBox(int which, Vector2 tile, string ObjectTexture, bool isRemovable = true, int price = 0, bool isSolid = false) { removable = isRemovable; + this.serializationName = Convert.ToString(GetType()); // this.thisType = GetType(); this.tileLocation = tile; this.InitializeBasics(0, tile); @@ -130,7 +136,7 @@ namespace AdditionalCropsFramework TextureSheet = ModCore.ModHelper.Content.Load(ObjectTexture); //Game1.content.Load("TileSheets\\furniture"); texturePath = ObjectTexture; } - + this.dataPath = ""; this.name = "Planter Box"; this.description = "A planter box that can be used to grow many different crops in many different locations."; @@ -164,44 +170,57 @@ namespace AdditionalCropsFramework public PlanterBox(int which, Vector2 tile, string ObjectTexture, string DataPath, bool isRemovable = true, bool isSolid = false) { + this.serializationName = Convert.ToString(GetType()); removable = isRemovable; // this.thisType = GetType(); this.tileLocation = tile; this.InitializeBasics(0, tile); TextureSheet = ModCore.ModHelper.Content.Load(ObjectTexture); //Game1.content.Load("TileSheets\\furniture"); texturePath = ObjectTexture; - Dictionary dictionary = ModCore.ModHelper.Content.Load>(DataPath); - dataPath = DataPath; - string s=""; - dictionary.TryGetValue(which,out s); - string[] array = s.Split('/'); - this.name = array[0]; - this.description = array[1]; - this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 1, 1); - - this.defaultSourceRect.Width = 1; - this.defaultSourceRect.Height = 1; - this.sourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, this.defaultSourceRect.Width * 16, this.defaultSourceRect.Height * 16); - this.defaultSourceRect = this.sourceRect; - - - this.defaultBoundingBox = new Rectangle((int)this.tileLocation.X, (int)this.tileLocation.Y, 1, 1); - - this.defaultBoundingBox.Width = 1; - this.defaultBoundingBox.Height = 1; - IsSolid = isSolid; - if (isSolid == true) + Dictionary dictionary; + try { - this.boundingBox = new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, this.defaultBoundingBox.Width * Game1.tileSize, this.defaultBoundingBox.Height * Game1.tileSize); + + dictionary = ModCore.ModHelper.Content.Load>(DataPath); + dataPath = DataPath; + + + string s = ""; + dictionary.TryGetValue(which, out s); + string[] array = s.Split('/'); + this.name = array[0]; + this.description = array[1]; + this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 1, 1); + + this.defaultSourceRect.Width = 1; + this.defaultSourceRect.Height = 1; + this.sourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, this.defaultSourceRect.Width * 16, this.defaultSourceRect.Height * 16); + this.defaultSourceRect = this.sourceRect; + + + this.defaultBoundingBox = new Rectangle((int)this.tileLocation.X, (int)this.tileLocation.Y, 1, 1); + + this.defaultBoundingBox.Width = 1; + this.defaultBoundingBox.Height = 1; + IsSolid = isSolid; + if (isSolid == true) + { + this.boundingBox = new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, this.defaultBoundingBox.Width * Game1.tileSize, this.defaultBoundingBox.Height * Game1.tileSize); + } + else + { + this.boundingBox = new Rectangle(int.MinValue, (int)this.tileLocation.Y * Game1.tileSize, 0, 0); //Throw the bounding box away as far as possible. + } + this.defaultBoundingBox = this.boundingBox; + this.updateDrawPosition(); + this.price = Convert.ToInt32(array[2]); + this.parentSheetIndex = which; } - else + catch(Exception e) { - this.boundingBox = new Rectangle(int.MinValue, (int)this.tileLocation.Y * Game1.tileSize, 0, 0); //Throw the bounding box away as far as possible. + Log.AsyncC(e); } - this.defaultBoundingBox = this.boundingBox; - this.updateDrawPosition(); - this.price =Convert.ToInt32(array[2]); - this.parentSheetIndex = which; + } @@ -305,6 +324,7 @@ namespace AdditionalCropsFramework Utilities.addItemToInventoryAndCleanTrackedList(this); this.flaggedForPickUp = true; this.thisLocation = null; + this.locationsName = ""; return true; } else @@ -324,6 +344,7 @@ namespace AdditionalCropsFramework // this.heldObject = null; Game1.playSound("coin"); this.thisLocation = null; + this.locationsName = ""; return true; } @@ -337,6 +358,7 @@ namespace AdditionalCropsFramework Utilities.addItemToInventoryAndCleanTrackedList(this); Game1.playSound("coin"); this.thisLocation = null; + this.locationsName = ""; return true; } @@ -678,15 +700,15 @@ namespace AdditionalCropsFramework this.modularCrop.draw(Game1.spriteBatch, this.tileLocation, Color.White, 0); Log.AsyncM("draw a modular crop now"); } - Log.AsyncC("wait WTF"); + // Log.AsyncC("wait WTF"); if (this.crop != null) { this.crop.draw(Game1.spriteBatch, this.tileLocation, Color.White, 0); - Log.AsyncG("COWS GO MOO"); + // Log.AsyncG("COWS GO MOO"); } } - else Log.AsyncM("I DONT UNDERSTAND"); + //else Log.AsyncM("I DONT UNDERSTAND"); } public void drawAtNonTileSpot(SpriteBatch spriteBatch, Vector2 location, float layerDepth, float alpha = 1f) @@ -720,5 +742,112 @@ namespace AdditionalCropsFramework { return Color.Purple; } + + public static new void Serialize(Item I) + { + ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.playerInventoryPath, I.Name + ".json"), (PlanterBox)I); + } + + public static Item ParseIntoInventory(string s) + { + // PlanterBox p = new PlanterBox(); + // return p; + + + + dynamic obj = JObject.Parse(s); + + PlanterBox d = new PlanterBox(); + + d.dataPath = obj.dataPath; + 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; + + // Log.AsyncC(t); + + d.TextureSheet = ModCore.ModHelper.Content.Load(t); + d.texturePath = t; + JArray array = obj.inventory; + d.inventory = array.ToObject>(); + d.inventoryMaxSize = obj.inventoryMaxSize; + d.itemReadyForHarvest = obj.itemReadyForHarvest; + d.lightsOn = obj.lightsOn; + // d.thisLocation = Game1.getLocationFromName(loc); + // d.thisLocation = obj.thisLocation; + // Log.AsyncC(d.thisLocation); + d.lightColor = obj.lightColor; + d.thisType = obj.thisType; + d.removable = obj.removable; + d.locationsName = obj.locationsName; + + d.drawColor = obj.drawColor; + + + try + { + return d; + } + catch (Exception e) + { + Log.AsyncM(e); + return null; + } + + //return base.ParseIntoInventory(); + } + + public static void SerializeFromWorld(Item c) + { + ModCore.serilaizationManager.WriteToJsonFile(Path.Combine(ModCore.serilaizationManager.objectsInWorldPath, (c as CoreObject).thisLocation.name, c.Name + ".json"), (PlanterBox)c); + } + + } } \ No newline at end of file diff --git a/GeneralMods/AdditionalCropsFramework/packages.config b/GeneralMods/AdditionalCropsFramework/packages.config index 5a0c3d1f..23914dec 100644 --- a/GeneralMods/AdditionalCropsFramework/packages.config +++ b/GeneralMods/AdditionalCropsFramework/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/OmegasisCore/OmegasisCore.sln b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore.sln similarity index 100% rename from OmegasisCore/OmegasisCore.sln rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore.sln diff --git a/OmegasisCore/OmegasisCore.zip b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore.zip similarity index 100% rename from OmegasisCore/OmegasisCore.zip rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore.zip diff --git a/OmegasisCore/OmegasisCore/AdditionalLogs.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/AdditionalLogs.cs similarity index 100% rename from OmegasisCore/OmegasisCore/AdditionalLogs.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/AdditionalLogs.cs diff --git a/OmegasisCore/OmegasisCore/Logger.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Logger.cs similarity index 100% rename from OmegasisCore/OmegasisCore/Logger.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Logger.cs diff --git a/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/ClickableTextureComponentExtended.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/ClickableTextureComponentExtended.cs similarity index 100% rename from OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/ClickableTextureComponentExtended.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/ClickableTextureComponentExtended.cs diff --git a/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/GameMenuComponentPair.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/GameMenuComponentPair.cs similarity index 100% rename from OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/GameMenuComponentPair.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/GameMenuComponentPair.cs diff --git a/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/TextureDataNode.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/TextureDataNode.cs similarity index 100% rename from OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/TextureDataNode.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/TextureDataNode.cs diff --git a/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/Utility.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/Utility.cs similarity index 100% rename from OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/Utility.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/MenuComponentsAndResources/Utility.cs diff --git a/OmegasisCore/OmegasisCore/Menus/ModdedGameMenu.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/ModdedGameMenu.cs similarity index 100% rename from OmegasisCore/OmegasisCore/Menus/ModdedGameMenu.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/ModdedGameMenu.cs diff --git a/OmegasisCore/OmegasisCore/Menus/ModdedMapPage.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/ModdedMapPage.cs similarity index 100% rename from OmegasisCore/OmegasisCore/Menus/ModdedMapPage.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Menus/ModdedMapPage.cs diff --git a/OmegasisCore/OmegasisCore/ModCore.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/ModCore.cs similarity index 100% rename from OmegasisCore/OmegasisCore/ModCore.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/ModCore.cs diff --git a/OmegasisCore/OmegasisCore/ModInfo.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/ModInfo.cs similarity index 100% rename from OmegasisCore/OmegasisCore/ModInfo.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/ModInfo.cs diff --git a/OmegasisCore/OmegasisCore/ModInfo.txt b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/ModInfo.txt similarity index 100% rename from OmegasisCore/OmegasisCore/ModInfo.txt rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/ModInfo.txt diff --git a/OmegasisCore/OmegasisCore/OmegasisCore.csproj b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/OmegasisCore.csproj similarity index 100% rename from OmegasisCore/OmegasisCore/OmegasisCore.csproj rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/OmegasisCore.csproj diff --git a/OmegasisCore/OmegasisCore/Properties/AssemblyInfo.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Properties/AssemblyInfo.cs similarity index 100% rename from OmegasisCore/OmegasisCore/Properties/AssemblyInfo.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Properties/AssemblyInfo.cs diff --git a/OmegasisCore/OmegasisCore/Resources/Dictionaries.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Resources/Dictionaries.cs similarity index 100% rename from OmegasisCore/OmegasisCore/Resources/Dictionaries.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Resources/Dictionaries.cs diff --git a/OmegasisCore/OmegasisCore/Resources/Lists.cs b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Resources/Lists.cs similarity index 100% rename from OmegasisCore/OmegasisCore/Resources/Lists.cs rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/Resources/Lists.cs diff --git a/OmegasisCore/OmegasisCore/manifest.json b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/manifest.json similarity index 100% rename from OmegasisCore/OmegasisCore/manifest.json rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/manifest.json diff --git a/OmegasisCore/OmegasisCore/packages.config b/GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/packages.config similarity index 100% rename from OmegasisCore/OmegasisCore/packages.config rename to GeneralMods/OutDatedMods/OmegasisCore/OmegasisCore/packages.config diff --git a/GeneralMods/OutDatedMods/OmegasisCoreLibrary/Class1.cs b/GeneralMods/OutDatedMods/OmegasisCoreLibrary/Class1.cs new file mode 100644 index 00000000..e84e9807 --- /dev/null +++ b/GeneralMods/OutDatedMods/OmegasisCoreLibrary/Class1.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OmegasisCoreLibrary +{ + public class Class1 + { + } +} diff --git a/GeneralMods/OutDatedMods/OmegasisCoreLibrary/OmegasisCoreLibrary.csproj b/GeneralMods/OutDatedMods/OmegasisCoreLibrary/OmegasisCoreLibrary.csproj new file mode 100644 index 00000000..2c2476f1 --- /dev/null +++ b/GeneralMods/OutDatedMods/OmegasisCoreLibrary/OmegasisCoreLibrary.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + da14f02d-8949-45a3-8023-dd07ac53fa8b + Library + Properties + OmegasisCoreLibrary + OmegasisCoreLibrary + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GeneralMods/OutDatedMods/OmegasisCoreLibrary/Properties/AssemblyInfo.cs b/GeneralMods/OutDatedMods/OmegasisCoreLibrary/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..756f45fb --- /dev/null +++ b/GeneralMods/OutDatedMods/OmegasisCoreLibrary/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OmegasisCoreLibrary")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OmegasisCoreLibrary")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("da14f02d-8949-45a3-8023-dd07ac53fa8b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GeneralMods/OutDatedMods/Serialization/Class1.cs b/GeneralMods/OutDatedMods/Serialization/Class1.cs new file mode 100644 index 00000000..14e175d9 --- /dev/null +++ b/GeneralMods/OutDatedMods/Serialization/Class1.cs @@ -0,0 +1,19 @@ +using StardewModdingAPI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Serialization +{ + public class ModCore: Mod + { + public override void Entry(IModHelper helper) + { + //base.Entry(helper); + } + + + } +} diff --git a/GeneralMods/AdditionalCropsFramework/CoreObject.cs b/GeneralMods/OutDatedMods/Serialization/CoreObject.cs similarity index 99% rename from GeneralMods/AdditionalCropsFramework/CoreObject.cs rename to GeneralMods/OutDatedMods/Serialization/CoreObject.cs index f03e7f6d..72f1c8c9 100644 --- a/GeneralMods/AdditionalCropsFramework/CoreObject.cs +++ b/GeneralMods/OutDatedMods/Serialization/CoreObject.cs @@ -9,7 +9,7 @@ using System; using System.Collections.Generic; using System.Xml.Serialization; -namespace AdditionalCropsFramework +namespace Omegasis.CoreLibraries { /// /// Extends StardewValley.Object. Might be broken and just mainly uses a ton of junk code. @@ -1547,5 +1547,22 @@ namespace AdditionalCropsFramework } + public static void Serialize(Item I) + { + + } + + public static Item ParseIntoInventory() + { + Item I = new CoreObject(0, Vector2.Zero, 0); + return I; + } + + public static void ParseIntoWorld() + { + //Item I = new CoreObject(0, Vector2.Zero, 0); + //return I; + } + } } diff --git a/GeneralMods/OutDatedMods/Serialization/Properties/AssemblyInfo.cs b/GeneralMods/OutDatedMods/Serialization/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..8f858ed0 --- /dev/null +++ b/GeneralMods/OutDatedMods/Serialization/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Serialization")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Serialization")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("e61753a9-057d-4495-b904-133269a802ea")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GeneralMods/OutDatedMods/Serialization/Serialization.cs b/GeneralMods/OutDatedMods/Serialization/Serialization.cs new file mode 100644 index 00000000..839617ae --- /dev/null +++ b/GeneralMods/OutDatedMods/Serialization/Serialization.cs @@ -0,0 +1,293 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Omegasis.CoreLibraries; +using StardewValley; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace Serialization +{ + + /// + /// TODO: Find a way to serialize objects and tools. + /// + + + public class SerializationManager + { + public string objectsInWorldPath; + public string playerInventoryPath; + public string SerializerTrashPath; + + public Dictionary acceptedTypes = new Dictionary(); + + public SerializationManager(string PlayerInventoryPath,string SerializerTrashPath,string ObjectsInWorldPath) + { + this.objectsInWorldPath = ObjectsInWorldPath; + this.playerInventoryPath = PlayerInventoryPath; + this.SerializerTrashPath = SerializerTrashPath; + + verifyAllDirectoriesExist(); + } + + private void verifyAllDirectoriesExist() + { + if (!Directory.Exists(this.playerInventoryPath)) Directory.CreateDirectory(this.playerInventoryPath); + //if (!Directory.Exists(this.SerializerTrashPath)) Directory.CreateDirectory(this.playerInventoryPath); + if (!Directory.Exists(this.objectsInWorldPath)) Directory.CreateDirectory(this.playerInventoryPath); + } + + public void cleanUpInventory() + { + ProcessDirectoryForDeletion(playerInventoryPath); + + //ProcessDirectoryForDeletion(SerializerTrashPath); + + List removalList = new List(); + foreach (Item d in Game1.player.items) + { + try + { + if (d == null) + { + //Log.AsyncG("WTF"); + continue; + } + // Log.AsyncC(d.GetType()); + } + catch (Exception e) + { + + } + string s = Convert.ToString((d.GetType())); + + + + + if (acceptedTypes.ContainsKey(s)) + { + SerializerDataNode t; + + bool works = acceptedTypes.TryGetValue(s, out t); + if (works == true) + { + t.serialize.Invoke(d); + removalList.Add(d); + } + } + } + foreach (var i in removalList) + { + Game1.player.removeItemFromInventory(i); + } + removalList.Clear(); + } + + + public void ProcessDirectoryForDeletion(string targetDirectory) + { + // Process the list of files found in the directory. + string[] fileEntries = Directory.GetFiles(targetDirectory); + foreach (string fileName in fileEntries) + { + File.Delete(fileName); + // File.Delete(fileName); + } + + // Recurse into subdirectories of this directory. + string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory); + foreach (string subdirectory in subdirectoryEntries) + ProcessDirectoryForDeletion(subdirectory); + + } + + + public void WriteToJsonFile(string filePath, T objectToWrite, bool append = false) where T : new() + { + TextWriter writer = null; + try + { + JsonSerializerSettings settings = new JsonSerializerSettings(); + //settings.TypeNameHandling = TypeNameHandling.Auto; + settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; + settings.TypeNameHandling = TypeNameHandling.Auto; + // settings.Formatting = Formatting.Indented; + var contentsToWriteToFile = JsonConvert.SerializeObject(objectToWrite, settings); + int i = 0; + string s = filePath; + while (File.Exists(s) == true) + { + s = filePath; + s = (s + Convert.ToString(i)); + i++; + } + filePath = s; + + writer = new StreamWriter(filePath, append); + + writer.Write(contentsToWriteToFile); + } + finally + { + if (writer != null) + writer.Close(); + } + } + + + public void serializeXML(Item I) + { + System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); + var newWriter = new StringWriter(); + using (var writer = XmlWriter.Create(newWriter)) + { + xmlSerializer.Serialize(writer,I); + } + } + + public void processDirectoryForDeserialization(string pathToXML,List thingsToAddBackIn) + { + string[] fileEntries = Directory.GetFiles(pathToXML); + foreach(var fileName in fileEntries) + { + ProcessFileForCleanUp(fileName,thingsToAddBackIn); + } + + string[] subDirectories = Directory.GetDirectories(pathToXML); + foreach(var folder in subDirectories) + { + processDirectoryForDeserialization(folder,thingsToAddBackIn); + } + + } + + + public void ProcessFileForCleanUp(string path, List thingsToAddBackIn) + { + string[] ehh = File.ReadAllLines(path); + string data = ehh[0]; + Item cObj; + string a; + string[] b; + string s = ""; + // Log.AsyncC(path); + // Log.AsyncC(data); + try + { + dynamic obj = JObject.Parse(data); + + + // Log.AsyncC(obj.thisType); + + a = obj.serializationName; + b = a.Split(','); + s = b.ElementAt(0); + // Log.AsyncC(s); + } + catch (Exception e) + { + + //USE XML STYLE DESERIALIZING + foreach (KeyValuePair pair in acceptedTypes) + { + var word = ParseXMLType(path); + if (pair.Key == word.ToString()) + { + cObj = pair.Value.parse.Invoke(path); + (cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName); + (cObj as CoreObject).resetTexture(); + if ((cObj as CoreObject).thisLocation == null) + { + Game1.player.addItemToInventory(cObj); + return; + } + else + { + (cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).tileLocation, (StardewValley.Object)cObj); + thingsToAddBackIn.Add(cObj); + //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false); + } + } + } + + // Log.AsyncG("attempting to parse from path and value of s is " + s); + } + + // var cObj = parseBagOfHolding(path); //pair.Value.parse.Invoke(path); + // cObj.TextureSheet = Game1.content.Load(Path.Combine("Revitalize", "CropsNSeeds", "Graphics", "seeds")); + /* + cObj.thisLocation = Game1.getLocationFromName(cObj.locationsName); + if (cObj.thisLocation == null) + { + Game1.player.addItemToInventory(cObj); + return; + } + else + { + cObj.thisLocation.objects.Add(cObj.tileLocation, cObj); + Lists.trackedObjectList.Add(cObj); + //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false); + } + */ + + //USE JSON STYLE DESERIALIZNG + if (acceptedTypes.ContainsKey(s)) + { + // Log.AsyncC("FUUUUU"); + foreach (KeyValuePair pair in acceptedTypes) + { + if (pair.Key == s) + { + try + { + //parse from Json Style + 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); + return; + } + else + { + (cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).tileLocation,(StardewValley.Object)cObj); + thingsToAddBackIn.Add(cObj); + //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false); + } + } + catch (Exception e) + { + + } + } + } + } + + } + + + public string ParseXMLType(string path) + { + string[] s = File.ReadAllLines(path); + string returnString = ""; + foreach (string v in s) + { + // Log.AsyncC(v); + if (v.Contains("serializationName")) + { + returnString = v.Remove(0, 12); + returnString = returnString.Remove(returnString.Length - 11, 11); + } + + } + return returnString; + } + + } +} diff --git a/GeneralMods/OutDatedMods/Serialization/Serialization.csproj b/GeneralMods/OutDatedMods/Serialization/Serialization.csproj new file mode 100644 index 00000000..f5fce020 --- /dev/null +++ b/GeneralMods/OutDatedMods/Serialization/Serialization.csproj @@ -0,0 +1,74 @@ + + + + + Debug + AnyCPU + {E61753A9-057D-4495-B904-133269A802EA} + Library + Properties + Serialization + Serialization + v4.5 + 512 + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/GeneralMods/OutDatedMods/Serialization/SerializerDataNode.cs b/GeneralMods/OutDatedMods/Serialization/SerializerDataNode.cs new file mode 100644 index 00000000..fd81c199 --- /dev/null +++ b/GeneralMods/OutDatedMods/Serialization/SerializerDataNode.cs @@ -0,0 +1,27 @@ +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Serialization +{ + public class SerializerDataNode + { + public delegate Item ParsingFunction(string data); + public delegate void SerializingFunction(Item item); + public delegate void WorldParsingFunction(Item obj); + + public SerializingFunction serialize; + public ParsingFunction parse; + public WorldParsingFunction worldObj; + + public SerializerDataNode(SerializingFunction serializeFunction, ParsingFunction parsingFunction, WorldParsingFunction worldObjectParsingFunction) + { + serialize = serializeFunction; + parse = parsingFunction; + worldObj = worldObjectParsingFunction; + } + } +} diff --git a/GeneralMods/OutDatedMods/Serialization/Utilities.cs b/GeneralMods/OutDatedMods/Serialization/Utilities.cs new file mode 100644 index 00000000..7afa430a --- /dev/null +++ b/GeneralMods/OutDatedMods/Serialization/Utilities.cs @@ -0,0 +1,37 @@ +using Microsoft.Xna.Framework; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Locations; +using StardewValley.Objects; +using StardewValley.TerrainFeatures; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using xTile.Dimensions; + +namespace Serialization +{ + class Utilities + { + + public static Microsoft.Xna.Framework.Rectangle parseRectFromJson(string s) + { + + + + s = s.Replace('{', ' '); + s = s.Replace('}', ' '); + s = s.Replace('^', ' '); + s = s.Replace(':', ' '); + string[] parsed = s.Split(' '); + foreach (var v in parsed) + { + //Log.AsyncY(v); + } + return new Microsoft.Xna.Framework.Rectangle(Convert.ToInt32(parsed[2]), Convert.ToInt32(parsed[4]), Convert.ToInt32(parsed[6]), Convert.ToInt32(parsed[8])); + } + + } +} diff --git a/GeneralMods/OutDatedMods/Serialization/manifest.json b/GeneralMods/OutDatedMods/Serialization/manifest.json new file mode 100644 index 00000000..a68feaa1 --- /dev/null +++ b/GeneralMods/OutDatedMods/Serialization/manifest.json @@ -0,0 +1,14 @@ +{ + "Name": "Serialization", + "Author": "Alpha_Omegasis", + "Version": { + "MajorVersion": 1, + "MinorVersion": 0, + "PatchVersion": 0, + "Build": null + }, + "MinimumApiVersion": "1.15", + "Description": "A simple serializer that allows easily adding custom items into the game.", + "UniqueID": "Omegasis.Serialization", + "EntryDll": "Serialization.dll" +} diff --git a/GeneralMods/OutDatedMods/Serialization/packages.config b/GeneralMods/OutDatedMods/Serialization/packages.config new file mode 100644 index 00000000..23914dec --- /dev/null +++ b/GeneralMods/OutDatedMods/Serialization/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/GeneralMods/StardewMods.sln b/GeneralMods/StardewMods.sln index 11491706..65de541c 100644 --- a/GeneralMods/StardewMods.sln +++ b/GeneralMods/StardewMods.sln @@ -49,6 +49,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleSoundManager", "Simpl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdditionalCropsFramework", "AdditionalCropsFramework\AdditionalCropsFramework.csproj", "{C5F88D48-EA20-40CD-91E2-C8725DC11795}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StardustCore", "StardustCore\StardustCore.csproj", "{0756D36A-95C8-480D-8EA6-4584C03010C6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -131,6 +133,10 @@ Global {C5F88D48-EA20-40CD-91E2-C8725DC11795}.Debug|Any CPU.Build.0 = Debug|Any CPU {C5F88D48-EA20-40CD-91E2-C8725DC11795}.Release|Any CPU.ActiveCfg = Release|Any CPU {C5F88D48-EA20-40CD-91E2-C8725DC11795}.Release|Any CPU.Build.0 = Release|Any CPU + {0756D36A-95C8-480D-8EA6-4584C03010C6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0756D36A-95C8-480D-8EA6-4584C03010C6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0756D36A-95C8-480D-8EA6-4584C03010C6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0756D36A-95C8-480D-8EA6-4584C03010C6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/GeneralMods/StardustCore/CoreObject.cs b/GeneralMods/StardustCore/CoreObject.cs new file mode 100644 index 00000000..87c738da --- /dev/null +++ b/GeneralMods/StardustCore/CoreObject.cs @@ -0,0 +1,1541 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Locations; +using StardewValley.Menus; +using StardewValley.Objects; +using System; +using System.Collections.Generic; +using System.Xml.Serialization; + +namespace StardustCore +{ + /// + /// Extends StardewValley.Object. Might be broken and just mainly uses a ton of junk code. Just extend off of this. + /// + /// + + public class CoreObject : StardewValley.Object + { + + public new int price; + + public int Decoration_type; + + public int rotations; + + public int currentRotation; + + public int sourceIndexOffset; + + protected Vector2 drawPosition; + + public Rectangle sourceRect; + + public Rectangle defaultSourceRect; + + public Rectangle defaultBoundingBox; + + public string description; + + [XmlIgnore] + public Texture2D TextureSheet; + + public new bool flipped; + + [XmlIgnore] + public bool flaggedForPickUp; + + public bool lightGlowAdded; + + public string texturePath; + + public List inventory; + + public int inventoryMaxSize; + + public bool itemReadyForHarvest; + + public bool lightsOn; + + public GameLocation thisLocation; + + public Color lightColor; + + public string thisType; + + public bool removable; + + public string locationsName; + + public Color drawColor; + + public bool useXML; + + public override string Name + { + get + { + return this.name; + } + + } + + public virtual void InitializeBasics(int InvMaxSize, Vector2 tile) + { + this.inventory = new List(); + this.inventoryMaxSize = InvMaxSize; + this.tileLocation = tile; + lightsOn = false; + + lightColor = Color.Black; + thisType = this.GetType().ToString(); + } + + public CoreObject() + { + this.updateDrawPosition(); + } + + public CoreObject(bool f) + { + //does nothng + } + + public CoreObject(int which, Vector2 Tile, int InventoryMaxSize) + { + InitializeBasics(InventoryMaxSize, Tile); + if (TextureSheet == null) + { + TextureSheet = Game1.content.Load("TileSheets\\furniture"); + texturePath = "TileSheets\\furniture"; + } + Dictionary dictionary = Game1.content.Load>("Data\\Furniture"); + string[] array = dictionary[which].Split(new char[] + { + '/' + }); + this.name = array[0]; + + this.Decoration_type = this.getTypeNumberFromName(array[1]); + this.description = "Can be placed inside your house."; + this.defaultSourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, 1, 1); + if (array[2].Equals("-1")) + { + this.sourceRect = this.getDefaultSourceRectForType(which, this.Decoration_type); + this.defaultSourceRect = this.sourceRect; + } + else + { + this.defaultSourceRect.Width = Convert.ToInt32(array[2].Split(new char[] + { + ' ' + })[0]); + this.defaultSourceRect.Height = Convert.ToInt32(array[2].Split(new char[] + { + ' ' + })[1]); + this.sourceRect = new Rectangle(which * 16 % TextureSheet.Width, which * 16 / TextureSheet.Width * 16, this.defaultSourceRect.Width * 16, this.defaultSourceRect.Height * 16); + this.defaultSourceRect = this.sourceRect; + } + this.defaultBoundingBox = new Rectangle((int)this.tileLocation.X, (int)this.tileLocation.Y, 1, 1); + if (array[3].Equals("-1")) + { + this.boundingBox = this.getDefaultBoundingBoxForType(this.Decoration_type); + this.defaultBoundingBox = this.boundingBox; + } + else + { + this.defaultBoundingBox.Width = Convert.ToInt32(array[3].Split(new char[] + { + ' ' + })[0]); + this.defaultBoundingBox.Height = Convert.ToInt32(array[3].Split(new char[] + { + ' ' + })[1]); + this.boundingBox = new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, this.defaultBoundingBox.Width * Game1.tileSize, this.defaultBoundingBox.Height * Game1.tileSize); + this.defaultBoundingBox = this.boundingBox; + } + this.updateDrawPosition(); + this.rotations = Convert.ToInt32(array[4]); + this.price = Convert.ToInt32(array[5]); + this.parentSheetIndex = which; + } + + public override string getDescription() + { + return this.description; + } + + public override bool performDropDownAction(StardewValley.Farmer who) + { + this.resetOnPlayerEntry((who == null) ? Game1.currentLocation : who.currentLocation); + return false; + } + + public override void hoverAction() + { + base.hoverAction(); + if (!Game1.player.isInventoryFull()) + { + Game1.mouseCursor = 2; + } + } + + public override bool checkForAction(StardewValley.Farmer who, bool justCheckingForActivity = false) + { + var mState = Microsoft.Xna.Framework.Input.Mouse.GetState(); + if (mState.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) + { + // Game1.showRedMessage("YOOO"); + //do some stuff when the right button is down + // rotate(); + if (this.heldObject != null) + { + // Game1.player.addItemByMenuIfNecessary(this.heldObject); + // this.heldObject = null; + } + else + { + // this.heldObject = Game1.player.ActiveObject; + // Game1.player.removeItemFromInventory(heldObject); + } + //this.minutesUntilReady = 30; + // Log.AsyncC("placed item!"); + } + else + { + //Game1.showRedMessage("CRY"); + } + + if (justCheckingForActivity) + { + return true; + } + return this.clicked(who); + } + + //DONT USE THIS BASE IT IS TERRIBLE + /* + public override bool clicked(StardewValley.Farmer who) + { + + // Game1.showRedMessage("THIS IS CLICKED!!!"); + Game1.haltAfterCheck = false; + + if (this.heldObject != null) + { + this.spillInventoryEverywhere(); + return false; + } + + if (this.heldObject == null && (who.ActiveObject == null || !(who.ActiveObject is CoreObject))) + { + if (Game1.player.currentLocation is FarmHouse) + { + // Game1.showRedMessage("Why2?"); + // this.spillInventoryEverywhere(); + + if (this.heldObject != null) Util.addItemToInventoryElseDrop(this.heldObject.getOne()); + this.heldObject = new CoreObject(parentSheetIndex, Vector2.Zero, this.inventoryMaxSize); + // Util.addItemToInventoryElseDrop(this.heldObject.getOne()); + this.heldObject = null; + this.flaggedForPickUp = true; + thisLocation = null; + return true; + } + else + { + // return true; + + this.flaggedForPickUp = true; + if (this is TV) + { + // this.heldObject = new TV(parentSheetIndex, Vector2.Zero); + } + else + { + + // Util.addItemToInventoryElseDrop(this.heldObject); + + var obj = new CoreObject(parentSheetIndex, Vector2.Zero, this.inventoryMaxSize); + // Util.addItemToInventoryElseDrop(obj); + // this.spillInventoryEverywhere(); + if (this.heldObject != null) this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); + + this.heldObject = null; + Game1.playSound("coin"); + thisLocation = null; + return true; + } + + } + } + if (this.heldObject != null && who.addItemToInventoryBool(this.heldObject, false)) + { + // Game1.showRedMessage("Why3?"); + // if(this.heldObject!=null) Game1.player.addItemByMenuIfNecessary((Item)this.heldObject); + // this.spillInventoryEverywhere(); + var obj = new CoreObject(parentSheetIndex, Vector2.Zero, this.inventoryMaxSize); + // Util.addItemToInventoryElseDrop(obj); + if (this.heldObject != null) this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); + this.heldObject = null; + Game1.playSound("coin"); + thisLocation = null; + return true; + } + + + + return false; + } + */ + + public virtual bool RightClicked(StardewValley.Farmer who) + { + // StardewModdingAPI.Log.AsyncC(lightColor); + // Game1.activeClickableMenu = new Revitalize.Menus.LightCustomizer(this); + + // Game1.showRedMessage("THIS IS CLICKED!!!"); + //var mState = Microsoft.Xna.Framework.Input.Mouse.GetState(); + /* + + Game1.haltAfterCheck = false; + if (this.Decoration_type == 11 && who.ActiveObject != null && who.ActiveObject != null && this.heldObject == null) + { + // Game1.showRedMessage("Why1?"); + return false; + } + if (this.heldObject == null && (who.ActiveObject == null || !(who.ActiveObject is Light))) + { + if (Game1.player.currentLocation is FarmHouse) + { + // + Game1.player.addItemByMenuIfNecessary(this); + removeLights(this.thisLocation); + this.lightsOn = false; + Game1.playSound("coin"); + // this.flaggedForPickUp = true; + return true; + } + else + { + // return true; + // this.heldObject = new Light(parentSheetIndex, Vector2.Zero, this.lightColor, this.inventoryMaxSize); + Game1.player.addItemByMenuIfNecessary(this); + removeLights(this.thisLocation); + this.lightsOn = false; + Game1.playSound("coin"); + return true; + + } + } + if (this.heldObject != null && who.addItemToInventoryBool(this.heldObject, false)) + { + // Game1.showRedMessage("Why3?"); + // if(this.heldObject!=null) Game1.player.addItemByMenuIfNecessary((Item)this.heldObject); + Util.addItemToInventoryElseDrop(this); + this.heldObject.performRemoveAction(this.tileLocation, who.currentLocation); + this.heldObject = null; + Game1.playSound("coin"); + removeLights(this.thisLocation); + this.lightsOn = false; + return true; + } + + */ + + return false; + } + + public override void DayUpdate(GameLocation location) + { + base.DayUpdate(location); + this.lightGlowAdded = false; + if (!Game1.isDarkOut() || (Game1.newDay && !Game1.isRaining)) + { + this.removeLights(location); + return; + } + this.addLights(location); + } + + public virtual void resetOnPlayerEntry(GameLocation environment) + { + this.removeLights(environment); + if (Game1.isDarkOut()) + { + this.addLights(environment); + } + } + + public override bool performObjectDropInAction(StardewValley.Object dropIn, bool probe, StardewValley.Farmer who) + { + // Log.AsyncG("HEY!"); + if ((this.Decoration_type == 11 || this.Decoration_type == 5) && this.heldObject == null && !dropIn.bigCraftable && (!(dropIn is CoreObject) || ((dropIn as CoreObject).getTilesWide() == 1 && (dropIn as CoreObject).getTilesHigh() == 1))) + { + this.heldObject = (StardewValley.Object)dropIn.getOne(); + this.heldObject.tileLocation = this.tileLocation; + this.heldObject.boundingBox.X = this.boundingBox.X; + this.heldObject.boundingBox.Y = this.boundingBox.Y; + // Log.AsyncO(getDefaultBoundingBoxForType((dropIn as CoreObject).Decoration_type)); + this.heldObject.performDropDownAction(who); + if (!probe) + { + Game1.playSound("woodyStep"); + // Log.AsyncC("HUH?"); + if (who != null) + { + who.reduceActiveItemByOne(); + } + } + return true; + } + return false; + } + + public virtual void addLights(GameLocation environment) + { + if (this.Decoration_type == 7) + { + if (this.sourceIndexOffset == 0) + { + this.sourceRect = this.defaultSourceRect; + this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; + } + this.sourceIndexOffset = 1; + if (this.lightSource == null) + { + Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + this.lightSource = new LightSource(4, new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y - Game1.tileSize)), 2f, lightColor, (int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + Game1.currentLightSources.Add(this.lightSource); + // Log.AsyncG("LIGHT SOURCE ADDED FFFFFFF"); + return; + } + } + else if (this.Decoration_type == 13) + { + if (this.sourceIndexOffset == 0) + { + this.sourceRect = this.defaultSourceRect; + this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; + } + this.sourceIndexOffset = 1; + if (this.lightGlowAdded) + { + environment.lightGlows.Remove(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize))); + this.lightGlowAdded = false; + } + } + else + { + + if (this.sourceIndexOffset == 0) + { + this.sourceRect = this.defaultSourceRect; + this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; + } + this.sourceIndexOffset = 1; + if (this.lightSource == null) + { + Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + this.lightSource = new LightSource(4, new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y - Game1.tileSize)), 2f, lightColor, (int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + Game1.currentLightSources.Add(this.lightSource); + return; + } + + } + } + + + public virtual void addLights(GameLocation environment, Color c) + { + if (this.Decoration_type == 7) + { + if (this.sourceIndexOffset == 0) + { + this.sourceRect = this.defaultSourceRect; + this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; + } + this.sourceIndexOffset = 1; + if (this.lightSource == null) + { + Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + this.lightSource = new LightSource(4, new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y - Game1.tileSize)), 2f, c, (int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + // this.lightSource.lightTexture = Game1.content.Load("LooseSprites\\Lighting\\BlueLight"); + Game1.currentLightSources.Add(this.lightSource); + // Log.AsyncG("LIGHT SOURCE ADDED FFFFFFF"); + return; + } + } + else if (this.Decoration_type == 13) + { + if (this.sourceIndexOffset == 0) + { + this.sourceRect = this.defaultSourceRect; + this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; + } + this.sourceIndexOffset = 1; + if (this.lightGlowAdded) + { + environment.lightGlows.Remove(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize))); + this.lightGlowAdded = false; + } + } + else + { + + if (this.sourceIndexOffset == 0) + { + this.sourceRect = this.defaultSourceRect; + this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; + } + this.sourceIndexOffset = 1; + if (this.lightSource == null) + { + Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + this.lightSource = new LightSource(4, new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y - Game1.tileSize)), 2f, c, (int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + Game1.currentLightSources.Add(this.lightSource); + return; + } + + } + } + + public void removeLights(GameLocation environment) + { + if (this.Decoration_type == 7) + { + if (this.sourceIndexOffset == 1) + { + this.sourceRect = this.defaultSourceRect; + } + this.sourceIndexOffset = 0; + Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + this.lightSource = null; + return; + } + if (this.Decoration_type == 13) + { + if (this.sourceIndexOffset == 1) + { + this.sourceRect = this.defaultSourceRect; + } + this.sourceIndexOffset = 0; + if (Game1.isRaining) + { + this.sourceRect = this.defaultSourceRect; + this.sourceRect.X = this.sourceRect.X + this.sourceRect.Width; + this.sourceIndexOffset = 1; + return; + } + if (!this.lightGlowAdded && !environment.lightGlows.Contains(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize)))) + { + environment.lightGlows.Add(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize))); + } + this.lightGlowAdded = true; + } + + if (this.sourceIndexOffset == 1) + { + this.sourceRect = this.defaultSourceRect; + } + this.sourceIndexOffset = 0; + Utility.removeLightSource((int)(this.tileLocation.X * 2000f + this.tileLocation.Y)); + this.lightSource = null; + return; + } + + public override bool minutesElapsed(int minutes, GameLocation environment) + { + // Log.Info("minutes passed in"+minutes); + // Log.Info("minues remaining" + this.minutesUntilReady); + this.minutesUntilReady = (this.minutesUntilReady - minutes); + if (Game1.isDarkOut()) + { + // this.addLights(environment,this.lightColor); + this.addLights(environment); + } + else + { + this.removeLights(environment); + } + + if (minutesUntilReady == 0) + { + // Log.AsyncC(this.name + "Is ready!"); + // Log.AsyncC(Game1.player.getStandingPosition()); + // Vector2 v2 = new Vector2(this.tileLocation.X * Game1.tileSize, this.tileLocation.Y * Game1.tileSize); + //Game1.createItemDebris((Item)this.heldObject, v2, Game1.player.getDirection()); + // minutesUntilReady = 30; + } + + return false; + } + + public override void performRemoveAction(Vector2 tileLocation, GameLocation environment) + { + this.removeLights(environment); + if (this.Decoration_type == 13 && this.lightGlowAdded) + { + environment.lightGlows.Remove(new Vector2((float)(this.boundingBox.X + Game1.tileSize / 2), (float)(this.boundingBox.Y + Game1.tileSize))); + this.lightGlowAdded = false; + } + this.spillInventoryEverywhere(); + base.performRemoveAction(tileLocation, environment); + } + + public virtual void rotate() + { + if (this.rotations < 2) + { + return; + } + int num = (this.rotations == 4) ? 1 : 2; + this.currentRotation += num; + this.currentRotation %= 4; + this.flipped = false; + Point point = default(Point); + int num2 = this.Decoration_type; + switch (num2) + { + case 2: + point.Y = 1; + point.X = -1; + break; + case 3: + point.X = -1; + point.Y = 1; + break; + case 4: + break; + case 5: + point.Y = 0; + point.X = -1; + break; + default: + if (num2 == 12) + { + point.X = 0; + point.Y = 0; + } + break; + } + bool flag = this.Decoration_type == 5 || this.Decoration_type == 12 || this.parentSheetIndex == 724 || this.parentSheetIndex == 727; + bool flag2 = this.defaultBoundingBox.Width != this.defaultBoundingBox.Height; + if (flag && this.currentRotation == 2) + { + this.currentRotation = 1; + } + if (flag2) + { + int height = this.boundingBox.Height; + switch (this.currentRotation) + { + case 0: + case 2: + this.boundingBox.Height = this.defaultBoundingBox.Height; + this.boundingBox.Width = this.defaultBoundingBox.Width; + break; + case 1: + case 3: + this.boundingBox.Height = this.boundingBox.Width + point.X * Game1.tileSize; + this.boundingBox.Width = height + point.Y * Game1.tileSize; + break; + } + } + Point point2 = default(Point); + int num3 = this.Decoration_type; + if (num3 == 12) + { + point2.X = 1; + point2.Y = -1; + } + if (flag2) + { + switch (this.currentRotation) + { + case 0: + this.sourceRect = this.defaultSourceRect; + break; + case 1: + this.sourceRect = new Rectangle(this.defaultSourceRect.X + this.defaultSourceRect.Width, this.defaultSourceRect.Y, this.defaultSourceRect.Height - 16 + point.Y * 16 + point2.X * 16, this.defaultSourceRect.Width + 16 + point.X * 16 + point2.Y * 16); + break; + case 2: + this.sourceRect = new Rectangle(this.defaultSourceRect.X + this.defaultSourceRect.Width + this.defaultSourceRect.Height - 16 + point.Y * 16 + point2.X * 16, this.defaultSourceRect.Y, this.defaultSourceRect.Width, this.defaultSourceRect.Height); + break; + case 3: + this.sourceRect = new Rectangle(this.defaultSourceRect.X + this.defaultSourceRect.Width, this.defaultSourceRect.Y, this.defaultSourceRect.Height - 16 + point.Y * 16 + point2.X * 16, this.defaultSourceRect.Width + 16 + point.X * 16 + point2.Y * 16); + this.flipped = true; + break; + } + } + else + { + this.flipped = (this.currentRotation == 3); + if (this.rotations == 2) + { + this.sourceRect = new Rectangle(this.defaultSourceRect.X + ((this.currentRotation == 2) ? 1 : 0) * this.defaultSourceRect.Width, this.defaultSourceRect.Y, this.defaultSourceRect.Width, this.defaultSourceRect.Height); + } + else + { + this.sourceRect = new Rectangle(this.defaultSourceRect.X + ((this.currentRotation == 3) ? 1 : this.currentRotation) * this.defaultSourceRect.Width, this.defaultSourceRect.Y, this.defaultSourceRect.Width, this.defaultSourceRect.Height); + } + } + if (flag && this.currentRotation == 1) + { + this.currentRotation = 2; + } + this.updateDrawPosition(); + } + + public virtual bool isGroundFurniture() + { + return this.Decoration_type != 13 && this.Decoration_type != 6 && this.Decoration_type != 13; + } + + public override bool canBeGivenAsGift() + { + return false; + } + /* + public override bool canBePlacedHere(GameLocation l, Vector2 tile) + { + if ((l is FarmHouse)) + { + for (int i = 0; i < this.boundingBox.Width / Game1.tileSize; i++) + { + for (int j = 0; j < this.boundingBox.Height / Game1.tileSize; j++) + { + Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize; + vector.X += (float)(Game1.tileSize / 2); + vector.Y += (float)(Game1.tileSize / 2); + foreach (KeyValuePair something in l.objects) + { + StardewValley.Object obj = something.Value; + if ((obj.GetType()).ToString().Contains("CoreObject")) + { + CoreObject current = (CoreObject)obj; + if (current.Decoration_type == 11 && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y) && current.heldObject == null && this.getTilesWide() == 1) + { + bool result = true; + return result; + } + if ((current.Decoration_type != 12 || this.Decoration_type == 12) && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y)) + { + bool result = false; + return result; + } + } + } + } + } + return Util.canBePlacedHere(this, l, tile); + } + else + { + // Game1.showRedMessage("NOT FARMHOUSE"); + for (int i = 0; i < this.boundingBox.Width / Game1.tileSize; i++) + { + for (int j = 0; j < this.boundingBox.Height / Game1.tileSize; j++) + { + Vector2 vector = tile * (float)Game1.tileSize + new Vector2((float)i, (float)j) * (float)Game1.tileSize; + vector.X += (float)(Game1.tileSize / 2); + vector.Y += (float)(Game1.tileSize / 2); + /* + foreach (CoreObject current in (l as FarmHouse).CoreObject) + { + if (current.Decoration_type == 11 && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y) && current.heldObject == null && this.getTilesWide() == 1) + { + bool result = true; + return result; + } + if ((current.Decoration_type != 12 || this.Decoration_type == 12) && current.getBoundingBox(current.tileLocation).Contains((int)vector.X, (int)vector.Y)) + { + bool result = false; + return result; + } + } + + } + } + return Util.canBePlacedHere(this, l, tile); + } + } + */ + public virtual void updateDrawPosition() + { + this.drawPosition = new Vector2((float)this.boundingBox.X, (float)(this.boundingBox.Y - (this.sourceRect.Height * Game1.pixelZoom - this.boundingBox.Height))); + } + + public virtual int getTilesWide() + { + return this.boundingBox.Width / Game1.tileSize; + } + + public virtual int getTilesHigh() + { + return this.boundingBox.Height / Game1.tileSize; + } + /* + public override bool placementAction(GameLocation location, int x, int y, StardewValley.Farmer who = null) + { + // Log.AsyncC(x); + // Log.AsyncM(y); + + if (location is FarmHouse) + { + Point point = new Point(x / Game1.tileSize, y / Game1.tileSize); + List walls = FarmHouse.getWalls((location as FarmHouse).upgradeLevel); + this.tileLocation = new Vector2((float)point.X, (float)point.Y); + bool flag = false; + if (this.Decoration_type == 6 || this.Decoration_type == 13 || this.parentSheetIndex == 1293) + { + int num = (this.parentSheetIndex == 1293) ? 3 : 0; + bool flag2 = false; + foreach (Rectangle current in walls) + { + if ((this.Decoration_type == 6 || this.Decoration_type == 13 || num != 0) && current.Y + num == point.Y && current.Contains(point.X, point.Y - num)) + { + flag2 = true; + break; + } + } + if (!flag2) + { + Game1.showRedMessage("Must be placed on wall"); + return false; + } + flag = true; + } + for (int i = point.X; i < point.X + this.getTilesWide(); i++) + { + for (int j = point.Y; j < point.Y + this.getTilesHigh(); j++) + { + if (location.doesTileHaveProperty(i, j, "NoFurniture", "Back") != null) + { + Game1.showRedMessage("Furniture can't be placed here"); + return false; + } + if (!flag && Utility.pointInRectangles(walls, i, j)) + { + Game1.showRedMessage("Can't place on wall"); + return false; + } + if (location.getTileIndexAt(i, j, "Buildings") != -1) + { + return false; + } + } + } + this.boundingBox = new Rectangle(x, y, this.boundingBox.Width, this.boundingBox.Height); + foreach (KeyValuePair c in location.objects) + { + StardewValley.Object ehh = c.Value; + if (((ehh.GetType()).ToString()).Contains("CoreObject")) + { + CoreObject current2 = (CoreObject)ehh; + if (current2.Decoration_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox)) + { + current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who); + bool result = true; + return result; + } + } + } + foreach (StardewValley.Farmer current3 in location.getStardewValley.Farmers()) + { + if (current3.GetBoundingBox().Intersects(this.boundingBox)) + { + Game1.showRedMessage("Can't place on top of a person."); + bool result = false; + return result; + } + } + this.updateDrawPosition(); + // Log.AsyncO(this.boundingBox); + // Log.AsyncO(x); + // Log.AsyncY(y); + for (int i = 0; i <= this.boundingBox.X / Game1.tileSize; i++) + { + base.placementAction(location, x + 1, y, who); + } + for (int i = 0; i <= this.boundingBox.Y / Game1.tileSize; i++) + { + base.placementAction(location, x, y + 1, who); + } + return true; + } + else + { + Point point = new Point(x / Game1.tileSize, y / Game1.tileSize); + // List walls = FarmHouse.getWalls((location as FarmHouse).upgradeLevel); + this.tileLocation = new Vector2((float)point.X, (float)point.Y); + bool flag = false; + if (this.Decoration_type == 6 || this.Decoration_type == 13 || this.parentSheetIndex == 1293) + { + int num = (this.parentSheetIndex == 1293) ? 3 : 0; + bool flag2 = false; + /* + foreach (Rectangle current in walls) + { + if ((this.Decoration_type == 6 || this.Decoration_type == 13 || num != 0) && current.Y + num == point.Y && current.Contains(point.X, point.Y - num)) + { + flag2 = true; + break; + } + } + + if (!flag2) + { + Game1.showRedMessage("Must be placed on wall"); + return false; + } + flag = true; + } + for (int i = point.X; i < point.X + this.getTilesWide(); i++) + { + for (int j = point.Y; j < point.Y + this.getTilesHigh(); j++) + { + if (location.doesTileHaveProperty(i, j, "NoFurniture", "Back") != null) + { + Game1.showRedMessage("Furniture can't be placed here"); + return false; + } + /* + if (!flag && Utility.pointInRectangles(walls, i, j)) + { + Game1.showRedMessage("Can't place on wall"); + return false; + } + + if (location.getTileIndexAt(i, j, "Buildings") != -1) + { + return false; + } + } + } + this.boundingBox = new Rectangle(x, y, this.boundingBox.Width, this.boundingBox.Height); + /* + foreach (Furniture current2 in (location as FarmHouse).furniture) + { + if (current2.furniture_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox)) + { + current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who); + bool result = true; + return result; + } + } + + foreach (StardewValley.Farmer current3 in location.getStardewValley.Farmers()) + { + if (current3.GetBoundingBox().Intersects(this.boundingBox)) + { + Game1.showRedMessage("Can't place on top of a person."); + bool result = false; + return result; + } + } + this.updateDrawPosition(); + thisLocation = Game1.player.currentLocation; + return base.placementAction(location, x, y, who); + } + + } + */ + public override bool placementAction(GameLocation location, int x, int y, StardewValley.Farmer who = null) + { + + + if (location is FarmHouse) + { + Point point = new Point(x / Game1.tileSize, y / Game1.tileSize); + List walls = FarmHouse.getWalls((location as FarmHouse).upgradeLevel); + this.tileLocation = new Vector2((float)point.X, (float)point.Y); + bool flag = false; + if (this.Decoration_type == 6 || this.Decoration_type == 13 || this.parentSheetIndex == 1293) + { + int num = (this.parentSheetIndex == 1293) ? 3 : 0; + bool flag2 = false; + foreach (Rectangle current in walls) + { + if ((this.Decoration_type == 6 || this.Decoration_type == 13 || num != 0) && current.Y + num == point.Y && current.Contains(point.X, point.Y - num)) + { + flag2 = true; + break; + } + } + if (!flag2) + { + Game1.showRedMessage("Must be placed on wall"); + return false; + } + flag = true; + } + for (int i = point.X; i < point.X + this.getTilesWide(); i++) + { + for (int j = point.Y; j < point.Y + this.getTilesHigh(); j++) + { + if (location.doesTileHaveProperty(i, j, "NoFurniture", "Back") != null) + { + Game1.showRedMessage("Furniture can't be placed here"); + return false; + } + if (!flag && Utility.pointInRectangles(walls, i, j)) + { + Game1.showRedMessage("Can't place on wall"); + return false; + } + if (location.getTileIndexAt(i, j, "Buildings") != -1) + { + return false; + } + } + } + this.boundingBox = new Rectangle(x / Game1.tileSize, y / Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); + foreach (KeyValuePair c in location.objects) + { + StardewValley.Object ehh = c.Value; + if (((ehh.GetType()).ToString()).Contains("Spawner")) + { + CoreObject current2 = (CoreObject)ehh; + if (current2.Decoration_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox)) + { + current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who); + bool result = true; + return result; + } + } + } + foreach (StardewValley.Farmer current3 in location.getFarmers()) + { + if (current3.GetBoundingBox().Intersects(this.boundingBox)) + { + Game1.showRedMessage("Can't place on top of a person."); + bool result = false; + return result; + } + } + this.updateDrawPosition(); + // Log.AsyncO(this.boundingBox); + // Log.AsyncO(x); + // Log.AsyncY(y); + for (int i = 0; i <= this.boundingBox.X / Game1.tileSize; i++) + { + base.placementAction(location, x + 1, y, who); + } + for (int i = 0; i <= this.boundingBox.Y / Game1.tileSize; i++) + { + base.placementAction(location, x, y + 1, who); + } + return true; + } + else + { + Point point = new Point(x / Game1.tileSize, y / Game1.tileSize); + // List walls = FarmHouse.getWalls((location as FarmHouse).upgradeLevel); + this.tileLocation = new Vector2((float)point.X, (float)point.Y); + bool flag = false; + if (this.Decoration_type == 6 || this.Decoration_type == 13 || this.parentSheetIndex == 1293) + { + int num = (this.parentSheetIndex == 1293) ? 3 : 0; + bool flag2 = false; + /* + foreach (Rectangle current in walls) + { + if ((this.Decoration_type == 6 || this.Decoration_type == 13 || num != 0) && current.Y + num == point.Y && current.Contains(point.X, point.Y - num)) + { + flag2 = true; + break; + } + } + */ + if (!flag2) + { + Game1.showRedMessage("Must be placed on wall"); + return false; + } + flag = true; + } + for (int i = point.X; i < point.X + this.getTilesWide(); i++) + { + for (int j = point.Y; j < point.Y + this.getTilesHigh(); j++) + { + if (location.doesTileHaveProperty(i, j, "NoFurniture", "Back") != null) + { + Game1.showRedMessage("Furniture can't be placed here"); + return false; + } + /* + if (!flag && Utility.pointInRectangles(walls, i, j)) + { + Game1.showRedMessage("Can't place on wall"); + return false; + } + */ + if (location.getTileIndexAt(i, j, "Buildings") != -1) + { + return false; + } + } + } + this.boundingBox = new Rectangle(x / Game1.tileSize, y / Game1.tileSize, this.boundingBox.Width, this.boundingBox.Height); + /* + foreach (Furniture current2 in (location as FarmHouse).furniture) + { + if (current2.furniture_type == 11 && current2.heldObject == null && current2.getBoundingBox(current2.tileLocation).Intersects(this.boundingBox)) + { + current2.performObjectDropInAction(this, false, (who == null) ? Game1.player : who); + bool result = true; + return result; + } + } + */ + foreach (StardewValley.Farmer current3 in location.getFarmers()) + { + if (current3.GetBoundingBox().Intersects(this.boundingBox)) + { + Game1.showRedMessage("Can't place on top of a person."); + bool result = false; + return result; + } + } + this.updateDrawPosition(); + this.thisLocation = Game1.player.currentLocation; + return base.placementAction(location, x * Game1.tileSize, y * Game1.tileSize, who); + } + } + + public override bool isPlaceable() + { + return true; + } + + public override Rectangle getBoundingBox(Vector2 tileLocation) + { + return this.boundingBox; + } + + private Rectangle getDefaultSourceRectForType(int tileIndex, int type) + { + int num; + int num2; + switch (type) + { + case 0: + num = 1; + num2 = 2; + goto IL_94; + case 1: + num = 2; + num2 = 2; + goto IL_94; + case 2: + num = 3; + num2 = 2; + goto IL_94; + case 3: + num = 2; + num2 = 2; + goto IL_94; + case 4: + num = 2; + num2 = 2; + goto IL_94; + case 5: + num = 5; + num2 = 3; + goto IL_94; + case 6: + num = 2; + num2 = 2; + goto IL_94; + case 7: + num = 1; + num2 = 3; + goto IL_94; + case 8: + num = 1; + num2 = 2; + goto IL_94; + case 10: + num = 2; + num2 = 3; + goto IL_94; + case 11: + num = 2; + num2 = 3; + goto IL_94; + case 12: + num = 3; + num2 = 2; + goto IL_94; + case 13: + num = 1; + num2 = 2; + goto IL_94; + } + num = 1; + num2 = 2; + IL_94: + return new Rectangle(tileIndex * 16 % TextureSheet.Width, tileIndex * 16 / TextureSheet.Width * 16, num * 16, num2 * 16); + } + + private Rectangle getDefaultBoundingBoxForType(int type) + { + int num; + int num2; + switch (type) + { + case 0: + num = 1; + num2 = 1; + goto IL_94; + case 1: + num = 2; + num2 = 1; + goto IL_94; + case 2: + num = 3; + num2 = 1; + goto IL_94; + case 3: + num = 2; + num2 = 1; + goto IL_94; + case 4: + num = 2; + num2 = 1; + goto IL_94; + case 5: + num = 5; + num2 = 2; + goto IL_94; + case 6: + num = 2; + num2 = 2; + goto IL_94; + case 7: + num = 1; + num2 = 1; + goto IL_94; + case 8: + num = 1; + num2 = 1; + goto IL_94; + case 10: + num = 2; + num2 = 1; + goto IL_94; + case 11: + num = 2; + num2 = 2; + goto IL_94; + case 12: + num = 3; + num2 = 2; + goto IL_94; + case 13: + num = 1; + num2 = 2; + goto IL_94; + } + num = 1; + num2 = 1; + IL_94: + return new Rectangle((int)this.tileLocation.X * Game1.tileSize, (int)this.tileLocation.Y * Game1.tileSize, num * Game1.tileSize, num2 * Game1.tileSize); + } + + private int getTypeNumberFromName(string typeName) + { + string key; + switch (key = typeName.ToLower()) + { + case "chair": + return 0; + case "bench": + return 1; + case "couch": + return 2; + case "armchair": + return 3; + case "dresser": + return 4; + case "long table": + return 5; + case "painting": + return 6; + case "lamp": + return 7; + case "decor": + return 8; + case "bookcase": + return 10; + case "table": + return 11; + case "rug": + return 12; + case "window": + return 13; + } + return 9; + } + + public override int salePrice() + { + return this.price; + } + + public override int maximumStackSize() + { + return 1; + } + + public override int getStack() + { + return this.stack; + } + + public override int addToStack(int amount) + { + return 1; + } + + private float getScaleSize() + { + int num = this.sourceRect.Width / 16; + int num2 = this.sourceRect.Height / 16; + if (num >= 5) + { + return 0.75f; + } + if (num2 >= 3) + { + return 1f; + } + if (num <= 2) + { + return 2f; + } + if (num <= 4) + { + return 1f; + } + return 0.1f; + } + + public override void drawWhenHeld(SpriteBatch spriteBatch, Vector2 objectPosition, StardewValley.Farmer f) + { + if (f.ActiveObject.bigCraftable) + { + spriteBatch.Draw(Game1.bigCraftableSpriteSheet, objectPosition, new Microsoft.Xna.Framework.Rectangle?(StardewValley.Object.getSourceRectForBigCraftable(f.ActiveObject.ParentSheetIndex)), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + return; + } + spriteBatch.Draw(Game1.objectSpriteSheet, objectPosition, new Microsoft.Xna.Framework.Rectangle?(Game1.currentLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + if (f.ActiveObject != null && f.ActiveObject.Name.Contains("=")) + { + spriteBatch.Draw(Game1.objectSpriteSheet, objectPosition + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), new Microsoft.Xna.Framework.Rectangle?(Game1.currentLocation.getSourceRectForObject(f.ActiveObject.ParentSheetIndex)), Color.White, 0f, new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize / 2)), (float)Game1.pixelZoom + Math.Abs(Game1.starCropShimmerPause) / 8f, SpriteEffects.None, Math.Max(0f, (float)(f.getStandingY() + 2) / 10000f)); + if (Math.Abs(Game1.starCropShimmerPause) <= 0.05f && Game1.random.NextDouble() < 0.97) + { + return; + } + Game1.starCropShimmerPause += 0.04f; + if (Game1.starCropShimmerPause >= 0.8f) + { + Game1.starCropShimmerPause = -0.8f; + } + } + //base.drawWhenHeld(spriteBatch, objectPosition, f); + } + + public override void drawInMenu(SpriteBatch spriteBatch, Vector2 location, float scaleSize, float transparency, float layerDepth, bool drawStackNumber) + { + spriteBatch.Draw(TextureSheet, location + new Vector2((float)(Game1.tileSize), (float)(Game1.tileSize)), new Rectangle?(this.defaultSourceRect), Color.White * transparency, 0f, new Vector2((float)(this.defaultSourceRect.Width / 2), (float)(this.defaultSourceRect.Height)), 1f * this.getScaleSize() * scaleSize * .5f, SpriteEffects.None, layerDepth); + } + + public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1f) + { + if (x == -1) + { + spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, this.drawPosition), new Rectangle?(this.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); + } + else + { + spriteBatch.Draw(TextureSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(x * Game1.tileSize), (float)(y * Game1.tileSize - (this.sourceRect.Height * Game1.pixelZoom - this.boundingBox.Height)))), new Rectangle?(this.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, (this.Decoration_type == 12) ? 0f : ((float)(this.boundingBox.Bottom - 8) / 10000f)); + } + if (this.heldObject != null) + { + if (this.heldObject is CoreObject) + { + (this.heldObject as CoreObject).drawAtNonTileSpot(spriteBatch, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - (this.heldObject as CoreObject).sourceRect.Height * Game1.pixelZoom - Game1.tileSize / 4))), (float)(this.boundingBox.Bottom - 7) / 10000f, alpha); + return; + } + spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))) + new Vector2((float)(Game1.tileSize / 2), (float)(Game1.tileSize * 5 / 6)), new Rectangle?(Game1.shadowTexture.Bounds), Color.White * alpha, 0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, (float)this.boundingBox.Bottom / 10000f); + spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(this.boundingBox.Center.X - Game1.tileSize / 2), (float)(this.boundingBox.Center.Y - Game1.tileSize * 4 / 3))), new Rectangle?(Game1.currentLocation.getSourceRectForObject(this.heldObject.ParentSheetIndex)), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, SpriteEffects.None, (float)(this.boundingBox.Bottom + 1) / 10000f); + } + } + + public virtual void drawAtNonTileSpot(SpriteBatch spriteBatch, Vector2 location, float layerDepth, float alpha = 1f) + { + spriteBatch.Draw(TextureSheet, location, new Rectangle?(this.sourceRect), Color.White * alpha, 0f, Vector2.Zero, (float)Game1.pixelZoom, this.flipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None, layerDepth); + } + + public override Item getOne() + { + CoreObject CoreObject = new CoreObject(this.parentSheetIndex, this.tileLocation, this.inventoryMaxSize); + + CoreObject.drawPosition = this.drawPosition; + CoreObject.defaultBoundingBox = this.defaultBoundingBox; + CoreObject.boundingBox = this.boundingBox; + CoreObject.currentRotation = this.currentRotation - 1; + CoreObject.rotations = this.rotations; + //rotate(); + + return CoreObject; + } + + public virtual bool isInventoryFull() + { + // Log.AsyncC("Count" + inventory.Count); + // Log.AsyncC("size" + inventoryMaxSize); + if (inventory.Count >= inventoryMaxSize) + { + + return true; + } + else + { + return false; + } + + } + + public virtual bool addItemToInventory(Item I) + { + if (isInventoryFull() == false) + { + inventory.Add(I.getOne()); + return true; + } + else return false; + } + + public virtual void spillInventoryEverywhere() + { + Game1.activeClickableMenu = new StorageContainer(this.inventory, 3, 3); + this.itemReadyForHarvest = false; + /* + Log.AsyncC("DROPPING INVENTORY!"); + + Random random = new Random(inventory.Count); + int i = random.Next(); + i = i % 4; + Vector2 v2 = new Vector2(this.tileLocation.X * Game1.tileSize, this.tileLocation.Y * Game1.tileSize); + foreach (var I in inventory) + { + Log.AsyncY(I.Name); + Log.AsyncO(I.getStack()); + Log.AsyncM(I.Stack); + Log.AsyncC("Dropping an item!"); + Game1.createItemDebris(I, v2, i); + } + inventory.Clear(); + */ + } + + public virtual bool addItemToInventoryElseDrop(Item I) + { + + if (isInventoryFull() == false) + { + foreach (Item C in inventory) + { + if (C == null) continue; + if (I.canStackWith(C) == true) + { + C.addToStack(I.Stack); + return true; + } + else + { + inventory.Add(I.getOne()); + return true; + } + } + inventory.Add(I.getOne()); + return true; + } + else + { + Random random = new Random(inventory.Count); + int i = random.Next(); + i = i % 4; + Vector2 v2 = new Vector2(this.tileLocation.X * Game1.tileSize, this.tileLocation.Y * Game1.tileSize); + Game1.createItemDebris(I.getOne(), v2, i); + return false; + } + } + + public virtual void toggleLights() + { + + if (lightsOn == false) + { + + // Log.AsyncG("ADD LIGHTS"); + this.Decoration_type = 7; + this.type = "Lamp"; + + // this.lightSource.lightTexture = Game1.content.Load("LooseSprites\\Lighting\\Lantern"); + // this.lightSource.position = tileLocation; + + // this.addLights(thisLocation, lightColor); + this.addLights(thisLocation, lightColor); + lightsOn = true; + } + if (lightsOn == true) + { + this.removeLights(Game1.player.currentLocation); + lightsOn = false; + } + + } + + public virtual void resetTexture() + { + TextureSheet = Game1.content.Load(this.texturePath); + } + + public override string getCategoryName() + { + return "Core Mod Object"; + // return base.getCategoryName(); + } + + public override Color getCategoryColor() + { + return Color.Black; + } + + + public static void Serialize(Item I) + { + + } + + public static Item ParseIntoInventory() + { + Item I = new CoreObject(0, Vector2.Zero, 0); + return I; + } + + public static void ParseIntoWorld() + { + //Item I = new CoreObject(0, Vector2.Zero, 0); + //return I; + } + + } +} diff --git a/GeneralMods/StardustCore/ModCore.cs b/GeneralMods/StardustCore/ModCore.cs new file mode 100644 index 00000000..9224f3a6 --- /dev/null +++ b/GeneralMods/StardustCore/ModCore.cs @@ -0,0 +1,14 @@ +using StardewModdingAPI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardustCore +{ + public class ModCore : Mod + { + + } +} diff --git a/GeneralMods/StardustCore/Properties/AssemblyInfo.cs b/GeneralMods/StardustCore/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..1f7d29d7 --- /dev/null +++ b/GeneralMods/StardustCore/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("StardustCore")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("StardustCore")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("0756d36a-95c8-480d-8ea6-4584c03010c6")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GeneralMods/StardustCore/Serialization/Serialization.cs b/GeneralMods/StardustCore/Serialization/Serialization.cs new file mode 100644 index 00000000..142edb93 --- /dev/null +++ b/GeneralMods/StardustCore/Serialization/Serialization.cs @@ -0,0 +1,417 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using StardewModdingAPI; +using StardewValley; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace StardustCore.Serialization +{ + + /// + /// TODO: Find a way to serialize objects and tools. + /// + + + public class SerializationManager + { + public string objectsInWorldPath; + public string playerInventoryPath; + public string SerializerTrashPath; + + public Dictionary acceptedTypes = new Dictionary(); + public List trackedObjectList = new List(); + + + + public SerializationManager(string PlayerInventoryPath,string SerializerTrashPath,string ObjectsInWorldPath) + { + this.objectsInWorldPath = ObjectsInWorldPath; + this.playerInventoryPath = PlayerInventoryPath; + this.SerializerTrashPath = SerializerTrashPath; + + 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); + } + + public void cleanUpInventory() + { + ProcessDirectoryForDeletion(playerInventoryPath); + + //ProcessDirectoryForDeletion(SerializerTrashPath); + + List removalList = new List(); + foreach (Item d in Game1.player.items) + { + try + { + if (d == null) + { + //Log.AsyncG("WTF"); + continue; + } + // Log.AsyncC(d.GetType()); + } + catch (Exception e) + { + + } + string s = Convert.ToString((d.GetType())); + + + + + if (acceptedTypes.ContainsKey(s)) + { + SerializerDataNode t; + + bool works = acceptedTypes.TryGetValue(s, out t); + if (works == true) + { + t.serialize.Invoke(d); + removalList.Add(d); + } + } + } + foreach (var i in removalList) + { + Game1.player.removeItemFromInventory(i); + } + removalList.Clear(); + } + + public void cleanUpWorld() + { + ProcessDirectoryForDeletion(objectsInWorldPath); + List removalList = new List(); + int countProcessed = 0; + List idk = new List(); + foreach (CoreObject d in trackedObjectList) + { + try + { + if (d == null) + { + //Log.AsyncG("WTF"); + continue; + } + // Log.AsyncC(d.GetType()); + } + catch (Exception e) + { + + } + string s = Convert.ToString((d.GetType())); + + if (acceptedTypes.ContainsKey(s)) + { + SerializerDataNode t; + + bool works = acceptedTypes.TryGetValue(s, out t); + if (works == true) + { + countProcessed++; + if (d.useXML == false) + { + t.worldObj.Invoke(d); + } + else + { + idk.Add(d); + } + // Log.AsyncC("Progress on saving objects: " + countProcessed + "/" + Lists.trackedObjectList.Count); + removalList.Add(d); + } + } + } + foreach (var i in removalList) + { + i.thisLocation.removeObject(i.tileLocation, false); + } + foreach (var v in idk) + { + string s = Convert.ToString((v.GetType())); + + if (acceptedTypes.ContainsKey(s)) + { + SerializerDataNode t; + + bool works = acceptedTypes.TryGetValue(s, out t); + if (works == true) + { + countProcessed++; + if ((v as CoreObject).useXML == true) + { + t.worldObj.Invoke(v as CoreObject); + } + //Log.AsyncG("Progress on saving objects: " + countProcessed + "/" + Lists.trackedObjectList.Count); + removalList.Add(v as CoreObject); + } + } + } + + removalList.Clear(); + // Log.AsyncM("Revitalize: Done cleaning world for saving."); + + } + + + public void restoreAllModObjects(List thingsToAddBackIn) + { + processDirectoryForDeserialization(this.playerInventoryPath,thingsToAddBackIn); + Log.AsyncG("DESERIALIZE???"); + try + { + trackedObjectList.Clear(); //clear whatever mod objects I'm tracking + processDirectoryForDeserialization(objectsInWorldPath,thingsToAddBackIn); //restore whatever I'm tracking here when I replace the object back into the world. This also works when loading up the game, not just when saving/loading + } + catch (Exception e) + { + + } + } + + + public void ProcessDirectoryForDeletion(string targetDirectory) + { + // Process the list of files found in the directory. + string[] fileEntries = Directory.GetFiles(targetDirectory); + foreach (string fileName in fileEntries) + { + File.Delete(fileName); + // File.Delete(fileName); + } + + // Recurse into subdirectories of this directory. + string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory); + foreach (string subdirectory in subdirectoryEntries) + ProcessDirectoryForDeletion(subdirectory); + + } + + + public void WriteToJsonFile(string filePath, T objectToWrite, bool append = false) where T : new() + { + TextWriter writer = null; + try + { + JsonSerializerSettings settings = new JsonSerializerSettings(); + //settings.TypeNameHandling = TypeNameHandling.Auto; + settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; + settings.TypeNameHandling = TypeNameHandling.Auto; + // settings.Formatting = Formatting.Indented; + var contentsToWriteToFile = JsonConvert.SerializeObject(objectToWrite, settings); + int i = 0; + string s = filePath; + while (File.Exists(s) == true) + { + s = filePath; + s = (s + Convert.ToString(i)); + i++; + } + filePath = s; + + writer = new StreamWriter(filePath, append); + + writer.Write(contentsToWriteToFile); + } + finally + { + if (writer != null) + writer.Close(); + } + } + + + public void serializeXML(Item I) + { + System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(T)); + var newWriter = new StringWriter(); + using (var writer = XmlWriter.Create(newWriter)) + { + xmlSerializer.Serialize(writer,I); + } + } + + /// + /// + /// + /// + /// Typically this would be the trackedObjectList. + public void processDirectoryForDeserialization(string pathToFile,List thingsToAddBackIn) + { + string[] fileEntries = Directory.GetFiles(pathToFile); + foreach(var fileName in fileEntries) + { + ProcessFileForCleanUp(fileName,thingsToAddBackIn); + } + + string[] subDirectories = Directory.GetDirectories(pathToFile); + foreach(var folder in subDirectories) + { + processDirectoryForDeserialization(folder,thingsToAddBackIn); + } + + } + + + public void ProcessFileForCleanUp(string path, List thingsToAddBackIn) + { + + Log.AsyncC(path); + + string[] ehh = File.ReadAllLines(path); + string data = ehh[0]; + CoreObject cObj; + string a; + string[] b; + string s = ""; + // Log.AsyncC(path); + // Log.AsyncC(data); + try + { + dynamic obj = JObject.Parse(data); + + + // Log.AsyncC(obj.thisType); + + a = obj.serializationName; + b = a.Split(','); + s = b.ElementAt(0); + Log.AsyncC(s); + } + catch (Exception e) + { + + //USE XML STYLE DESERIALIZING + foreach (KeyValuePair pair in acceptedTypes) + { + var word = ParseXMLType(path); + if (pair.Key == word.ToString()) + { + cObj =(CoreObject) pair.Value.parse.Invoke(path); + (cObj as CoreObject).thisLocation = Game1.getLocationFromName((cObj as CoreObject).locationsName); + (cObj as CoreObject).resetTexture(); + if ((cObj as CoreObject).thisLocation == null) + { + Game1.player.addItemToInventory(cObj); + Log.AsyncY("ADDED ITEM TO INVENTORY"); + return; + } + else + { + (cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).tileLocation, (StardewValley.Object)cObj); + thingsToAddBackIn.Add(cObj); + //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false); + } + } + } + + // Log.AsyncG("attempting to parse from path and value of s is " + s); + } + + // var cObj = parseBagOfHolding(path); //pair.Value.parse.Invoke(path); + // cObj.TextureSheet = Game1.content.Load(Path.Combine("Revitalize", "CropsNSeeds", "Graphics", "seeds")); + /* + cObj.thisLocation = Game1.getLocationFromName(cObj.locationsName); + if (cObj.thisLocation == null) + { + Game1.player.addItemToInventory(cObj); + return; + } + else + { + cObj.thisLocation.objects.Add(cObj.tileLocation, cObj); + Lists.trackedObjectList.Add(cObj); + //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false); + } + */ + + //USE JSON STYLE DESERIALIZNG + if (acceptedTypes.ContainsKey(s)) + { + Log.AsyncC("FUUUUU"); + foreach (KeyValuePair pair in acceptedTypes) + { + Log.AsyncY(pair.Key); + if (pair.Key == s) + { + try + { + //parse from Json Style + 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"); + return; + } + else + { + (cObj as CoreObject).thisLocation.objects.Add((cObj as CoreObject).tileLocation,(StardewValley.Object)cObj); + thingsToAddBackIn.Add(cObj); + //Util.placementAction(cObj, cObj.thisLocation,(int)cObj.tileLocation.X,(int) cObj.tileLocation.Y,null,false); + } + } + catch (Exception e) + { + Log.AsyncO(e); + } + } + } + } + else + { + Log.AsyncM("Error parsing unknown object type: " + s); + } + + } + + + public string ParseXMLType(string path) + { + string[] s = File.ReadAllLines(path); + string returnString = ""; + foreach (string v in s) + { + // Log.AsyncC(v); + if (v.Contains("serializationName")) + { + returnString = v.Remove(0, 12); + returnString = returnString.Remove(returnString.Length - 11, 11); + } + + } + return returnString; + } + + public static Microsoft.Xna.Framework.Rectangle parseRectFromJson(string s) + { + s = s.Replace('{', ' '); + s = s.Replace('}', ' '); + s = s.Replace('^', ' '); + s = s.Replace(':', ' '); + string[] parsed = s.Split(' '); + foreach (var v in parsed) + { + //Log.AsyncY(v); + } + return new Microsoft.Xna.Framework.Rectangle(Convert.ToInt32(parsed[2]), Convert.ToInt32(parsed[4]), Convert.ToInt32(parsed[6]), Convert.ToInt32(parsed[8])); + } + + } +} diff --git a/GeneralMods/StardustCore/Serialization/SerializerDataNode.cs b/GeneralMods/StardustCore/Serialization/SerializerDataNode.cs new file mode 100644 index 00000000..ba1faa26 --- /dev/null +++ b/GeneralMods/StardustCore/Serialization/SerializerDataNode.cs @@ -0,0 +1,27 @@ +using StardewValley; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace StardustCore.Serialization +{ + public class SerializerDataNode + { + public delegate Item ParsingFunction(string data); + public delegate void SerializingFunction(Item item); + public delegate void WorldParsingFunction(Item obj); + + public SerializingFunction serialize; + public ParsingFunction parse; + public WorldParsingFunction worldObj; + + public SerializerDataNode(SerializingFunction serializeFunction, ParsingFunction parsingFunction, WorldParsingFunction worldObjectParsingFunction) + { + serialize = serializeFunction; + parse = parsingFunction; + worldObj = worldObjectParsingFunction; + } + } +} diff --git a/GeneralMods/StardustCore/StardustCore.csproj b/GeneralMods/StardustCore/StardustCore.csproj new file mode 100644 index 00000000..d4abd9b7 --- /dev/null +++ b/GeneralMods/StardustCore/StardustCore.csproj @@ -0,0 +1,82 @@ + + + + + Debug + AnyCPU + {0756D36A-95C8-480D-8EA6-4584C03010C6} + Library + Properties + StardustCore + StardustCore + v4.5 + 512 + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + \ No newline at end of file diff --git a/GeneralMods/StardustCore/manifest.json b/GeneralMods/StardustCore/manifest.json new file mode 100644 index 00000000..bc64c422 --- /dev/null +++ b/GeneralMods/StardustCore/manifest.json @@ -0,0 +1,14 @@ +{ + "Name": "StardustCore", + "Author": "Alpha_Omegasis", + "Version": { + "MajorVersion": 2, + "MinorVersion": 0, + "PatchVersion": 0, + "Build": null + }, + "MinimumApiVersion": "1.15", + "Description": "A core mod that allows for other mods to be run.", + "UniqueID": "Omegasis.StardustCore", + "EntryDll": "StardustCore.dll" +} diff --git a/GeneralMods/StardustCore/packages.config b/GeneralMods/StardustCore/packages.config new file mode 100644 index 00000000..23914dec --- /dev/null +++ b/GeneralMods/StardustCore/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/SunDrop/ReadMe.txt b/SunDrop/ReadMe.txt new file mode 100644 index 00000000..a05614ba --- /dev/null +++ b/SunDrop/ReadMe.txt @@ -0,0 +1 @@ +Transfer these mods over to the general mod folder. \ No newline at end of file