public void FromJson(JToken inventoriesToken) { JArray inventoriesJArray = (JArray)inventoriesToken; foreach (JToken inventoryToken in inventoriesJArray) { int x = (int)inventoryToken["X"]; int y = (int)inventoryToken["Y"]; int z = (int)inventoryToken["Z"]; GameInventory inventory = new GameInventory(); inventory.FromJson(inventoryToken); PlaceInventory(World.Current.GetTileAt(x, y, z), inventory); } }
public void FromJson(JToken charactersToken) { if (charactersToken == null) { return; } JArray charactersJArray = (JArray)charactersToken; foreach (JToken characterToken in charactersJArray) { GameCharacter character; int x = (int)characterToken["X"]; int y = (int)characterToken["Y"]; int z = (int)characterToken["Z"]; if (characterToken["Colors"] != null) { JToken colorToken = characterToken["Colors"]; Color color = ColorUtilities.ParseColorFromString((string)colorToken["CharacterColor"][0], (string)colorToken["CharacterColor"][1], (string)colorToken["CharacterColor"][2]); Color colorUni = ColorUtilities.ParseColorFromString((string)colorToken["UniformColor"][0], (string)colorToken["UniformColor"][1], (string)colorToken["UniformColor"][2]); Color colorSkin = ColorUtilities.ParseColorFromString((string)colorToken["SkinColor"][0], (string)colorToken["SkinColor"][1], (string)colorToken["SkinColor"][2]); character = Create(World.Current.GetTileAt(x, y, z), color, colorUni, colorSkin, (string)characterToken["Name"]); } else { character = Create(World.Current.GetTileAt(x, y, z), (string)characterToken["Name"]); } if (characterToken["Inventories"] != null) { foreach (JToken inventoryToken in characterToken["Inventories"]) { GameInventory inventory = new GameInventory(); inventory.FromJson(inventoryToken); World.Current.InventoryManager.PlaceInventory(character, inventory); } } if (characterToken["Stats"] != null) { foreach (string stat in character.Stats.Keys) { if (characterToken["Stats"][stat] != null) { character.Stats[stat].Value = (int)characterToken["Stats"][stat]; } } } if (characterToken["Needs"] != null) { foreach (Need need in character.Needs) { if (characterToken["Needs"][need.Type] != null) { need.Amount = (int)characterToken["Needs"][need.Type]; } } } } }