CBonusTypeHandler.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * CBonusTypeHandler.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 "IBonusTypeHandler.h"
  12. #include "IHandlerBase.h"
  13. #include "bonuses/Bonus.h"
  14. VCMI_LIB_NAMESPACE_BEGIN
  15. class JsonNode;
  16. class DLL_LINKAGE CBonusType
  17. {
  18. public:
  19. CBonusType();
  20. std::string getNameTextID() const;
  21. std::string getDescriptionTextID() const;
  22. template <typename Handler> void serialize(Handler & h)
  23. {
  24. h & icon;
  25. h & identifier;
  26. h & hidden;
  27. }
  28. private:
  29. friend class CBonusTypeHandler;
  30. std::string icon;
  31. std::string identifier;
  32. bool hidden;
  33. };
  34. class DLL_LINKAGE CBonusTypeHandler : public IBonusTypeHandler
  35. {
  36. public:
  37. CBonusTypeHandler();
  38. virtual ~CBonusTypeHandler();
  39. std::string bonusToString(const std::shared_ptr<Bonus> & bonus, const IBonusBearer * bearer, bool description) const override;
  40. ImagePath bonusToGraphics(const std::shared_ptr<Bonus> & bonus) const override;
  41. template <typename Handler> void serialize(Handler & h)
  42. {
  43. //for now always use up to date configuration
  44. //once modded bonus type will be implemented, serialize only them
  45. std::vector<CBonusType> ignore;
  46. h & ignore;
  47. }
  48. private:
  49. void load();
  50. void load(const JsonNode & config);
  51. void loadItem(const JsonNode & source, CBonusType & dest, const std::string & name) const;
  52. std::vector<CBonusType> bonusTypes; //index = BonusType
  53. };
  54. VCMI_LIB_NAMESPACE_END
  55. #ifndef INSTANTIATE_CBonusTypeHandler_HERE
  56. extern template class std::vector<VCMI_LIB_WRAP_NAMESPACE(CBonusType)>;
  57. #endif