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:
parent
e3c1ad2da6
commit
a7f3ce4050
4 changed files with 55 additions and 6 deletions
|
@ -256,8 +256,35 @@ void PictureLoadingThread::waitForInit()
|
||||||
mutex.unlock();
|
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)
|
CardInfo::CardInfo(CardDatabase *_db,
|
||||||
: 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)
|
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++)
|
for (int i = 0; i < sets.size(); i++)
|
||||||
sets[i]->append(this);
|
sets[i]->append(this);
|
||||||
|
@ -419,6 +446,8 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
|
||||||
xml.writeTextElement("pt", info->getPowTough());
|
xml.writeTextElement("pt", info->getPowTough());
|
||||||
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")
|
||||||
|
xml.writeTextElement("loyalty", QString::number(info->getLoyalty()));
|
||||||
if (info->getCipt())
|
if (info->getCipt())
|
||||||
xml.writeTextElement("cipt", "1");
|
xml.writeTextElement("cipt", "1");
|
||||||
xml.writeEndElement(); // card
|
xml.writeEndElement(); // card
|
||||||
|
@ -546,6 +575,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
|
||||||
QMap<QString, QString> picURLs, picURLsHq, picURLsSt;
|
QMap<QString, QString> picURLs, picURLsHq, picURLsSt;
|
||||||
SetList sets;
|
SetList sets;
|
||||||
int tableRow = 0;
|
int tableRow = 0;
|
||||||
|
int loyalty = 0;
|
||||||
bool cipt = false;
|
bool cipt = false;
|
||||||
while (!xml.atEnd()) {
|
while (!xml.atEnd()) {
|
||||||
if (xml.readNext() == QXmlStreamReader::EndElement)
|
if (xml.readNext() == QXmlStreamReader::EndElement)
|
||||||
|
@ -575,8 +605,10 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
|
||||||
tableRow = xml.readElementText().toInt();
|
tableRow = xml.readElementText().toInt();
|
||||||
else if (xml.name() == "cipt")
|
else if (xml.name() == "cipt")
|
||||||
cipt = (xml.readElementText() == "1");
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,7 @@ private:
|
||||||
QString powtough;
|
QString powtough;
|
||||||
QString text;
|
QString text;
|
||||||
QStringList colors;
|
QStringList colors;
|
||||||
|
int loyalty;
|
||||||
QMap<QString, QString> picURLs, picURLsHq, picURLsSt;
|
QMap<QString, QString> picURLs, picURLsHq, picURLsSt;
|
||||||
bool cipt;
|
bool cipt;
|
||||||
int tableRow;
|
int tableRow;
|
||||||
|
@ -127,6 +128,7 @@ public:
|
||||||
const QString &_powtough = QString(),
|
const QString &_powtough = QString(),
|
||||||
const QString &_text = QString(),
|
const QString &_text = QString(),
|
||||||
const QStringList &_colors = QStringList(),
|
const QStringList &_colors = QStringList(),
|
||||||
|
int _loyalty = 0,
|
||||||
bool cipt = false,
|
bool cipt = false,
|
||||||
int _tableRow = 0,
|
int _tableRow = 0,
|
||||||
const SetList &_sets = SetList(),
|
const SetList &_sets = SetList(),
|
||||||
|
@ -140,6 +142,7 @@ public:
|
||||||
const QString &getCardType() const { return cardtype; }
|
const QString &getCardType() const { return cardtype; }
|
||||||
const QString &getPowTough() const { return powtough; }
|
const QString &getPowTough() const { return powtough; }
|
||||||
const QString &getText() const { return text; }
|
const QString &getText() const { return text; }
|
||||||
|
const int &getLoyalty() const { return loyalty; }
|
||||||
bool getCipt() const { return cipt; }
|
bool getCipt() const { return cipt; }
|
||||||
void setText(const QString &_text) { text = _text; }
|
void setText(const QString &_text) { text = _text; }
|
||||||
const QStringList &getColors() const { return colors; }
|
const QStringList &getColors() const { return colors; }
|
||||||
|
@ -152,6 +155,7 @@ public:
|
||||||
QString getCorrectedName() const;
|
QString getCorrectedName() const;
|
||||||
int getTableRow() const { return tableRow; }
|
int getTableRow() const { return tableRow; }
|
||||||
void setTableRow(int _tableRow) { tableRow = _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 setPicURL(const QString &_set, const QString &_picURL) { picURLs.insert(_set, _picURL); }
|
||||||
void setPicURLHq(const QString &_set, const QString &_picURL) { picURLsHq.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); }
|
void setPicURLSt(const QString &_set, const QString &_picURL) { picURLsSt.insert(_set, _picURL); }
|
||||||
|
|
|
@ -73,7 +73,14 @@ bool OracleImporter::readSetsFromXml(QXmlStreamReader &xml)
|
||||||
return true;
|
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");
|
QString fullCardText = cardText.join("\n");
|
||||||
bool splitCard = false;
|
bool splitCard = false;
|
||||||
|
@ -128,6 +135,9 @@ CardInfo *OracleImporter::addCard(const QString &setName, QString cardName, int
|
||||||
tableRow = 2;
|
tableRow = 2;
|
||||||
card->setTableRow(tableRow);
|
card->setTableRow(tableRow);
|
||||||
|
|
||||||
|
if (mainCardType == "Planeswalker")
|
||||||
|
card->setLoyalty(cardLoyalty);
|
||||||
|
|
||||||
cardHash.insert(cardName, card);
|
cardHash.insert(cardName, card);
|
||||||
}
|
}
|
||||||
card->setPicURL(setName, getPictureUrl(pictureUrl, cardId, cardName, setName));
|
card->setPicURL(setName, getPictureUrl(pictureUrl, cardId, cardName, setName));
|
||||||
|
@ -164,6 +174,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QByteArray &data)
|
||||||
if (divClass.nodeValue() == "textspoiler") {
|
if (divClass.nodeValue() == "textspoiler") {
|
||||||
QString cardName, cardCost, cardType, cardPT, cardText;
|
QString cardName, cardCost, cardType, cardPT, cardText;
|
||||||
int cardId = 0;
|
int cardId = 0;
|
||||||
|
int cardLoyalty = 0;
|
||||||
|
|
||||||
QDomNodeList trs = div.elementsByTagName("tr");
|
QDomNodeList trs = div.elementsByTagName("tr");
|
||||||
for (int j = 0; j < trs.size(); ++j) {
|
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)
|
for (int i = 0; i < cardTextSplit.size(); ++i)
|
||||||
cardTextSplit[i] = cardTextSplit[i].trimmed();
|
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)) {
|
if (!set->contains(card)) {
|
||||||
card->addToSet(set);
|
card->addToSet(set);
|
||||||
cards++;
|
cards++;
|
||||||
|
@ -197,6 +208,8 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QByteArray &data)
|
||||||
cardPT = v2.simplified().remove('(').remove(')');
|
cardPT = v2.simplified().remove('(').remove(')');
|
||||||
else if (v1 == "Rules Text:")
|
else if (v1 == "Rules Text:")
|
||||||
cardText = v2.trimmed();
|
cardText = v2.trimmed();
|
||||||
|
else if (v1 == "Loyalty:")
|
||||||
|
cardLoyalty = v2.trimmed().remove('(').remove(')').toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -35,7 +35,7 @@ private:
|
||||||
|
|
||||||
void downloadNextFile();
|
void downloadNextFile();
|
||||||
bool readSetsFromXml(QXmlStreamReader &xml);
|
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:
|
private slots:
|
||||||
void httpRequestFinished(int requestId, bool error);
|
void httpRequestFinished(int requestId, bool error);
|
||||||
void readResponseHeader(const QHttpResponseHeader &responseHeader);
|
void readResponseHeader(const QHttpResponseHeader &responseHeader);
|
||||||
|
|
Loading…
Reference in a new issue