mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-16 07:22:16 -07:00
Refactor exportDeckToDecklist
This commit is contained in:
parent
d6f5cacca1
commit
70509c77bf
1 changed files with 43 additions and 47 deletions
|
|
@ -239,54 +239,33 @@ static QString getDomainForWebsite(DeckLoader::DecklistWebsite website)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This struct is here to support the forEachCard function call, defined in decklist. It
|
/**
|
||||||
// requires a function to be called for each card, and passes an inner node and a card for
|
* Converts the card to the String that represents it in the decklist export
|
||||||
// each card in the decklist.
|
*/
|
||||||
struct FormatDeckListForExport
|
static QString toDecklistExportString(const DecklistCardNode *card)
|
||||||
{
|
{
|
||||||
// Create refrences for the strings that will be passed in.
|
QString cardString;
|
||||||
QString &mainBoardCards;
|
// Get the number of cards and add the card name
|
||||||
QString &sideBoardCards;
|
cardString += QString::number(card->getNumber());
|
||||||
// create main operator for struct, allowing the foreachcard to work.
|
// Add a space between card num and name
|
||||||
FormatDeckListForExport(QString &_mainBoardCards, QString &_sideBoardCards)
|
cardString += "%20";
|
||||||
: mainBoardCards(_mainBoardCards), sideBoardCards(_sideBoardCards){};
|
// Add card name
|
||||||
|
cardString += card->getName();
|
||||||
|
|
||||||
void operator()(const InnerDecklistNode *node, const DecklistCardNode *card) const
|
if (!card->getCardSetShortName().isNull()) {
|
||||||
{
|
cardString += "%20";
|
||||||
// Get the card name
|
cardString += "(" + card->getCardSetShortName() + ")";
|
||||||
CardInfoPtr dbCard = CardDatabaseManager::getInstance()->getCard(card->getName());
|
|
||||||
if (!dbCard || dbCard->getIsToken()) {
|
|
||||||
// If it's a token, we don't care about the card.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it's a sideboard card.
|
|
||||||
if (node->getName() == DECK_ZONE_SIDE) {
|
|
||||||
// Get the number of cards and add the card name
|
|
||||||
sideBoardCards += QString::number(card->getNumber());
|
|
||||||
// Add a space between card num and name
|
|
||||||
sideBoardCards += "%20";
|
|
||||||
// Add card name
|
|
||||||
sideBoardCards += card->getName();
|
|
||||||
// Add a return at the end of the card
|
|
||||||
sideBoardCards += "%0A";
|
|
||||||
} else // If it's a mainboard card, do the same thing, but for the mainboard card string
|
|
||||||
{
|
|
||||||
mainBoardCards += QString::number(card->getNumber());
|
|
||||||
mainBoardCards += "%20";
|
|
||||||
mainBoardCards += card->getName();
|
|
||||||
if (!card->getCardSetShortName().isNull()) {
|
|
||||||
mainBoardCards += "%20";
|
|
||||||
mainBoardCards += "(" + card->getCardSetShortName() + ")";
|
|
||||||
}
|
|
||||||
if (!card->getCardCollectorNumber().isNull()) {
|
|
||||||
mainBoardCards += "%20";
|
|
||||||
mainBoardCards += card->getCardCollectorNumber();
|
|
||||||
}
|
|
||||||
mainBoardCards += "%0A";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
if (!card->getCardCollectorNumber().isNull()) {
|
||||||
|
cardString += "%20";
|
||||||
|
cardString += card->getCardCollectorNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add a return at the end of the card
|
||||||
|
cardString += "%0A";
|
||||||
|
|
||||||
|
return cardString;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export deck to decklist function, called to format the deck in a way to be sent to a server
|
* Export deck to decklist function, called to format the deck in a way to be sent to a server
|
||||||
|
|
@ -298,8 +277,25 @@ QString DeckLoader::exportDeckToDecklist(DecklistWebsite website)
|
||||||
QString deckString = "https://" + getDomainForWebsite(website) + "/?";
|
QString deckString = "https://" + getDomainForWebsite(website) + "/?";
|
||||||
// Create two strings to pass to function
|
// Create two strings to pass to function
|
||||||
QString mainBoardCards, sideBoardCards;
|
QString mainBoardCards, sideBoardCards;
|
||||||
// Set up the struct to call.
|
|
||||||
FormatDeckListForExport formatDeckListForExport(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::getInstance()->getCard(card->getName());
|
||||||
|
if (!dbCard || dbCard->getIsToken()) {
|
||||||
|
// If it's a token, we don't care about the card.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
// call our struct function for each card in the deck
|
||||||
forEachCard(formatDeckListForExport);
|
forEachCard(formatDeckListForExport);
|
||||||
// Remove the extra return at the end of the last cards
|
// Remove the extra return at the end of the last cards
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue