Render and filter Continuum Universes Essence symbols instead of MTG mana

This commit is contained in:
Christian Daniel Jensen 2026-11-02 05:50:01 -07:00
parent 10d68be254
commit 93fd16dc3a

View file

@ -2,6 +2,7 @@
#include "../../../../client/settings/cache_settings.h" #include "../../../../client/settings/cache_settings.h"
#include "libcockatrice/card/card_info.h" #include "libcockatrice/card/card_info.h"
#include <libcockatrice/card/essence_types.h>
#include "mana_symbol_widget.h" #include "mana_symbol_widget.h"
#include <QChar> #include <QChar>
@ -41,9 +42,9 @@ ColorIdentityWidget::ColorIdentityWidget(QWidget *parent, const CardInfoPtr &car
void ColorIdentityWidget::populateManaSymbolWidgets() void ColorIdentityWidget::populateManaSymbolWidgets()
{ {
// Define the full WUBRG set (White, Blue, Black, Red, Green) // Continuum Universes supports fourteen named Essence codes plus N (colorless).
QString fullColorIdentity = "WUBRG"; const QString &allEssences = Essence::symbols();
QStringList symbols = parseColorIdentity(colorIdentity); // Parse mana cost string QStringList symbols = parseColorIdentity(colorIdentity);
// clear old layout // clear old layout
QtUtils::clearLayoutRec(layout); QtUtils::clearLayoutRec(layout);
@ -55,7 +56,8 @@ void ColorIdentityWidget::populateManaSymbolWidgets()
// populate mana symbols // populate mana symbols
if (SettingsCache::instance().visualDeckStorage().getVisualDeckStorageDrawUnusedColorIdentities()) { if (SettingsCache::instance().visualDeckStorage().getVisualDeckStorageDrawUnusedColorIdentities()) {
for (const QString symbol : fullColorIdentity) { for (const QChar code : allEssences) {
const QString symbol(code);
auto *manaSymbol = new ManaSymbolWidget(this, symbol, symbols.contains(symbol)); auto *manaSymbol = new ManaSymbolWidget(this, symbol, symbols.contains(symbol));
layout->addWidget(manaSymbol); layout->addWidget(manaSymbol);
} }
@ -120,28 +122,11 @@ void ColorIdentityWidget::resizeEvent(QResizeEvent *event)
} }
} }
QStringList ColorIdentityWidget::parseColorIdentity(const QString &manaString) QStringList ColorIdentityWidget::parseColorIdentity(const QString &essenceIdentity)
{ {
QStringList symbols; QStringList symbols;
for (const QChar code : Essence::normalizeIdentity(essenceIdentity)) {
// Handle split costs (e.g., "3U // 4UU") symbols.append(QString(code));
QStringList splitCosts = manaString.split(" // ");
for (const QString &part : splitCosts) {
QRegularExpression regex(R"(\{([^}]+)\}|(\d+)|([WUBRGCSPX]))");
QRegularExpressionMatchIterator matches = regex.globalMatch(part);
while (matches.hasNext()) {
QRegularExpressionMatch match = matches.next();
if (match.captured(1).isEmpty()) { // If no `{}` group was captured, check other groups
if (!match.captured(2).isEmpty()) {
symbols.append(match.captured(2)); // Number match
} else {
symbols.append(match.captured(3)); // Single mana letter match
}
} else {
symbols.append(match.captured(1)); // `{}` enclosed match
}
}
} }
return symbols; return symbols;
} }