mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 06:22:15 -07:00
Store allowedCounts by format
Took 15 minutes Took 6 seconds
This commit is contained in:
parent
0d33a79387
commit
b1f0026b6c
4 changed files with 94 additions and 43 deletions
|
|
@ -622,6 +622,17 @@ bool DeckListModel::isCardLegalForCurrentFormat(const CardInfoPtr cardInfo)
|
|||
return true;
|
||||
}
|
||||
|
||||
int maxAllowedForLegality(const FormatRules &format, const QString &legality)
|
||||
{
|
||||
for (const AllowedCount &c : format.allowedCounts) {
|
||||
if (c.label == legality) {
|
||||
return c.max;
|
||||
}
|
||||
}
|
||||
return -1; // unknown legality → treat as illegal
|
||||
}
|
||||
|
||||
|
||||
bool DeckListModel::isCardQuantityLegalForCurrentFormat(const CardInfoPtr cardInfo, int quantity)
|
||||
{
|
||||
auto formatRules = CardDatabaseManager::query()->getFormat(deckList->getGameFormat());
|
||||
|
|
@ -630,24 +641,29 @@ bool DeckListModel::isCardQuantityLegalForCurrentFormat(const CardInfoPtr cardIn
|
|||
return true;
|
||||
}
|
||||
|
||||
if (cardHasAnyException(*cardInfo.data(), *formatRules.data())) {
|
||||
// Exceptions always win
|
||||
if (cardHasAnyException(*cardInfo, *formatRules)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (cardInfo->getProperties().contains("format-" + deckList->getGameFormat())) {
|
||||
QString formatLegality = cardInfo->getProperty("format-" + deckList->getGameFormat());
|
||||
if (formatLegality == "legal") {
|
||||
if (quantity <= formatRules->maxCopies) {
|
||||
return true;
|
||||
}
|
||||
} else if (formatLegality == "restricted") {
|
||||
if (quantity <= formatRules->maxRestrictedCopies) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const QString legalityProp = "format-" + deckList->getGameFormat();
|
||||
if (!cardInfo->getProperties().contains(legalityProp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
const QString legality = cardInfo->getProperty(legalityProp);
|
||||
|
||||
int maxAllowed = maxAllowedForLegality(*formatRules, legality);
|
||||
|
||||
if (maxAllowed == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (maxAllowed < 0) { // unlimited
|
||||
return true;
|
||||
}
|
||||
|
||||
return quantity <= maxAllowed;
|
||||
}
|
||||
|
||||
void DeckListModel::refreshCardFormatLegalities()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue