From 12c4f8d18c66534c32322cfd15c89d60af0a6db5 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 4 Sep 2023 22:21:57 +0300 Subject: [PATCH] Fixed serialization of PlayerColor in json --- client/gui/InterfaceObjectConfigurable.cpp | 2 +- lib/mapObjects/CGObjectInstance.cpp | 7 +------ lib/mapObjects/CQuest.cpp | 2 +- lib/modding/IdentifierStorage.cpp | 9 +++++---- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/client/gui/InterfaceObjectConfigurable.cpp b/client/gui/InterfaceObjectConfigurable.cpp index dc97aba1a..a42ec6c07 100644 --- a/client/gui/InterfaceObjectConfigurable.cpp +++ b/client/gui/InterfaceObjectConfigurable.cpp @@ -238,7 +238,7 @@ PlayerColor InterfaceObjectConfigurable::readPlayerColor(const JsonNode & config { logGlobal->debug("Reading PlayerColor"); if(!config.isNull() && config.isString()) - return PlayerColor(vstd::find_pos(GameConstants::PLAYER_COLOR_NAMES, config.String())); + return PlayerColor::decode(config.String()); logGlobal->debug("Unknown PlayerColor attribute"); return PlayerColor::CANNOT_DETERMINE; diff --git a/lib/mapObjects/CGObjectInstance.cpp b/lib/mapObjects/CGObjectInstance.cpp index 4b081c4e5..50e52f7b0 100644 --- a/lib/mapObjects/CGObjectInstance.cpp +++ b/lib/mapObjects/CGObjectInstance.cpp @@ -341,12 +341,7 @@ void CGObjectInstance::serializeJsonOptions(JsonSerializeFormat & handler) void CGObjectInstance::serializeJsonOwner(JsonSerializeFormat & handler) { - ui8 temp = tempOwner.getNum(); - - handler.serializeEnum("owner", temp, PlayerColor::NEUTRAL.getNum(), GameConstants::PLAYER_COLOR_NAMES); - - if(!handler.saving) - tempOwner = PlayerColor(temp); + handler.serializeId("owner", tempOwner, PlayerColor::NEUTRAL); } BattleField CGObjectInstance::getBattlefield() const diff --git a/lib/mapObjects/CQuest.cpp b/lib/mapObjects/CQuest.cpp index 9e73793ca..22cfe4df6 100644 --- a/lib/mapObjects/CQuest.cpp +++ b/lib/mapObjects/CQuest.cpp @@ -534,7 +534,7 @@ void CQuest::serializeJson(JsonSerializeFormat & handler, const std::string & fi handler.serializeId("hero", m13489val, 0); break; case MISSION_PLAYER: - handler.serializeEnum("player", m13489val, PlayerColor::CANNOT_DETERMINE.getNum(), GameConstants::PLAYER_COLOR_NAMES); + handler.serializeId("player", m13489val, PlayerColor::NEUTRAL); break; default: logGlobal->error("Invalid quest mission type"); diff --git a/lib/modding/IdentifierStorage.cpp b/lib/modding/IdentifierStorage.cpp index b35ecba59..0cf1b9f22 100644 --- a/lib/modding/IdentifierStorage.cpp +++ b/lib/modding/IdentifierStorage.cpp @@ -31,9 +31,11 @@ CIdentifierStorage::CIdentifierStorage() registerObject(ModScope::scopeBuiltin(), "spellSchool", "any", SpellSchool(ESpellSchool::ANY)); for (int i = 0; i < GameConstants::RESOURCE_QUANTITY; ++i) - { registerObject(ModScope::scopeBuiltin(), "resource", GameConstants::RESOURCE_NAMES[i], i); - } + + for (int i = 0; i < std::size(GameConstants::PLAYER_COLOR_NAMES); ++i) + registerObject(ModScope::scopeBuiltin(), "playerColor", GameConstants::PLAYER_COLOR_NAMES[i], i); + for(int i=0; i CIdentifierStorage::getIdentifier(const std::string & scope, const std::string & type, const std::string & name, bool silent) const { - //TODO: RE-ENABLE - //assert(state != ELoadingState::LOADING); + assert(state != ELoadingState::LOADING); auto idList = getPossibleIdentifiers(ObjectCallback::fromNameAndType(scope, type, name, std::function(), silent));