Additionally, remove an unneeded split() + join() call on every card
text
This commit is contained in:
Fabio Bas 2015-03-29 17:48:59 +02:00
parent 49c1eec345
commit 48d588f6cd
2 changed files with 16 additions and 15 deletions

View file

@ -69,9 +69,9 @@ CardInfo *OracleImporter::addCard(const QString &setName,
const QString &cardType, const QString &cardType,
const QString &cardPT, const QString &cardPT,
int cardLoyalty, int cardLoyalty,
const QStringList &cardText) const QString &cardText)
{ {
QString fullCardText = cardText.join("\n"); QStringList cardTextRows = cardText.split("\n");
bool splitCard = false; bool splitCard = false;
if (cardName.contains('(')) { if (cardName.contains('(')) {
cardName.remove(QRegExp(" \\(.*\\)")); cardName.remove(QRegExp(" \\(.*\\)"));
@ -90,13 +90,13 @@ CardInfo *OracleImporter::addCard(const QString &setName,
CardInfo *card; CardInfo *card;
if (cards.contains(cardName)) { if (cards.contains(cardName)) {
card = cards.value(cardName); card = cards.value(cardName);
if (splitCard && !card->getText().contains(fullCardText)) if (splitCard && !card->getText().contains(cardText))
card->setText(card->getText() + "\n---\n" + fullCardText); card->setText(card->getText() + "\n---\n" + cardText);
} else { } else {
bool mArtifact = false; bool mArtifact = false;
if (cardType.endsWith("Artifact")) if (cardType.endsWith("Artifact"))
for (int i = 0; i < cardText.size(); ++i) for (int i = 0; i < cardTextRows.size(); ++i)
if (cardText[i].contains("{T}") && cardText[i].contains("to your mana pool")) if (cardTextRows[i].contains("{T}") && cardTextRows[i].contains("to your mana pool"))
mArtifact = true; mArtifact = true;
QStringList colors; QStringList colors;
@ -105,20 +105,21 @@ CardInfo *OracleImporter::addCard(const QString &setName,
if (cardCost.contains(allColors[i])) if (cardCost.contains(allColors[i]))
colors << allColors[i]; colors << allColors[i];
if (cardText.contains(cardName + " is white.")) if (cardTextRows.contains(cardName + " is white."))
colors << "W"; colors << "W";
if (cardText.contains(cardName + " is blue.")) if (cardTextRows.contains(cardName + " is blue."))
colors << "U"; colors << "U";
if (cardText.contains(cardName + " is black.")) if (cardTextRows.contains(cardName + " is black."))
colors << "B"; colors << "B";
if (cardText.contains(cardName + " is red.")) if (cardTextRows.contains(cardName + " is red."))
colors << "R"; colors << "R";
if (cardText.contains(cardName + " is green.")) if (cardTextRows.contains(cardName + " is green."))
colors << "G"; colors << "G";
bool cipt = (cardText.contains(cardName + " enters the battlefield tapped.")); bool cipt = 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, fullCardText, colors, cardLoyalty, cipt); card = new CardInfo(this, cardName, isToken, cardCost, cmc, cardType, cardPT, cardText, colors, cardLoyalty, cipt);
int tableRow = 1; int tableRow = 1;
QString mainCardType = card->getMainCardType(); QString mainCardType = card->getMainCardType();
if ((mainCardType == "Land") || mArtifact) if ((mainCardType == "Land") || mArtifact)
@ -225,7 +226,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.split("\n")); CardInfo *card = addCard(set->getShortName(), cardName, cardIsToken, cardId, cardCost, cmc, cardType, cardPT, cardLoyalty, cardText);
if (!set->contains(card)) { if (!set->contains(card)) {
card->addToSet(set); card->addToSet(set);

View file

@ -32,7 +32,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 QStringList &cardText); 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);
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);