CardInfo *OracleImporter::addCard(const QString &setName, QString cardName, bool isToken, int cardId, QString &setNumber, QString &cardCost, QString &cmc, const QString &cardType, const QString &cardPT, int cardLoyalty, const QString &cardText, const QStringList & colors, const QStringList & relatedCards, const QStringList & reverseRelatedCards, bool upsideDown ) { QStringList cardTextRows = cardText.split("\n"); // Workaround for card name weirdness cardName = cardName.replace("Æ", "AE"); cardName = cardName.replace("’", "'"); CardInfo * card; if (cards.contains(cardName)) { card = cards.value(cardName); } else { // Remove {} around mana costs cardCost.remove(QChar('{')); cardCost.remove(QChar('}')); // detect mana generator artifacts bool mArtifact = false; if (cardType.endsWith("Artifact")) for (int i = 0; i < cardTextRows.size(); ++i) if (cardTextRows[i].contains("{T}") && cardTextRows[i].contains("to your mana pool")) mArtifact = true; // detect cards that enter the field tapped bool cipt = cardText.contains("Hideaway") || (cardText.contains(cardName + " enters the battlefield tapped") && !cardText.contains(cardName + " enters the battlefield tapped unless")); // insert the card and its properties card = new CardInfo(cardName, isToken, cardCost, cmc, cardType, cardPT, cardText, colors, relatedCards, reverseRelatedCards, upsideDown, cardLoyalty, cipt); int tableRow = 1; QString mainCardType = card->getMainCardType(); if ((mainCardType == "Land") || mArtifact) tableRow = 0; else if ((mainCardType == "Sorcery") || (mainCardType == "Instant")) tableRow = 3; else if (mainCardType == "Creature") tableRow = 2; card->setTableRow(tableRow); cards.insert(cardName, card); } card->setMuId(setName, cardId); card->setSetNumber(setName, setNumber); return card; }
void DeckListModel::rebuildTree() { beginResetModel(); root->clearTree(); InnerDecklistNode *listRoot = deckList->getRoot(); for (int i = 0; i < listRoot->size(); i++) { InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i)); InnerDecklistNode *node = new InnerDecklistNode(currentZone->getName(), root); for (int j = 0; j < currentZone->size(); j++) { DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j)); // XXX better sanity checking if (!currentCard) continue; CardInfo *info = db->getCard(currentCard->getName()); QString cardType; if (!info) cardType = "unknown"; else cardType = info->getMainCardType(); InnerDecklistNode *cardTypeNode = dynamic_cast<InnerDecklistNode *>(node->findChild(cardType)); if (!cardTypeNode) cardTypeNode = new InnerDecklistNode(cardType, node); new DecklistModelCardNode(currentCard, cardTypeNode); } } endResetModel(); }
QModelIndex DeckListModel::addCard(const QString &cardName, const QString &zoneName) { InnerDecklistNode *zoneNode = createNodeIfNeeded(zoneName, root); CardInfo *info = db->getCard(cardName); QString cardType = info->getMainCardType(); InnerDecklistNode *cardTypeNode = createNodeIfNeeded(cardType, zoneNode); DecklistModelCardNode *cardNode = dynamic_cast<DecklistModelCardNode *>(cardTypeNode->findChild(cardName)); if (!cardNode) { DecklistCardNode *decklistCard = deckList->addCard(cardName, zoneName); QModelIndex parentIndex = nodeToIndex(cardTypeNode); beginInsertRows(parentIndex, cardTypeNode->size(), cardTypeNode->size()); cardNode = new DecklistModelCardNode(decklistCard, cardTypeNode); endInsertRows(); sort(1); emitRecursiveUpdates(parentIndex); return nodeToIndex(cardNode); } else { cardNode->setNumber(cardNode->getNumber() + 1); QModelIndex ind = nodeToIndex(cardNode); emitRecursiveUpdates(ind); return ind; } }
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const { CardInfo *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow); if (!cardNameBeginning.isEmpty()) if (!info->getName().startsWith(cardNameBeginning, Qt::CaseInsensitive)) return false; if (!cardName.isEmpty()) if (!info->getName().contains(cardName, Qt::CaseInsensitive)) return false; if (!cardText.isEmpty()) if (!info->getText().contains(cardText, Qt::CaseInsensitive)) return false; if (!cardColors.isEmpty()) if (QSet<QString>::fromList(info->getColors()).intersect(cardColors).isEmpty() && !(info->getColors().isEmpty() && cardColors.contains("X"))) return false; if (!cardTypes.isEmpty()) if (!cardTypes.contains(info->getMainCardType())) return false; return true; }
DecklistModelCardNode *DeckListModel::findCardNode(const QString &cardName, const QString &zoneName) const { InnerDecklistNode *zoneNode, *typeNode; CardInfo *info; QString cardType; zoneNode = dynamic_cast<InnerDecklistNode *>(root->findChild(zoneName)); if(!zoneNode) return NULL; info = db->getCard(cardName); if(!info) return NULL; cardType = info->getMainCardType(); typeNode = dynamic_cast<InnerDecklistNode *>(zoneNode->findChild(cardType)); if(!typeNode) return NULL; return dynamic_cast<DecklistModelCardNode *>(typeNode->findChild(cardName)); }
CardInfo *OracleImporter::addCard(const QString &setName, QString cardName, bool isToken, int cardId, const QString &cardCost, const QString &cardType, const QString &cardPT, int cardLoyalty, const QStringList &cardText) { QString fullCardText = cardText.join("\n"); bool splitCard = false; if (cardName.contains('(')) { cardName.remove(QRegExp(" \\(.*\\)")); splitCard = true; } // Workaround for card name weirdness if (cardName.contains("XX")) cardName.remove("XX"); cardName = cardName.replace("Æ", "AE"); cardName = cardName.replace("’", "'"); CardInfo *card; if (cardHash.contains(cardName)) { card = cardHash.value(cardName); if (splitCard && !card->getText().contains(fullCardText)) card->setText(card->getText() + "\n---\n" + fullCardText); } else { bool mArtifact = false; if (cardType.endsWith("Artifact")) for (int i = 0; i < cardText.size(); ++i) if (cardText[i].contains("{T}") && cardText[i].contains("to your mana pool")) mArtifact = true; QStringList colors; QStringList allColors = QStringList() << "W" << "U" << "B" << "R" << "G"; for (int i = 0; i < allColors.size(); i++) if (cardCost.contains(allColors[i])) colors << allColors[i]; if (cardText.contains(cardName + " is white.")) colors << "W"; if (cardText.contains(cardName + " is blue.")) colors << "U"; if (cardText.contains(cardName + " is black.")) colors << "B"; if (cardText.contains(cardName + " is red.")) colors << "R"; if (cardText.contains(cardName + " is green.")) colors << "G"; bool cipt = (cardText.contains(cardName + " enters the battlefield tapped.")); card = new CardInfo(this, cardName, isToken, cardCost, cardType, cardPT, fullCardText, colors, cardLoyalty, cipt); int tableRow = 1; QString mainCardType = card->getMainCardType(); if ((mainCardType == "Land") || mArtifact) tableRow = 0; else if ((mainCardType == "Sorcery") || (mainCardType == "Instant")) tableRow = 3; else if (mainCardType == "Creature") tableRow = 2; card->setTableRow(tableRow); cardHash.insert(cardName, card); } card->setPicURL(setName, getPictureUrl(pictureUrl, cardId, cardName, setName)); card->setPicURLHq(setName, getPictureUrl(pictureUrlHq, cardId, cardName, setName)); card->setPicURLSt(setName, getPictureUrl(pictureUrlSt, cardId, cardName, setName)); return card; }