ItemFilter.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #pragma once
  2. #include <Array.h>
  3. #include <functional>
  4. #include <ReferenceCounter.h>
  5. #include <TypeRegistry.h>
  6. class Item;
  7. class ItemType;
  8. class ItemSlot;
  9. class ItemFilter : public virtual Framework::ReferenceCounter
  10. {
  11. public:
  12. ItemFilter();
  13. virtual bool matchItem(const Item* zItem) const;
  14. virtual bool matchSourceSlot(ItemSlot* zSlot) const;
  15. virtual bool matchTargetSlot(ItemSlot* zSlot) const;
  16. virtual Framework::Text getLogicUIML() const = 0;
  17. };
  18. class CombinedItemFilter : public ItemFilter
  19. {
  20. private:
  21. Framework::RCArray<ItemFilter> filters;
  22. std::function<bool(bool, bool)> op;
  23. public:
  24. CombinedItemFilter();
  25. CombinedItemFilter(Framework::RCArray<ItemFilter> filters,
  26. std::function<bool(bool, bool)> op);
  27. bool matchItem(const Item* zItem) const override;
  28. bool matchSourceSlot(ItemSlot* zSlot) const override;
  29. bool matchTargetSlot(ItemSlot* zSlot) const override;
  30. Framework::Text getLogicUIML() const override;
  31. void addFilter(ItemFilter* filter);
  32. const Framework::RCArray<ItemFilter>& getFilters() const;
  33. void setOp(std::function<bool(bool, bool)> op);
  34. std::function<bool(bool, bool)> getOp() const;
  35. };
  36. class CombinedItemFilterFactory
  37. : public SubTypeFactory<ItemFilter, CombinedItemFilter>
  38. {
  39. public:
  40. CombinedItemFilterFactory();
  41. CombinedItemFilter* createValue(
  42. Framework::JSON::JSONObject* zJson) const override;
  43. void fromJson(CombinedItemFilter* zResult,
  44. Framework::JSON::JSONObject* zJson) const override;
  45. void toJson(CombinedItemFilter* zObject,
  46. Framework::JSON::JSONObject* zResult) const override;
  47. JSONObjectValidationBuilder* addToValidator(
  48. JSONObjectValidationBuilder* builder) const override;
  49. Framework::Text getTypeToken() const override;
  50. };
  51. class AnyItemFilter : public ItemFilter
  52. {
  53. public:
  54. AnyItemFilter();
  55. bool matchItem(const Item* zItem) const override;
  56. Framework::Text getLogicUIML() const override;
  57. };
  58. class AnyItemFilterFactory : public SubTypeFactory<ItemFilter, AnyItemFilter>
  59. {
  60. public:
  61. AnyItemFilterFactory();
  62. AnyItemFilter* createValue(
  63. Framework::JSON::JSONObject* zJson) const override;
  64. void fromJson(AnyItemFilter* zResult,
  65. Framework::JSON::JSONObject* zJson) const override;
  66. void toJson(AnyItemFilter* zObject,
  67. Framework::JSON::JSONObject* zResult) const override;
  68. JSONObjectValidationBuilder* addToValidator(
  69. JSONObjectValidationBuilder* builder) const override;
  70. Framework::Text getTypeToken() const override;
  71. };
  72. class TypeItemFilter : public ItemFilter
  73. {
  74. private:
  75. const ItemType* type;
  76. public:
  77. TypeItemFilter();
  78. bool matchItem(const Item* zItem) const override;
  79. Framework::Text getLogicUIML() const override;
  80. void setType(const ItemType* type);
  81. const ItemType* zType() const;
  82. };
  83. class TypeItemFilterFactory : public SubTypeFactory<ItemFilter, TypeItemFilter>
  84. {
  85. public:
  86. TypeItemFilterFactory();
  87. TypeItemFilter* createValue(
  88. Framework::JSON::JSONObject* zJson) const override;
  89. void fromJson(TypeItemFilter* zResult,
  90. Framework::JSON::JSONObject* zJson) const override;
  91. void toJson(TypeItemFilter* zObject,
  92. Framework::JSON::JSONObject* zResult) const override;
  93. JSONObjectValidationBuilder* addToValidator(
  94. JSONObjectValidationBuilder* builder) const override;
  95. Framework::Text getTypeToken() const override;
  96. };
  97. class SpecificSlotFilter : public ItemFilter
  98. {
  99. private:
  100. int sourceSlotId;
  101. int targetSlotId;
  102. public:
  103. SpecificSlotFilter(int sourceSlotId, int targetSlotId);
  104. bool matchSourceSlot(ItemSlot* zSlot) const override;
  105. bool matchTargetSlot(ItemSlot* zSlot) const override;
  106. Framework::Text getLogicUIML() const override;
  107. };
  108. class SourceSlotBlacklistFilter : public ItemFilter
  109. {
  110. private:
  111. Framework::Array<int> blackList;
  112. public:
  113. SourceSlotBlacklistFilter();
  114. void addBlackListSlotId(int id);
  115. bool matchSourceSlot(ItemSlot* zSlot) const override;
  116. bool matchTargetSlot(ItemSlot* zSlot) const override;
  117. Framework::Text getLogicUIML() const override;
  118. };
  119. class TargetSlotBlacklistFilter : public ItemFilter
  120. {
  121. private:
  122. Framework::Array<int> blackList;
  123. public:
  124. TargetSlotBlacklistFilter();
  125. void addBlackListSlotId(int id);
  126. bool matchSourceSlot(ItemSlot* zSlot) const override;
  127. bool matchTargetSlot(ItemSlot* zSlot) const override;
  128. Framework::Text getLogicUIML() const override;
  129. };
  130. class GroupItemFilter : public ItemFilter
  131. {
  132. private:
  133. Framework::RCArray<Framework::Text> groups;
  134. public:
  135. GroupItemFilter();
  136. bool matchItem(const Item* zItem) const override;
  137. Framework::Text getLogicUIML() const override;
  138. void addGroup(const Framework::Text group);
  139. const Framework::RCArray<Framework::Text>& getGroups() const;
  140. };
  141. class GroupItemFilterFactory
  142. : public SubTypeFactory<ItemFilter, GroupItemFilter>
  143. {
  144. public:
  145. GroupItemFilterFactory();
  146. GroupItemFilter* createValue(
  147. Framework::JSON::JSONObject* zJson) const override;
  148. void fromJson(GroupItemFilter* zResult,
  149. Framework::JSON::JSONObject* zJson) const override;
  150. void toJson(GroupItemFilter* zObject,
  151. Framework::JSON::JSONObject* zResult) const override;
  152. JSONObjectValidationBuilder* addToValidator(
  153. JSONObjectValidationBuilder* builder) const override;
  154. Framework::Text getTypeToken() const override;
  155. };