Deck legality checker.

Took 51 seconds

Took 1 minute

Took 1 minute

Took 5 minutes

Took 3 minutes
This commit is contained in:
Lukas Brübach 2025-09-10 09:40:28 +02:00
parent 2e2682aad4
commit 3f06c848e1
31 changed files with 921 additions and 27 deletions

View file

@ -463,6 +463,69 @@ int OracleImporter::importCardsFromSet(const CardSetPtr &currentSet, const QList
return numCards;
}
FormatRulesNameMap OracleImporter::createDefaultMagicFormats()
{
// Predefined common exceptions
CardCondition superTypeIsBasic;
superTypeIsBasic.field = "type";
superTypeIsBasic.matchType = "contains";
superTypeIsBasic.value = "Basic Land";
ExceptionRule basicLands;
basicLands.conditions.append(superTypeIsBasic);
CardCondition anyNumberAllowed;
anyNumberAllowed.field = "text";
anyNumberAllowed.matchType = "contains";
anyNumberAllowed.value = "may contain any number of";
ExceptionRule mayContainAnyNumber;
mayContainAnyNumber.conditions.append(anyNumberAllowed);
// Map to store default rules
FormatRulesNameMap defaultFormatRulesNameMap;
// ----------------- Helper lambda to create format -----------------
auto makeFormat = [&](const QString &name, int maxCopies = 4, int minDeck = 60, int maxDeck = -1,
int maxSideboardSize = 15) -> FormatRulesPtr {
FormatRulesPtr f(new FormatRules);
f->formatName = name;
f->maxCopies = maxCopies;
f->minDeckSize = minDeck;
f->maxDeckSize = maxDeck;
f->maxSideboardSize = maxSideboardSize;
f->exceptions.append(basicLands);
f->exceptions.append(mayContainAnyNumber);
defaultFormatRulesNameMap.insert(name.toLower(), f);
return f;
};
// ----------------- Standard formats -----------------
makeFormat("Alchemy", 4, 60);
makeFormat("Brawl", 1, 60, 60);
makeFormat("Commander", 1, 100, 100);
makeFormat("Duel", 1, 100, 100);
makeFormat("Future");
makeFormat("Gladiator", 4, 60, 60, 0);
makeFormat("Historic");
makeFormat("Legacy");
makeFormat("Modern");
makeFormat("Oathbreaker", 1, 60, 60);
makeFormat("OldSchool");
makeFormat("Pauper");
makeFormat("PauperCommander", 1, 100, 100);
makeFormat("Penny");
makeFormat("Pioneer");
makeFormat("Predh", 1, 100, 100);
makeFormat("Premodern");
makeFormat("Standard");
makeFormat("StandardBrawl", 1, 60, 60);
makeFormat("Timeless");
makeFormat("Vintage");
return defaultFormatRulesNameMap;
}
int OracleImporter::startImport()
{
static ICardSetPriorityController *noOpController = new NoopCardSetPriorityController();
@ -497,7 +560,8 @@ int OracleImporter::startImport()
bool OracleImporter::saveToFile(const QString &fileName, const QString &sourceUrl, const QString &sourceVersion)
{
CockatriceXml4Parser parser(new NoopCardPreferenceProvider());
return parser.saveToFile(sets, cards, fileName, sourceUrl, sourceVersion);
return parser.saveToFile(createDefaultMagicFormats(), sets, cards, fileName, sourceUrl, sourceVersion);
}
void OracleImporter::clear()

View file

@ -154,6 +154,7 @@ public:
int startImport();
bool saveToFile(const QString &fileName, const QString &sourceUrl, const QString &sourceVersion);
int importCardsFromSet(const CardSetPtr &currentSet, const QList<QVariant> &cardsList);
FormatRulesNameMap createDefaultMagicFormats();
const CardNameMap &getCardList() const
{
return cards;