Refactor function structs into lambdas (#5675)

* change signature to use lambda

* reuse comparator

* inline structs in forEachCard

* inline structs

* Refactor exportDeckToDecklist

* fix unit test
This commit is contained in:
RickyRister 2025-04-19 21:07:22 -07:00 committed by GitHub
parent 1d259a86c1
commit 26dcb015ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 108 additions and 213 deletions

View file

@ -67,26 +67,15 @@ void DeckStatsInterface::analyzeDeck(DeckList *deck)
manager->post(request, data);
}
struct CopyIfNotAToken
void DeckStatsInterface::copyDeckWithoutTokens(DeckList &source, DeckList &destination)
{
CardDatabase &cardDatabase;
DeckList &destination;
CopyIfNotAToken(CardDatabase &_cardDatabase, DeckList &_destination)
: cardDatabase(_cardDatabase), destination(_destination){};
void operator()(const InnerDecklistNode *node, const DecklistCardNode *card) const
{
auto copyIfNotAToken = [this, &destination](const auto node, const auto card) {
CardInfoPtr dbCard = cardDatabase.getCard(card->getName());
if (dbCard && !dbCard->getIsToken()) {
DecklistCardNode *addedCard = destination.addCard(card->getName(), node->getName());
addedCard->setNumber(card->getNumber());
}
}
};
};
void DeckStatsInterface::copyDeckWithoutTokens(DeckList &source, DeckList &destination)
{
CopyIfNotAToken copyIfNotAToken(cardDatabase, destination);
source.forEachCard(copyIfNotAToken);
}