mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33: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()
|
||||
{
|
||||
// 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);
|
||||
bool modeImpossible[modeCount] = {};
|
||||
|
||||
|
|
@ -262,23 +263,29 @@ void VisualDatabaseDisplayColorFilterWidget::syncWithFilterModel()
|
|||
filters.append(filterModel->getFiltersOfType(CardFilter::Attr::AttrColor));
|
||||
filters.append(filterModel->getFiltersOfType(CardFilter::Attr::AttrColorIdentity));
|
||||
|
||||
if (filters.empty()) {
|
||||
// Remove the modes that should always contain filters.
|
||||
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 {
|
||||
for (int i = 0; i < modeCount; ++i) {
|
||||
FilterModeInfo modeInfo = getFilterModeInfo(static_cast<FilterMode>(i));
|
||||
|
||||
// Remove the modes that cannot create one of the filters.
|
||||
for (const CardFilter *filter : filters) {
|
||||
for (int i = 0; i < modeCount; ++i) {
|
||||
FilterModeInfo modeInfo = getFilterModeInfo(static_cast<FilterMode>(i));
|
||||
if (filter->attr() != modeInfo.attr ||
|
||||
(filter->type() != modeInfo.includeType && filter->type() != modeInfo.excludeType)) {
|
||||
if (filter->attr() != modeInfo.attr ||
|
||||
(filter->type() != modeInfo.includeType && filter->type() != modeInfo.excludeType)) {
|
||||
modeImpossible[i] = true;
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue