| 137 | } |
| 138 | |
| 139 | BiomePtr BiomeDatabase::createBiome(String const& biomeName, uint64_t seed, float verticalMidPoint, float threatLevel) const { |
| 140 | if (!m_biomes.contains(biomeName)) |
| 141 | throw BiomeException(strf("No such biome '{}'", biomeName)); |
| 142 | |
| 143 | auto& root = Root::singleton(); |
| 144 | auto materialDatabase = root.materialDatabase(); |
| 145 | |
| 146 | try { |
| 147 | RandomSource random(seed); |
| 148 | auto config = m_biomes.get(biomeName); |
| 149 | |
| 150 | auto biome = make_shared<Biome>(); |
| 151 | float mainHueShift = biomeHueShift(biomeName, seed); |
| 152 | |
| 153 | biome->baseName = biomeName; |
| 154 | biome->description = config.parameters.getString("description", ""); |
| 155 | |
| 156 | if (config.parameters.contains("mainBlock")) |
| 157 | biome->mainBlock = materialDatabase->materialId(config.parameters.getString("mainBlock")); |
| 158 | |
| 159 | for (Json v : config.parameters.getArray("subBlocks", {})) |
| 160 | biome->subBlocks.append(materialDatabase->materialId(v.toString())); |
| 161 | |
| 162 | biome->ores = readOres(config.parameters.get("ores", {}), threatLevel); |
| 163 | |
| 164 | biome->surfacePlaceables = readBiomePlaceables(config.parameters.getObject("surfacePlaceables", {}), random.randu64(), mainHueShift); |
| 165 | biome->undergroundPlaceables = readBiomePlaceables(config.parameters.getObject("undergroundPlaceables", {}), random.randu64(), mainHueShift); |
| 166 | |
| 167 | biome->hueShift = mainHueShift; |
| 168 | biome->materialHueShift = materialHueFromDegrees(biome->hueShift); |
| 169 | |
| 170 | if (config.parameters.contains("parallax")) { |
| 171 | auto parallaxFile = AssetPath::relativeTo(config.path, config.parameters.getString("parallax")); |
| 172 | biome->parallax = make_shared<Parallax>(parallaxFile, seed, verticalMidPoint, mainHueShift, biome->surfacePlaceables.firstTreeType()); |
| 173 | } |
| 174 | |
| 175 | if (config.parameters.contains("musicTrack")) |
| 176 | biome->musicTrack = make_shared<AmbientNoisesDescription>(config.parameters.getObject("musicTrack"), config.path); |
| 177 | |
| 178 | if (config.parameters.contains("ambientNoises")) |
| 179 | biome->ambientNoises = make_shared<AmbientNoisesDescription>(config.parameters.getObject("ambientNoises"), config.path); |
| 180 | |
| 181 | if (config.parameters.contains("spawnProfile")) |
| 182 | biome->spawnProfile = constructSpawnProfile(config.parameters.getObject("spawnProfile"), seed); |
| 183 | |
| 184 | return biome; |
| 185 | } catch (std::exception const& cause) { |
| 186 | throw BiomeException(strf("Failed to parse biome: '{}'", biomeName), cause); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | float BiomeDatabase::pickHueShiftFromJson(Json source, uint64_t seed, String const& key) { |
| 191 | if (source.isNull()) |
no test coverage detected