Class l2df.class.entity

Last updated 2021-05-28 15:24:22

Entity class.

Inherited from l2df.Class.

Info:

Functions

Entity:new([kwargs[, key=true[, ...]]]) Constructor for eating an entity instance.
Entity:clone() Create copy of current object (with all attached nodes).
Entity:attach(entity) Adding an inheritor to an entity.
Entity:attachMultiple(array) Adding some inheritors to an entity.
Entity:detach(entity) Removing an inheritor from entity.
Entity:detachAll() Remove all nodes attached to the entity.
Entity:detachParent() Removing entity from inheritors list of his parent.
Entity:destroy() Destroy entity.
Entity:getNodes([filter]) Getting a list of entity's inheritors.
Entity:getParent() Option to obtain a parent using the function.
Entity:sync([state]) Backup / restore entity.
Entity:isDescendant(entity) Check for inheritance from an object.
Entity:setActive([active[, propagate=false]]) Set / toggle active state of this entity.
Entity:createComponent(class, ...) Create new component and add to this entity.
Entity:addComponent(component, ...) Add component to entity.
Entity:removeComponent(component, ...) Remove component from entity.
Entity:clearComponents() Remove all components added to entity.
Entity:upComponent(component) Floats up existing component of the object like a bubble.
Entity:hasComponent(component) Check if component exists on entity.
Entity:hasComponentClass(componentClass) Check if component exists on entity,
Entity:getComponentById(id) Get attached component by ID,
Entity:getComponent(componentClass) Get a single attached component of given class.
Entity:getComponents(componentClass) Get a list of attached components of given class.
Entity:enum([active=false[, skipped=false]]) Enumerate entities' tree.

Tables

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.

Fields

Entity.key Key string.
Entity.parent Parent entity.
Entity.active Entity's state.


Functions

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:

  1. number or boolean
  2. 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:

  • state table Table containing snapshot of the entity's state:
    { active = [boolean], parent = [l2df.class.entity], data = [table] }
    . (optional)

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:

  1. number
  2. l2df.class.component
  3. boolean
Entity:addComponent(component, ...)
Add component to entity.

Parameters:

Returns:

  1. number
  2. l2df.class.component
  3. 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:

  1. number or boolean
  2. 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

Tables

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!

Fields

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.