diff --git a/cockatrice/src/interface/widgets/cards/deck_card_zone_display_widget.cpp b/cockatrice/src/interface/widgets/cards/deck_card_zone_display_widget.cpp index 4742467b1..7d45d9cc9 100644 --- a/cockatrice/src/interface/widgets/cards/deck_card_zone_display_widget.cpp +++ b/cockatrice/src/interface/widgets/cards/deck_card_zone_display_widget.cpp @@ -2,6 +2,7 @@ #include "card_group_display_widgets/flat_card_group_display_widget.h" #include "card_group_display_widgets/overlapped_card_group_display_widget.h" +#include "libcockatrice/card/database/card_database_manager.h" #include #include @@ -230,10 +231,13 @@ QList DeckCardZoneDisplayWidget::getGroupCriteriaValueList() { QList groupCriteriaValues; - QList cardsInZone = deckListModel->getCardsForZone(zoneName); + QList nodes = deckListModel->getCardNodesForZone(zoneName); - for (const ExactCard &cardInZone : cardsInZone) { - groupCriteriaValues.append(cardInZone.getInfo().getProperty(activeGroupCriteria)); + for (auto node : nodes) { + CardInfoPtr info = CardDatabaseManager::query()->getCardInfo(node->getName()); + if (info) { + groupCriteriaValues.append(info->getProperty(activeGroupCriteria)); + } } groupCriteriaValues.removeDuplicates(); diff --git a/cockatrice/src/interface/widgets/deck_analytics/analyzer_modules/draw_probability/draw_probability_widget.cpp b/cockatrice/src/interface/widgets/deck_analytics/analyzer_modules/draw_probability/draw_probability_widget.cpp index 92ebea630..146ab6f1c 100644 --- a/cockatrice/src/interface/widgets/deck_analytics/analyzer_modules/draw_probability/draw_probability_widget.cpp +++ b/cockatrice/src/interface/widgets/deck_analytics/analyzer_modules/draw_probability/draw_probability_widget.cpp @@ -170,7 +170,7 @@ void DrawProbabilityWidget::updateFilterOptions() const auto nodes = analyzer->getModel()->getCardNodes(); for (auto *node : nodes) { - CardInfoPtr info = CardDatabaseManager::query()->getCard({node->getName()}).getCardPtr(); + CardInfoPtr info = CardDatabaseManager::query()->getCardInfo(node->getName()); if (!info) { continue; } diff --git a/cockatrice/src/interface/widgets/deck_analytics/deck_list_statistics_analyzer.cpp b/cockatrice/src/interface/widgets/deck_analytics/deck_list_statistics_analyzer.cpp index 7d0259c72..a1dc1ab55 100644 --- a/cockatrice/src/interface/widgets/deck_analytics/deck_list_statistics_analyzer.cpp +++ b/cockatrice/src/interface/widgets/deck_analytics/deck_list_statistics_analyzer.cpp @@ -19,82 +19,91 @@ void DeckListStatisticsAnalyzer::analyze() { clearData(); - QList cards = model->getCards(); + QList nodes = model->getCardNodes(); - for (auto card : cards) { - auto info = card.getInfo(); - const int cmc = info.getCmc().toInt(); + for (auto node : nodes) { + CardInfoPtr info = CardDatabaseManager::query()->getCardInfo(node->getName()); + if (!info) { + continue; + } + + const int amount = node->getNumber(); + QStringList copiesOfName; + for (int i = 0; i < amount; i++) { + copiesOfName.append(node->getName()); + } // Convert once - QStringList types = info.getMainCardType().split(' '); - QStringList subtypes = info.getCardType().split('-').last().split(" "); - QString colors = info.getColors(); - int power = info.getPowTough().split("/").first().toInt(); - int toughness = info.getPowTough().split("/").last().toInt(); + const int cmc = info->getCmc().toInt(); + QStringList types = info->getMainCardType().split(' '); + QStringList subtypes = info->getCardType().split('-').last().split(" "); + QString colors = info->getColors(); + int power = info->getPowTough().split("/").first().toInt(); + int toughness = info->getPowTough().split("/").last().toInt(); // For each copy of card // ---------------- Mana Curve ---------------- if (config.computeManaCurve) { - manaCurveMap[cmc]++; + manaCurveMap[cmc] += amount; } // per-type curve for (auto &t : types) { - manaCurveByType[t][cmc]++; - manaCurveCardsByType[t][cmc].append(info.getName()); + manaCurveByType[t][cmc] += amount; + manaCurveCardsByType[t][cmc] << copiesOfName; } // Per-subtype curve for (auto &st : subtypes) { - manaCurveBySubtype[st][cmc]++; - manaCurveCardsBySubtype[st][cmc].append(info.getName()); + manaCurveBySubtype[st][cmc] += amount; + manaCurveCardsBySubtype[st][cmc] << copiesOfName; } // per-color curve for (auto &c : colors) { - manaCurveByColor[c][cmc]++; - manaCurveCardsByColor[c][cmc].append(info.getName()); + manaCurveByColor[c][cmc] += amount; + manaCurveCardsByColor[c][cmc] << copiesOfName; } // Power/toughness - manaCurveByPower[QString::number(power)][cmc]++; - manaCurveCardsByPower[QString::number(power)][cmc].append(info.getName()); - manaCurveByToughness[QString::number(toughness)][cmc]++; - manaCurveCardsByToughness[QString::number(toughness)][cmc].append(info.getName()); + manaCurveByPower[QString::number(power)][cmc] += amount; + manaCurveCardsByPower[QString::number(power)][cmc] << copiesOfName; + manaCurveByToughness[QString::number(toughness)][cmc] += amount; + manaCurveCardsByToughness[QString::number(toughness)][cmc] << copiesOfName; // ========== Category Counts =========== for (auto &t : types) { - typeCount[t]++; + typeCount[t] += amount; } for (auto &st : subtypes) { - subtypeCount[st]++; + subtypeCount[st] += amount; } for (auto &c : colors) { - colorCount[c]++; + colorCount[c] += amount; } - manaValueCount[cmc]++; + manaValueCount[cmc] += amount; // ---------------- Mana Base ---------------- if (config.computeManaBase) { - auto prod = determineManaProduction(info.getText()); + auto prod = determineManaProduction(info->getText()); for (auto it = prod.begin(); it != prod.end(); ++it) { if (it.value() > 0) { - productionPipCount[it.key()] += it.value(); - productionCardCount[it.key()]++; + productionPipCount[it.key()] += it.value() * amount; + productionCardCount[it.key()] += amount; } - manaBaseMap[it.key()] += it.value(); + manaBaseMap[it.key()] += it.value() * amount; } } // ---------------- Devotion ---------------- if (config.computeDevotion) { - auto devo = countManaSymbols(info.getManaCost()); + auto devo = countManaSymbols(info->getManaCost()); for (auto &d : devo) { if (d.second > 0) { - devotionPipCount[QString(d.first)] += d.second; - devotionCardCount[QString(d.first)]++; + devotionPipCount[QString(d.first)] += d.second * amount; + devotionCardCount[QString(d.first)] += amount; } - manaDevotionMap[d.first] += d.second; + manaDevotionMap[d.first] += d.second * amount; } } } diff --git a/cockatrice/src/interface/widgets/visual_deck_editor/visual_deck_editor_sample_hand_widget.cpp b/cockatrice/src/interface/widgets/visual_deck_editor/visual_deck_editor_sample_hand_widget.cpp index 24f521760..fb5ae780c 100644 --- a/cockatrice/src/interface/widgets/visual_deck_editor/visual_deck_editor_sample_hand_widget.cpp +++ b/cockatrice/src/interface/widgets/visual_deck_editor/visual_deck_editor_sample_hand_widget.cpp @@ -81,13 +81,30 @@ void VisualDeckEditorSampleHandWidget::updateDisplay() } } +static QList cardNodesToExactCards(QList nodes) +{ + QList 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 VisualDeckEditorSampleHandWidget::getRandomCards(int amountToGet) { QList randomCards; if (!deckListModel) return randomCards; - QList mainDeckCards = deckListModel->getCardsForZone(DECK_ZONE_MAIN); + QList mainDeckCards = cardNodesToExactCards(deckListModel->getCardNodesForZone(DECK_ZONE_MAIN)); if (mainDeckCards.isEmpty()) return randomCards; diff --git a/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.cpp b/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.cpp index 23dbd7fec..499208a6d 100644 --- a/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.cpp +++ b/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.cpp @@ -608,35 +608,6 @@ void DeckListModel::forEachCard(const std::functionforEachCard(func); } -static QList cardNodesToExactCards(QList nodes) -{ - QList 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 DeckListModel::getCards() const -{ - auto nodes = deckList->getCardNodes(); - return cardNodesToExactCards(nodes); -} - -QList DeckListModel::getCardsForZone(const QString &zoneName) const -{ - auto nodes = deckList->getCardNodes({zoneName}); - return cardNodesToExactCards(nodes); -} - QList DeckListModel::getCardNodes() const { return deckList->getCardNodes(); diff --git a/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.h b/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.h index e7a79d13e..133e7a947 100644 --- a/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.h +++ b/libcockatrice_models/libcockatrice/models/deck_list/deck_list_model.h @@ -329,16 +329,6 @@ public: */ void forEachCard(const std::function &func); - /** - * @brief Creates a list consisting of the entries of the model mapped into ExactCards (with each entry looked up - * in the card database). - * If a card node has number > 1, it will be added that many times to the list. - * If an entry's card is not found in the card database, that entry will be left out of the list. - * @return An ordered list of ExactCards - */ - [[nodiscard]] QList getCards() const; - [[nodiscard]] QList getCardsForZone(const QString &zoneName) const; - /** * @brief Gets a list of all card nodes in the deck. */