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:
commit
dca7f59dbc
@ -9,9 +9,14 @@ 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.getObject("equippedTechs")) {
|
||||||
}, mem_fn(&Json::toString));
|
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 {
|
Json PlayerTech::toJson() const {
|
||||||
|
Loading…
Reference in New Issue
Block a user