Extend decklist parsing (#5316)

* Extend the decklist parsing from clipboard to also support SetName, CollectorNumber and Foil Status.

* Q_UNUSED foil for now but keep parsing logic for future PR's/compatibility.

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-01-06 03:07:17 +01:00 committed by GitHub
parent cc16b8779c
commit 81b85e97df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 140 additions and 28 deletions

View file

@ -176,6 +176,42 @@ QString DeckLoader::exportDeckToDecklist()
return deckString;
}
// This struct is here to support the forEachCard function call, defined in decklist.
// It requires a function to be called for each card, and it will set the providerId.
struct SetProviderId
{
// Main operator for struct, allowing the foreachcard to work.
SetProviderId()
{
}
void operator()(const InnerDecklistNode *node, DecklistCardNode *card) const
{
Q_UNUSED(node);
// Retrieve the providerId based on setName and collectorNumber
QString providerId =
CardDatabaseManager::getInstance()
->getSpecificSetForCard(card->getName(), card->getCardSetShortName(), card->getCardCollectorNumber())
.getProperty("uuid");
// Set the providerId on the card
card->setCardProviderId(providerId);
}
};
/**
* This function iterates through each card in the decklist and sets the providerId
* on each card based on its set name and collector number.
*/
void DeckLoader::resolveSetNameAndNumberToProviderID()
{
// Set up the struct to call.
SetProviderId setProviderId;
// Call the forEachCard method for each card in the deck
forEachCard(setProviderId);
}
DeckLoader::FileFormat DeckLoader::getFormatFromName(const QString &fileName)
{
if (fileName.endsWith(".cod", Qt::CaseInsensitive)) {

View file

@ -47,6 +47,8 @@ public:
bool saveToFile(const QString &fileName, FileFormat fmt);
QString exportDeckToDecklist();
void resolveSetNameAndNumberToProviderID();
// overload
bool saveToStream_Plain(QTextStream &out, bool addComments = true);

View file

@ -85,7 +85,7 @@ struct CopyIfNotAToken
}
};
void DeckStatsInterface::copyDeckWithoutTokens(const DeckList &source, DeckList &destination)
void DeckStatsInterface::copyDeckWithoutTokens(DeckList &source, DeckList &destination)
{
CopyIfNotAToken copyIfNotAToken(cardDatabase, destination);
source.forEachCard(copyIfNotAToken);

View file

@ -24,7 +24,7 @@ private:
* closest non-token card instead. So we construct a new deck which has no
* tokens.
*/
void copyDeckWithoutTokens(const DeckList &source, DeckList &destination);
void copyDeckWithoutTokens(DeckList &source, DeckList &destination);
private slots:
void queryFinished(QNetworkReply *reply);