mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 03:28:49 -07:00
0 values in power/toughness filters won't match non-zero values anymore (#3250)
## Related Ticket(s) - Fixes #3212 ## What will change with this Pull Request? - `0` input on power/toughness filters will only return `0` values - `relationCheck` method will only get called after simple string comparison failed - due to their similar structure `acceptPower` and `acceptToughness` methods has been merged
This commit is contained in:
parent
ec4a99e47b
commit
b3df71ae41
2 changed files with 25 additions and 14 deletions
|
|
@ -272,16 +272,25 @@ bool FilterItem::acceptLoyalty(const CardInfoPtr info) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterItem::acceptPower(const CardInfoPtr info) const
|
bool FilterItem::acceptPowerToughness(const CardInfoPtr info, CardFilter::Attr attr) const
|
||||||
{
|
{
|
||||||
int slash = info->getPowTough().indexOf("/");
|
int slash = info->getPowTough().indexOf("/");
|
||||||
return (slash != -1) ? (relationCheck(info->getPowTough().mid(0, slash).toInt())) : false;
|
if (slash == -1) {
|
||||||
}
|
return false;
|
||||||
|
}
|
||||||
bool FilterItem::acceptToughness(const CardInfoPtr info) const
|
QString valueString;
|
||||||
{
|
if (attr == CardFilter::AttrPow) {
|
||||||
int slash = info->getPowTough().indexOf("/");
|
valueString = info->getPowTough().mid(0, slash);
|
||||||
return (slash != -1) ? (relationCheck(info->getPowTough().mid(slash + 1).toInt())) : false;
|
} else {
|
||||||
|
valueString = info->getPowTough().mid(slash + 1);
|
||||||
|
}
|
||||||
|
if (term == valueString) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// advanced filtering should only happen after fast string comparison failed
|
||||||
|
bool conversion;
|
||||||
|
int value = valueString.toInt(&conversion);
|
||||||
|
return conversion ? relationCheck(value) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FilterItem::acceptRarity(const CardInfoPtr info) const
|
bool FilterItem::acceptRarity(const CardInfoPtr info) const
|
||||||
|
|
@ -337,7 +346,7 @@ bool FilterItem::relationCheck(int cardInfo) const
|
||||||
{
|
{
|
||||||
bool result, conversion;
|
bool result, conversion;
|
||||||
|
|
||||||
// if int conversion fails, there must be either an operator at the start
|
// if int conversion fails, there's probably an operator at the start
|
||||||
result = (cardInfo == term.toInt(&conversion));
|
result = (cardInfo == term.toInt(&conversion));
|
||||||
if (!conversion) {
|
if (!conversion) {
|
||||||
// leading whitespaces could cause indexing to fail
|
// leading whitespaces could cause indexing to fail
|
||||||
|
|
@ -358,8 +367,11 @@ bool FilterItem::relationCheck(int cardInfo) const
|
||||||
result = (cardInfo < termInt);
|
result = (cardInfo < termInt);
|
||||||
} else if (trimmedTerm.startsWith('>')) {
|
} else if (trimmedTerm.startsWith('>')) {
|
||||||
result = (cardInfo > termInt);
|
result = (cardInfo > termInt);
|
||||||
} else {
|
} else if (trimmedTerm.startsWith("=")) {
|
||||||
result = (cardInfo == termInt);
|
result = (cardInfo == termInt);
|
||||||
|
} else {
|
||||||
|
// the int conversion hasn't failed due to an operator at the start
|
||||||
|
result = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -386,9 +398,9 @@ bool FilterItem::acceptCardAttr(const CardInfoPtr info, CardFilter::Attr attr) c
|
||||||
case CardFilter::AttrRarity:
|
case CardFilter::AttrRarity:
|
||||||
return acceptRarity(info);
|
return acceptRarity(info);
|
||||||
case CardFilter::AttrPow:
|
case CardFilter::AttrPow:
|
||||||
return acceptPower(info);
|
|
||||||
case CardFilter::AttrTough:
|
case CardFilter::AttrTough:
|
||||||
return acceptToughness(info);
|
// intentional fallthrough
|
||||||
|
return acceptPowerToughness(info, attr);
|
||||||
case CardFilter::AttrLoyalty:
|
case CardFilter::AttrLoyalty:
|
||||||
return acceptLoyalty(info);
|
return acceptLoyalty(info);
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -210,8 +210,7 @@ public:
|
||||||
bool acceptSet(const CardInfoPtr info) const;
|
bool acceptSet(const CardInfoPtr info) const;
|
||||||
bool acceptManaCost(const CardInfoPtr info) const;
|
bool acceptManaCost(const CardInfoPtr info) const;
|
||||||
bool acceptCmc(const CardInfoPtr info) const;
|
bool acceptCmc(const CardInfoPtr info) const;
|
||||||
bool acceptPower(const CardInfoPtr info) const;
|
bool acceptPowerToughness(const CardInfoPtr info, CardFilter::Attr attr) const;
|
||||||
bool acceptToughness(const CardInfoPtr info) const;
|
|
||||||
bool acceptLoyalty(const CardInfoPtr info) const;
|
bool acceptLoyalty(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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue