public Biome(string type_, List<BiomeTile> validTiles_, List<BiomeResource> validResources_, BiomeRequirements requirements_) { type = type_; validTiles = validTiles_; validResources = validResources_; requirements = requirements_; foreach (BiomeResource res in validResources) { foreach (Tile tile in res.Resource.ValidTiles) { List<BiomeResource> resources = null; DictValidResources.TryGetValue(tile.GetName(), out resources); if (resources != null) { resources.Add(res); } else { resources = new List<BiomeResource>(); resources.Add(res); DictValidResources.Add(tile.GetName(), resources); } } } }
public static bool Load(string filePath_) { TextAsset asset = (TextAsset)Resources.Load(filePath_); if (asset == null) { Debug.Log("file '" + filePath_ + "' could not be loaded"); return false; } JSONNode jsonData = JSON.Parse(asset.text); //for every biome in file for (int i = 0; i < jsonData.Count; ++i) { string name = jsonData[i]["Name"]; List<BiomeTile> tempTiles = new List<BiomeTile>(); for (int j = 0; j < jsonData[i]["ValidTiles"].Count; ++j) { Tile tile = Tile.GetTile(jsonData[i]["ValidTiles"][j]["Name"]); float chance = jsonData[i]["ValidTiles"][j]["Chance"].AsFloat; tempTiles.Add(new BiomeTile(tile, chance)); } List<BiomeResource> tempResources = new List<BiomeResource>(); for (int j = 0; j < jsonData[i]["ValidResources"].Count; ++j) { GameResource resource = GameResource.GetResource(jsonData[i]["ValidResources"][j]["Name"]); float chance = jsonData[i]["ValidResources"][j]["Chance"].AsFloat; tempResources.Add(new BiomeResource(resource, chance)); } float hMin = jsonData[i]["Requirements"]["Height"]["Min"].AsFloat; float hMax = jsonData[i]["Requirements"]["Height"]["Max"].AsFloat; float tMin = jsonData[i]["Requirements"]["Temperature"]["Min"].AsFloat; float tMax = jsonData[i]["Requirements"]["Temperature"]["Max"].AsFloat; float rMin = jsonData[i]["Requirements"]["Rainfall"]["Min"].AsFloat; float rMax = jsonData[i]["Requirements"]["Rainfall"]["Max"].AsFloat; BiomeRequirements newRequirements = new BiomeRequirements(hMin, hMax, tMin, tMax, rMin, rMax); Biome biome = new Biome(name, tempTiles, tempResources, newRequirements); Biomes.Add(biome); } Debug.Log(Biomes.Count + " Biomes loaded from '" + filePath_ + "'"); return true; }