Terasology / ModuleTestingEnvironment

3 stars 15 forks source link

Let users specify component types in TestEventReceiver #4

Closed kaen closed 4 years ago

kaen commented 6 years ago

Currently, the TestEventReceiver allows to specify the event class to be caught, but it lacks the abilitiy to restrict event handling to a specific set of components to be present. This, however, is crucial for events such as OnAddedComponent which themselves don't carry any information. Without the indication of component classes it is impossible to react to these kind of "informative events" that rely on the component check.

Note that this event will only be received by @ReceiveEvent methods where all components in its list are present and at least one is involved in the action causing the event.

As the components are just specified as list of component class it may be possible to extend the existing interface with another parameter taking this list:

TestEventReceiver receiver = new TestEventReceiver<>(context, OnComponentAdded.class, (event, entity) -> {
  // do something with the event or entity
}, List.of(StunEffect.class));

This receiver signature should be equivalent to the following event handler:

@ReceiveEvent(components = {StunEffect.class})
public void onStunAdded(OnComponentAdded event, EntityRef entity) {
  // do something with the event or entity
}

~Blocked by https://github.com/MovingBlocks/Terasology/pull/3147~

Cervator commented 6 years ago

No longer blocked! Code away :-)

skaldarnar commented 4 years ago

Updated the issue description with more information and motivation.

kaen commented 4 years ago

Fixed in #19 :tada: