Add code support for planeswalker loyalty.

Added to CardInfo object and to the oracle importer. Next step is the
card info widget.
This commit is contained in:
Daenyth 2011-12-03 16:03:45 -05:00
parent e3c1ad2da6
commit a7f3ce4050
4 changed files with 55 additions and 6 deletions

View file

@ -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<QString, QString> &_picURLs, const QMap<QString, QString> &_picURLsHq, const QMap<QString, QString> &_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<QString, QString> &_picURLs,
const QMap<QString, QString> &_picURLsHq,
const QMap<QString, QString> &_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<QString, QString> 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));
}
}
}

View file

@ -114,6 +114,7 @@ private:
QString powtough;
QString text;
QStringList colors;
int loyalty;
QMap<QString, QString> 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); }

View file

@ -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;

View file

@ -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);