| 9 | namespace Star { |
| 10 | |
| 11 | MonsterDatabase::MonsterDatabase() { |
| 12 | auto assets = Root::singleton().assets(); |
| 13 | |
| 14 | auto& monsterTypes = assets->scanExtension("monstertype"); |
| 15 | auto& monsterParts = assets->scanExtension("monsterpart"); |
| 16 | auto& monsterSkills = assets->scanExtension("monsterskill"); |
| 17 | auto& monsterColors = assets->scanExtension("monstercolors"); |
| 18 | |
| 19 | assets->queueJsons(monsterTypes); |
| 20 | assets->queueJsons(monsterParts); |
| 21 | assets->queueJsons(monsterSkills); |
| 22 | assets->queueJsons(monsterColors); |
| 23 | |
| 24 | for (auto const& file : monsterTypes) { |
| 25 | try { |
| 26 | auto config = assets->json(file); |
| 27 | String typeName = config.getString("type"); |
| 28 | |
| 29 | if (m_monsterTypes.contains(typeName)) |
| 30 | throw MonsterException(strf("Repeat monster type name '{}'", typeName)); |
| 31 | |
| 32 | MonsterType& monsterType = m_monsterTypes[typeName]; |
| 33 | |
| 34 | monsterType.typeName = typeName; |
| 35 | monsterType.shortDescription = config.optString("shortdescription"); |
| 36 | monsterType.description = config.optString("description"); |
| 37 | |
| 38 | monsterType.categories = jsonToStringList(config.get("categories")); |
| 39 | monsterType.partTypes = jsonToStringList(config.get("parts")); |
| 40 | |
| 41 | monsterType.animationConfigPath = AssetPath::relativeTo(file, config.getString("animation")); |
| 42 | monsterType.colors = config.getString("colors", "default"); |
| 43 | |
| 44 | monsterType.reversed = config.getBool("reversed", false); |
| 45 | |
| 46 | if (config.contains("dropPools")) |
| 47 | monsterType.dropPools = config.getArray("dropPools"); |
| 48 | |
| 49 | monsterType.baseParameters = config.get("baseParameters", {}); |
| 50 | |
| 51 | // for updated monsters, use the partParameterDescription from the |
| 52 | // .partparams file |
| 53 | if (config.contains("partParameters")) { |
| 54 | Json partParameterSource = assets->json(AssetPath::relativeTo(file, config.getString("partParameters"))); |
| 55 | monsterType.partParameterDescription = partParameterSource.getObject("partParameterDescription"); |
| 56 | monsterType.partParameterOverrides = partParameterSource.getObject("partParameters"); |
| 57 | } else { |
| 58 | // outdated monsters still have partParameterDescription defined |
| 59 | // directly in the |
| 60 | // .monstertype file |
| 61 | monsterType.partParameterDescription = config.getObject("partParameterDescription", {}); |
| 62 | } |
| 63 | |
| 64 | } catch (StarException const& e) { |
| 65 | throw MonsterException(strf("Error loading monster type '{}'", file), e); |
| 66 | } |
| 67 | } |
| 68 |
nothing calls this directly
no test coverage detected