#include "stats_tally.h" #include "../board/card_item.h" #include #include #include static int sumPowers(const QList &cards) { // calculate total power; int total = 0; for (auto card : cards) { QVariantList parsed = CardItem::parsePT(card->getPT()); if (!parsed.isEmpty()) { int power = parsed.first().toInt(); // toInt will default to 0 if it's not an int total += qMax(power, 0); } } return total; } QList StatsTally::computeTotalPower(const QList &cards) { // don't bother if none of the cards have pt bool hasPT = std::any_of(cards.cbegin(), cards.cend(), [](const CardItem *card) { return !card->getPT().isEmpty(); }); if (!hasPT) { return {}; } int total = sumPowers(cards); QString name = QCoreApplication::translate("StatsTally", "Total Power"); return {TallyRow{name, QString::number(total)}}; } static int sumToughness(const QList &cards) { int total = 0; for (auto card : cards) { QVariantList parsed = CardItem::parsePT(card->getPT()); if (parsed.size() == 2) { int toughness = parsed.at(1).toInt(); // toInt will default to 0 if it's not an int total += qMax(toughness, 0); } } return total; } QList StatsTally::computeTotalToughness(const QList &cards) { // don't bother if none of the cards have pt bool hasPT = std::any_of(cards.cbegin(), cards.cend(), [](const CardItem *card) { return !card->getPT().isEmpty(); }); if (!hasPT) { return {}; } int total = sumToughness(cards); QString name = QCoreApplication::translate("StatsTally", "Total Toughness"); return {TallyRow{name, QString::number(total)}}; }