Module system.game.Entities

Classes

ECS.TypeMetaData
Entity
EntitySnapshot

Functions

convert (entity, targetTypeName) Converts the given entity to the given type.
defragmentEntityIDs ()
deserializeState (serializedState) Restores a snapshot of the whole entity system's current state
despawn (entityID) Deletes the entity with the given ID.
entitiesWithComponents (componentNames) Iterates over entities that have all of the given components.
entityExists (entityID) Returns true if there is an entity with the given ID, false otherwise.
getEntitiesByType (typeName) Returns a list of entities of the given type.
getEntityByID (entityID) Returns the entity with the given ID.
getEntityPrototype (typeName) Returns the prototype (an immutable entity with id 0) for the given type.
getEntityTypeID (entityID) Deprecated.
getEntityTypeName (entity) Accepts an entity or type name, returns a type name (like entity.name, but also safe on strings)
getEntityTypesWithComponents (componentList) Returns a list of types that have all of the given components.
hasAllComponents (entity, components)
isValidComponent (componentName) Returns true if a component exists with the given name, false otherwise
isValidEntityType (typeName) Returns true if a type exists with the given name, false otherwise
prototypesWithComponents (componentList) Iterates over prototypes of types that have all of the given components.
resetAll () Deletes all entities, and fully reset ECS state.
resolveEntityType (typeName) Deprecated.
serializeState () Creates a snapshot of the whole entity system's current state
spawn (typeName) Creates and initializes an entity of the given type.
typeHasComponent (typeName, componentName) Returns true if the given type has a component with the given name.
typesWithComponents (componentList) Iterates over types that have all of the given components.


Classes

ECS.TypeMetaData
  • components string[] List of component names for this entity type
  • mutableComponents string[] List of component names for this entity type with at least one mutable field
  • setters table Maps component name => field name => setter function
  • fieldIDs table Maps component name => field name => field ID
  • layoutComponents string[] Maps field ID => component name
  • layoutFields string[] Maps field ID => field name
  • initialValues string Serialized table containing all default values for this entity type
Entity
: table
  • id integer Unique ID of the entity (always >0)
  • name string Entity type name
EntitySnapshot

Functions

convert (entity, targetTypeName)
Converts the given entity to the given type. Components are added and removed to match the target type. For components that exist on both the source and target types, mutable fields keep their current values, while constant fields are reset to the target type’s default.

Parameters:

  • entity Entity
  • targetTypeName string

Returns:

    Entity
defragmentEntityIDs ()
deserializeState (serializedState)
Restores a snapshot of the whole entity system's current state

Parameters:

  • serializedState EntitySnapshot
despawn (entityID)
Deletes the entity with the given ID.

Parameters:

  • entityID integer
entitiesWithComponents (componentNames)
Iterates over entities that have all of the given components.

Parameters:

  • componentNames string[]

Returns:

  1. fun(state: table):Entity
  2. table
entityExists (entityID)
Returns true if there is an entity with the given ID, false otherwise.

Parameters:

  • entityID number

Returns:

    boolean
getEntitiesByType (typeName)
Returns a list of entities of the given type.

Parameters:

  • typeName
getEntityByID (entityID)
Returns the entity with the given ID. For compatibility, this also accepts entities, returning them unchanged.

Parameters:

  • entityID integer|Entity

Returns:

    Entity?
getEntityPrototype (typeName)
Returns the prototype (an immutable entity with id 0) for the given type.

Parameters:

  • typeName string

Returns:

    Entity
getEntityTypeID (entityID)
Deprecated. Use ecs.getEntityByID(entityID).name.

Parameters:

  • entityID integer

Returns:

    string
getEntityTypeName (entity)
Accepts an entity or type name, returns a type name (like entity.name, but also safe on strings)

Parameters:

  • entity Entity|string

Returns:

    string
getEntityTypesWithComponents (componentList)
Returns a list of types that have all of the given components.

Parameters:

  • componentList string[]

Returns:

    string[]
hasAllComponents (entity, components)

Parameters:

  • entity
  • components
isValidComponent (componentName)
Returns true if a component exists with the given name, false otherwise

Parameters:

  • componentName string

Returns:

    boolean
isValidEntityType (typeName)
Returns true if a type exists with the given name, false otherwise

Parameters:

  • typeName string

Returns:

    boolean
prototypesWithComponents (componentList)
Iterates over prototypes of types that have all of the given components.

Parameters:

  • componentList string[]

Returns:

  1. fun(table: table, i?: integer):integer, Entity
  2. table
  3. integer i
resetAll ()
Deletes all entities, and fully reset ECS state.
resolveEntityType (typeName)
Deprecated. Does nothing.

Parameters:

  • typeName string

Returns:

    string
serializeState ()
Creates a snapshot of the whole entity system's current state

Returns:

    EntitySnapshot
spawn (typeName)
Creates and initializes an entity of the given type. Returns the newly created entity.

Parameters:

  • typeName string

Returns:

    Entity
typeHasComponent (typeName, componentName)
Returns true if the given type has a component with the given name. Returns nil for invalid types, and false for valid types that don’t have the component.

Parameters:

  • typeName string
  • componentName string

Returns:

    boolean
typesWithComponents (componentList)
Iterates over types that have all of the given components.

Parameters:

  • componentList string[]

Returns:

  1. fun(table: table, i?: integer):integer, string
  2. table
  3. integer i
generated by LDoc 1.4.6