ItemFilter.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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* fromJson(
  42. Framework::JSON::JSONObject* zJson) const override;
  43. Framework::JSON::JSONObject* toJsonObject(
  44. CombinedItemFilter* zObject) const override;
  45. JSONObjectValidationBuilder* addToValidator(
  46. JSONObjectValidationBuilder* builder) const override;
  47. const char* getTypeToken() const override;
  48. };
  49. class AnyItemFilter : public ItemFilter
  50. {
  51. public:
  52. AnyItemFilter();
  53. bool matchItem(const Item* zItem) const override;
  54. Framework::Text getLogicUIML() const override;
  55. };
  56. class AnyItemFilterFactory : public SubTypeFactory<ItemFilter, AnyItemFilter>
  57. {
  58. public:
  59. AnyItemFilterFactory();
  60. AnyItemFilter* fromJson(Framework::JSON::JSONObject* zJson) const override;
  61. Framework::JSON::JSONObject* toJsonObject(
  62. AnyItemFilter* zObject) const override;
  63. JSONObjectValidationBuilder* addToValidator(
  64. JSONObjectValidationBuilder* builder) const override;
  65. const char* getTypeToken() const override;
  66. };
  67. class TypeItemFilter : public ItemFilter
  68. {
  69. private:
  70. const ItemType* type;
  71. public:
  72. TypeItemFilter();
  73. bool matchItem(const Item* zItem) const override;
  74. Framework::Text getLogicUIML() const override;
  75. void setType(const ItemType* type);
  76. const ItemType* zType() const;
  77. };
  78. class TypeItemFilterFactory : public SubTypeFactory<ItemFilter, TypeItemFilter>
  79. {
  80. public:
  81. TypeItemFilterFactory();
  82. TypeItemFilter* fromJson(Framework::JSON::JSONObject* zJson) const override;
  83. Framework::JSON::JSONObject* toJsonObject(
  84. TypeItemFilter* zObject) const override;
  85. JSONObjectValidationBuilder* addToValidator(
  86. JSONObjectValidationBuilder* builder) const override;
  87. const char* getTypeToken() const override;
  88. };
  89. class SpecificSlotFilter : public ItemFilter
  90. {
  91. private:
  92. int sourceSlotId;
  93. int targetSlotId;
  94. public:
  95. SpecificSlotFilter(int sourceSlotId, int targetSlotId);
  96. bool matchSourceSlot(ItemSlot* zSlot) const override;
  97. bool matchTargetSlot(ItemSlot* zSlot) const override;
  98. Framework::Text getLogicUIML() const override;
  99. };
  100. class SourceSlotBlacklistFilter : public ItemFilter
  101. {
  102. private:
  103. Framework::Array<int> blackList;
  104. public:
  105. SourceSlotBlacklistFilter();
  106. void addBlackListSlotId(int id);
  107. bool matchSourceSlot(ItemSlot* zSlot) const override;
  108. bool matchTargetSlot(ItemSlot* zSlot) const override;
  109. Framework::Text getLogicUIML() const override;
  110. };
  111. class TargetSlotBlacklistFilter : public ItemFilter
  112. {
  113. private:
  114. Framework::Array<int> blackList;
  115. public:
  116. TargetSlotBlacklistFilter();
  117. void addBlackListSlotId(int id);
  118. bool matchSourceSlot(ItemSlot* zSlot) const override;
  119. bool matchTargetSlot(ItemSlot* zSlot) const override;
  120. Framework::Text getLogicUIML() const override;
  121. };
  122. class GroupItemFilter : public ItemFilter
  123. {
  124. private:
  125. Framework::RCArray<Framework::Text> groups;
  126. public:
  127. GroupItemFilter();
  128. bool matchItem(const Item* zItem) const override;
  129. Framework::Text getLogicUIML() const override;
  130. void addGroup(const Framework::Text group);
  131. const Framework::RCArray<Framework::Text>& getGroups() const;
  132. };
  133. class GroupItemFilterFactory
  134. : public SubTypeFactory<ItemFilter, GroupItemFilter>
  135. {
  136. public:
  137. GroupItemFilterFactory();
  138. GroupItemFilter* fromJson(
  139. Framework::JSON::JSONObject* zJson) const override;
  140. Framework::JSON::JSONObject* toJsonObject(
  141. GroupItemFilter* zObject) const override;
  142. JSONObjectValidationBuilder* addToValidator(
  143. JSONObjectValidationBuilder* builder) const override;
  144. const char* getTypeToken() const override;
  145. };