Relation checks added to relevant fields in card filter (#3080)
* comments and <=, >=, == support added
This commit is contained in:
parent
b58aa459a4
commit
4cbec71882
2 changed files with 37 additions and 3 deletions
|
@ -231,19 +231,19 @@ bool FilterItem::acceptManaCost(const CardInfoPtr info) const
|
||||||
|
|
||||||
bool FilterItem::acceptCmc(const CardInfoPtr info) const
|
bool FilterItem::acceptCmc(const CardInfoPtr info) const
|
||||||
{
|
{
|
||||||
return (info->getCmc() == term);
|
return relationCheck(info->getCmc().toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterItem::acceptPower(const CardInfoPtr info) const
|
bool FilterItem::acceptPower(const CardInfoPtr info) const
|
||||||
{
|
{
|
||||||
int slash = info->getPowTough().indexOf("/");
|
int slash = info->getPowTough().indexOf("/");
|
||||||
return (slash != -1) ? (info->getPowTough().mid(0, slash) == term) : false;
|
return (slash != -1) ? (relationCheck(info->getPowTough().mid(0, slash).toInt())) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterItem::acceptToughness(const CardInfoPtr info) const
|
bool FilterItem::acceptToughness(const CardInfoPtr info) const
|
||||||
{
|
{
|
||||||
int slash = info->getPowTough().indexOf("/");
|
int slash = info->getPowTough().indexOf("/");
|
||||||
return (slash != -1) ? (info->getPowTough().mid(slash + 1) == term) : false;
|
return (slash != -1) ? (relationCheck(info->getPowTough().mid(slash + 1).toInt())) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterItem::acceptRarity(const CardInfoPtr info) const
|
bool FilterItem::acceptRarity(const CardInfoPtr info) const
|
||||||
|
@ -295,6 +295,39 @@ bool FilterItem::acceptRarity(const CardInfoPtr info) const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FilterItem::relationCheck(int cardInfo) const
|
||||||
|
{
|
||||||
|
bool result, conversion;
|
||||||
|
|
||||||
|
// if int conversion fails, there must be either an operator at the start
|
||||||
|
result = (cardInfo == term.toInt(&conversion));
|
||||||
|
if (!conversion) {
|
||||||
|
// leading whitespaces could cause indexing to fail
|
||||||
|
QString trimmedTerm = term.trimmed();
|
||||||
|
// check whether it's a 2 char operator (<=, >=, or ==)
|
||||||
|
if (trimmedTerm[1] == '=') {
|
||||||
|
int termInt = trimmedTerm.mid(2).toInt();
|
||||||
|
if (trimmedTerm.startsWith('<')) {
|
||||||
|
result = (cardInfo <= termInt);
|
||||||
|
} else if (trimmedTerm.startsWith('>')) {
|
||||||
|
result = (cardInfo >= termInt);
|
||||||
|
} else {
|
||||||
|
result = (cardInfo == termInt);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int termInt = trimmedTerm.mid(1).toInt();
|
||||||
|
if (trimmedTerm.startsWith('<')) {
|
||||||
|
result = (cardInfo < termInt);
|
||||||
|
} else if (trimmedTerm.startsWith('>')) {
|
||||||
|
result = (cardInfo > termInt);
|
||||||
|
} else {
|
||||||
|
result = (cardInfo == termInt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
bool FilterItem::acceptCardAttr(const CardInfoPtr info, CardFilter::Attr attr) const
|
bool FilterItem::acceptCardAttr(const CardInfoPtr info, CardFilter::Attr attr) const
|
||||||
{
|
{
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
|
|
|
@ -214,6 +214,7 @@ public:
|
||||||
bool acceptToughness(const CardInfoPtr info) const;
|
bool acceptToughness(const CardInfoPtr info) const;
|
||||||
bool acceptRarity(const CardInfoPtr info) const;
|
bool acceptRarity(const CardInfoPtr info) const;
|
||||||
bool acceptCardAttr(const CardInfoPtr info, CardFilter::Attr attr) const;
|
bool acceptCardAttr(const CardInfoPtr info, CardFilter::Attr attr) const;
|
||||||
|
bool relationCheck(int cardInfo) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FilterTree : public QObject, public FilterTreeBranch<LogicMap *>
|
class FilterTree : public QObject, public FilterTreeBranch<LogicMap *>
|
||||||
|
|
Loading…
Reference in a new issue