mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-22 09:35:08 -07:00
[Game] Implement total power tally (#7057)
* [Game] Implement total power tally * PR comments
This commit is contained in:
parent
a4557454a7
commit
ca1c063687
7 changed files with 67 additions and 1 deletions
|
|
@ -99,6 +99,7 @@ set(cockatrice_SOURCES
|
||||||
src/game_graphics/player/menu/sideboard_menu.cpp
|
src/game_graphics/player/menu/sideboard_menu.cpp
|
||||||
src/game_graphics/player/menu/tally_menu.cpp
|
src/game_graphics/player/menu/tally_menu.cpp
|
||||||
src/game_graphics/player/menu/utility_menu.cpp
|
src/game_graphics/player/menu/utility_menu.cpp
|
||||||
|
src/game_graphics/tally/stats_tally.cpp
|
||||||
src/game_graphics/tally/subtype_tally.cpp
|
src/game_graphics/tally/subtype_tally.cpp
|
||||||
src/game_graphics/tally/tally.cpp
|
src/game_graphics/tally/tally.cpp
|
||||||
src/game/player/player_actions.cpp
|
src/game/player/player_actions.cpp
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,12 @@ TallyMenu::TallyMenu()
|
||||||
|
|
||||||
aTallyNone = createTallyAction(TallyType::None);
|
aTallyNone = createTallyAction(TallyType::None);
|
||||||
aTallySubtypes = createTallyAction(TallyType::Subtypes);
|
aTallySubtypes = createTallyAction(TallyType::Subtypes);
|
||||||
|
aTallyTotalPower = createTallyAction(TallyType::TotalPower);
|
||||||
|
|
||||||
addAction(aTallyNone);
|
addAction(aTallyNone);
|
||||||
addSeparator();
|
addSeparator();
|
||||||
addAction(aTallySubtypes);
|
addAction(aTallySubtypes);
|
||||||
|
addAction(aTallyTotalPower);
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
@ -51,4 +53,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"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ private:
|
||||||
|
|
||||||
QAction *aTallyNone = nullptr;
|
QAction *aTallyNone = nullptr;
|
||||||
QAction *aTallySubtypes = nullptr;
|
QAction *aTallySubtypes = nullptr;
|
||||||
|
QAction *aTallyTotalPower = nullptr;
|
||||||
|
|
||||||
QAction *createTallyAction(TallyType tallyType);
|
QAction *createTallyAction(TallyType tallyType);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
36
cockatrice/src/game_graphics/tally/stats_tally.cpp
Normal file
36
cockatrice/src/game_graphics/tally/stats_tally.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
#include "stats_tally.h"
|
||||||
|
|
||||||
|
#include "../board/card_item.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QList>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
static int sumPowers(const QList<CardItem *> &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<TallyRow> StatsTally::computeTotalPower(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 = sumPowers(cards);
|
||||||
|
|
||||||
|
QString name = QCoreApplication::translate("StatsTally", "Total Power");
|
||||||
|
return {TallyRow{name, QString::number(total)}};
|
||||||
|
}
|
||||||
21
cockatrice/src/game_graphics/tally/stats_tally.h
Normal file
21
cockatrice/src/game_graphics/tally/stats_tally.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef COCKATRICE_STATS_TALLY_H
|
||||||
|
#define COCKATRICE_STATS_TALLY_H
|
||||||
|
#include "tally.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Extracts and tallies stats from selected cards.
|
||||||
|
*/
|
||||||
|
namespace StatsTally
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sums the power 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> computeTotalPower(const QList<CardItem *> &cards);
|
||||||
|
|
||||||
|
} // namespace StatsTally
|
||||||
|
|
||||||
|
#endif // COCKATRICE_STATS_TALLY_H
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "tally.h"
|
#include "tally.h"
|
||||||
|
|
||||||
|
#include "stats_tally.h"
|
||||||
#include "subtype_tally.h"
|
#include "subtype_tally.h"
|
||||||
|
|
||||||
TallyType Tally::intToType(int value)
|
TallyType Tally::intToType(int value)
|
||||||
|
|
@ -18,6 +19,8 @@ QList<TallyRow> Tally::compute(const QList<CardItem *> &cards, const TallyType t
|
||||||
return {};
|
return {};
|
||||||
case TallyType::Subtypes:
|
case TallyType::Subtypes:
|
||||||
return SubtypeTally::countSubtypes(cards);
|
return SubtypeTally::countSubtypes(cards);
|
||||||
|
case TallyType::TotalPower:
|
||||||
|
return StatsTally::computeTotalPower(cards);
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,8 @@ enum class TallyType
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
Subtypes,
|
Subtypes,
|
||||||
MaxValue = Subtypes // sentinel value
|
TotalPower,
|
||||||
|
MaxValue = TotalPower // sentinel value
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Tally
|
namespace Tally
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue