void DeckViewScene::rebuildTree() { clearContents(); if (!deck) return; InnerDecklistNode *listRoot = deck->getRoot(); for (int i = 0; i < listRoot->size(); i++) { InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i)); DeckViewCardContainer *container = cardContainers.value(currentZone->getName(), 0); if (!container) { container = new DeckViewCardContainer(currentZone->getName()); cardContainers.insert(currentZone->getName(), container); addItem(container); } for (int j = 0; j < currentZone->size(); j++) { DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j)); if (!currentCard) continue; for (int k = 0; k < currentCard->getNumber(); ++k) { DeckViewCard *newCard = new DeckViewCard(currentCard->getName(), currentZone->getName(), container); container->addCard(newCard); emit newCardAdded(newCard); } } } }
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(); }
bool DeckList::saveToStream_Plain(QTextStream &out) { // Support for this is only possible if the internal structure doesn't get more complicated. for (int i = 0; i < root->size(); i++) { InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i)); for (int j = 0; j < node->size(); j++) { DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j)); out << QString("%1%2 %3\n").arg(node->getName() == "side" ? "SB: " : "").arg(card->getNumber()).arg(card->getName()); } } return true; }
void DeckList::updateDeckHash() { QStringList cardList; for (int i = 0; i < root->size(); i++) { InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i)); for (int j = 0; j < node->size(); j++) { DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j)); for (int k = 0; k < card->getNumber(); ++k) cardList.append((node->getName() == "side" ? "SB:" : "") + card->getName().toLower()); } } cardList.sort(); QByteArray deckHashArray = QCryptographicHash::hash(cardList.join(";").toUtf8(), QCryptographicHash::Sha1); quint64 number = (((quint64) (unsigned char) deckHashArray[0]) << 32) + (((quint64) (unsigned char) deckHashArray[1]) << 24) + (((quint64) (unsigned char) deckHashArray[2] << 16)) + (((quint64) (unsigned char) deckHashArray[3]) << 8) + (quint64) (unsigned char) deckHashArray[4]; deckHash = QString::number(number, 32).rightJustified(8, '0'); emit deckHashChanged(); }
void Server_Player::setupZones() { // This may need to be customized according to the game rules. // ------------------------------------------------------------------ // Create zones Server_CardZone *deckZone = new Server_CardZone(this, "deck", false, HiddenZone); addZone(deckZone); Server_CardZone *sbZone = new Server_CardZone(this, "sb", false, HiddenZone); addZone(sbZone); addZone(new Server_CardZone(this, "table", true, PublicZone)); addZone(new Server_CardZone(this, "hand", false, PrivateZone)); addZone(new Server_CardZone(this, "stack", false, PublicZone)); addZone(new Server_CardZone(this, "grave", false, PublicZone)); addZone(new Server_CardZone(this, "rfg", false, PublicZone)); addCounter(new Server_Counter(0, "life", Color(255, 255, 255), 25, 20)); addCounter(new Server_Counter(1, "w", Color(255, 255, 150), 20, 0)); addCounter(new Server_Counter(2, "u", Color(150, 150, 255), 20, 0)); addCounter(new Server_Counter(3, "b", Color(150, 150, 150), 20, 0)); addCounter(new Server_Counter(4, "r", Color(250, 150, 150), 20, 0)); addCounter(new Server_Counter(5, "g", Color(150, 255, 150), 20, 0)); addCounter(new Server_Counter(6, "x", Color(255, 255, 255), 20, 0)); addCounter(new Server_Counter(7, "storm", Color(255, 255, 255), 20, 0)); initialCards = 7; // ------------------------------------------------------------------ // Assign card ids and create deck from decklist InnerDecklistNode *listRoot = deck->getRoot(); nextCardId = 0; for (int i = 0; i < listRoot->size(); ++i) { InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i)); Server_CardZone *z; if (currentZone->getName() == "main") z = deckZone; else if (currentZone->getName() == "side") z = sbZone; else continue; for (int j = 0; j < currentZone->size(); ++j) { DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j)); if (!currentCard) continue; for (int k = 0; k < currentCard->getNumber(); ++k) z->cards.append(new Server_Card(currentCard->getName(), nextCardId++, 0, 0)); } } const QList<MoveCardToZone *> &sideboardPlan = deck->getCurrentSideboardPlan(); for (int i = 0; i < sideboardPlan.size(); ++i) { MoveCardToZone *m = sideboardPlan[i]; Server_CardZone *start, *target; if (m->getStartZone() == "main") start = deckZone; else if (m->getStartZone() == "side") start = sbZone; else continue; if (m->getTargetZone() == "main") target = deckZone; else if (m->getTargetZone() == "side") target = sbZone; else continue; for (int j = 0; j < start->cards.size(); ++j) if (start->cards[j]->getName() == m->getCardName()) { Server_Card *card = start->cards[j]; start->cards.removeAt(j); target->cards.append(card); break; } } deckZone->shuffle(); }