1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

MetaIdentifier now uses std::variant internally

This commit is contained in:
Ivan Savenko
2023-10-14 18:13:59 +03:00
parent b394158dc9
commit 80e6485965
61 changed files with 487 additions and 421 deletions

View File

@@ -37,6 +37,8 @@
#include "TerrainHandler.h" //TODO: remove
#include "BattleFieldHandler.h"
#include "ObstacleHandler.h"
#include "CTownHandler.h"
#include "mapObjectConstructors/CObjectClassesHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -134,6 +136,40 @@ std::string HeroClassID::entityType()
return "heroClass";
}
si32 ObjectInstanceID::decode(const std::string & identifier)
{
return std::stoi(identifier);
}
std::string ObjectInstanceID::encode(const si32 index)
{
return std::to_string(index);
}
si32 CampaignScenarioID::decode(const std::string & identifier)
{
return std::stoi(identifier);
}
std::string CampaignScenarioID::encode(const si32 index)
{
return std::to_string(index);
}
std::string Obj::encode(int32_t index)
{
return VLC->objtypeh->getObjectHandlerName(index);
}
si32 Obj::decode(const std::string & identifier)
{
auto rawId = VLC->identifiers()->getIdentifier(ModScope::scopeGame(), "objects", identifier);
if(rawId)
return rawId.value();
else
return -1;
}
si32 HeroTypeID::decode(const std::string & identifier)
{
auto rawId = VLC->identifiers()->getIdentifier(ModScope::scopeMap(), "hero", identifier);
@@ -182,6 +218,20 @@ std::string ArtifactID::entityType()
return "artifact";
}
si32 SecondarySkill::decode(const std::string& identifier)
{
auto rawId = VLC->identifiers()->getIdentifier(ModScope::scopeGame(), "secondarySkill", identifier);
if(rawId)
return rawId.value();
else
return -1;
}
std::string SecondarySkill::encode(const si32 index)
{
return VLC->skills()->getById(SecondarySkill(index))->getJsonKey();
}
const CCreature * CreatureIDBase::toCreature() const
{
return VLC->creh->objects.at(num);
@@ -240,6 +290,20 @@ std::string SpellID::encode(const si32 index)
return VLC->spells()->getByIndex(index)->getJsonKey();
}
si32 BattleField::decode(const std::string & identifier)
{
auto rawId = VLC->identifiers()->getIdentifier(ModScope::scopeGame(), "spell", identifier);
if(rawId)
return rawId.value();
else
return -1;
}
std::string BattleField::encode(const si32 index)
{
return VLC->spells()->getByIndex(index)->getJsonKey();
}
std::string SpellID::entityType()
{
return "spell";
@@ -257,8 +321,6 @@ bool PlayerColor::isSpectator() const
std::string PlayerColor::toString() const
{
if (num == -1)
return "neutral";
return encode(num);
}
@@ -269,6 +331,9 @@ si32 PlayerColor::decode(const std::string & identifier)
std::string PlayerColor::encode(const si32 index)
{
if (index == -1)
return "neutral";
if (index < 0 || index >= std::size(GameConstants::PLAYER_COLOR_NAMES))
{
assert(0);
@@ -373,6 +438,18 @@ std::string GameResID::encode(const si32 index)
return GameConstants::RESOURCE_NAMES[index];
}
si32 BuildingTypeUniqueID::decode(const std::string & identifier)
{
assert(0); //TODO
return -1;
}
std::string BuildingTypeUniqueID::encode(const si32 index)
{
assert(0); // TODO
return "";
}
std::string GameResID::entityType()
{
return "resource";