If the concord folder is in the root directory of your game, you can import this module like so:
concord. entity = require ( 'concord.entity' )
contains components which are processed by systems.
Name
Type
Description
has
fun(self: Entity , name: string): boolean
remove
fun(self: Entity , name: string): Entity
Name
Type
Description
__world?
World
Creates a new Entity. Optionally queues it to be added to a World.
If Entity.SERIALIZE_BY_DEFAULT is true, the Entity is given a “serializable” Component.
entity = Entity. new ( world )
Name
Type
Description
world
World
World to add the entity to
Name
Type
Description
entity
Entity
Gives an Entity a Component.
If the Component already exists, it’s overridden by this new Component.
Name
Type
Description
name
string
Name of the ComponentClass
...
any
Additional arguments to pass to the Component’s populate function
Pass an existing Component instance (already populated, not attached to an entity). Skips name and populate arguments.
Ensures an Entity has a Component.
If the Component already exists, no action is taken.
entity : ensure ( name, ... )
Name
Type
Description
name
string
Name of the ComponentClass
...
any
Additional arguments to pass to the Component’s populate function
entity : ensure ( component )
Pass an existing Component instance (already populated, not attached to an entity). Skips name and populate arguments.
Removes a Component from an Entity.
Name
Type
Description
name
string
Name of the ComponentClass to remove
Assembles an Entity.
entity : assemble ( assemblage, ... )
Name
Type
Description
assemblage
fun(entity: Entity , …)
Function that will assemble an entity
...
any
Additional arguments to pass to the assemblage function.
Destroys the Entity.
Queues removal from its World if it’s in one. The Entity stays in the World until the next flush.
Returns true if the Entity has a Component.
boolean = entity : has ( name )
Name
Type
Description
name
string
Name of the ComponentClass to check
Name
Type
Description
boolean
boolean
Gets a Component from the Entity.
Name
Type
Description
name
string
Name of the ComponentClass to get
Name
Type
Description
Component |nil
The Component, or nil if the Entity does not have it
Returns a shallow copy of the Entity’s fields, excluding __world and __isEntity.
This is primarily the Entity’s Components. Extra non-component fields are also copied.
Mutating a copied Component still mutates the Entity’s Component.
matches = entity : getComponents ( output )
Name
Type
Description
output
table
Table to copy into. A new table is created if omitted.
Name
Type
Description
matches
table
Returns true if the Entity has been assigned a World.
True as soon as addition is queued, and remains true until removal is flushed.
boolean = entity : inWorld ()
Name
Type
Description
boolean
boolean
Returns the World the Entity is in.
world = entity : getWorld ()
Name
Type
Description
world
World
Serializes the Entity’s Components.
Components that return nil from serialize are omitted.
matches = entity : serialize ( ignoreKey )
Name
Type
Description
ignoreKey
boolean
If true, the key Component is omitted
Name
Type
Description
matches
table
Serialized Entity data
Deserializes Components onto the Entity.
entity : deserialize ( data )
Name
Type
Description
data
table
Serialized Entity data