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

This commit is contained in:
Lukas Brübach 2024-12-23 09:30:58 +01:00
parent cc16b8779c
commit 38c5cb1259
11 changed files with 147 additions and 39 deletions

View file

@ -120,7 +120,7 @@ struct FormatDeckListForExport
QString &sideBoardCards;
// create main operator for struct, allowing the foreachcard to work.
FormatDeckListForExport(QString &_mainBoardCards, QString &_sideBoardCards)
: mainBoardCards(_mainBoardCards), sideBoardCards(_sideBoardCards){};
: mainBoardCards(_mainBoardCards), sideBoardCards(_sideBoardCards) {};
void operator()(const InnerDecklistNode *node, const DecklistCardNode *card) const
{
@ -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)) {