Skip to content

Commit

Permalink
Ensure the match is loaded before checking for dynamic filters (#991)
Browse files Browse the repository at this point in the history
Signed-off-by: KingSimon <[email protected]>
  • Loading branch information
KingOfSquares authored May 13, 2022
1 parent d7a6f5c commit 13b0a94
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
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
38 changes: 28 additions & 10 deletions core/src/main/java/tc/oc/pgm/filters/dynamic/FilterMatchModule.java
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

0 comments on commit 13b0a94

Please sign in to comment.