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) { PlayerTech::PlayerTech(Json const& json) {
m_availableTechs = jsonToStringSet(json.get("availableTechs")); m_availableTechs = jsonToStringSet(json.get("availableTechs"));
m_enabledTechs = jsonToStringSet(json.get("enabledTechs")); m_enabledTechs = jsonToStringSet(json.get("enabledTechs"));
m_equippedTechs = jsonToMapKV<HashMap<TechType, String>>(json.get("equippedTechs"), [](Json t) { auto techDatabase = Root::singleton().techDatabase();
return TechTypeNames.getLeft(t.toString()); for (auto p : json.get("equippedTechs", JsonObject()).iterateObject()) {
}, mem_fn(&Json::toString)); 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 { Json PlayerTech::toJson() const {