public void testFocusPointDeserialization() { string focusPointString = "{\n\"description\":\"Small boost to speed\",\n\"statMods\":{\n\"SPD\":[5, 1]\n}\n}"; FocusPoint actual = FocusPoint.fromJSONObject(JSONObject.Create(focusPointString)); List <Pair <StatName, StatModifier> > statMods = new List <Pair <StatName, StatModifier> >(); statMods.Add(new Pair <StatName, StatModifier>(StatName.SPD, new StatModifier(5, 1))); FocusPoint expected = new FocusPoint(null, null, statMods, "Small boost to speed"); Assert.That(actual.Equals(expected)); }
public static FocalPoints fromJSONObject(JSONObject json) { if (json.type != JSONObject.Type.ARRAY) { throw new System.Exception("FocalPoints deserialization failed: json is not array"); } if (json.list.Count != 4) { throw new System.Exception("FocalPoints deserialization failed: item count is not 4"); } List <FocusPoint> points = new List <FocusPoint>(); foreach (JSONObject j in json.list) { points.Add(FocusPoint.fromJSONObject(j)); } return(new FocalPoints(points[0], points[1], points[2], points[3])); }