ResourceTypeHandler.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 "../constants/EntityIdentifiers.h"
  14. #include "../IHandlerBase.h"
  15. #include "../filesystem/ResourcePath.h"
  16. VCMI_LIB_NAMESPACE_BEGIN
  17. class ResourceTypeHandler;
  18. namespace resources
  19. {
  20. class DLL_LINKAGE ResourceType : public EntityT<GameResID>
  21. {
  22. friend class VCMI_LIB_WRAP_NAMESPACE(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
  32. {
  33. return price;
  34. }
  35. std::string getJsonKey() const override { return identifier; }
  36. int32_t getIndex() const override { return id.getNum(); }
  37. GameResID getId() const override { return id;}
  38. int32_t getIconIndex() const override { return 0; }
  39. std::string getModScope() const override { return modScope; };
  40. void registerIcons(const IconRegistar & cb) const override;
  41. std::string getNameTextID() const override;
  42. std::string getNameTranslated() const override;
  43. };
  44. }
  45. class DLL_LINKAGE ResourceTypeHandler : public IHandlerBase
  46. {
  47. std::shared_ptr<resources::ResourceType> loadObjectImpl(std::string scope, std::string name, const JsonNode & data, size_t index);
  48. public:
  49. std::vector<JsonNode> loadLegacyData() override;
  50. /// loads single object into game. Scope is namespace of this object, same as name of source mod
  51. void loadObject(std::string scope, std::string name, const JsonNode & data) override;
  52. void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
  53. std::vector<GameResID> getAllObjects() const;
  54. const resources::ResourceType * getById(GameResID index) const
  55. {
  56. return objects.at(index).get();
  57. }
  58. private:
  59. std::vector<std::shared_ptr<resources::ResourceType>> objects;
  60. };
  61. VCMI_LIB_NAMESPACE_END