-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup filters & implement players, rank & countdown filters (#1005)
Signed-off-by: Pablete1234 <[email protected]>
- Loading branch information
1 parent
c42e86c
commit 42c8279
Showing
144 changed files
with
1,795 additions
and
1,290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 35 additions & 1 deletion
36
core/src/main/java/tc/oc/pgm/api/feature/FeatureDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,43 @@ | ||
package tc.oc.pgm.api.feature; | ||
|
||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Used as a base-class for all templates of features. Kept around during parsing time so that we | ||
* can easily convert a definition into a Feature for match-time, and persist the ID from the XML. | ||
* Also stored in the {@link tc.oc.pgm.features.FeatureDefinitionContext} so that we don't collide | ||
* IDs. | ||
*/ | ||
public interface FeatureDefinition {} | ||
public interface FeatureDefinition { | ||
|
||
default FeatureDefinition get() { | ||
return this; | ||
} | ||
|
||
/** Concrete class of the definition object (rather than a proxy). */ | ||
default Class<? extends FeatureDefinition> getDefinitionType() { | ||
return getClass(); | ||
} | ||
|
||
default boolean isInstanceOf(Class<? extends FeatureDefinition> type) { | ||
return type.isAssignableFrom(getDefinitionType()); | ||
} | ||
|
||
default Stream<? extends FeatureDefinition> dependencies() { | ||
return Stream.of(); | ||
} | ||
|
||
default <T extends FeatureDefinition> Stream<? extends T> dependencies(Class<T> type) { | ||
//noinspection unchecked | ||
return (Stream<T>) dependencies().filter(type::isInstance); | ||
} | ||
|
||
default <T extends FeatureDefinition> Stream<? extends T> deepDependencies(Class<T> type) { | ||
Stream<? extends T> stream = dependencies(type).flatMap(dep -> dep.deepDependencies(type)); | ||
if (isInstanceOf(type)) { | ||
//noinspection unchecked | ||
stream = Stream.concat(Stream.of((T) get()), stream); | ||
} | ||
return stream; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/main/java/tc/oc/pgm/api/feature/FeatureDefinitionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package tc.oc.pgm.api.feature; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** A checked exception indicating a problem related to a particular {@link FeatureDefinition} */ | ||
public class FeatureDefinitionException extends Exception { | ||
|
||
private final FeatureDefinition featureDefinition; | ||
|
||
public FeatureDefinitionException(@Nullable String message, FeatureDefinition featureDefinition) { | ||
this(message, null, featureDefinition); | ||
} | ||
|
||
public FeatureDefinitionException( | ||
@Nullable String message, @Nullable Throwable cause, FeatureDefinition featureDefinition) { | ||
super(message, cause); | ||
this.featureDefinition = featureDefinition; | ||
} | ||
|
||
public FeatureDefinition featureDefinition() { | ||
return featureDefinition; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 15 additions & 12 deletions
27
core/src/main/java/tc/oc/pgm/api/filter/FilterListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
package tc.oc.pgm.api.filter; | ||
|
||
import javax.annotation.Nullable; | ||
import tc.oc.pgm.api.filter.query.Query; | ||
import tc.oc.pgm.filters.FilterMatchModule; | ||
import tc.oc.pgm.filters.Filterable; | ||
|
||
/** | ||
* Can be registered to listen for changes in the response to particular queries on particular | ||
* filters. When registered, the listener will be called immediately with null as oldResponse and | ||
* the current value of the query as newResponse. After that, the listener will only be called when | ||
* the response has changed. | ||
* Handler of dynamic {@link Filter} events | ||
* | ||
* @see FilterMatchModule#onChange(Class, Filter, FilterListener) | ||
*/ | ||
public interface FilterListener { | ||
void filterQueryChanged( | ||
Filter filter, | ||
Query query, | ||
@Nullable Filter.QueryResponse oldResponse, | ||
Filter.QueryResponse newResponse); | ||
@FunctionalInterface | ||
public interface FilterListener<F extends Filterable<?>> { | ||
|
||
/** | ||
* The callback method. | ||
* | ||
* @param filterable the filterable that the filter has a new response for | ||
* @param response the new response, {@code true} if rise and {@code false} if fall | ||
*/ | ||
void filterQueryChanged(F filterable, boolean response); | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/main/java/tc/oc/pgm/api/filter/FilterTypeException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package tc.oc.pgm.api.filter; | ||
|
||
import tc.oc.pgm.api.feature.FeatureDefinitionException; | ||
import tc.oc.pgm.api.filter.query.Query; | ||
|
||
public class FilterTypeException extends FeatureDefinitionException { | ||
|
||
private final Class<? extends Query> queryType; | ||
|
||
public FilterTypeException(Filter filter, Class<? extends Query> queryType) { | ||
super( | ||
"Filter type " | ||
+ filter.getDefinitionType().getSimpleName() | ||
+ " cannot respond to queries of type " | ||
+ queryType.getSimpleName(), | ||
filter); | ||
this.queryType = queryType; | ||
} | ||
|
||
public Class<? extends Query> queryType() { | ||
return queryType; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package tc.oc.pgm.api.filter; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import java.util.List; | ||
import tc.oc.pgm.api.match.Match; | ||
import tc.oc.pgm.api.party.Party; | ||
import tc.oc.pgm.api.player.MatchPlayer; | ||
import tc.oc.pgm.filters.Filterable; | ||
|
||
public interface Filterables { | ||
/** {@link Filterable}s ordered from general to specific */ | ||
List<Class<? extends Filterable<?>>> SCOPES = | ||
ImmutableList.of(Match.class, Party.class, MatchPlayer.class); | ||
|
||
/** | ||
* Return the "scope" of the given filter, which is the most general {@link Filterable} type that | ||
* it responds to. | ||
*/ | ||
static Class<? extends Filterable<?>> scope(Filter filter) { | ||
for (Class<? extends Filterable<?>> scope : SCOPES) { | ||
if (filter.respondsTo(scope)) return scope; | ||
} | ||
|
||
throw new IllegalStateException( | ||
"Filter type " + filter.getClass().getSimpleName() + " does not have a filterable scope"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.