Started object manager.

This commit is contained in:
JoshuaNavarro 2019-05-23 16:53:44 -07:00
parent 76aa7f7894
commit c1509c9371
4 changed files with 241 additions and 141 deletions

View File

@ -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<string, LampMultiTiledObject> objs = new Dictionary<string, LampMultiTiledObject>();
//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<FactoryInfo>(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<FactoryInfo>(file);
Dictionary<string, LampMultiTiledObject> objs = new Dictionary<string, LampMultiTiledObject>();
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<Vector2, FakeLightSource> 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<FactoryInfo>(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<FactoryInfo>(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<Vector2, FakeLightSource> 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<string, ChairMultiTiledObject> chairObjects = new Dictionary<string, ChairMultiTiledObject>();
//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<string, ChairMultiTiledObject> chairObjects = new Dictionary<string, ChairMultiTiledObject>();
//Deserialize container.
foreach (string file in files)
{
chairObjects.Add(Path.GetFileNameWithoutExtension(file), new ChairMultiTiledObject(ModCore.Serializer.DeserializeContentFile<ChairFactoryInfo>(file).info));
if ((Path.GetFileName(file)).Contains("_") == true) continue;
else
{
chairObjects.Add(Path.GetFileNameWithoutExtension(file), new ChairMultiTiledObject(ModCore.Serializer.DeserializeContentFile<ChairFactoryInfo>(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<ChairFactoryInfo>(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<ChairFactoryInfo>(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<string, TableMultiTiledObject> chairObjects = new Dictionary<string, TableMultiTiledObject>();
//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<string, TableMultiTiledObject> chairObjects = new Dictionary<string, TableMultiTiledObject>();
//Deserialize container.
foreach (string file in files)
{
chairObjects.Add(Path.GetFileNameWithoutExtension(file), new TableMultiTiledObject(ModCore.Serializer.DeserializeContentFile<TableFactoryInfo>(file).info));
if ((Path.GetFileName(file)).Contains("_") == true) continue;
else
{
chairObjects.Add(Path.GetFileNameWithoutExtension(file), new TableMultiTiledObject(ModCore.Serializer.DeserializeContentFile<TableFactoryInfo>(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<TableFactoryInfo>(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<TableFactoryInfo>(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);
}
}

View File

@ -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<string, string> additionalSaveData, object replacement)
{
CustomObjectData data = CustomObjectData.collection[additionalSaveData["id"]];
return new GarbageTest((BasicItemInformation)data, (replacement as Chest).TileLocation);
}
}
}

View File

@ -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
{
/// <summary>
/// All of the object managers id'd by a mod's or content pack's unique id.
/// </summary>
public static Dictionary<string, ObjectManager> ObjectPools;
/// <summary>
/// The name of this object manager.
/// </summary>
public string name;
/// <summary>
/// All of the chairs held by this object pool.
/// </summary>
public Dictionary<string, ChairMultiTiledObject> chairs;
/// <summary>
/// All of the tables held by this object pool.
/// </summary>
public Dictionary<string, TableMultiTiledObject> tables;
/// <summary>
/// All of the lamps held by this object pool.
/// </summary>
public Dictionary<string, LampMultiTiledObject> lamps;
/// <summary>
/// All of the rugs held by this object pool.
/// </summary>
public Dictionary<string, RugMultiTiledObject> rugs;
/// <summary>
/// Constructor.
/// </summary>
public ObjectManager()
{
this.initialize();
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="manifest"></param>
public ObjectManager(IManifest manifest)
{
this.name = manifest.UniqueID;
this.initialize();
}
/// <summary>
/// Initialize all objects used to manage this class.
/// </summary>
private void initialize()
{
this.chairs = new Dictionary<string, ChairMultiTiledObject>();
this.tables = new Dictionary<string, TableMultiTiledObject>();
this.lamps = new Dictionary<string, LampMultiTiledObject>();
this.rugs = new Dictionary<string, RugMultiTiledObject>();
}
/// <summary>
/// Gets a random object from the dictionary passed in.
/// </summary>
/// <param name="dictionary"></param>
/// <returns></returns>
public Item getRandomObject(Dictionary<string,CustomObject> dictionary)
{
if (dictionary.Count == 0) return null;
List<CustomObject> objs = new List<CustomObject>();
foreach(KeyValuePair<string,CustomObject> pair in dictionary)
{
objs.Add(pair.Value);
}
int rand = Game1.random.Next(0,objs.Count);
return objs[rand].getOne();
}
/// <summary>
/// Gets an object from the dictionary that is passed in.
/// </summary>
/// <param name="objectName"></param>
/// <param name="dictionary"></param>
/// <returns></returns>
public Item getObject(string objectName, Dictionary<string,CustomObject> dictionary)
{
if (dictionary.ContainsKey(objectName))
{
return dictionary[objectName].getOne();
}
else
{
throw new Exception("Object pool doesn't contain said object.");
}
}
/// <summary>
/// Adds a new object manager to the master pool of managers.
/// </summary>
/// <param name="Manifest"></param>
public static void AddObjectManager(IManifest Manifest)
{
if (ObjectPools == null) ObjectPools = new Dictionary<string, ObjectManager>();
ObjectPools.Add(Manifest.UniqueID, new ObjectManager(Manifest));
}
}
}

View File

@ -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 Dictionary<string, MultiTiledObject>ObjectGroups;
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()