1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-12-13 23:57:41 +02:00

Improve serialization of IDs from mods, so they are resolved correctly after all mods are loaded.

This commit is contained in:
Tomasz Zieliński
2023-07-05 20:53:00 +02:00
parent 50bed178ca
commit 9f2bfbc1d8
5 changed files with 53 additions and 38 deletions

View File

@@ -33,6 +33,7 @@
#include "StringConstants.h"
#include "CGeneralTextHandler.h"
#include "CModHandler.h"//todo: remove
#include "TerrainHandler.h" //TODO: remove
#include "BattleFieldHandler.h"
#include "ObstacleHandler.h"
@@ -203,7 +204,7 @@ const FactionID FactionID::NEUTRAL = FactionID(9);
si32 FactionID::decode(const std::string & identifier)
{
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), "faction", identifier);
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), scope(), identifier);
if(rawId)
return rawId.value();
else
@@ -215,6 +216,31 @@ std::string FactionID::encode(const si32 index)
return VLC->factions()->getByIndex(index)->getJsonKey();
}
std::string FactionID::scope()
{
return "faction";
}
si32 TerrainID::decode(const std::string & identifier)
{
auto rawId = VLC->modh->identifiers.getIdentifier(CModHandler::scopeGame(), scope(), identifier);
if(rawId)
return rawId.value();
else
return static_cast<si32>(ETerrainId::NONE);
}
std::string TerrainID::encode(const si32 index)
{
return VLC->terrainTypeHandler->getByIndex(index)->getJsonKey();
}
std::string TerrainID::scope()
{
return "terrain";
}
std::ostream & operator<<(std::ostream & os, const EActionType actionType)
{
static const std::map<EActionType, std::string> actionTypeToString =