mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-21 00:55:09 -07:00
[DeckShare] Replace the duplicate computeColorIdentity with the shared getDeckColorIdentity
This commit is contained in:
parent
65adf1c6af
commit
e6d6cbde1e
2 changed files with 3 additions and 39 deletions
|
|
@ -4,7 +4,6 @@
|
|||
#include "../../../../interface/widgets/dialogs/dlg_convert_deck_to_cod_format.h"
|
||||
#include "../../../deck_loader/deck_loader.h"
|
||||
#include "../../cards/additional_info/color_identity_widget.h"
|
||||
#include "../../cards/additional_info/deck_color_identity.h"
|
||||
#include "../../cards/deck_preview_card_picture_widget.h"
|
||||
#include "../visual_deck_storage_quick_settings_widget.h"
|
||||
#include "../visual_deck_storage_tag_filter_widget.h"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "visual_deck_storage_model.h"
|
||||
|
||||
#include "../../deck_loader/deck_loader.h"
|
||||
#include "../cards/additional_info/deck_color_identity.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
|
|
@ -119,8 +120,6 @@ DeckScanResult scanDeckDirectory(const QString &deckPath)
|
|||
}
|
||||
} // namespace
|
||||
|
||||
static QString computeColorIdentity(const LoadedDeck &deck);
|
||||
|
||||
VisualDeckStorageModel::VisualDeckStorageModel(QObject *parent) : QAbstractListModel(parent)
|
||||
{
|
||||
}
|
||||
|
|
@ -306,7 +305,7 @@ void VisualDeckStorageModel::beginLoad(int row)
|
|||
}
|
||||
// Color identity walks every card through the database, so compute it here to
|
||||
// keep the completion handler on the UI thread cheap.
|
||||
const QString colorIdentity = computeColorIdentity(*deck);
|
||||
const QString colorIdentity = getDeckColorIdentity(deck->deckList, CardDatabaseManager::query());
|
||||
return DeckLoadResult{std::move(*deck), QFileInfo(filePath).lastModified(), colorIdentity};
|
||||
}));
|
||||
}
|
||||
|
|
@ -367,40 +366,6 @@ void VisualDeckStorageModel::drainPendingLoads()
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Computes the color identity of a deck in WUBRG order.
|
||||
*/
|
||||
static QString computeColorIdentity(const LoadedDeck &deck)
|
||||
{
|
||||
QStringList cardList = deck.deckList.getCardList({DECK_ZONE_MAIN, DECK_ZONE_SIDE});
|
||||
if (cardList.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QSet<QChar> colorSet; // A set to collect unique color symbols (e.g., W, U, B, R, G)
|
||||
|
||||
for (const QString &cardName : cardList) {
|
||||
CardInfoPtr currentCard = CardDatabaseManager::query()->getCardInfo(cardName);
|
||||
if (currentCard) {
|
||||
const QString colors = currentCard->getColors(); // Something like "WUB"
|
||||
for (const QChar &color : colors) {
|
||||
colorSet.insert(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the color identity is in WUBRG order
|
||||
QString colorIdentity;
|
||||
const QString wubrgOrder = "WUBRG";
|
||||
for (const QChar &color : wubrgOrder) {
|
||||
if (colorSet.contains(color)) {
|
||||
colorIdentity.append(color);
|
||||
}
|
||||
}
|
||||
|
||||
return colorIdentity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Recomputes all derived metadata of a row from its loaded deck.
|
||||
*/
|
||||
|
|
@ -414,7 +379,7 @@ void VisualDeckStorageModel::recomputeDeckMetadata(DeckPreviewData &data, bool r
|
|||
data.lastLoaded = QDateTime::fromString(deckList.getLastLoadedTimestamp());
|
||||
data.bannerCard = deckList.getBannerCard();
|
||||
if (recomputeColorIdentity) {
|
||||
data.colorIdentity = computeColorIdentity(data.deck);
|
||||
data.colorIdentity = getDeckColorIdentity(data.deck.deckList, CardDatabaseManager::query());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue