mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-23 10:05:10 -07:00
[Game] Implement total toughness tally (#7252)
This commit is contained in:
parent
ada774f5cc
commit
0f003eabf9
6 changed files with 44 additions and 1 deletions
|
|
@ -12,11 +12,13 @@ TallyMenu::TallyMenu()
|
||||||
aTallyNone = createTallyAction(TallyType::None);
|
aTallyNone = createTallyAction(TallyType::None);
|
||||||
aTallySubtypes = createTallyAction(TallyType::Subtypes);
|
aTallySubtypes = createTallyAction(TallyType::Subtypes);
|
||||||
aTallyTotalPower = createTallyAction(TallyType::TotalPower);
|
aTallyTotalPower = createTallyAction(TallyType::TotalPower);
|
||||||
|
aTallyTotalToughness = createTallyAction(TallyType::TotalToughness);
|
||||||
|
|
||||||
addAction(aTallyNone);
|
addAction(aTallyNone);
|
||||||
addSeparator();
|
addSeparator();
|
||||||
addAction(aTallySubtypes);
|
addAction(aTallySubtypes);
|
||||||
addAction(aTallyTotalPower);
|
addAction(aTallyTotalPower);
|
||||||
|
addAction(aTallyTotalToughness);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
@ -54,4 +56,5 @@ void TallyMenu::retranslateUi()
|
||||||
aTallyNone->setText(tr("None"));
|
aTallyNone->setText(tr("None"));
|
||||||
aTallySubtypes->setText(tr("Subtypes"));
|
aTallySubtypes->setText(tr("Subtypes"));
|
||||||
aTallyTotalPower->setText(tr("Total Power"));
|
aTallyTotalPower->setText(tr("Total Power"));
|
||||||
|
aTallyTotalToughness->setText(tr("Total Toughness"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ private:
|
||||||
QAction *aTallyNone = nullptr;
|
QAction *aTallyNone = nullptr;
|
||||||
QAction *aTallySubtypes = nullptr;
|
QAction *aTallySubtypes = nullptr;
|
||||||
QAction *aTallyTotalPower = nullptr;
|
QAction *aTallyTotalPower = nullptr;
|
||||||
|
QAction *aTallyTotalToughness = nullptr;
|
||||||
|
|
||||||
QAction *createTallyAction(TallyType tallyType);
|
QAction *createTallyAction(TallyType tallyType);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -34,3 +34,31 @@ QList<TallyRow> StatsTally::computeTotalPower(const QList<CardItem *> &cards)
|
||||||
QString name = QCoreApplication::translate("StatsTally", "Total Power");
|
QString name = QCoreApplication::translate("StatsTally", "Total Power");
|
||||||
return {TallyRow{name, QString::number(total)}};
|
return {TallyRow{name, QString::number(total)}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int sumToughness(const QList<CardItem *> &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<TallyRow> StatsTally::computeTotalToughness(const QList<CardItem *> &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)}};
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,14 @@ namespace StatsTally
|
||||||
*/
|
*/
|
||||||
QList<TallyRow> computeTotalPower(const QList<CardItem *> &cards);
|
QList<TallyRow> computeTotalPower(const QList<CardItem *> &cards);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sums the toughness of all selected cards
|
||||||
|
*
|
||||||
|
* @param cards The list of selected card items to analyze.
|
||||||
|
* @return A single row containing the total, or an empty list if none of the cards have pt
|
||||||
|
*/
|
||||||
|
QList<TallyRow> computeTotalToughness(const QList<CardItem *> &cards);
|
||||||
|
|
||||||
} // namespace StatsTally
|
} // namespace StatsTally
|
||||||
|
|
||||||
#endif // COCKATRICE_STATS_TALLY_H
|
#endif // COCKATRICE_STATS_TALLY_H
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ QList<TallyRow> Tally::compute(const QList<CardItem *> &cards, const TallyType t
|
||||||
return SubtypeTally::countSubtypes(cards);
|
return SubtypeTally::countSubtypes(cards);
|
||||||
case TallyType::TotalPower:
|
case TallyType::TotalPower:
|
||||||
return StatsTally::computeTotalPower(cards);
|
return StatsTally::computeTotalPower(cards);
|
||||||
|
case TallyType::TotalToughness:
|
||||||
|
return StatsTally::computeTotalToughness(cards);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,8 @@ enum class TallyType
|
||||||
None,
|
None,
|
||||||
Subtypes,
|
Subtypes,
|
||||||
TotalPower,
|
TotalPower,
|
||||||
MaxValue = TotalPower // sentinel value
|
TotalToughness,
|
||||||
|
MaxValue = TotalToughness // sentinel value
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Tally
|
namespace Tally
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue