mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-17 04:27:45 -07:00
[DeckListModel] Refactor to use forEachCard in legality check (#6550)
This commit is contained in:
parent
d363ec5154
commit
bfeb3a7ca9
1 changed files with 19 additions and 22 deletions
|
|
@ -738,29 +738,26 @@ static bool isCardQuantityLegalForFormat(const QString &format, const CardInfo &
|
||||||
return quantity <= maxAllowed;
|
return quantity <= maxAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isCardNodeLegalForFormat(const QString &format, const InnerDecklistNode *zone, const DecklistCardNode *card)
|
||||||
|
{
|
||||||
|
Q_UNUSED(zone)
|
||||||
|
|
||||||
|
// unknown cards are not legal
|
||||||
|
ExactCard exactCard = CardDatabaseManager::query()->getCard(card->toCardRef());
|
||||||
|
if (!exactCard) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// actual check
|
||||||
|
return isCardQuantityLegalForFormat(format, exactCard.getInfo(), card->getNumber());
|
||||||
|
}
|
||||||
|
|
||||||
void DeckListModel::refreshCardFormatLegalities()
|
void DeckListModel::refreshCardFormatLegalities()
|
||||||
{
|
{
|
||||||
InnerDecklistNode *listRoot = deckList->getTree()->getRoot();
|
QString format = deckList->getGameFormat();
|
||||||
|
|
||||||
for (int i = 0; i < listRoot->size(); i++) {
|
deckList->forEachCard([&format](const InnerDecklistNode *zone, DecklistCardNode *card) {
|
||||||
auto *currentZone = static_cast<InnerDecklistNode *>(listRoot->at(i));
|
bool legal = isCardNodeLegalForFormat(format, zone, card);
|
||||||
for (int j = 0; j < currentZone->size(); j++) {
|
card->setFormatLegality(legal);
|
||||||
auto *currentCard = static_cast<DecklistCardNode *>(currentZone->at(j));
|
});
|
||||||
|
|
||||||
// TODO: better sanity checking
|
|
||||||
if (currentCard == nullptr) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ExactCard exactCard = CardDatabaseManager::query()->getCard(currentCard->toCardRef());
|
|
||||||
if (!exactCard) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString format = deckList->getGameFormat();
|
|
||||||
bool legal = isCardQuantityLegalForFormat(format, exactCard.getInfo(), currentCard->getNumber());
|
|
||||||
|
|
||||||
currentCard->setFormatLegality(legal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue