mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 11:03:25 -08:00
Improved checking that ExactMatch is valid by making sure all colors have a valid filter
This commit is contained in:
parent
7c065ebae9
commit
0bb93fa909
1 changed files with 22 additions and 15 deletions
|
|
@ -254,7 +254,8 @@ QList<QChar> VisualDatabaseDisplayColorFilterWidget::getActiveColors()
|
||||||
void VisualDatabaseDisplayColorFilterWidget::syncWithFilterModel()
|
void VisualDatabaseDisplayColorFilterWidget::syncWithFilterModel()
|
||||||
{
|
{
|
||||||
// Determine the correct currentMode from the filter model by finding which modes
|
// Determine the correct currentMode from the filter model by finding which modes
|
||||||
// are not possible due to the model containing filters that that mode cannot add.
|
// are not possible due to the model containing (a combination of) filters that
|
||||||
|
// that mode cannot add.
|
||||||
constexpr int modeCount = static_cast<int>(FilterMode::End);
|
constexpr int modeCount = static_cast<int>(FilterMode::End);
|
||||||
bool modeImpossible[modeCount] = {};
|
bool modeImpossible[modeCount] = {};
|
||||||
|
|
||||||
|
|
@ -262,23 +263,29 @@ void VisualDatabaseDisplayColorFilterWidget::syncWithFilterModel()
|
||||||
filters.append(filterModel->getFiltersOfType(CardFilter::Attr::AttrColor));
|
filters.append(filterModel->getFiltersOfType(CardFilter::Attr::AttrColor));
|
||||||
filters.append(filterModel->getFiltersOfType(CardFilter::Attr::AttrColorIdentity));
|
filters.append(filterModel->getFiltersOfType(CardFilter::Attr::AttrColorIdentity));
|
||||||
|
|
||||||
if (filters.empty()) {
|
for (int i = 0; i < modeCount; ++i) {
|
||||||
// Remove the modes that should always contain filters.
|
FilterModeInfo modeInfo = getFilterModeInfo(static_cast<FilterMode>(i));
|
||||||
for (int i = 0; i < modeCount; ++i) {
|
|
||||||
FilterModeInfo modeInfo = getFilterModeInfo(static_cast<FilterMode>(i));
|
|
||||||
if (modeInfo.includeType != CardFilter::Type::TypeEnd &&
|
|
||||||
modeInfo.excludeType != CardFilter::Type::TypeEnd) {
|
|
||||||
modeImpossible[i] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Remove the modes that cannot create one of the filters.
|
// Remove the modes that cannot create one of the filters.
|
||||||
for (const CardFilter *filter : filters) {
|
for (const CardFilter *filter : filters) {
|
||||||
for (int i = 0; i < modeCount; ++i) {
|
if (filter->attr() != modeInfo.attr ||
|
||||||
FilterModeInfo modeInfo = getFilterModeInfo(static_cast<FilterMode>(i));
|
(filter->type() != modeInfo.includeType && filter->type() != modeInfo.excludeType)) {
|
||||||
if (filter->attr() != modeInfo.attr ||
|
modeImpossible[i] = true;
|
||||||
(filter->type() != modeInfo.includeType && filter->type() != modeInfo.excludeType)) {
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modes that have both an include and exclude filter should always have a filter for each color.
|
||||||
|
if (modeInfo.includeType != CardFilter::Type::TypeEnd && modeInfo.excludeType != CardFilter::Type::TypeEnd &&
|
||||||
|
!modeImpossible[i]) {
|
||||||
|
for (const QChar &color : QString("WUBRG")) {
|
||||||
|
int count = 0;
|
||||||
|
for (const CardFilter *filter : filters) {
|
||||||
|
count += filter->term() == color;
|
||||||
|
}
|
||||||
|
if (count != 1) {
|
||||||
modeImpossible[i] = true;
|
modeImpossible[i] = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue