Import related cards in the card database

This commit is contained in:
Fabio Bas 2015-06-11 10:48:50 +02:00
parent 50b908c7c4
commit da84bb33e1
4 changed files with 28 additions and 9 deletions

View file

@ -482,13 +482,15 @@ CardInfo::CardInfo(CardDatabase *_db,
const QString &_powtough, const QString &_powtough,
const QString &_text, const QString &_text,
const QStringList &_colors, const QStringList &_colors,
const QStringList &_relatedCards,
int _loyalty, int _loyalty,
bool _cipt, bool _cipt,
int _tableRow, int _tableRow,
const SetList &_sets, const SetList &_sets,
const QStringMap &_customPicURLs, const QStringMap &_customPicURLs,
const QStringMap &_customPicURLsHq, const QStringMap &_customPicURLsHq,
MuidMap _muIds) MuidMap _muIds
)
: db(_db), : db(_db),
name(_name), name(_name),
isToken(_isToken), isToken(_isToken),
@ -499,6 +501,7 @@ CardInfo::CardInfo(CardDatabase *_db,
powtough(_powtough), powtough(_powtough),
text(_text), text(_text),
colors(_colors), colors(_colors),
relatedCards(_relatedCards),
loyalty(_loyalty), loyalty(_loyalty),
customPicURLs(_customPicURLs), customPicURLs(_customPicURLs),
customPicURLsHq(_customPicURLsHq), customPicURLsHq(_customPicURLsHq),
@ -685,6 +688,10 @@ static QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
for (int i = 0; i < colors.size(); i++) for (int i = 0; i < colors.size(); i++)
xml.writeTextElement("color", colors[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("manacost", info->getManaCost());
xml.writeTextElement("cmc", info->getCmc()); xml.writeTextElement("cmc", info->getCmc());
xml.writeTextElement("type", info->getCardType()); xml.writeTextElement("type", info->getCardType());
@ -852,7 +859,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens)
break; break;
if (xml.name() == "card") { if (xml.name() == "card") {
QString name, manacost, cmc, type, pt, text; QString name, manacost, cmc, type, pt, text;
QStringList colors; QStringList colors, relatedCards;
QStringMap customPicURLs, customPicURLsHq; QStringMap customPicURLs, customPicURLsHq;
MuidMap muids; MuidMap muids;
SetList sets; SetList sets;
@ -890,6 +897,8 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens)
} }
} else if (xml.name() == "color") } else if (xml.name() == "color")
colors << xml.readElementText(); colors << xml.readElementText();
else if (xml.name() == "related")
relatedCards << xml.readElementText();
else if (xml.name() == "tablerow") else if (xml.name() == "tablerow")
tableRow = xml.readElementText().toInt(); tableRow = xml.readElementText().toInt();
else if (xml.name() == "cipt") else if (xml.name() == "cipt")
@ -901,7 +910,7 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens)
} }
if (isToken == 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));
} }
} }
} }

View file

@ -138,6 +138,7 @@ private:
bool cipt; bool cipt;
int tableRow; int tableRow;
QString pixmapCacheKey; QString pixmapCacheKey;
QStringList relatedCards;
public: public:
CardInfo(CardDatabase *_db, CardInfo(CardDatabase *_db,
const QString &_name = QString(), const QString &_name = QString(),
@ -148,13 +149,15 @@ 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(),
const QStringList &_relatedCards = QStringList(),
int _loyalty = 0, int _loyalty = 0,
bool _cipt = false, bool _cipt = false,
int _tableRow = 0, int _tableRow = 0,
const SetList &_sets = SetList(), const SetList &_sets = SetList(),
const QStringMap &_customPicURLs = QStringMap(), const QStringMap &_customPicURLs = QStringMap(),
const QStringMap &_customPicURLsHq = QStringMap(), const QStringMap &_customPicURLsHq = QStringMap(),
MuidMap muids = MuidMap()); MuidMap muids = MuidMap()
);
~CardInfo(); ~CardInfo();
const QString &getName() const { return name; } const QString &getName() const { return name; }
const QString &getSimpleName() const { return simpleName; } const QString &getSimpleName() const { return simpleName; }
@ -174,6 +177,7 @@ public:
void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); } void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); }
void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); } void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); }
const QStringList &getColors() const { return colors; } const QStringList &getColors() const { return colors; }
const QStringList &getRelatedCards() const { return relatedCards; }
QString getCustomPicURL(const QString &set) const { return customPicURLs.value(set); } QString getCustomPicURL(const QString &set) const { return customPicURLs.value(set); }
QString getCustomPicURLHq(const QString &set) const { return customPicURLsHq.value(set); } QString getCustomPicURLHq(const QString &set) const { return customPicURLsHq.value(set); }
int getMuId(const QString &set) const { return muIds.value(set); } int getMuId(const QString &set) const { return muIds.value(set); }

View file

@ -65,7 +65,9 @@ CardInfo *OracleImporter::addCard(const QString &setName,
const QString &cardPT, const QString &cardPT,
int cardLoyalty, int cardLoyalty,
const QString &cardText, const QString &cardText,
const QStringList & colors) const QStringList & colors,
const QStringList & relatedCards
)
{ {
QStringList cardTextRows = cardText.split("\n"); QStringList cardTextRows = cardText.split("\n");
bool splitCard = false; 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")); 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; int tableRow = 1;
QString mainCardType = card->getMainCardType(); QString mainCardType = card->getMainCardType();
if ((mainCardType == "Land") || mArtifact) if ((mainCardType == "Land") || mArtifact)
@ -147,6 +149,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data)
QString cardPT; QString cardPT;
QString cardText; QString cardText;
QStringList colors; QStringList colors;
QStringList relatedCards;
int cardId; int cardId;
int cardLoyalty; int cardLoyalty;
bool cardIsToken = false; bool cardIsToken = false;
@ -169,7 +172,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data)
cardLoyalty = 0; cardLoyalty = 0;
// determine which subcard is the first one in the split // 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 && if(names.count()>0 &&
map.contains("name") && map.contains("name") &&
0 == QString::compare(map.value("name").toString(), names.at(0))) 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); extractColors(card2->value("colors").toStringList(), colors);
colors.removeDuplicates(); colors.removeDuplicates();
relatedCards = QStringList();
} else { } else {
// first card of a pair; enqueue for later merging // first card of a pair; enqueue for later merging
// Conditional on cardId because promo prints have no muid - see #640 // 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; cardId = map.contains("multiverseid") ? map.value("multiverseid").toInt() : 0;
cardLoyalty = map.contains("loyalty") ? map.value("loyalty").toInt() : 0; cardLoyalty = map.contains("loyalty") ? map.value("loyalty").toInt() : 0;
cardIsToken = map.value("layout") == "token"; cardIsToken = map.value("layout") == "token";
relatedCards = map.contains("names") ? map.value("names").toStringList() : QStringList();
relatedCards.removeAll(cardName);
colors.clear(); colors.clear();
extractColors(map.value("colors").toStringList(), colors); extractColors(map.value("colors").toStringList(), colors);
@ -233,7 +239,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QVariant &data)
} }
if (!cardIsToken) { 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)) { if (!set->contains(card)) {
card->addToSet(set); card->addToSet(set);

View file

@ -29,7 +29,7 @@ private:
QVariantMap setsMap; QVariantMap setsMap;
QString dataDir; 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: signals:
void setIndexChanged(int cardsImported, int setIndex, const QString &setName); void setIndexChanged(int cardsImported, int setIndex, const QString &setName);
void dataReadProgress(int bytesRead, int totalBytes); void dataReadProgress(int bytesRead, int totalBytes);