Merge pull request #68 from WasabiRaptor/missing-tech-check-on-player-load

Prevent crashes when player has techs that don't exist
This commit is contained in:
Kae 2024-05-29 11:32:43 +10:00 committed by GitHub
commit dca7f59dbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,9 +9,14 @@ 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.getObject("equippedTechs")) {
String techName = p.second.toString();
if (techDatabase->contains(techName))
m_equippedTechs.set(TechTypeNames.getLeft(p.first), techName);
else
Logger::warn("Unequipping unknown tech '{}' from slot '{}'", techName, p.first);
}
}
Json PlayerTech::toJson() const {