mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-24 10:23:02 -07:00
[Card] Add a Tag attribute to the card filter tree
This commit is contained in:
parent
d65d23ffce
commit
0ea0e231bf
5 changed files with 35 additions and 0 deletions
|
|
@ -84,6 +84,8 @@ const QString CardFilter::attrName(Attr a)
|
||||||
return tr("Loyalty");
|
return tr("Loyalty");
|
||||||
case AttrFormat:
|
case AttrFormat:
|
||||||
return tr("Format");
|
return tr("Format");
|
||||||
|
case AttrTag:
|
||||||
|
return tr("Tag");
|
||||||
case AttrMainType:
|
case AttrMainType:
|
||||||
return tr("Main Type");
|
return tr("Main Type");
|
||||||
case AttrSubType:
|
case AttrSubType:
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ public:
|
||||||
AttrMainType,
|
AttrMainType,
|
||||||
AttrSubType,
|
AttrSubType,
|
||||||
AttrFormat,
|
AttrFormat,
|
||||||
|
AttrTag,
|
||||||
AttrEnd,
|
AttrEnd,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "filter_card.h"
|
#include "filter_card.h"
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
#include <libcockatrice/card/game_specific_terms.h>
|
||||||
|
|
||||||
template <class T> FilterTreeNode *FilterTreeBranch<T>::nodeAt(int i) const
|
template <class T> FilterTreeNode *FilterTreeBranch<T>::nodeAt(int i) const
|
||||||
{
|
{
|
||||||
|
|
@ -341,6 +342,16 @@ bool FilterItem::acceptFormat(const CardInfoPtr info) const
|
||||||
return info->getLegalityProp(term.toLower()) == "legal";
|
return info->getLegalityProp(term.toLower()) == "legal";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FilterItem::acceptTag(const CardInfoPtr info) const
|
||||||
|
{
|
||||||
|
const QString stored = info->getProperty(Mtg::Tags);
|
||||||
|
if (stored.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Tags are stored space-separated; match whole slugs, not substrings.
|
||||||
|
return stored.split(" ", Qt::SkipEmptyParts).contains(term.trimmed(), Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
bool FilterItem::acceptLoyalty(const CardInfoPtr info) const
|
bool FilterItem::acceptLoyalty(const CardInfoPtr info) const
|
||||||
{
|
{
|
||||||
if (info->getLoyalty().isEmpty()) {
|
if (info->getLoyalty().isEmpty()) {
|
||||||
|
|
@ -495,6 +506,8 @@ bool FilterItem::acceptCardAttr(const CardInfoPtr info,
|
||||||
return acceptLoyalty(info);
|
return acceptLoyalty(info);
|
||||||
case CardFilter::AttrFormat:
|
case CardFilter::AttrFormat:
|
||||||
return acceptFormat(info);
|
return acceptFormat(info);
|
||||||
|
case CardFilter::AttrTag:
|
||||||
|
return acceptTag(info);
|
||||||
case CardFilter::AttrMainType:
|
case CardFilter::AttrMainType:
|
||||||
return acceptMainType(info);
|
return acceptMainType(info);
|
||||||
case CardFilter::AttrSubType:
|
case CardFilter::AttrSubType:
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,7 @@ public:
|
||||||
[[nodiscard]] bool
|
[[nodiscard]] bool
|
||||||
acceptCardAttr(CardInfoPtr info, CardFilter::Attr attr, const CardSearchLanguage &searchLanguage) const;
|
acceptCardAttr(CardInfoPtr info, CardFilter::Attr attr, const CardSearchLanguage &searchLanguage) const;
|
||||||
[[nodiscard]] bool acceptFormat(CardInfoPtr info) const;
|
[[nodiscard]] bool acceptFormat(CardInfoPtr info) const;
|
||||||
|
[[nodiscard]] bool acceptTag(CardInfoPtr info) const;
|
||||||
[[nodiscard]] bool relationCheck(int cardInfo) const;
|
[[nodiscard]] bool relationCheck(int cardInfo) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
#include <libcockatrice/filters/filter_string.h>
|
#include <libcockatrice/filters/filter_string.h>
|
||||||
|
#include <libcockatrice/filters/filter_tree.h>
|
||||||
#include <libcockatrice/interfaces/noop_card_preference_provider.h>
|
#include <libcockatrice/interfaces/noop_card_preference_provider.h>
|
||||||
#include <libcockatrice/interfaces/noop_card_set_priority_controller.h>
|
#include <libcockatrice/interfaces/noop_card_set_priority_controller.h>
|
||||||
|
|
||||||
|
|
@ -160,6 +161,23 @@ TEST_F(CardQuery, TagQueryTreatsCommasAsPartOfTheSlug)
|
||||||
ASSERT_FALSE(FilterString("tags:ramp,removal").check(tagged));
|
ASSERT_FALSE(FilterString("tags:ramp,removal").check(tagged));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(CardQuery, FilterTreeTagAttribute)
|
||||||
|
{
|
||||||
|
const CardData tagged = taggedCard();
|
||||||
|
|
||||||
|
FilterTree matching;
|
||||||
|
matching.termNode(CardFilter::AttrTag, CardFilter::TypeAnd, "ramp");
|
||||||
|
ASSERT_TRUE(matching.acceptsCard(tagged, CardSearchLanguage{}));
|
||||||
|
|
||||||
|
FilterTree partial;
|
||||||
|
partial.termNode(CardFilter::AttrTag, CardFilter::TypeAnd, "ram");
|
||||||
|
ASSERT_FALSE(partial.acceptsCard(tagged, CardSearchLanguage{}));
|
||||||
|
|
||||||
|
FilterTree missing;
|
||||||
|
missing.termNode(CardFilter::AttrTag, CardFilter::TypeAnd, "squirrel");
|
||||||
|
ASSERT_FALSE(missing.acceptsCard(tagged, CardSearchLanguage{}));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(CardQuery, TagQueryFalseWhenCardHasNoTags)
|
TEST_F(CardQuery, TagQueryFalseWhenCardHasNoTags)
|
||||||
{
|
{
|
||||||
ASSERT_FALSE(FilterString("tags:ramp").check(cat));
|
ASSERT_FALSE(FilterString("tags:ramp").check(cat));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue