Entity class.
Inherited from l2df.Class.
Info:
- Copyright: Atom-TM 2019
- Author: Abelidze, Kasai
Entity.R |
Meta-table for performing search in sub-nodes of the entity object. |
Entity.C |
Table containing components for easy access. |
Entity.data |
Entity's public storage for all variables and user data. |
Methods
-
Entity:new([kwargs[, key=true[, ...]]])
-
Constructor for eating an entity instance.
Parameters:
-
kwargs
table
Keyword arguments. Also passed to all adding components.
-
key
string
String key used for performing entity-search via Entity.R meta-variable.
(optional)
-
...
Arguments redirected to Entity:init() function.
-
Entity:clone()
-
Create copy of current object (with all attached nodes).
Returns:
l2df.class.entity
-
Entity:attach(entity)
-
Adding an inheritor to an entity.
Parameters:
Returns:
-
number or boolean
-
l2df.class.entity or nil
-
Entity:attachMultiple(array)
-
Adding some inheritors to an entity.
Parameters:
-
Entity:detach(entity)
-
Removing an inheritor from entity.
Parameters:
-
Entity:detachAll()
-
Remove all nodes attached to the entity.
-
Entity:detachParent()
-
Removing entity from inheritors list of his parent.
Returns:
l2df.class.entity
-
Entity:destroy()
-
Destroy entity.
-
Entity:getNodes([filter])
-
Getting a list of entity's inheritors.
Parameters:
-
filter
function
Filter predicate function.
(optional)
Returns:
table
-
Entity:getParent()
-
Option to obtain a parent using the function.
Returns:
l2df.class.entity
-
Entity:sync([state])
-
Backup / restore entity.
Parameters:
Returns:
table or nil
-
Entity:isDescendant(entity)
-
Check for inheritance from an object.
Parameters:
Returns:
boolean
-
Entity:setActive([active[, propagate=false]])
-
Set / toggle active state of this entity.
Parameters:
-
active
boolean
Active state to set. Toggles current if not setted.
(optional)
-
propagate
boolean
Propagates state to subnodes if setted to true.
(default false)
Returns:
boolean
-
Entity:createComponent(class, ...)
-
Create new component and add to this entity.
Parameters:
Returns:
-
number
-
l2df.class.component
-
boolean
-
Entity:addComponent(component, ...)
-
Add component to entity.
Parameters:
Returns:
-
number
-
l2df.class.component
-
boolean
-
Entity:removeComponent(component, ...)
-
Remove component from entity.
Parameters:
Returns:
boolean
-
Entity:clearComponents()
-
Remove all components added to entity.
Returns:
boolean
-
Entity:upComponent(component)
-
Floats up existing component of the object like a bubble. Can be used to reorder components execution.
Parameters:
Returns:
-
number or boolean
-
l2df.class.component or nil
-
Entity:hasComponent(component)
-
Check if component exists on entity.
Parameters:
Returns:
boolean
-
Entity:hasComponentClass(componentClass)
-
Check if component exists on entity,
Parameters:
Returns:
boolean
-
Entity:getComponentById(id)
-
Get attached component by ID,
Parameters:
-
id
number
Component's ID.
Returns:
l2df.class.component
-
Entity:getComponent(componentClass)
-
Get a single attached component of given class.
Parameters:
Returns:
l2df.class.component or nil
-
Entity:getComponents(componentClass)
-
Get a list of attached components of given class.
Parameters:
Returns:
table
-
Entity:enum([active=false[, skipped=false]])
-
Enumerate entities' tree.
Parameters:
-
active
boolean
Enumerate only active nodes.
(default false)
-
skipped
boolean
Skip self in enumeration.
(default false)
Returns:
function
-
Entity.R
-
Meta-table for performing search in sub-nodes of the entity object.
Fields:
-
__index
function
Doing search. Ex.:
local btn_ref = Entity.R.MENU.BUTTON
-
__newindex
function
Set object key after search. Ex.:
Entity.R.MENU.BUTTON.text = 'Click'
-
__call
function
Returns "clear" entity object.
Important cuz Entity.R variable is not an actual entity. Ex.:
local btn = Entity.R.MENU.BUTTON()
-
Entity.C
-
Table containing components for easy access.
Components must manually add / remove them from this list if it is required.
-
Entity.data
-
Entity's public storage for all variables and user data.
It is important to use this and do not garbage actual entity's table since:
1. It's more secure;
2. It's used by all the components to store and transfer data;
3. It's a part of rollback system;
4. Networking doesn't work without this!
-
Entity.key
string
-
Key string. Used for searching via Entity.R.
-
Entity.parent
l2df.class.entity
-
Parent entity. Can be
nil
meaning no parent attached.
-
Entity.active
boolean
-
Entity's state.
If false entity would not receive any update and draw events.