Package com.prineside.tdi2.events
Class EventDispatcher
java.lang.Object
com.prineside.tdi2.events.EventDispatcher
- All Implemented Interfaces:
KryoSerializable
Creates and manages instances of EventListeners on demand.
Allows to access listener groups by event type, queue events and trigger them.
If you want to subscribe to an event or to trigger an event, use this.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondescribe()
Describes the dispatcher and all existing listener groups as a string, for debug purposesObjectIntMap<Class<? extends Event>>
Array<EventListeners<?>>
<T extends Event>
EventListeners<T>getListeners
(Class<T> eventClass) Get listeners of some specific event type.boolean
Not used by the game currently.<T extends Event>
voidqueue
(T event) Use Pools.obtain(EventType.class) to create an event object.void
void
reset
(boolean full) Reset the dispatcher and clear it from listeners<T extends Event>
Ttrigger
(T event) Notify listeners about the event.void
-
Field Details
-
CLASS_COMPARATOR
-
-
Constructor Details
-
EventDispatcher
public EventDispatcher()
-
-
Method Details
-
write
- Specified by:
write
in interfaceKryoSerializable
-
read
- Specified by:
read
in interfaceKryoSerializable
-
getListeners
Get listeners of some specific event type. New event listener group will be registered if it does not exist yet.- Parameters:
eventClass
- type of an event- Returns:
- listener group for the specified event type
-
queue
Use Pools.obtain(EventType.class) to create an event object. It will be freed back to the pool after trigger. Not used by the game currently. -
hasQueuedEvents
public boolean hasQueuedEvents()Not used by the game currently. -
trigger
Notify listeners about the event.- Type Parameters:
T
- type of event- Parameters:
event
- event object to pass to the listeners- Returns:
- event passed to this method (for chaining purposes)
-
getClassToId
- Returns:
- registry of event type classes where value is an id / index in an array of listenerGroups
-
getListenerGroups
- Returns:
- all of the registered EventListeners groups where index is a value from the classToId map
-
getQueuedEvents
- Returns:
- an array of queued events scheduled by queue() and are awaiting to be triggered by triggerQueuedEvents()
-
reset
public void reset(boolean full) Reset the dispatcher and clear it from listeners- Parameters:
full
- type of reset: - false (partial) - will keep the class registry and all of the FLAG_PERSISTENT listeners - true (full) - no listeners nor registered classes will remain
-
describe
Describes the dispatcher and all existing listener groups as a string, for debug purposes- Returns:
- description of this dispatcher as a string
-