Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the match is loaded when checking for initial dynamic filter responses #991

Merged
merged 1 commit into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/java/tc/oc/pgm/api/filter/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ default boolean response(Query query) {
case DENY:
return false;
default:
throw new UnsupportedOperationException("Filter did not respond to the query");
throw new UnsupportedOperationException(
"Filter " + this + " did not respond to the query " + query);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,34 @@ public void onMatchLoad(MatchLoadEvent event) {
}
this.registerListenersFor(filter.getRelevantEvents());
});

// Lastly dispatch initial states of all dynamic filters for the relevant scopes
// Has to be last since many filters depend on objects loaded in a non-consequent way during
// match load e.g. the goals
for (Filter filter : this.listeners.rowKeySet()) {
Map<Class<? extends Filterable<?>>, ListenerSet> row = this.listeners.row(filter);
for (Class<? extends Filterable<?>> scope : Filterables.SCOPES) {
ListenerSet set = row.get(scope);
if (set == null) continue;
match
.getFilterableDescendants(scope)
.forEach(
filterable -> {
final boolean last = this.lastResponse(filter, filterable);
if (!last) {
for (FilterListener<?> filterListener : set.fall) {
dispatch(
(FilterListener<Filterable<?>>) filterListener, filter, filterable, last);
}
} else {
for (FilterListener<?> filterListener : set.rise) {
dispatch(
(FilterListener<Filterable<?>>) filterListener, filter, filterable, last);
}
}
});
}
}
}

@Override
Expand Down Expand Up @@ -132,16 +160,6 @@ private <F extends Filterable<?>> void register(
this.listeners.row(filter).computeIfAbsent(scope, s -> new ListenerSet());

(response ? listenerSet.rise : listenerSet.fall).add(listener);

match
.getFilterableDescendants(scope)
.forEach(
filterable -> {
final boolean last = this.lastResponse(filter, filterable);
if (last == response) {
dispatch(listener, filter, filterable, last);
}
});
}

/**
Expand Down