Class l2df.class.component.behaviour
Behaviour component.
Inherited from l2df.class.Component class.
Info:
- Copyright: Atom-TM 2020
- Author: Abelidze
Functions
| Behaviour:added(obj[, kwargs]) | Component was added to Entity event. |
| Behaviour:invoke(obj, method, ...) | Search and invoke method on all currently subscribed objects. |
| Behaviour:append(obj, item[, params]) | Subscribe object update event. |
| Behaviour:remove(obj, item) | Unsubscribe object from update event. |
| Behaviour:clear(obj[, depth=0]) | Unsubscribe all appended objects. |
| Behaviour:has(obj, item) | Returns true if object currently subscribed to this behaviour. |
| Behaviour:push(obj, item[, params]) | Put all subscribed objects in stack meaning they won't watch update event and subscribe passed object. |
| Behaviour:pop(obj) | Unsubscribe all appended objects and restore objects previously stored in stack or do nothing. |
| Behaviour:switch(obj, item[, params]) | Unsubscribe all appended objects, clear stack and subscribe only passed object. |
| Behaviour:preupdate(obj, dt) | Pre-update event handler. |
| Behaviour:update(obj, dt) | Update event handler. |
| Behaviour:postupdate(obj, dt) | Post-update event handler. |
Fields
| Behaviour.data.size | Current stack size. |
Functions
Methods- Behaviour:added(obj[, kwargs])
-
Component was added to Entity event.
Parameters:
- obj l2df.class.entity Entity's instance.
-
kwargs
{function,...}
Keyword arguments. Contains function for creating single-function behaviours.
- behaviours table List of initial behaviours to add. (optional)
- Behaviour:invoke(obj, method, ...)
-
Search and invoke method on all currently subscribed objects.
Parameters:
- obj l2df.class.entity Entity's instance.
- method string Name of the Entity's method to invoke.
- ... Arguments passed to calling method.
- Behaviour:append(obj, item[, params])
-
Subscribe object update event.
Calls
item:enable()function if available.Parameters:
- obj l2df.class.entity Entity's instance.
- item table Object to subscribe.
- params table Arguments array to pass during update. (optional)
Returns:
-
boolean
- Behaviour:remove(obj, item)
-
Unsubscribe object from update event.
Calls
item:disable()function if available.Parameters:
- obj l2df.class.entity Entity's instance.
- item table Object to unsubscribe.
Returns:
-
boolean
- Behaviour:clear(obj[, depth=0])
-
Unsubscribe all appended objects.
Calls
:enable()function for each unsubscribed object where applicable.Parameters:
- obj l2df.class.entity Entity's instance.
- depth number Depth of the stack deletion. Clears everything when set to 0. (default 0)
Returns:
-
boolean
- Behaviour:has(obj, item)
-
Returns true if object currently subscribed to this behaviour.
It will return false if object is subscribed but is located in stack (see push).
Parameters:
- obj l2df.class.entity Entity's instance.
- item table Source object.
Returns:
-
boolean
- Behaviour:push(obj, item[, params])
-
Put all subscribed objects in stack meaning they won't watch update event and subscribe passed object.
Calls
:disable()function for each object put in stack.Parameters:
- obj l2df.class.entity Entity's instance.
- item table Source object.
- params table Arguments array to pass during update. (optional)
Returns:
-
boolean
- Behaviour:pop(obj)
-
Unsubscribe all appended objects and restore objects previously stored in stack or do nothing.
Calls
:enable()function for each subscribed and:disable()for each unsubscribed object.Parameters:
- obj l2df.class.entity Entity's instance.
- Behaviour:switch(obj, item[, params])
-
Unsubscribe all appended objects, clear stack and subscribe only passed object.
Calls
:enable()function for each subscribed and:disable()for each unsubscribed object.Parameters:
- obj l2df.class.entity Entity's instance.
- item table Source object.
- params table Arguments array to pass during update. (optional)
Returns:
-
boolean
- Behaviour:preupdate(obj, dt)
-
Pre-update event handler. Calls once per game tick before main update.
Invokes "preupdate" event on all subscribed objects.
Parameters:
- obj l2df.class.entity Entity's instance.
- dt number Delta-time since last game tick.
- Behaviour:update(obj, dt)
-
Update event handler. Calls once per game tick during main update.
Invokes "update" event on all subscribed objects.
Parameters:
- obj l2df.class.entity Entity's instance.
- dt number Delta-time since last game tick.
- Behaviour:postupdate(obj, dt)
-
Post-update event handler. Calls once per game tick after main update.
Invokes "postupdate" event on all subscribed objects.
Parameters:
- obj l2df.class.entity Entity's instance.
- dt number Delta-time since last game tick.
Fields
- Behaviour.data.size number
- Current stack size. To access use Behaviour:data() function.