Entity

Entity

An entity is simply by an id used to reference zero to many components. The types of components that an entity references must be unique.

Constructor

new Entity()

Members

(private) id :number

A literal that identifies the entity.

(private) state :*

The data contained in the component, it is immutable.

Methods

addComponents(…components) → {Entity}

Adds all the specified components to the entity.
Parameters
Name Type Attributes Description
components Component <repeatable>
the components to add
Fires:
Throws
TypeError
Will throw this error when an argument other than a Component is passed.
ReferenceError
Will throw this error When invoked after the entity has been disposed.
Returns
Itself
Type
Entity

getComponents(…types) → {Component|Map.<string, Component>}

Gets all components contained in the entity for specified component types. Returns only a single component if only one type is specified, but returns a map of all components is returned if no types are specified.
Parameters
Name Type Attributes Description
types string <repeatable>
the desired types of components
Fires:
  • module:transvolve#event:error
Throws
TypeError
when an argument other than a string is passed.
ReferenceError
when invoked after the entity has been disposed.
Returns
A single component or the map of components to component type
Type
Component | Map.<string, Component>

getId() → {integer}

Get the id.
Throws
ReferenceError
Will throw this error if invoked after being disposed.
Returns
The entity id.
Type
integer

hasComponents(…types) → {boolean}

Determines if the entity has components of all the specified types.
Parameters
Name Type Attributes Description
types string <repeatable>
The component types
Throws
TypeError
Will throw this error when an argument other than a string is passed.
ReferenceError
Will throw this error when invoked after the entity has been disposed.
Returns
The result
Type
boolean

removeComponents(…componentsOrTypes) → {Entity}

Removes all the specified components or types of components from the entity. Each component that is removed is disposed.
Parameters
Name Type Attributes Description
componentsOrTypes Component | string <repeatable>
the components and/or component types to remove
Fires:
Throws
TypeError
Will throw this error when an argument other than a Component is passed.
ReferenceError
Will throw this error when invoked after the entity has been disposed.
Returns
Itself
Type
Entity

Events

entity:add

An entity:add event occurs when an entity adds a component.
Parameters
Name Type Description
entity Entity The entity that added the component.
component Component The component that was added.

entity:add:{type}

An entity:add:{type} event occurs when an entity adds a component.
Parameters
Name Type Description
entity Entity The entity that added the component.
component Component The component that was added.

entity:change

An entity:change event occurs when a component, that an entity owns, changes.
Parameters
Name Type Description
entity Entity The entity that owns the component.
component Component The component that caused the change.
newState * The new value of the component.
oldState * The old value of the component.

entity:change:{type}

A entity:change:{type} event occurs when a component, that an entity owns, changes.
Parameters
Name Type Description
entity Entity The entity that owns the component.
component Component The component that was changed.
newState * The new value of the component.
oldState * The old value of the component.

entity:dispose

An entity:dispose event occurs when an entity is being disposed.
Parameters
Name Type Description
entity Entity The entity that is being disposed.

entity:remove

An entity:remove event occurs when an entity disposes a component.
Parameters
Name Type Description
entity Entity The entity that disposing the component.
component Component The component that is being disposed.

entity:remove:{type}

An entity:remove:{type} event occurs when an entity disposes a component.
Parameters
Name Type Description
entity Entity The entity that is disposing the component.
component Component The component that is being disposed.