error handling for missing techs

This commit is contained in:
WasabiRaptor 2024-05-28 10:44:34 -04:00
parent 74dabf2244
commit 20882990e0

View File

@ -9,9 +9,13 @@ PlayerTech::PlayerTech() {}
PlayerTech::PlayerTech(Json const& json) {
m_availableTechs = jsonToStringSet(json.get("availableTechs"));
m_enabledTechs = jsonToStringSet(json.get("enabledTechs"));
m_equippedTechs = jsonToMapKV<HashMap<TechType, String>>(json.get("equippedTechs"), [](Json t) {
return TechTypeNames.getLeft(t.toString());
}, mem_fn(&Json::toString));
auto techDatabase = Root::singleton().techDatabase();
for (auto p : json.get("equippedTechs", JsonObject()).iterateObject()) {
if (techDatabase->contains(p.second.toString()))
m_equippedTechs.set(TechTypeNames.getLeft(p.first), p.second.toString());
else
Logger::warn("Missing tech '%s' in slot '%s'", p.second.toString(), p.first);
}
}
Json PlayerTech::toJson() const {