diff --git a/GeneralMods/Revitalize/Framework/Factories/Objects/Furniture/FurnitureFactory.cs b/GeneralMods/Revitalize/Framework/Factories/Objects/Furniture/FurnitureFactory.cs index aa7bc8a7..3dcc3cd9 100644 --- a/GeneralMods/Revitalize/Framework/Factories/Objects/Furniture/FurnitureFactory.cs +++ b/GeneralMods/Revitalize/Framework/Factories/Objects/Furniture/FurnitureFactory.cs @@ -65,10 +65,10 @@ namespace Revitalize.Framework.Factories.Objects FactoryInfo lO = new FactoryInfo(lamp); - ModCore.Serializer.SerializeContentFile("OakLamp_0_-2", lT, LampsFolder); - ModCore.Serializer.SerializeContentFile("OakLamp_0_-1", lM, LampsFolder); - ModCore.Serializer.SerializeContentFile("OakLamp_0_0", lB, LampsFolder); - ModCore.Serializer.SerializeContentFile("OakLamp", lO, LampsFolder); + ModCore.Serializer.SerializeContentFile("OakLamp_0_-2", lT,Path.Combine(LampsFolder,"OakLamp")); + ModCore.Serializer.SerializeContentFile("OakLamp_0_-1", lM, Path.Combine(LampsFolder, "OakLamp")); + ModCore.Serializer.SerializeContentFile("OakLamp_0_0", lB, Path.Combine(LampsFolder, "OakLamp")); + ModCore.Serializer.SerializeContentFile("OakLamp", lO, Path.Combine(LampsFolder, "OakLamp")); //ModCore.customObjects.Add(lamp.info.id, lamp); } @@ -76,51 +76,58 @@ namespace Revitalize.Framework.Factories.Objects private static void DeserializeLamps() { if (!Directory.Exists(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", LampsFolder))) Directory.CreateDirectory(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", LampsFolder)); - string[] files = Directory.GetFiles(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", LampsFolder)); + string[] directories = Directory.GetDirectories(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", LampsFolder)); - Dictionary objs = new Dictionary(); - - //Deserialize container. - foreach (string file in files) + foreach(string directory in directories) { - if ((Path.GetFileName(file)).Contains("_") == true) continue; - else - { - objs.Add(Path.GetFileNameWithoutExtension(file), new LampMultiTiledObject(ModCore.Serializer.DeserializeContentFile(file).info)); - } - } - //Deseralize components - foreach (string file in files) - { - if ((Path.GetFileName(file)).Contains("_") == false) continue; - else - { + string[] files = Directory.GetFiles(directory); - string[] splits = Path.GetFileNameWithoutExtension(file).Split('_'); - string name = splits[0]; - Vector2 offset = new Vector2(Convert.ToInt32(splits[1]), Convert.ToInt32(splits[2])); - FactoryInfo info = ModCore.Serializer.DeserializeContentFile(file); + Dictionary objs = new Dictionary(); - LampTileComponent lampPiece = new LampTileComponent(info.info); - //Recreate the lights info. - if (lampPiece.lights != null) + //Deserialize container. + foreach (string file in files) + { + if ((Path.GetFileName(file)).Contains("_") == true) continue; + else { - //ModCore.log("Info for file"+Path.GetFileNameWithoutExtension(file)+" has this many lights: " + info.info.lightManager.fakeLights.Count); - lampPiece.lights.lights.Clear(); - foreach (KeyValuePair light in info.info.lightManager.fakeLights) - { - lampPiece.lights.addLight(new Vector2(Game1.tileSize), new LightSource(light.Value.id, new Vector2(0, 0), light.Value.radius,light.Value.color.Invert()), lampPiece); - } + objs.Add(Path.GetFileNameWithoutExtension(file), new LampMultiTiledObject(ModCore.Serializer.DeserializeContentFile(file).info)); } + } + //Deseralize components + foreach (string file in files) + { + if ((Path.GetFileName(file)).Contains("_") == false) continue; + else + { + + string[] splits = Path.GetFileNameWithoutExtension(file).Split('_'); + string name = splits[0]; + Vector2 offset = new Vector2(Convert.ToInt32(splits[1]), Convert.ToInt32(splits[2])); + FactoryInfo info = ModCore.Serializer.DeserializeContentFile(file); + + LampTileComponent lampPiece = new LampTileComponent(info.info); + //Recreate the lights info. + if (lampPiece.lights != null) + { + //ModCore.log("Info for file"+Path.GetFileNameWithoutExtension(file)+" has this many lights: " + info.info.lightManager.fakeLights.Count); + lampPiece.lights.lights.Clear(); + foreach (KeyValuePair light in info.info.lightManager.fakeLights) + { + lampPiece.lights.addLight(new Vector2(Game1.tileSize), new LightSource(light.Value.id, new Vector2(0, 0), light.Value.radius, light.Value.color.Invert()), lampPiece); + } + } - objs[name].addComponent(offset,lampPiece ); + objs[name].addComponent(offset, lampPiece); + } + } + foreach (var v in objs) + { + ModCore.customObjects.Add(v.Value.info.id, v.Value); } } - foreach (var v in objs) - { - ModCore.customObjects.Add(v.Value.info.id, v.Value); - } + + } @@ -219,43 +226,48 @@ namespace Revitalize.Framework.Factories.Objects ChairFactoryInfo obj = new ChairFactoryInfo(oakChair); - ModCore.Serializer.SerializeContentFile("OakChair_0_-1", top, ChairFolder); - ModCore.Serializer.SerializeContentFile("OakChair_0_0", bottom, ChairFolder); - ModCore.Serializer.SerializeContentFile("OakChair", obj, ChairFolder); + ModCore.Serializer.SerializeContentFile("OakChair_0_-1", top, Path.Combine(ChairFolder, "OakChair")); + ModCore.Serializer.SerializeContentFile("OakChair_0_0", bottom, Path.Combine(ChairFolder, "OakChair")); + ModCore.Serializer.SerializeContentFile("OakChair", obj, Path.Combine(ChairFolder, "OakChair")); } private static void DeserializeChairs() { if (!Directory.Exists(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", ChairFolder))) Directory.CreateDirectory(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", ChairFolder)); - string[] files = Directory.GetFiles(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", ChairFolder)); + string[] directories = Directory.GetDirectories(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", ChairFolder)); - Dictionary chairObjects = new Dictionary(); - - //Deserialize container. - foreach (string file in files) + foreach (string directory in directories) { - if ((Path.GetFileName(file)).Contains("_") == true) continue; - else + string[] files = Directory.GetFiles(directory); + + Dictionary chairObjects = new Dictionary(); + + //Deserialize container. + foreach (string file in files) { - chairObjects.Add(Path.GetFileNameWithoutExtension(file), new ChairMultiTiledObject(ModCore.Serializer.DeserializeContentFile(file).info)); + if ((Path.GetFileName(file)).Contains("_") == true) continue; + else + { + chairObjects.Add(Path.GetFileNameWithoutExtension(file), new ChairMultiTiledObject(ModCore.Serializer.DeserializeContentFile(file).info)); + } } - } - //Deseralize components - foreach (string file in files) - { - if ((Path.GetFileName(file)).Contains("_") == false) continue; - else + //Deseralize components + foreach (string file in files) { + if ((Path.GetFileName(file)).Contains("_") == false) continue; + else + { - string[] splits = Path.GetFileNameWithoutExtension(file).Split('_'); - string name = splits[0]; - Vector2 offset = new Vector2(Convert.ToInt32(splits[1]), Convert.ToInt32(splits[2])); - ChairFactoryInfo info = ModCore.Serializer.DeserializeContentFile(file); - chairObjects[name].addComponent(offset, new ChairTileComponent(info.info, info.chairInfo)); + string[] splits = Path.GetFileNameWithoutExtension(file).Split('_'); + string name = splits[0]; + Vector2 offset = new Vector2(Convert.ToInt32(splits[1]), Convert.ToInt32(splits[2])); + ChairFactoryInfo info = ModCore.Serializer.DeserializeContentFile(file); + chairObjects[name].addComponent(offset, new ChairTileComponent(info.info, info.chairInfo)); + } + } + foreach (var v in chairObjects) + { + ModCore.customObjects.Add(v.Value.info.id, v.Value); } - } - foreach (var v in chairObjects) - { - ModCore.customObjects.Add(v.Value.info.id, v.Value); } } @@ -280,50 +292,56 @@ namespace Revitalize.Framework.Factories.Objects TableFactoryInfo table = new TableFactoryInfo(obj); - ModCore.Serializer.SerializeContentFile("OakTable_0_0", uL, TablesFolder); - ModCore.Serializer.SerializeContentFile("OakTable_1_0", uR, TablesFolder); - ModCore.Serializer.SerializeContentFile("OakTable_0_1", cL, TablesFolder); - ModCore.Serializer.SerializeContentFile("OakTable_1_1", cR, TablesFolder); - ModCore.Serializer.SerializeContentFile("OakTable_0_2", bL, TablesFolder); - ModCore.Serializer.SerializeContentFile("OakTable_1_2", bR, TablesFolder); + ModCore.Serializer.SerializeContentFile("OakTable_0_0", uL, Path.Combine(TablesFolder, "OakTable")); + ModCore.Serializer.SerializeContentFile("OakTable_1_0", uR, Path.Combine(TablesFolder, "OakTable")); + ModCore.Serializer.SerializeContentFile("OakTable_0_1", cL, Path.Combine(TablesFolder, "OakTable")); + ModCore.Serializer.SerializeContentFile("OakTable_1_1", cR, Path.Combine(TablesFolder, "OakTable")); + ModCore.Serializer.SerializeContentFile("OakTable_0_2", bL, Path.Combine(TablesFolder, "OakTable")); + ModCore.Serializer.SerializeContentFile("OakTable_1_2", bR, Path.Combine(TablesFolder, "OakTable")); - ModCore.Serializer.SerializeContentFile("OakTable", table, TablesFolder); + ModCore.Serializer.SerializeContentFile("OakTable", table, Path.Combine(TablesFolder, "OakTable")); } private static void DeserializeTableFiles() { if (!Directory.Exists(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", TablesFolder))) Directory.CreateDirectory(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", TablesFolder)); - string[] files = Directory.GetFiles(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", TablesFolder)); - Dictionary chairObjects = new Dictionary(); - - //Deserialize container. - foreach (string file in files) + string[] directories = Directory.GetDirectories(Path.Combine(ModCore.ModHelper.DirectoryPath, "Content", TablesFolder)); + foreach (string directory in directories) { - if ((Path.GetFileName(file)).Contains("_") == true) continue; - else + + string[] files = Directory.GetFiles(directory); + + Dictionary chairObjects = new Dictionary(); + + //Deserialize container. + foreach (string file in files) { - chairObjects.Add(Path.GetFileNameWithoutExtension(file), new TableMultiTiledObject(ModCore.Serializer.DeserializeContentFile(file).info)); + if ((Path.GetFileName(file)).Contains("_") == true) continue; + else + { + chairObjects.Add(Path.GetFileNameWithoutExtension(file), new TableMultiTiledObject(ModCore.Serializer.DeserializeContentFile(file).info)); + } } - } - //Deseralize components - foreach (string file in files) - { - if ((Path.GetFileName(file)).Contains("_") == false) continue; - else + //Deseralize components + foreach (string file in files) { + if ((Path.GetFileName(file)).Contains("_") == false) continue; + else + { - string[] splits = Path.GetFileNameWithoutExtension(file).Split('_'); - string name = splits[0]; - Vector2 offset = new Vector2(Convert.ToInt32(splits[1]), Convert.ToInt32(splits[2])); - TableFactoryInfo info = ModCore.Serializer.DeserializeContentFile(file); - chairObjects[name].addComponent(offset, new TableTileComponent(info.info, info.tableInfo)); + string[] splits = Path.GetFileNameWithoutExtension(file).Split('_'); + string name = splits[0]; + Vector2 offset = new Vector2(Convert.ToInt32(splits[1]), Convert.ToInt32(splits[2])); + TableFactoryInfo info = ModCore.Serializer.DeserializeContentFile(file); + chairObjects[name].addComponent(offset, new TableTileComponent(info.info, info.tableInfo)); + } + } + foreach (var v in chairObjects) + { + ModCore.customObjects.Add(v.Value.info.id, v.Value); } - } - foreach (var v in chairObjects) - { - ModCore.customObjects.Add(v.Value.info.id, v.Value); } } diff --git a/GeneralMods/Revitalize/Framework/Objects/GarbageTest.cs b/GeneralMods/Revitalize/Framework/Objects/GarbageTest.cs deleted file mode 100644 index 0da2c209..00000000 --- a/GeneralMods/Revitalize/Framework/Objects/GarbageTest.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Xna.Framework; -using PyTK.CustomElementHandler; -using StardewValley; -using StardewValley.Objects; - -namespace Revitalize.Framework.Objects -{ - public class GarbageTest:CustomObject - { - public GarbageTest() - { - - } - - public GarbageTest(BasicItemInformation info) : base(info) - { - - } - - public GarbageTest(BasicItemInformation info,Vector2 TileLocation) : base(info,TileLocation) - { - - } - - public override Item getOne() - { - return new GarbageTest(this.info); - } - - public override ICustomObject recreate(Dictionary additionalSaveData, object replacement) - { - CustomObjectData data = CustomObjectData.collection[additionalSaveData["id"]]; - return new GarbageTest((BasicItemInformation)data, (replacement as Chest).TileLocation); - } - - } -} diff --git a/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs new file mode 100644 index 00000000..9bc98292 --- /dev/null +++ b/GeneralMods/Revitalize/Framework/Objects/ObjectManager.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Revitalize.Framework.Objects.Furniture; +using StardewModdingAPI; +using StardewValley; + +namespace Revitalize.Framework.Objects +{ + public class ObjectManager + { + /// + /// All of the object managers id'd by a mod's or content pack's unique id. + /// + public static Dictionary ObjectPools; + + + /// + /// The name of this object manager. + /// + public string name; + + /// + /// All of the chairs held by this object pool. + /// + public Dictionary chairs; + /// + /// All of the tables held by this object pool. + /// + public Dictionary tables; + /// + /// All of the lamps held by this object pool. + /// + public Dictionary lamps; + /// + /// All of the rugs held by this object pool. + /// + public Dictionary rugs; + + /// + /// Constructor. + /// + public ObjectManager() + { + this.initialize(); + } + + /// + /// Constructor. + /// + /// + public ObjectManager(IManifest manifest) + { + this.name = manifest.UniqueID; + this.initialize(); + } + + /// + /// Initialize all objects used to manage this class. + /// + private void initialize() + { + this.chairs = new Dictionary(); + this.tables = new Dictionary(); + this.lamps = new Dictionary(); + this.rugs = new Dictionary(); + } + + /// + /// Gets a random object from the dictionary passed in. + /// + /// + /// + public Item getRandomObject(Dictionary dictionary) + { + if (dictionary.Count == 0) return null; + List objs = new List(); + foreach(KeyValuePair pair in dictionary) + { + objs.Add(pair.Value); + } + int rand = Game1.random.Next(0,objs.Count); + return objs[rand].getOne(); + } + + /// + /// Gets an object from the dictionary that is passed in. + /// + /// + /// + /// + public Item getObject(string objectName, Dictionary dictionary) + { + if (dictionary.ContainsKey(objectName)) + { + return dictionary[objectName].getOne(); + } + else + { + throw new Exception("Object pool doesn't contain said object."); + } + } + + /// + /// Adds a new object manager to the master pool of managers. + /// + /// + public static void AddObjectManager(IManifest Manifest) + { + if (ObjectPools == null) ObjectPools = new Dictionary(); + ObjectPools.Add(Manifest.UniqueID, new ObjectManager(Manifest)); + } + + + } +} diff --git a/GeneralMods/Revitalize/ModCore.cs b/GeneralMods/Revitalize/ModCore.cs index 59a6344d..de9c3204 100644 --- a/GeneralMods/Revitalize/ModCore.cs +++ b/GeneralMods/Revitalize/ModCore.cs @@ -27,9 +27,8 @@ namespace Revitalize // -load content MUST be enabled for the table to be placed?????? WTF // TODO: // - // -Add in object pool class to handle the multitudes of objects I'll be making. + // -Add in object pool class to handle the multitudes of objects I'll be making. (WIP) // -Make this mod able to load content packs for easier future modding - // -Make deserialize/serialize look through sub directories instead of just one directory. // // -Multiple Lights On Object // -Illumination Colors @@ -57,6 +56,8 @@ namespace Revitalize // -Tin/Bronze/Alluminum/Silver?Platinum/Etc // -Crafting Menu // -Item Grab Menu (Extendable) + // -Yes/No Dialogue Box + // -Multi Choice dialogue box // -Gift Boxes // Magic! // -Alchemy Bags @@ -68,7 +69,7 @@ namespace Revitalize // -Connected chests much like Project EE2 from MC // // - // + // -Food? // -Bigger chests // // Festivals @@ -119,6 +120,9 @@ namespace Revitalize public static DictionaryObjectGroups; + + + public static PlayerInfo playerInfo; public static Serializer Serializer; @@ -211,8 +215,10 @@ namespace Revitalize Directory.CreateDirectory(Path.Combine(this.Helper.DirectoryPath, "Content")); Directory.CreateDirectory(Path.Combine(this.Helper.DirectoryPath,"Content" ,"Graphics")); - Directory.CreateDirectory(Path.Combine(this.Helper.DirectoryPath, "Content", "Graphics","Furniture")); + //Directory.CreateDirectory(Path.Combine(this.Helper.DirectoryPath, "Content", "Graphics","Furniture")); Directory.CreateDirectory(Path.Combine(this.Helper.DirectoryPath, "Content", "Graphics", "Furniture","Chairs")); + Directory.CreateDirectory(Path.Combine(this.Helper.DirectoryPath, "Content", "Graphics", "Furniture", "Lamps")); + Directory.CreateDirectory(Path.Combine(this.Helper.DirectoryPath, "Content", "Graphics", "Furniture", "Tables")); } private void initailizeComponents()