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

introduce toResourceType

This commit is contained in:
Laserlicht
2025-09-15 00:08:18 +02:00
parent acd067e587
commit d808bd6412
34 changed files with 160 additions and 102 deletions

View File

@@ -21,6 +21,8 @@
#include <vcmi/HeroTypeService.h>
#include <vcmi/HeroClass.h>
#include <vcmi/HeroClassService.h>
#include <vcmi/ResourceType.h>
#include <vcmi/ResourceTypeService.h>
#include <vcmi/Services.h>
#include <vcmi/spells/Spell.h>
@@ -399,6 +401,16 @@ const HeroType * HeroTypeID::toEntity(const Services * services) const
return services->heroTypes()->getByIndex(num);
}
const Resource * GameResID::toResource() const
{
return dynamic_cast<const Resource*>(toEntity(LIBRARY));
}
const ResourceType * GameResID::toEntity(const Services * services) const
{
return services->resources()->getByIndex(num);
}
si32 SpellID::decode(const std::string & identifier)
{
if (identifier == "preset")
@@ -629,7 +641,7 @@ si32 GameResID::decode(const std::string & identifier)
std::string GameResID::encode(const si32 index)
{
return LIBRARY->resourceTypeHandler->getById(index)->getJsonKey();
return GameResID(index).toResource()->getJsonKey();
}
si32 BuildingTypeUniqueID::decode(const std::string & identifier)