ItemModifier.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #pragma once
  2. #include <ReferenceCounter.h>
  3. #include <Text.h>
  4. #include "Item.h"
  5. class ItemModifier : public virtual Framework::ReferenceCounter
  6. {
  7. public:
  8. ItemModifier();
  9. virtual void applyOn(Item* zItem) = 0;
  10. };
  11. class ConsumeItemModifier : public ItemModifier
  12. {
  13. public:
  14. ConsumeItemModifier();
  15. void applyOn(Item* zItem) override;
  16. };
  17. class ConsumeItemModifierFactory
  18. : public SubTypeFactory<ItemModifier, ConsumeItemModifier>
  19. {
  20. public:
  21. ConsumeItemModifierFactory();
  22. ConsumeItemModifier* fromJson(
  23. Framework::JSON::JSONObject* zJson) const override;
  24. Framework::JSON::JSONObject* toJsonObject(
  25. ConsumeItemModifier* zObject) const override;
  26. JSONObjectValidationBuilder* addToValidator(
  27. JSONObjectValidationBuilder* builder) const override;
  28. const char* getTypeToken() const override;
  29. };
  30. class DoNothingModifier : public ItemModifier
  31. {
  32. public:
  33. DoNothingModifier();
  34. void applyOn(Item* zItem) override;
  35. };
  36. class DoNothingModifierFactory
  37. : public SubTypeFactory<ItemModifier, DoNothingModifier>
  38. {
  39. public:
  40. DoNothingModifierFactory();
  41. DoNothingModifier* fromJson(
  42. Framework::JSON::JSONObject* zJson) const override;
  43. Framework::JSON::JSONObject* toJsonObject(
  44. DoNothingModifier* zObject) const override;
  45. JSONObjectValidationBuilder* addToValidator(
  46. JSONObjectValidationBuilder* builder) const override;
  47. const char* getTypeToken() const override;
  48. };
  49. class AttributeItemModifier : public ItemModifier
  50. {
  51. private:
  52. Framework::RCArray<Framework::Text> attributes;
  53. Framework::RCArray<Framework::JSON::JSONValue> values;
  54. public:
  55. AttributeItemModifier();
  56. void applyOn(Item* zItem) override;
  57. void addAttribute(Framework::Text name, Framework::JSON::JSONValue* value);
  58. const Framework::RCArray<Framework::Text>& getAttributes() const;
  59. const Framework::RCArray<Framework::JSON::JSONValue>& getValues() const;
  60. };
  61. class AttributeItemModifierFactory
  62. : public SubTypeFactory<ItemModifier, AttributeItemModifier>
  63. {
  64. public:
  65. AttributeItemModifierFactory();
  66. AttributeItemModifier* fromJson(
  67. Framework::JSON::JSONObject* zJson) const override;
  68. Framework::JSON::JSONObject* toJsonObject(
  69. AttributeItemModifier* zObject) const override;
  70. JSONObjectValidationBuilder* addToValidator(
  71. JSONObjectValidationBuilder* builder) const override;
  72. const char* getTypeToken() const override;
  73. };
  74. class CombinedItemModifier : public ItemModifier
  75. {
  76. Framework::RCArray<ItemModifier> modifiers;
  77. public:
  78. CombinedItemModifier();
  79. void applyOn(Item* zItem) override;
  80. void addModifier(ItemModifier* zModifier);
  81. const Framework::RCArray<ItemModifier>& getModifiers() const;
  82. };
  83. class CombinedItemModifierFactory
  84. : public SubTypeFactory<ItemModifier, CombinedItemModifier>
  85. {
  86. public:
  87. CombinedItemModifierFactory();
  88. CombinedItemModifier* fromJson(
  89. Framework::JSON::JSONObject* zJson) const override;
  90. Framework::JSON::JSONObject* toJsonObject(
  91. CombinedItemModifier* zObject) const override;
  92. JSONObjectValidationBuilder* addToValidator(
  93. JSONObjectValidationBuilder* builder) const override;
  94. const char* getTypeToken() const override;
  95. };