Updated the serializer to allow for Spawner and GiftPackage classes.

This commit is contained in:
Joshua Navarro 2017-01-01 15:27:06 -08:00
parent e2fe241d33
commit 57b70e53fe
2 changed files with 196 additions and 1 deletions

View File

@ -40,7 +40,8 @@ namespace Revitalize.Resources
acceptedTypes.Add("Revitalize.Objects.Light", new SerializerDataNode(new ser(Serialize.serializeLight), new par(Serialize.parseLight))); acceptedTypes.Add("Revitalize.Objects.Light", new SerializerDataNode(new ser(Serialize.serializeLight), new par(Serialize.parseLight)));
acceptedTypes.Add("Revitalize.Objects.shopObject", new SerializerDataNode(new ser(Serialize.serializeShopObject), new par(Serialize.parseShopObject))); acceptedTypes.Add("Revitalize.Objects.shopObject", new SerializerDataNode(new ser(Serialize.serializeShopObject), new par(Serialize.parseShopObject)));
acceptedTypes.Add("Revitalize.Objects.Machines.Quarry", new SerializerDataNode(new ser(Serialize.serializeQuarry), new par(Serialize.parseQuarry))); acceptedTypes.Add("Revitalize.Objects.Machines.Quarry", new SerializerDataNode(new ser(Serialize.serializeQuarry), new par(Serialize.parseQuarry)));
acceptedTypes.Add("Revitalize.Objects.Machines.Spawner", new SerializerDataNode(new ser(Serialize.serializeSpawner), new par(Serialize.parseSpawner)));
acceptedTypes.Add("Revitalize.Objects.GiftPackage", new SerializerDataNode(new ser(Serialize.serializeGiftPackage), new par(Serialize.parseGiftPackage)));
} }

View File

@ -198,6 +198,200 @@ namespace Revitalize
Serialize.WriteToJsonFile(Path.Combine(CleanUp.InvPath, d.Name + ".json"), (Decoration)d); Serialize.WriteToJsonFile(Path.Combine(CleanUp.InvPath, d.Name + ".json"), (Decoration)d);
} }
public static Spawner parseSpawner(string data)
{
dynamic obj = JObject.Parse(data);
// Log.AsyncC(obj.thisType);
Spawner d = new Spawner(false);
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 = Util.parseRectFromJson(s1);
string s2 = Convert.ToString(obj.defaultSourceRect);
d.defaultSourceRect = Util.parseRectFromJson(s2);
string s3 = Convert.ToString(obj.defaultBoundingBox);
d.defaultBoundingBox = Util.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 = Util.parseRectFromJson(s4);
d.scale = obj.scale;
d.lightSource = obj.lightSource;
d.shakeTimer = obj.shakeTimer;
d.internalSound = obj.internalSound;
d.specialVariable = obj.specialVariable;
d.category = obj.category;
d.specialItem = obj.specialItem;
d.hasBeenInInventory = obj.hasBeenInInventory;
string t = obj.texturePath;
d.TextureSheet = Game1.content.Load<Texture2D>(t);
d.texturePath = t;
JArray array = obj.inventory;
d.inventory = array.ToObject<List<Item>>();
d.inventoryMaxSize = obj.inventoryMaxSize;
d.itemReadyForHarvest = obj.itemReadyForHarvest;
d.lightsOn = obj.lightsOn;
d.thisLocation = obj.thisLocation;
d.lightColor = obj.lightColor;
d.thisType = obj.thisType;
d.removable = obj.removable;
try
{
return d;
}
catch (Exception e)
{
Log.AsyncM(e);
return null;
}
}
public static void serializeSpawner(Item d)
{
Serialize.WriteToJsonFile(Path.Combine(CleanUp.InvPath, d.Name + ".json"), (Spawner)d);
}
public static GiftPackage parseGiftPackage(string data)
{
dynamic obj = JObject.Parse(data);
// Log.AsyncC(obj.thisType);
GiftPackage d = new GiftPackage(false);
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 = Util.parseRectFromJson(s1);
string s2 = Convert.ToString(obj.defaultSourceRect);
d.defaultSourceRect = Util.parseRectFromJson(s2);
string s3 = Convert.ToString(obj.defaultBoundingBox);
d.defaultBoundingBox = Util.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 = Util.parseRectFromJson(s4);
d.scale = obj.scale;
d.lightSource = obj.lightSource;
d.shakeTimer = obj.shakeTimer;
d.internalSound = obj.internalSound;
d.specialVariable = obj.specialVariable;
d.category = obj.category;
d.specialItem = obj.specialItem;
d.hasBeenInInventory = obj.hasBeenInInventory;
string t = obj.texturePath;
d.TextureSheet = Game1.content.Load<Texture2D>(t);
d.texturePath = t;
JArray array = obj.inventory;
d.inventory = array.ToObject<List<Item>>();
d.inventoryMaxSize = obj.inventoryMaxSize;
d.itemReadyForHarvest = obj.itemReadyForHarvest;
d.lightsOn = obj.lightsOn;
d.thisLocation = obj.thisLocation;
d.lightColor = obj.lightColor;
d.thisType = obj.thisType;
d.removable = obj.removable;
try
{
return d;
}
catch (Exception e)
{
Log.AsyncM(e);
return null;
}
}
public static void serializeGiftPackage(Item d)
{
Serialize.WriteToJsonFile(Path.Combine(CleanUp.InvPath, d.Name + ".json"), (GiftPackage)d);
}
public static Light parseLight(string data) public static Light parseLight(string data)
{ {