mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
Honor finite deck copy limits across printings and deck zones [skip ci]
This commit is contained in:
parent
e08402ac94
commit
142341bc3c
9 changed files with 438 additions and 48 deletions
|
|
@ -295,6 +295,7 @@ CardInfoPtr OracleImporter::addCard(QString name,
|
|||
qDebug() << "warning: an empty card was added to set" << printingInfo.getSet()->getShortName();
|
||||
}
|
||||
cards.insert(name, newCard);
|
||||
magicFormatsDirty = true;
|
||||
|
||||
return newCard;
|
||||
}
|
||||
|
|
@ -756,8 +757,38 @@ static FormatRulesNameMap buildDefaultMagicFormats()
|
|||
|
||||
const FormatRulesNameMap &OracleImporter::createDefaultMagicFormats()
|
||||
{
|
||||
static const FormatRulesNameMap cached = buildDefaultMagicFormats();
|
||||
return cached;
|
||||
static const FormatRulesNameMap defaults = buildDefaultMagicFormats();
|
||||
if (!magicFormatsDirty) {
|
||||
return magicFormats;
|
||||
}
|
||||
|
||||
// Sort by name so saved rules are independent of QHash iteration order.
|
||||
QMap<QString, int> finiteLimits;
|
||||
for (const auto &card : cards) {
|
||||
if (const auto limit = parseDeckCopyLimit(card->getName(), card->getText())) {
|
||||
finiteLimits.insert(card->getName(), *limit);
|
||||
}
|
||||
}
|
||||
magicFormats = defaults;
|
||||
if (!finiteLimits.isEmpty()) {
|
||||
for (auto it = magicFormats.begin(); it != magicFormats.end(); ++it) {
|
||||
// Copy the value before appending: defaults and other importer
|
||||
// instances retain their existing shared FormatRules objects.
|
||||
FormatRulesPtr format(new FormatRules(*it.value()));
|
||||
for (auto limit = finiteLimits.cbegin(); limit != finiteLimits.cend(); ++limit) {
|
||||
ExceptionRule exception;
|
||||
exception.conditions.append({"name", "equals", limit.key()});
|
||||
// A card's copy allowance does not make it legal in a format
|
||||
// where it is banned, restricted or outside the card pool.
|
||||
exception.conditions.append({"format-" + it.key(), "equals", "legal"});
|
||||
exception.maxCopies = limit.value();
|
||||
format->exceptions.append(exception);
|
||||
}
|
||||
it.value() = format;
|
||||
}
|
||||
}
|
||||
magicFormatsDirty = false;
|
||||
return magicFormats;
|
||||
}
|
||||
|
||||
int OracleImporter::startImport()
|
||||
|
|
@ -863,6 +894,8 @@ void OracleImporter::clear()
|
|||
{
|
||||
sets.clear();
|
||||
cards.clear();
|
||||
magicFormats.clear();
|
||||
magicFormatsDirty = true;
|
||||
allSets.clear();
|
||||
rawSetsData.clear();
|
||||
localizedEntries.clear();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue