ReactionTable class final

Reactions keyed by event type: the game's own table of what each event looks and feels like.

The game decides; this only keeps the decisions in one place. A rule is registered for an event class and is handed every event of that class and its subclasses, in the order the events happened; an event no rule names shows nothing. Within one event, rules run in registration order, so a table written as a list reads the way a switch over the events did.

final table = ReactionTable()
  ..on<Landed>((r) => r.out.jolts.add(Felt.kick(Vector3(0, -0.1, 0))))
  ..on<Exploded>((r) {
    r.out.bursts.add(Shown(Effects.fire, r.event.at));
    r.out.flash = true;
  });
final reaction = table.react(events);

A game makes its own table with ReactionTable() and fills it with on.

Constructors

ReactionTable()

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
types → List<Type>
The event types this table has a rule for, in registration order.
no setter

Methods

decide(Iterable<BusEvent> events, ReactionBuilder out) → void
Writes what events look like into out.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
on<T extends BusEvent>(ReactionRule<T> rule) → void
Adds rule for every event that is a T.
react(Iterable<BusEvent> events) → Reaction
What events look like.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited