ResourceTypeHandler.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 identifier;
  26. std::string modScope;
  27. public:
  28. int getPrice() const
  29. {
  30. return price;
  31. }
  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 0; }
  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. }
  42. class DLL_LINKAGE ResourceTypeHandler : public IHandlerBase
  43. {
  44. std::shared_ptr<resources::ResourceType> loadObjectImpl(std::string scope, std::string name, const JsonNode & data, size_t index);
  45. public:
  46. std::vector<JsonNode> loadLegacyData() override;
  47. /// loads single object into game. Scope is namespace of this object, same as name of source mod
  48. void loadObject(std::string scope, std::string name, const JsonNode & data) override;
  49. void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
  50. std::vector<GameResID> getAllObjects() const;
  51. const resources::ResourceType * getById(GameResID index) const
  52. {
  53. return objects.at(index).get();
  54. }
  55. private:
  56. std::vector<std::shared_ptr<resources::ResourceType>> objects;
  57. };
  58. VCMI_LIB_NAMESPACE_END