public static Creature fromJSONObject(JSONObject json) { int creatureId = (int)json.GetField("creatureId").n; string creatureName = json.GetField("creatureName").str; CreatureStats baseStats = CreatureStats.fromJSONObject(json.GetField("baseStats")); //TODO deserialize Abilities Ability ability = null; HashSet <Move> moves = new HashSet <Move>(); foreach (JSONObject moveName in json.GetField("moves").list) { string n = moveName.str; moves.Add(MoveLibrary.get(n)); } FocalPoints focalPoints = FocalPoints.fromJSONObject(json.GetField("focalPoints")); CreatureForm baseForm = CreatureForm.fromJSONObject(json.GetField("baseForm")); List <CreatureForm> availableForms = new List <CreatureForm>(); foreach (JSONObject formJSON in json.GetField("availableForms").list) { CreatureForm creatureForm = CreatureForm.fromJSONObject(formJSON); availableForms.Add(CreatureForm.fromJSONObject(formJSON)); } Creature result = new Creature(creatureId, creatureName, moves, focalPoints, ability, baseStats, baseForm, availableForms); return(result); }
public void testCreatureStatsDeserialization() { string statsString = "[10, 2, 5, 6.0]"; CreatureStats expected = new CreatureStats(10, 2, 5, 6); CreatureStats actual = CreatureStats.fromJSONObject(JSONObject.Create(statsString)); Assert.That(expected.Equals(actual)); }