diff --git a/cockatrice/src/interface/deck_loader/deck_loader.cpp b/cockatrice/src/interface/deck_loader/deck_loader.cpp index 841c67056..de07a0199 100644 --- a/cockatrice/src/interface/deck_loader/deck_loader.cpp +++ b/cockatrice/src/interface/deck_loader/deck_loader.cpp @@ -269,6 +269,23 @@ static QString toDecklistExportString(const DecklistCardNode *card) return cardString; } +/** + * Converts all cards in the list to their decklist export string and joins them into one string + */ +static QString toDecklistExportString(const QList &cardNodes) +{ + QString cardsString; + for (auto card : cardNodes) { + // Get the card name + // If it's a token, we don't care about the card. + CardInfoPtr dbCard = CardDatabaseManager::query()->getCardInfo(card->getName()); + if (dbCard && !dbCard->getIsToken()) { + cardsString += toDecklistExportString(card); + } + } + return cardsString; +} + /** * Export deck to decklist function, called to format the deck in a way to be sent to a server * @@ -279,29 +296,11 @@ QString DeckLoader::exportDeckToDecklist(const DeckList *deckList, DecklistWebsi { // Add the base url QString deckString = "https://" + getDomainForWebsite(website) + "/?"; - // Create two strings to pass to function - QString mainBoardCards, sideBoardCards; - // Set up the function to call - auto formatDeckListForExport = [&mainBoardCards, &sideBoardCards](const auto *node, const auto *card) { - // Get the card name - CardInfoPtr dbCard = CardDatabaseManager::query()->getCardInfo(card->getName()); - if (!dbCard || dbCard->getIsToken()) { - // If it's a token, we don't care about the card. - return; - } + // export all cards in zone + QString mainBoardCards = toDecklistExportString(deckList->getCardNodes({DECK_ZONE_MAIN})); + QString sideBoardCards = toDecklistExportString(deckList->getCardNodes({DECK_ZONE_SIDE})); - // Check if it's a sideboard card. - if (node->getName() == DECK_ZONE_SIDE) { - sideBoardCards += toDecklistExportString(card); - } else { - // If it's a mainboard card, do the same thing, but for the mainboard card string - mainBoardCards += toDecklistExportString(card); - } - }; - - // call our struct function for each card in the deck - deckList->forEachCard(formatDeckListForExport); // Remove the extra return at the end of the last cards mainBoardCards.chop(3); sideBoardCards.chop(3);