123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- #include "ItemFilter.h"
- #include "Item.h"
- #include "ItemSlot.h"
- #include "ItemType.h"
- ItemFilter::ItemFilter()
- : ReferenceCounter()
- {}
- bool ItemFilter::matchItem(const Item* zItem) const
- {
- return 1;
- }
- bool ItemFilter::matchSourceSlot(ItemSlot* zSlot) const
- {
- return zSlot->zStack() ? matchItem(zSlot->zStack()->zItem()) : 0;
- }
- bool ItemFilter::matchTargetSlot(ItemSlot* zSlot) const
- {
- return 1;
- }
- CombinedItemFilter::CombinedItemFilter(ItemFilter* filterA,
- ItemFilter* filterB,
- std::function<bool(bool, bool)> op)
- : ItemFilter(),
- filterA(filterA),
- filterB(filterB),
- op(op)
- {}
- CombinedItemFilter::~CombinedItemFilter()
- {
- filterA->release();
- filterB->release();
- }
- bool CombinedItemFilter::matchItem(const Item* zItem) const
- {
- return op(filterA->matchItem(zItem), filterB->matchItem(zItem));
- }
- bool CombinedItemFilter::matchSourceSlot(ItemSlot* zSlot) const
- {
- return op(filterA->matchSourceSlot(zSlot), filterB->matchSourceSlot(zSlot));
- }
- bool CombinedItemFilter::matchTargetSlot(ItemSlot* zSlot) const
- {
- return op(filterA->matchTargetSlot(zSlot), filterB->matchTargetSlot(zSlot));
- }
- Framework::Text CombinedItemFilter::getImageUIML() const
- {
- return filterA->getImageUIML() + filterB->getImageUIML();
- }
- Framework::Text CombinedItemFilter::getLogicUIML() const
- {
- Framework::Text result = "<operator result_0_0=\"";
- result += op(0, 0);
- result += "\" result_0_1=\"";
- result += op(0, 1);
- result += "\" result_1_0=\"";
- result += op(1, 0);
- result += "\" result_1_1=\"";
- result += op(1, 1);
- result += ">";
- result += filterA->getLogicUIML();
- result += filterB->getLogicUIML();
- result += "</operator>";
- return result;
- }
- AnyItemFilter::AnyItemFilter()
- : ItemFilter()
- {}
- bool AnyItemFilter::matchItem(const Item* zItem) const
- {
- return true;
- }
- Framework::Text AnyItemFilter::getImageUIML() const
- {
- return "<img str=\"bilder/gui_icons.ltdb/anyItem.png\"/>";
- }
- Framework::Text AnyItemFilter::getLogicUIML() const
- {
- return "<anyItem/>";
- }
- TypeItemFilter::TypeItemFilter(const ItemType* zType)
- : ItemFilter(),
- zType(zType)
- {}
- bool TypeItemFilter::matchItem(const Item* zItem) const
- {
- return zItem->zItemType() == zType;
- }
- Framework::Text TypeItemFilter::getImageUIML() const
- {
- Framework::Text result = "<img itemType=\"";
- result += zType->getId();
- result += "\"/>";
- return result;
- }
- Framework::Text TypeItemFilter::getLogicUIML() const
- {
- Framework::Text result = "<attribute name=\"Type\" operator=\"=\" value=\"";
- result += zType->getName();
- result += "\"/>";
- return result;
- }
- SpecificSlotFilter::SpecificSlotFilter(int sourceSlotId, int targetSlotId)
- : ItemFilter(),
- sourceSlotId(sourceSlotId),
- targetSlotId(targetSlotId)
- {}
- bool SpecificSlotFilter::matchSourceSlot(ItemSlot* zSlot) const
- {
- return sourceSlotId == zSlot->getId();
- }
- bool SpecificSlotFilter::matchTargetSlot(ItemSlot* zSlot) const
- {
- return targetSlotId == zSlot->getId();
- }
- Framework::Text SpecificSlotFilter::getImageUIML() const
- {
- return "<img str=\"bilder/gui_icons.ltdb/anyItem.png\"/>";
- }
- Framework::Text SpecificSlotFilter::getLogicUIML() const
- {
- return "<anyItem/>";
- }
- SourceSlotBlacklistFilter::SourceSlotBlacklistFilter()
- : ItemFilter()
- {}
- void SourceSlotBlacklistFilter::addBlackListSlotId(int id)
- {
- blackList.add(id);
- }
- bool SourceSlotBlacklistFilter::matchSourceSlot(ItemSlot* zSlot) const
- {
- for (int black : blackList)
- {
- if (black == zSlot->getId()) return 0;
- }
- return 1;
- }
- bool SourceSlotBlacklistFilter::matchTargetSlot(ItemSlot* zSlot) const
- {
- return 1;
- }
- Framework::Text SourceSlotBlacklistFilter::getImageUIML() const
- {
- return "<img str=\"bilder/gui_icons.ltdb/anyItem.png\"/>";
- }
- Framework::Text SourceSlotBlacklistFilter::getLogicUIML() const
- {
- return "<anyItem/>";
- }
- TargetSlotBlacklistFilter::TargetSlotBlacklistFilter()
- : ItemFilter()
- {}
- void TargetSlotBlacklistFilter::addBlackListSlotId(int id)
- {
- blackList.add(id);
- }
- bool TargetSlotBlacklistFilter::matchSourceSlot(ItemSlot* zSlot) const
- {
- return 1;
- }
- bool TargetSlotBlacklistFilter::matchTargetSlot(ItemSlot* zSlot) const
- {
- for (int black : blackList)
- {
- if (black == zSlot->getId()) return 0;
- }
- return 1;
- }
- Framework::Text TargetSlotBlacklistFilter::getImageUIML() const
- {
- return "<img str=\"bilder/gui_icons.ltdb/anyItem.png\"/>";
- }
- Framework::Text TargetSlotBlacklistFilter::getLogicUIML() const
- {
- return "<anyItem/>";
- }
|