2
0

CBonusTypeHandler.h 1.8 KB

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