-
class Entity :
Object
¶ The superclass of entitys and cells, holding their components.
-
components:
Component
[]¶ A table containing all of the entity’s component instances. Generated at runtime.
-
componentCache:
table
<Component
,Component
>¶ This is a cache of prototype -> component for component queries, reducing most queries to a hashmap lookup.
-
__new(self:
Entity
)¶ Constructor for an entity. Initializes and copies the entity’s fields from its prototype.
-
give(self:
Entity
, component:Component
)Entity
¶ Adds a component to the entity, replacing any existing component of the same type. Will check if the component’s prerequisites are met and will throw an error if they are not.
-
ensure(self:
Entity
, component:Component
)Entity
¶ Gives the component, but only if the entity doesn’t already have it.
-
has(self:
Entity
, ...:Component
) has:boolean
¶ Checks whether the entity has all of the components given.
- Parameters:
... (
Component
) – The list of component prototypes.- Returns:
has (
boolean
) – True if the entity has all of the components given.
-
get(self:
Entity
, prototype: <T
>, ...:unknown
) <T
>?, ...?:Component
¶ Returns the components for the prototypes given, or nil if the entity does not have it.
- Parameters:
prototype (<
T
>) – The type of the component to return.
-
components: