ResourceTypeHandler.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * ResourceTypeHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include <vcmi/EntityService.h>
  12. #include <vcmi/Entity.h>
  13. #include <vcmi/ResourceType.h>
  14. #include <vcmi/ResourceTypeService.h>
  15. #include "../constants/EntityIdentifiers.h"
  16. #include "../IHandlerBase.h"
  17. #include "../filesystem/ResourcePath.h"
  18. VCMI_LIB_NAMESPACE_BEGIN
  19. class ResourceTypeHandler;
  20. class DLL_LINKAGE Resource : public ResourceType
  21. {
  22. friend class ResourceTypeHandler;
  23. GameResID id; //backlink
  24. int price;
  25. std::string iconSmall;
  26. std::string iconMedium;
  27. std::string iconLarge;
  28. std::string identifier;
  29. std::string modScope;
  30. public:
  31. int getPrice() const override { return price; }
  32. std::string getJsonKey() const override { return identifier; }
  33. int32_t getIndex() const override { return id.getNum(); }
  34. GameResID getId() const override { return id;}
  35. int32_t getIconIndex() const override { return id.getNum(); }
  36. std::string getModScope() const override { return modScope; };
  37. void registerIcons(const IconRegistar & cb) const override;
  38. std::string getNameTextID() const override;
  39. std::string getNameTranslated() const override;
  40. };
  41. class DLL_LINKAGE ResourceTypeHandler : public CHandlerBase<GameResID, ResourceType, Resource, ResourceTypeService>
  42. {
  43. public:
  44. std::shared_ptr<Resource> loadFromJson(const std::string & scope,
  45. const JsonNode & json,
  46. const std::string & identifier,
  47. size_t index) override;
  48. const std::vector<std::string> & getTypeNames() const override;
  49. std::vector<JsonNode> loadLegacyData() override;
  50. std::vector<GameResID> getAllObjects() const;
  51. };
  52. VCMI_LIB_NAMESPACE_END