[DeckListModel] optimize by iterating over cardNodes instead of ExactCards (#6485)

* [DeckListModel] optimize by iterating over cardNodes instead of ExactCards

* fix build failure

* another optimization

* fix build failure
This commit is contained in:
RickyRister 2026-01-03 19:19:04 -08:00 committed by GitHub
parent f16c552d97
commit 746f2af044
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 67 additions and 76 deletions

View file

@ -81,13 +81,30 @@ void VisualDeckEditorSampleHandWidget::updateDisplay()
}
}
static QList<ExactCard> cardNodesToExactCards(QList<const DecklistCardNode *> nodes)
{
QList<ExactCard> cards;
for (auto node : nodes) {
ExactCard card = CardDatabaseManager::query()->getCard(node->toCardRef());
if (card) {
for (int k = 0; k < node->getNumber(); ++k) {
cards.append(card);
}
} else {
qDebug() << "Card not found in database!";
}
}
return cards;
}
QList<ExactCard> VisualDeckEditorSampleHandWidget::getRandomCards(int amountToGet)
{
QList<ExactCard> randomCards;
if (!deckListModel)
return randomCards;
QList<ExactCard> mainDeckCards = deckListModel->getCardsForZone(DECK_ZONE_MAIN);
QList<ExactCard> mainDeckCards = cardNodesToExactCards(deckListModel->getCardNodesForZone(DECK_ZONE_MAIN));
if (mainDeckCards.isEmpty())
return randomCards;