Loyalty filter added (#3087)

This commit is contained in:
Vafthrudnir 2018-02-07 17:33:01 +01:00 committed by Zach H
parent 35159ef61a
commit a0d6a342d3
9 changed files with 39 additions and 19 deletions

View file

@ -235,7 +235,7 @@ CardInfo::CardInfo(const QString &_name,
const QList<CardRelation *> &_relatedCards, const QList<CardRelation *> &_relatedCards,
const QList<CardRelation *> &_reverseRelatedCards, const QList<CardRelation *> &_reverseRelatedCards,
bool _upsideDownArt, bool _upsideDownArt,
int _loyalty, const QString &_loyalty,
bool _cipt, bool _cipt,
int _tableRow, int _tableRow,
const SetList &_sets, const SetList &_sets,
@ -271,7 +271,7 @@ CardInfoPtr CardInfo::newInstance(const QString &_name,
const QList<CardRelation *> &_relatedCards, const QList<CardRelation *> &_relatedCards,
const QList<CardRelation *> &_reverseRelatedCards, const QList<CardRelation *> &_reverseRelatedCards,
bool _upsideDownArt, bool _upsideDownArt,
int _loyalty, const QString &_loyalty,
bool _cipt, bool _cipt,
int _tableRow, int _tableRow,
const SetList &_sets, const SetList &_sets,
@ -488,7 +488,7 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfoPtr &in
xml.writeTextElement("tablerow", QString::number(info->getTableRow())); xml.writeTextElement("tablerow", QString::number(info->getTableRow()));
xml.writeTextElement("text", info->getText()); xml.writeTextElement("text", info->getText());
if (info->getMainCardType() == "Planeswalker") { if (info->getMainCardType() == "Planeswalker") {
xml.writeTextElement("loyalty", QString::number(info->getLoyalty())); xml.writeTextElement("loyalty", info->getLoyalty());
} }
if (info->getCipt()) { if (info->getCipt()) {
xml.writeTextElement("cipt", "1"); xml.writeTextElement("cipt", "1");
@ -665,7 +665,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
} }
if (xml.name() == "card") { if (xml.name() == "card") {
QString name, manacost, cmc, type, pt, text; QString name, manacost, cmc, type, pt, text, loyalty;
QStringList colors; QStringList colors;
QList<CardRelation *> relatedCards, reverseRelatedCards; QList<CardRelation *> relatedCards, reverseRelatedCards;
QStringMap customPicURLs; QStringMap customPicURLs;
@ -673,7 +673,6 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
QStringMap collectorNumbers, rarities; QStringMap collectorNumbers, rarities;
SetList sets; SetList sets;
int tableRow = 0; int tableRow = 0;
int loyalty = 0;
bool cipt = false; bool cipt = false;
bool isToken = false; bool isToken = false;
bool upsideDown = false; bool upsideDown = false;
@ -758,7 +757,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
} else if (xml.name() == "upsidedown") { } else if (xml.name() == "upsidedown") {
upsideDown = (xml.readElementText() == "1"); upsideDown = (xml.readElementText() == "1");
} else if (xml.name() == "loyalty") { } else if (xml.name() == "loyalty") {
loyalty = xml.readElementText().toInt(); loyalty = xml.readElementText();
} else if (xml.name() == "token") { } else if (xml.name() == "token") {
isToken = static_cast<bool>(xml.readElementText().toInt()); isToken = static_cast<bool>(xml.readElementText().toInt());
} else if (xml.name() != "") { } else if (xml.name() != "") {

View file

@ -145,7 +145,7 @@ private:
QString setsNames; QString setsNames;
bool upsideDownArt; bool upsideDownArt;
int loyalty; QString loyalty;
QStringMap customPicURLs; QStringMap customPicURLs;
MuidMap muIds; MuidMap muIds;
QStringMap collectorNumbers; QStringMap collectorNumbers;
@ -166,7 +166,7 @@ public:
const QList<CardRelation *> &_relatedCards = QList<CardRelation *>(), const QList<CardRelation *> &_relatedCards = QList<CardRelation *>(),
const QList<CardRelation *> &_reverseRelatedCards = QList<CardRelation *>(), const QList<CardRelation *> &_reverseRelatedCards = QList<CardRelation *>(),
bool _upsideDownArt = false, bool _upsideDownArt = false,
int _loyalty = 0, const QString &_loyalty = QString(),
bool _cipt = false, bool _cipt = false,
int _tableRow = 0, int _tableRow = 0,
const SetList &_sets = SetList(), const SetList &_sets = SetList(),
@ -187,7 +187,7 @@ public:
const QList<CardRelation *> &_relatedCards = QList<CardRelation *>(), const QList<CardRelation *> &_relatedCards = QList<CardRelation *>(),
const QList<CardRelation *> &_reverseRelatedCards = QList<CardRelation *>(), const QList<CardRelation *> &_reverseRelatedCards = QList<CardRelation *>(),
bool _upsideDownArt = false, bool _upsideDownArt = false,
int _loyalty = 0, const QString &_loyalty = QString(),
bool _cipt = false, bool _cipt = false,
int _tableRow = 0, int _tableRow = 0,
const SetList &_sets = SetList(), const SetList &_sets = SetList(),
@ -245,7 +245,7 @@ public:
{ {
return pixmapCacheKey; return pixmapCacheKey;
} }
const int &getLoyalty() const const QString &getLoyalty() const
{ {
return loyalty; return loyalty;
} }

View file

@ -39,6 +39,8 @@ const char *CardFilter::attrName(Attr a)
return "Power"; return "Power";
case AttrTough: case AttrTough:
return "Toughness"; return "Toughness";
case AttrLoyalty:
return "Loyalty";
default: default:
return ""; return "";
} }

View file

@ -21,6 +21,7 @@ public:
{ {
AttrCmc = 0, AttrCmc = 0,
AttrColor, AttrColor,
AttrLoyalty,
AttrManaCost, AttrManaCost,
AttrName, AttrName,
AttrPow, AttrPow,

View file

@ -63,7 +63,7 @@ void CardInfoText::setCard(CardInfoPtr card)
colorLabel2->setText(card->getColors().join("")); colorLabel2->setText(card->getColors().join(""));
cardtypeLabel2->setText(card->getCardType()); cardtypeLabel2->setText(card->getCardType());
powtoughLabel2->setText(card->getPowTough()); powtoughLabel2->setText(card->getPowTough());
loyaltyLabel2->setText(card->getLoyalty() > 0 ? QString::number(card->getLoyalty()) : QString()); loyaltyLabel2->setText(card->getLoyalty());
textLabel->setText(card->getText()); textLabel->setText(card->getText());
} else { } else {
nameLabel2->setText(""); nameLabel2->setText("");

View file

@ -234,6 +234,22 @@ bool FilterItem::acceptCmc(const CardInfoPtr info) const
return relationCheck(info->getCmc().toInt()); return relationCheck(info->getCmc().toInt());
} }
bool FilterItem::acceptLoyalty(const CardInfoPtr info) const
{
if (info->getLoyalty().isEmpty()) {
return false;
} else {
bool success;
// if loyalty can't be converted to "int" it must be "X"
int loyalty = info->getLoyalty().toInt(&success);
if (success) {
return relationCheck(loyalty);
} else {
return term.trimmed().toUpper() == info->getLoyalty();
}
}
}
bool FilterItem::acceptPower(const CardInfoPtr info) const bool FilterItem::acceptPower(const CardInfoPtr info) const
{ {
int slash = info->getPowTough().indexOf("/"); int slash = info->getPowTough().indexOf("/");
@ -287,7 +303,7 @@ bool FilterItem::acceptRarity(const CardInfoPtr info) const
} }
} }
foreach (QString rareLevel, info->getRarities()) { for (const QString &rareLevel : info->getRarities()) {
if (rareLevel.compare(converted_term, Qt::CaseInsensitive) == 0) { if (rareLevel.compare(converted_term, Qt::CaseInsensitive) == 0) {
return true; return true;
} }
@ -351,6 +367,8 @@ bool FilterItem::acceptCardAttr(const CardInfoPtr info, CardFilter::Attr attr) c
return acceptPower(info); return acceptPower(info);
case CardFilter::AttrTough: case CardFilter::AttrTough:
return acceptToughness(info); return acceptToughness(info);
case CardFilter::AttrLoyalty:
return acceptLoyalty(info);
default: default:
return true; /* ignore this attribute */ return true; /* ignore this attribute */
} }
@ -464,4 +482,4 @@ void FilterTree::clear()
while (childCount() > 0) { while (childCount() > 0) {
deleteAt(0); deleteAt(0);
} }
} }

View file

@ -212,6 +212,7 @@ public:
bool acceptCmc(const CardInfoPtr info) const; bool acceptCmc(const CardInfoPtr info) const;
bool acceptPower(const CardInfoPtr info) const; bool acceptPower(const CardInfoPtr info) const;
bool acceptToughness(const CardInfoPtr info) const; bool acceptToughness(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;
bool relationCheck(int cardInfo) const; bool relationCheck(int cardInfo) const;

View file

@ -60,7 +60,7 @@ CardInfoPtr OracleImporter::addCard(const QString &setName,
QString &cmc, QString &cmc,
const QString &cardType, const QString &cardType,
const QString &cardPT, const QString &cardPT,
int cardLoyalty, const QString &cardLoyalty,
const QString &cardText, const QString &cardText,
const QStringList &colors, const QStringList &colors,
const QList<CardRelation *> &relatedCards, const QList<CardRelation *> &relatedCards,
@ -152,7 +152,7 @@ int OracleImporter::importTextSpoiler(CardSetPtr set, const QVariant &data)
int cardId; int cardId;
QString setNumber; QString setNumber;
QString rarity; QString rarity;
int cardLoyalty; QString cardLoyalty;
bool upsideDown = false; bool upsideDown = false;
QMap<int, QVariantMap> splitCards; QMap<int, QVariantMap> splitCards;
@ -184,7 +184,7 @@ int OracleImporter::importTextSpoiler(CardSetPtr set, const QVariant &data)
cardId = map.contains("multiverseid") ? map.value("multiverseid").toInt() : 0; cardId = map.contains("multiverseid") ? map.value("multiverseid").toInt() : 0;
setNumber = map.contains("number") ? map.value("number").toString() : QString(""); setNumber = map.contains("number") ? map.value("number").toString() : QString("");
rarity = map.contains("rarity") ? map.value("rarity").toString() : QString(""); rarity = map.contains("rarity") ? map.value("rarity").toString() : QString("");
cardLoyalty = map.contains("loyalty") ? map.value("loyalty").toInt() : 0; cardLoyalty = map.contains("loyalty") ? map.value("loyalty").toString() : QString("");
relatedCards = QList<CardRelation *>(); relatedCards = QList<CardRelation *>();
if (map.contains("names")) if (map.contains("names"))
foreach (const QString &name, map.value("names").toStringList()) { foreach (const QString &name, map.value("names").toStringList()) {
@ -237,9 +237,8 @@ int OracleImporter::importTextSpoiler(CardSetPtr set, const QVariant &data)
cardText = ""; cardText = "";
setNumber = ""; setNumber = "";
rarity = ""; rarity = "";
cardLoyalty = "";
colors.clear(); colors.clear();
// this is currently an integer; can't accept 2 values
cardLoyalty = 0;
// loop cards and merge their contents // loop cards and merge their contents
QString prefix = QString(" // "); QString prefix = QString(" // ");

View file

@ -66,7 +66,7 @@ private:
QString &cmc, QString &cmc,
const QString &cardType, const QString &cardType,
const QString &cardPT, const QString &cardPT,
int cardLoyalty, const QString &cardLoyalty,
const QString &cardText, const QString &cardText,
const QStringList &colors, const QStringList &colors,
const QList<CardRelation *> &relatedCards, const QList<CardRelation *> &relatedCards,