From da84bb33e12698cd57f0b8991e7d3a6cf4a7a837 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Thu, 11 Jun 2015 10:48:50 +0200 Subject: [PATCH] Import related cards in the card database --- cockatrice/src/carddatabase.cpp | 15 ++++++++++++--- cockatrice/src/carddatabase.h | 6 +++++- oracle/src/oracleimporter.cpp | 14 ++++++++++---- oracle/src/oracleimporter.h | 2 +- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 17b18a8a..072d397c 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -482,13 +482,15 @@ CardInfo::CardInfo(CardDatabase *_db, const QString &_powtough, const QString &_text, const QStringList &_colors, + const QStringList &_relatedCards, int _loyalty, bool _cipt, int _tableRow, const SetList &_sets, const QStringMap &_customPicURLs, const QStringMap &_customPicURLsHq, - MuidMap _muIds) + MuidMap _muIds + ) : db(_db), name(_name), isToken(_isToken), @@ -499,6 +501,7 @@ CardInfo::CardInfo(CardDatabase *_db, powtough(_powtough), text(_text), colors(_colors), + relatedCards(_relatedCards), loyalty(_loyalty), customPicURLs(_customPicURLs), customPicURLsHq(_customPicURLsHq), @@ -685,6 +688,10 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info) for (int i = 0; i < colors.size(); i++) xml.writeTextElement("color", colors[i]); + const QStringList &related = info->getRelatedCards(); + for (int i = 0; i < related.size(); i++) + xml.writeTextElement("related", related[i]); + xml.writeTextElement("manacost", info->getManaCost()); xml.writeTextElement("cmc", info->getCmc()); xml.writeTextElement("type", info->getCardType()); @@ -852,7 +859,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens) break; if (xml.name() == "card") { QString name, manacost, cmc, type, pt, text; - QStringList colors; + QStringList colors, relatedCards; QStringMap customPicURLs, customPicURLsHq; MuidMap muids; SetList sets; @@ -890,6 +897,8 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens) } } else if (xml.name() == "color") colors << xml.readElementText(); + else if (xml.name() == "related") + relatedCards << xml.readElementText(); else if (xml.name() == "tablerow") tableRow = xml.readElementText().toInt(); else if (xml.name() == "cipt") @@ -901,7 +910,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens) } if (isToken == tokens) { - addCard(new CardInfo(this, name, isToken, manacost, cmc, type, pt, text, colors, loyalty, cipt, tableRow, sets, customPicURLs, customPicURLsHq, muids)); + addCard(new CardInfo(this, name, isToken, manacost, cmc, type, pt, text, colors, relatedCards, loyalty, cipt, tableRow, sets, customPicURLs, customPicURLsHq, muids)); } } } diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index 30fdc1e0..a6264274 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -138,6 +138,7 @@ private: bool cipt; int tableRow; QString pixmapCacheKey; + QStringList relatedCards; public: CardInfo(CardDatabase *_db, const QString &_name = QString(), @@ -148,13 +149,15 @@ public: const QString &_powtough = QString(), const QString &_text = QString(), const QStringList &_colors = QStringList(), + const QStringList &_relatedCards = QStringList(), int _loyalty = 0, bool _cipt = false, int _tableRow = 0, const SetList &_sets = SetList(), const QStringMap &_customPicURLs = QStringMap(), const QStringMap &_customPicURLsHq = QStringMap(), - MuidMap muids = MuidMap()); + MuidMap muids = MuidMap() + ); ~CardInfo(); const QString &getName() const { return name; } const QString &getSimpleName() const { return simpleName; } @@ -174,6 +177,7 @@ public: void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); } void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); } const QStringList &getColors() const { return colors; } + const QStringList &getRelatedCards() const { return relatedCards; } QString getCustomPicURL(const QString &set) const { return customPicURLs.value(set); } QString getCustomPicURLHq(const QString &set) const { return customPicURLsHq.value(set); } int getMuId(const QString &set) const { return muIds.value(set); } diff --git a/oracle/src/oracleimporter.cpp b/oracle/src/oracleimporter.cpp index 84e742a8..78b5f16a 100644 --- a/oracle/src/oracleimporter.cpp +++ b/oracle/src/oracleimporter.cpp @@ -65,7 +65,9 @@ CardInfo *OracleImporter::addCard(const QString &setName, const QString &cardPT, int cardLoyalty, const QString &cardText, - const QStringList & colors) + const QStringList & colors, + const QStringList & relatedCards + ) { QStringList cardTextRows = cardText.split("\n"); bool splitCard = false; @@ -97,7 +99,7 @@ CardInfo *OracleImporter::addCard(const QString &setName, bool cipt = cardText.contains("Hideaway") || (cardText.contains(cardName + " enters the battlefield tapped") && !cardText.contains(cardName + " enters the battlefield tapped unless")); - card = new CardInfo(this, cardName, isToken, cardCost, cmc, cardType, cardPT, cardText, colors, cardLoyalty, cipt); + card = new CardInfo(this, cardName, isToken, cardCost, cmc, cardType, cardPT, cardText, colors, relatedCards, cardLoyalty, cipt); int tableRow = 1; QString mainCardType = card->getMainCardType(); if ((mainCardType == "Land") || mArtifact) @@ -147,6 +149,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data) QString cardPT; QString cardText; QStringList colors; + QStringList relatedCards; int cardId; int cardLoyalty; bool cardIsToken = false; @@ -169,7 +172,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data) cardLoyalty = 0; // determine which subcard is the first one in the split - QStringList names=map.contains("names") ? map.value("names").toStringList() : QStringList(""); + QStringList names=map.contains("names") ? map.value("names").toStringList() : QStringList(); if(names.count()>0 && map.contains("name") && 0 == QString::compare(map.value("name").toString(), names.at(0))) @@ -204,6 +207,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data) extractColors(card2->value("colors").toStringList(), colors); colors.removeDuplicates(); + relatedCards = QStringList(); } else { // first card of a pair; enqueue for later merging // Conditional on cardId because promo prints have no muid - see #640 @@ -222,6 +226,8 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data) cardId = map.contains("multiverseid") ? map.value("multiverseid").toInt() : 0; cardLoyalty = map.contains("loyalty") ? map.value("loyalty").toInt() : 0; cardIsToken = map.value("layout") == "token"; + relatedCards = map.contains("names") ? map.value("names").toStringList() : QStringList(); + relatedCards.removeAll(cardName); colors.clear(); extractColors(map.value("colors").toStringList(), colors); @@ -233,7 +239,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data) } if (!cardIsToken) { - CardInfo *card = addCard(set->getShortName(), cardName, cardIsToken, cardId, cardCost, cmc, cardType, cardPT, cardLoyalty, cardText, colors); + CardInfo *card = addCard(set->getShortName(), cardName, cardIsToken, cardId, cardCost, cmc, cardType, cardPT, cardLoyalty, cardText, colors, relatedCards); if (!set->contains(card)) { card->addToSet(set); diff --git a/oracle/src/oracleimporter.h b/oracle/src/oracleimporter.h index e3f06a44..294d4c28 100644 --- a/oracle/src/oracleimporter.h +++ b/oracle/src/oracleimporter.h @@ -29,7 +29,7 @@ private: QVariantMap setsMap; QString dataDir; - CardInfo *addCard(const QString &setName, QString cardName, bool isToken, int cardId, QString &cardCost, QString &cmc, const QString &cardType, const QString &cardPT, int cardLoyalty, const QString &cardText, const QStringList & colors); + CardInfo *addCard(const QString &setName, QString cardName, bool isToken, int cardId, QString &cardCost, QString &cmc, const QString &cardType, const QString &cardPT, int cardLoyalty, const QString &cardText, const QStringList & colors, const QStringList & relatedCards); signals: void setIndexChanged(int cardsImported, int setIndex, const QString &setName); void dataReadProgress(int bytesRead, int totalBytes);