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

View file

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

View file

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

View file

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

View file

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

View file

@ -234,6 +234,22 @@ bool FilterItem::acceptCmc(const CardInfoPtr info) const
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
{
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) {
return true;
}
@ -351,6 +367,8 @@ bool FilterItem::acceptCardAttr(const CardInfoPtr info, CardFilter::Attr attr) c
return acceptPower(info);
case CardFilter::AttrTough:
return acceptToughness(info);
case CardFilter::AttrLoyalty:
return acceptLoyalty(info);
default:
return true; /* ignore this attribute */
}

View file

@ -212,6 +212,7 @@ public:
bool acceptCmc(const CardInfoPtr info) const;
bool acceptPower(const CardInfoPtr info) const;
bool acceptToughness(const CardInfoPtr info) const;
bool acceptLoyalty(const CardInfoPtr info) const;
bool acceptRarity(const CardInfoPtr info) const;
bool acceptCardAttr(const CardInfoPtr info, CardFilter::Attr attr) const;
bool relationCheck(int cardInfo) const;

View file

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

View file

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