ItemModifier.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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* createValue(
  23. Framework::JSON::JSONObject* zJson) const override;
  24. void fromJson(ConsumeItemModifier* zResult,
  25. Framework::JSON::JSONObject* zJson) const override;
  26. void toJson(ConsumeItemModifier* zObject,
  27. Framework::JSON::JSONObject* zResult) const override;
  28. JSONObjectValidationBuilder* addToValidator(
  29. JSONObjectValidationBuilder* builder) const override;
  30. Framework::Text getTypeToken() const override;
  31. };
  32. class DoNothingModifier : public ItemModifier
  33. {
  34. public:
  35. DoNothingModifier();
  36. void applyOn(Item* zItem) override;
  37. };
  38. class DoNothingModifierFactory
  39. : public SubTypeFactory<ItemModifier, DoNothingModifier>
  40. {
  41. public:
  42. DoNothingModifierFactory();
  43. DoNothingModifier* createValue(
  44. Framework::JSON::JSONObject* zJson) const override;
  45. void fromJson(DoNothingModifier* zResult,
  46. Framework::JSON::JSONObject* zJson) const override;
  47. void toJson(DoNothingModifier* zObject,
  48. Framework::JSON::JSONObject* zResult) const override;
  49. JSONObjectValidationBuilder* addToValidator(
  50. JSONObjectValidationBuilder* builder) const override;
  51. Framework::Text getTypeToken() const override;
  52. };
  53. class AttributeItemModifier : public ItemModifier
  54. {
  55. private:
  56. Framework::RCArray<Framework::Text> attributes;
  57. Framework::RCArray<Framework::JSON::JSONValue> values;
  58. public:
  59. AttributeItemModifier();
  60. void applyOn(Item* zItem) override;
  61. void addAttribute(Framework::Text name, Framework::JSON::JSONValue* value);
  62. const Framework::RCArray<Framework::Text>& getAttributes() const;
  63. const Framework::RCArray<Framework::JSON::JSONValue>& getValues() const;
  64. };
  65. class AttributeItemModifierFactory
  66. : public SubTypeFactory<ItemModifier, AttributeItemModifier>
  67. {
  68. public:
  69. AttributeItemModifierFactory();
  70. AttributeItemModifier* createValue(
  71. Framework::JSON::JSONObject* zJson) const override;
  72. void fromJson(AttributeItemModifier* zResult,
  73. Framework::JSON::JSONObject* zJson) const override;
  74. void toJson(AttributeItemModifier* zObject,
  75. Framework::JSON::JSONObject* zResult) const override;
  76. JSONObjectValidationBuilder* addToValidator(
  77. JSONObjectValidationBuilder* builder) const override;
  78. Framework::Text getTypeToken() const override;
  79. };
  80. class CombinedItemModifier : public ItemModifier
  81. {
  82. Framework::RCArray<ItemModifier> modifiers;
  83. public:
  84. CombinedItemModifier();
  85. void applyOn(Item* zItem) override;
  86. void addModifier(ItemModifier* zModifier);
  87. const Framework::RCArray<ItemModifier>& getModifiers() const;
  88. };
  89. class CombinedItemModifierFactory
  90. : public SubTypeFactory<ItemModifier, CombinedItemModifier>
  91. {
  92. public:
  93. CombinedItemModifierFactory();
  94. CombinedItemModifier* createValue(
  95. Framework::JSON::JSONObject* zJson) const override;
  96. void fromJson(CombinedItemModifier* zResult,
  97. Framework::JSON::JSONObject* zJson) const override;
  98. void toJson(CombinedItemModifier* zObject,
  99. Framework::JSON::JSONObject* zResult) const override;
  100. JSONObjectValidationBuilder* addToValidator(
  101. JSONObjectValidationBuilder* builder) const override;
  102. Framework::Text getTypeToken() const override;
  103. };