Class l2df.manager.event
Event manager.
Info:
- Copyright: Atom-TM 2019
- Author: Kasai
Functions
Manager:init([kwargs]) | Configure EventManager. |
Manager:classInit(entity) | Embed references to EventManager's methods in the entity instance that you create. |
Manager.subscribe(subscriber[, event=false], handler, source) | Allows the object to listen events sent to the Manager. |
Manager:unsubscribe(event, handler) | Disables event tracking by objects using handler. |
Manager:unsubscribeById(event, id) | Disables event tracking by objects using ID. |
Manager:invoke(event, source) | Invoke an event for all active subscribers. |
Manager:monitoring(source, events[, alias[, save_result=false]]) | Monitors whether an object calls certain functions. |
Manager:update(...) | Update event handler. |
Tables
DefaultUpdateEvents | Default update events bindings. |
UpdateEvent | Custom update event description. |
Fields
Manager.active | EventManager's enabled state. |
Functions
Methods- Manager:init([kwargs])
-
Configure EventManager.
Parameters:
-
kwargs
table
Keyword arguments.
- updates {l2df.manager.event.UpdateEvent,...} Customizes update events. Overrides default bindings. (optional)
Returns:
-
kwargs
table
Keyword arguments.
- Manager:classInit(entity)
-
Embed references to EventManager's methods in the entity instance that you create.
Embedded methods are:
subscribe, unsubscribe and unsubscribeById.
Parameters:
- entity l2df.class.entity Entity's instance.
- Manager.subscribe(subscriber[, event=false], handler, source)
-
Allows the object to listen events sent to the Manager.
Parameters:
-
subscriber
l2df.class.entity or table
Subscriber object.
-
active
boolean
EventManager will watch for this property
on each EventManager:invoke() call. If
false
the fired event will be ignored (default false)
-
active
boolean
EventManager will watch for this property
on each EventManager:invoke() call. If
- event string Name of the event.
- handler function Callback function which would be called with an invoked event.
- source l2df.class.entity Source object of the calling event. If event with the same name comes from another source it would be ignored.
Returns:
-
number
Subscription ID. Can be used with EventManager:unsubscribeById().
-
subscriber
l2df.class.entity or table
Subscriber object.
- Manager:unsubscribe(event, handler)
-
Disables event tracking by objects using handler.
Parameters:
Returns:
-
boolean
true
if unsubscribed,false
otherwise. - Manager:unsubscribeById(event, id)
-
Disables event tracking by objects using ID.
Parameters:
- event string Name of the event.
- id number ID returned by EventManager:subscribe().
Returns:
-
boolean
true
if unsubscribed,false
otherwise. - Manager:invoke(event, source)
-
Invoke an event for all active subscribers.
Parameters:
- event string Name of the event.
- source l2df.class.entity Source object of the calling event. It is used by EventManager:subscribe() to filter out events depending on its source.
- Manager:monitoring(source, events[, alias[, save_result=false]])
-
Monitors whether an object calls certain functions.
Parameters:
- source l2df.class.entity or table Source object of the calling event. It is used by EventManager:subscribe() to filter out events depending on its source.
- events table or string Name(s) of the field(s) containing function to hook.
- alias table or string If setted makes an alias which would be passed to the. EventManager:invoke() method instead of the original function name. (optional)
- save_result boolean Whether to save the result of the function execution. (default false)
- Manager:update(...)
-
Update event handler.
Executes UpdateEvents on each entity and its.
components in the order they were passed to EventManager:init().
Parameters:
-
...
Passes all arguments to each update event and
liftdown
/liftup
callbacks.
-
...
Passes all arguments to each update event and
Tables
- DefaultUpdateEvents
-
Default update events bindings.
These events are executed in the same order they are represented here (or at
kwargs.updates
passed to EventManager:init()) on each EventManager:update() call.Fields:
- DefaultUpdateEvents[1] {'preupdate','beforepreupdate',false}
- DefaultUpdateEvents[2] {'update','beforeupdate',true}
- DefaultUpdateEvents[3] {'postupdate','beforepostupdate',false}
- DefaultUpdateEvents[4] {'lastupdate','beforelastupdate',false}
- UpdateEvent
-
Custom update event description.
Fields: