mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
introduce toResourceType
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -25,6 +25,9 @@ class CHero;
|
||||
class CHeroClass;
|
||||
class HeroClass;
|
||||
class HeroTypeService;
|
||||
class Resource;
|
||||
class ResourceType;
|
||||
class ResourceTypeService;
|
||||
class CFaction;
|
||||
class Faction;
|
||||
class Skill;
|
||||
@@ -1079,6 +1082,9 @@ public:
|
||||
static si32 decode(const std::string & identifier);
|
||||
static std::string encode(const si32 index);
|
||||
static std::string entityType();
|
||||
|
||||
const Resource * toResource() const;
|
||||
const ResourceType * toEntity(const Services * services) const;
|
||||
};
|
||||
|
||||
class DLL_LINKAGE BuildingTypeUniqueID : public Identifier<BuildingTypeUniqueID>
|
||||
|
||||
Reference in New Issue
Block a user