| 60 | } |
| 61 | |
| 62 | TenantPtr TenantDatabase::readTenant(String const& path) { |
| 63 | try { |
| 64 | auto assets = Root::singleton().assets(); |
| 65 | Json config = assets->json(path); |
| 66 | |
| 67 | String name = config.getString("name"); |
| 68 | float priority = config.getFloat("priority"); |
| 69 | |
| 70 | StringMap<unsigned> colonyTagCriteria; |
| 71 | for (pair<String, Json> const& entry : config.getObject("colonyTagCriteria").pairs()) { |
| 72 | colonyTagCriteria[entry.first] = entry.second.toUInt(); |
| 73 | } |
| 74 | |
| 75 | List<TenantSpawnable> tenants = config.getArray("tenants").transformed([](Json const& json) -> TenantSpawnable { |
| 76 | String spawn = json.getString("spawn"); |
| 77 | if (spawn == "monster") { |
| 78 | return TenantMonsterSpawnable{json.getString("type"), json.optFloat("level"), json.opt("overrides")}; |
| 79 | } else { |
| 80 | starAssert(json.getString("spawn") == "npc"); |
| 81 | |
| 82 | Json speciesJson = json.get("species"); |
| 83 | List<String> species; |
| 84 | if (speciesJson.isType(Json::Type::Array)) |
| 85 | species = speciesJson.toArray().transformed(mem_fn(&Json::toString)); |
| 86 | else |
| 87 | species.append(speciesJson.toString()); |
| 88 | |
| 89 | return TenantNpcSpawnable{species, json.getString("type"), json.optFloat("level"), json.opt("overrides")}; |
| 90 | } |
| 91 | }); |
| 92 | |
| 93 | Maybe<TenantRent> rent = config.opt("rent").apply([](Json const& json) { |
| 94 | return TenantRent{jsonToVec2F(json.get("periodRange")), json.getString("pool")}; |
| 95 | }); |
| 96 | |
| 97 | return make_shared<Tenant>(Tenant{name, priority, colonyTagCriteria, tenants, rent, config}); |
| 98 | } catch (std::exception const& e) { |
| 99 | throw TenantException::format("Error loading tenant '{}': {}", path, outputException(e, false)); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | } |
nothing calls this directly
no test coverage detected