mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-11 12:54:10 -07:00
[Game] Refactor subtype tally code to be more generic (#7021)
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 15 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker Image / amd64 & arm64 (push) Waiting to run
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 15 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker Image / amd64 & arm64 (push) Waiting to run
* [Game] Refactor subtype tally code to be more generic * remove default case * consolidate empty check * fix include guard * backwards compatibility with qt5
This commit is contained in:
parent
430fc117b4
commit
c5b37cdffe
8 changed files with 138 additions and 84 deletions
|
|
@ -1,64 +0,0 @@
|
|||
#include "selection_subtype_tally.h"
|
||||
|
||||
#include "../game_graphics/board/card_item.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <algorithm>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
/** @brief Extracts subtypes from a single card face's type line. */
|
||||
QStringList extractSubtypesFromFace(const QString &faceType)
|
||||
{
|
||||
// Card type format: "Creature — Goblin Warrior" or "Legendary Enchantment — Saga"
|
||||
QStringList parts = faceType.split(QStringLiteral(" — "));
|
||||
if (parts.size() > 1) {
|
||||
return parts[1].split(QStringLiteral(" "), Qt::SkipEmptyParts);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
namespace SelectionSubtypeTally
|
||||
{
|
||||
|
||||
QList<SubtypeEntry> countSubtypes(const QList<CardItem *> &cards)
|
||||
{
|
||||
QMap<QString, int> subtypeCounts;
|
||||
|
||||
for (CardItem *card : cards) {
|
||||
if (card->getFaceDown() || card->getCard().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QString cardType = card->getCardInfo().getCardType();
|
||||
// Handle double-faced cards: "Creature — Human // Creature — Werewolf"
|
||||
QStringList cardFaces = cardType.split(QStringLiteral(" // "));
|
||||
|
||||
for (const QString &face : cardFaces) {
|
||||
QStringList subtypes = extractSubtypesFromFace(face);
|
||||
for (const QString &subtype : subtypes) {
|
||||
subtypeCounts[subtype]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<SubtypeEntry> entries;
|
||||
for (auto it = subtypeCounts.constBegin(); it != subtypeCounts.constEnd(); ++it) {
|
||||
entries.append({it.key(), it.value()});
|
||||
}
|
||||
|
||||
// Sort by count ascending, then alphabetically (lowest counts at bottom of display)
|
||||
std::sort(entries.begin(), entries.end(), [](const SubtypeEntry &a, const SubtypeEntry &b) {
|
||||
if (a.count != b.count) {
|
||||
return a.count < b.count;
|
||||
}
|
||||
return a.name < b.name;
|
||||
});
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
} // namespace SelectionSubtypeTally
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#ifndef SELECTION_SUBTYPE_TALLY_H
|
||||
#define SELECTION_SUBTYPE_TALLY_H
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
class CardItem;
|
||||
|
||||
/** @brief A single subtype (e.g., "Goblin", "Warrior") with its occurrence count. */
|
||||
struct SubtypeEntry
|
||||
{
|
||||
QString name; ///< The subtype name
|
||||
int count; ///< Number of selected cards with this subtype
|
||||
|
||||
bool operator==(const SubtypeEntry &other) const
|
||||
{
|
||||
return name == other.name && count == other.count;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Extracts and tallies subtypes from selected cards.
|
||||
*/
|
||||
namespace SelectionSubtypeTally
|
||||
{
|
||||
/**
|
||||
* @brief Parses card type lines and counts each subtype occurrence.
|
||||
*
|
||||
* Skips face-down cards and cards without type info.
|
||||
* @param cards The list of selected card items to analyze.
|
||||
* @return Entries sorted by count ascending, then alphabetically.
|
||||
*/
|
||||
QList<SubtypeEntry> countSubtypes(const QList<CardItem *> &cards);
|
||||
} // namespace SelectionSubtypeTally
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue