From a7f3ce4050b2cd703b4a7e02c13cece4f473a4d9 Mon Sep 17 00:00:00 2001 From: Daenyth Date: Sat, 3 Dec 2011 16:03:45 -0500 Subject: [PATCH] Add code support for planeswalker loyalty. Added to CardInfo object and to the oracle importer. Next step is the card info widget. --- cockatrice/src/carddatabase.cpp | 38 ++++++++++++++++++++++++++++++--- cockatrice/src/carddatabase.h | 4 ++++ oracle/src/oracleimporter.cpp | 17 +++++++++++++-- oracle/src/oracleimporter.h | 2 +- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 96918984..65df3884 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -256,8 +256,35 @@ void PictureLoadingThread::waitForInit() mutex.unlock(); } -CardInfo::CardInfo(CardDatabase *_db, const QString &_name, const QString &_manacost, const QString &_cardtype, const QString &_powtough, const QString &_text, const QStringList &_colors, bool _cipt, int _tableRow, const SetList &_sets, const QMap &_picURLs, const QMap &_picURLsHq, const QMap &_picURLsSt) - : db(_db), name(_name), sets(_sets), manacost(_manacost), cardtype(_cardtype), powtough(_powtough), text(_text), colors(_colors), picURLs(_picURLs), picURLsHq(_picURLsHq), picURLsSt(_picURLsSt), cipt(_cipt), tableRow(_tableRow), pixmap(NULL) +CardInfo::CardInfo(CardDatabase *_db, + const QString &_name, + const QString &_manacost, + const QString &_cardtype, + const QString &_powtough, + const QString &_text, + const QStringList &_colors, + int _loyalty, + bool _cipt, + int _tableRow, + const SetList &_sets, + const QMap &_picURLs, + const QMap &_picURLsHq, + const QMap &_picURLsSt) + : db(_db), + name(_name), + sets(_sets), + manacost(_manacost), + cardtype(_cardtype), + powtough(_powtough), + text(_text), + colors(_colors), + loyalty(_loyalty), + picURLs(_picURLs), + picURLsHq(_picURLsHq), + picURLsSt(_picURLsSt), + cipt(_cipt), + tableRow(_tableRow), + pixmap(NULL) { for (int i = 0; i < sets.size(); i++) sets[i]->append(this); @@ -419,6 +446,8 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info) xml.writeTextElement("pt", info->getPowTough()); xml.writeTextElement("tablerow", QString::number(info->getTableRow())); xml.writeTextElement("text", info->getText()); + if (info->getMainCardType() == "Planeswalker") + xml.writeTextElement("loyalty", QString::number(info->getLoyalty())); if (info->getCipt()) xml.writeTextElement("cipt", "1"); xml.writeEndElement(); // card @@ -546,6 +575,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml) QMap picURLs, picURLsHq, picURLsSt; SetList sets; int tableRow = 0; + int loyalty = 0; bool cipt = false; while (!xml.atEnd()) { if (xml.readNext() == QXmlStreamReader::EndElement) @@ -575,8 +605,10 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml) tableRow = xml.readElementText().toInt(); else if (xml.name() == "cipt") cipt = (xml.readElementText() == "1"); + else if (xml.name() == "loyalty") + loyalty = xml.readElementText().toInt(); } - cardHash.insert(name, new CardInfo(this, name, manacost, type, pt, text, colors, cipt, tableRow, sets, picURLs, picURLsHq, picURLsSt)); + cardHash.insert(name, new CardInfo(this, name, manacost, type, pt, text, colors, loyalty, cipt, tableRow, sets, picURLs, picURLsHq, picURLsSt)); } } } diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index 04a92f0f..fe892a03 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -114,6 +114,7 @@ private: QString powtough; QString text; QStringList colors; + int loyalty; QMap picURLs, picURLsHq, picURLsSt; bool cipt; int tableRow; @@ -127,6 +128,7 @@ public: const QString &_powtough = QString(), const QString &_text = QString(), const QStringList &_colors = QStringList(), + int _loyalty = 0, bool cipt = false, int _tableRow = 0, const SetList &_sets = SetList(), @@ -140,6 +142,7 @@ public: const QString &getCardType() const { return cardtype; } const QString &getPowTough() const { return powtough; } const QString &getText() const { return text; } + const int &getLoyalty() const { return loyalty; } bool getCipt() const { return cipt; } void setText(const QString &_text) { text = _text; } const QStringList &getColors() const { return colors; } @@ -152,6 +155,7 @@ public: QString getCorrectedName() const; int getTableRow() const { return tableRow; } void setTableRow(int _tableRow) { tableRow = _tableRow; } + void setLoyalty(int _loyalty) { loyalty = _loyalty; } void setPicURL(const QString &_set, const QString &_picURL) { picURLs.insert(_set, _picURL); } void setPicURLHq(const QString &_set, const QString &_picURL) { picURLsHq.insert(_set, _picURL); } void setPicURLSt(const QString &_set, const QString &_picURL) { picURLsSt.insert(_set, _picURL); } diff --git a/oracle/src/oracleimporter.cpp b/oracle/src/oracleimporter.cpp index add5e538..18b1be49 100644 --- a/oracle/src/oracleimporter.cpp +++ b/oracle/src/oracleimporter.cpp @@ -73,7 +73,14 @@ bool OracleImporter::readSetsFromXml(QXmlStreamReader &xml) return true; } -CardInfo *OracleImporter::addCard(const QString &setName, QString cardName, int cardId, const QString &cardCost, const QString &cardType, const QString &cardPT, const QStringList &cardText) +CardInfo *OracleImporter::addCard(const QString &setName, + QString cardName, + int cardId, + const QString &cardCost, + const QString &cardType, + const QString &cardPT, + int cardLoyalty, + const QStringList &cardText) { QString fullCardText = cardText.join("\n"); bool splitCard = false; @@ -128,6 +135,9 @@ CardInfo *OracleImporter::addCard(const QString &setName, QString cardName, int tableRow = 2; card->setTableRow(tableRow); + if (mainCardType == "Planeswalker") + card->setLoyalty(cardLoyalty); + cardHash.insert(cardName, card); } card->setPicURL(setName, getPictureUrl(pictureUrl, cardId, cardName, setName)); @@ -164,6 +174,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QByteArray &data) if (divClass.nodeValue() == "textspoiler") { QString cardName, cardCost, cardType, cardPT, cardText; int cardId = 0; + int cardLoyalty = 0; QDomNodeList trs = div.elementsByTagName("tr"); for (int j = 0; j < trs.size(); ++j) { @@ -174,7 +185,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QByteArray &data) for (int i = 0; i < cardTextSplit.size(); ++i) cardTextSplit[i] = cardTextSplit[i].trimmed(); - CardInfo *card = addCard(set->getShortName(), cardName, cardId, cardCost, cardType, cardPT, cardTextSplit); + CardInfo *card = addCard(set->getShortName(), cardName, cardId, cardCost, cardType, cardPT, cardLoyalty, cardTextSplit); if (!set->contains(card)) { card->addToSet(set); cards++; @@ -197,6 +208,8 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QByteArray &data) cardPT = v2.simplified().remove('(').remove(')'); else if (v1 == "Rules Text:") cardText = v2.trimmed(); + else if (v1 == "Loyalty:") + cardLoyalty = v2.trimmed().remove('(').remove(')').toInt(); } } break; diff --git a/oracle/src/oracleimporter.h b/oracle/src/oracleimporter.h index 3f6e4899..c29a7883 100644 --- a/oracle/src/oracleimporter.h +++ b/oracle/src/oracleimporter.h @@ -35,7 +35,7 @@ private: void downloadNextFile(); bool readSetsFromXml(QXmlStreamReader &xml); - CardInfo *addCard(const QString &setName, QString cardName, int cardId, const QString &cardCost, const QString &cardType, const QString &cardPT, const QStringList &cardText); + CardInfo *addCard(const QString &setName, QString cardName, int cardId, const QString &cardCost, const QString &cardType, const QString &cardPT, int cardLoyalty, const QStringList &cardText); private slots: void httpRequestFinished(int requestId, bool error); void readResponseHeader(const QHttpResponseHeader &responseHeader);