Fixed more serialization issues. Now to figure out how to get items back to player inventories....

This commit is contained in:
JoshuaNavarro 2019-08-21 20:03:16 -07:00
parent b24420d368
commit c7770cb8d7
10 changed files with 298 additions and 7 deletions

View File

@ -92,6 +92,33 @@ namespace Revitalize.Framework.Objects.Extras
}
public override void recreate()
{
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
{
guids.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
this.childrenGuids.Remove(pair.Key);
ArcadeCabinetTile component = Revitalize.ModCore.Serializer.DeserializeGUID<ArcadeCabinetTile>(pair.Value.ToString());
component.InitNetFields();
this.removeComponent(pair.Key);
this.addComponent(pair.Key, component);
}
this.InitNetFields();
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
{
Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
}
}
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{

View File

@ -105,6 +105,33 @@ namespace Revitalize.Framework.Objects.Furniture
}
}
public override void recreate()
{
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
{
guids.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
this.childrenGuids.Remove(pair.Key);
ChairTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<ChairTileComponent>(pair.Value.ToString());
component.InitNetFields();
this.removeComponent(pair.Key);
this.addComponent(pair.Key, component);
}
this.InitNetFields();
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
{
Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
}
}
}
}

View File

@ -108,6 +108,33 @@ namespace Revitalize.Framework.Objects.Furniture
}
public override void recreate()
{
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
{
guids.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
this.childrenGuids.Remove(pair.Key);
ChairTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<ChairTileComponent>(pair.Value.ToString());
component.InitNetFields();
this.removeComponent(pair.Key);
this.addComponent(pair.Key, component);
}
this.InitNetFields();
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
{
Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
}
}
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{

View File

@ -72,7 +72,7 @@ namespace Revitalize.Framework.Objects.Furniture
//Revitalize.ModCore.log("DESERIALIZE: " + pair.Value.ToString());
LampTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<LampTileComponent>(pair.Value.ToString());
component.InitNetFields();
obj.addComponent(pair.Key, component);
@ -92,6 +92,33 @@ namespace Revitalize.Framework.Objects.Furniture
}
public override void recreate()
{
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
{
guids.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
this.childrenGuids.Remove(pair.Key);
LampTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<LampTileComponent>(pair.Value.ToString());
component.InitNetFields();
this.removeComponent(pair.Key);
this.addComponent(pair.Key, component);
}
this.InitNetFields();
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
{
Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
}
}
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{

View File

@ -94,6 +94,33 @@ namespace Revitalize.Framework.Objects.Furniture
}
public override void recreate()
{
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
{
guids.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
this.childrenGuids.Remove(pair.Key);
RugTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<RugTileComponent>(pair.Value.ToString());
component.InitNetFields();
this.removeComponent(pair.Key);
this.addComponent(pair.Key, component);
}
this.InitNetFields();
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
{
Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
}
}
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{

View File

@ -92,7 +92,32 @@ namespace Revitalize.Framework.Objects.Furniture
}
public override void recreate()
{
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
{
guids.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
this.childrenGuids.Remove(pair.Key);
StorageFurnitureTile component = Revitalize.ModCore.Serializer.DeserializeGUID<StorageFurnitureTile>(pair.Value.ToString());
component.InitNetFields();
this.removeComponent(pair.Key);
this.addComponent(pair.Key, component);
}
this.InitNetFields();
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
{
Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
}
}
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{
return base.canBePlacedHere(l, tile);

View File

@ -93,6 +93,32 @@ namespace Revitalize.Framework.Objects.Furniture
}
public override void recreate()
{
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
{
guids.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
this.childrenGuids.Remove(pair.Key);
TableTileComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<TableTileComponent>(pair.Value.ToString());
component.InitNetFields();
this.removeComponent(pair.Key);
this.addComponent(pair.Key, component);
}
this.InitNetFields();
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
{
Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
}
}
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{

View File

@ -290,10 +290,9 @@ namespace Revitalize.Framework.Objects
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
obj.childrenGuids.Remove(pair.Key);
//Revitalize.ModCore.log("DESERIALIZE: " + pair.Value.ToString());
MultiTiledComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>(pair.Value.ToString());
component.InitNetFields();
obj.removeComponent(pair.Key);
obj.addComponent(pair.Key, component);
@ -313,14 +312,40 @@ namespace Revitalize.Framework.Objects
}
/// <summary>
/// Recreate the data from data already stored on the object.
/// </summary>
public virtual void recreate()
{
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
{
guids.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
this.childrenGuids.Remove(pair.Key);
MultiTiledComponent component = Revitalize.ModCore.Serializer.DeserializeGUID<MultiTiledComponent>(pair.Value.ToString());
component.InitNetFields();
this.removeComponent(pair.Key);
this.addComponent(pair.Key, component);
}
this.InitNetFields();
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
{
Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
}
}
public override Dictionary<string, string> getAdditionalSaveData()
{
Dictionary<string, string> saveData = base.getAdditionalSaveData();
Revitalize.ModCore.log("Serialize: " + this.guid.ToString());
saveData.Add("GUID", this.guid.ToString());
Revitalize.ModCore.Serializer.SerializeGUID(this.guid.ToString(), this);
return saveData;
}

View File

@ -104,6 +104,33 @@ namespace Revitalize.Framework.Objects.Resources.OreVeins
}
public override void recreate()
{
Dictionary<Vector2, Guid> guids = new Dictionary<Vector2, Guid>();
foreach (KeyValuePair<Vector2, Guid> pair in this.childrenGuids)
{
guids.Add(pair.Key, pair.Value);
}
foreach (KeyValuePair<Vector2, Guid> pair in guids)
{
this.childrenGuids.Remove(pair.Key);
OreVeinTile component = Revitalize.ModCore.Serializer.DeserializeGUID<OreVeinTile>(pair.Value.ToString());
component.InitNetFields();
this.removeComponent(pair.Key);
this.addComponent(pair.Key, component);
}
this.InitNetFields();
if (!Revitalize.ModCore.ObjectGroups.ContainsKey(this.guid.ToString()))
{
Revitalize.ModCore.ObjectGroups.Add(this.guid.ToString(), this);
}
}
public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{

View File

@ -396,6 +396,59 @@ namespace Revitalize
}
}
foreach(GameLocation loc in Game1.locations)
{
foreach(StardewValley.Object c in loc.Objects.Values)
{
if (c is Chest)
{
List<Item> toRemove=new List<Item>();
List<Item> toAdd=new List<Item>();
foreach (Item o in (c as Chest).items)
{
if (o is Chest && o.Name != "Chest")
{
ModCore.log("Found a custom object in a chest!");
string jsonString = o.Name;
string guidName = jsonString.Split(new string[] { "GUID=" },StringSplitOptions.None)[1];
ModCore.log(jsonString);
string type = jsonString.Split('|')[2];
Item I=(Item)Serializer.DeserializeGUID(guidName, Type.GetType(type));
if(I is MultiTiledObject)
{
(I as MultiTiledObject).recreate();
}
toAdd.Add(I);
toRemove.Add(o);
//Item i = Serializer.DeserializeFromJSONString<Item>(jsonString);
//ModCore.log("Deserialized item is: "+i.Name);
}
}
foreach(Item i in toRemove)
{
(c as Chest).items.Remove(i);
}
foreach(Item I in toAdd)
{
(c as Chest).items.Add(I);
}
}
else if(c is StorageFurnitureTile)
{
foreach (Item o in (c as StorageFurnitureTile).info.inventory.items)
{
if (o is Chest&& o.Name != "Chest")
{
ModCore.log("Found a custom object in a chest!");
}
}
}
}
}
// Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.BigTiledTest"));
Game1.player.addItemToInventory(ObjectManager.getChair("Omegasis.Revitalize.Furniture.Chairs.OakChair"));
//Game1.player.addItemToInventory(GetObjectFromPool("Omegasis.Revitalize.Furniture.Rugs.RugTest"));