-
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.
-
getName(self:
Entity):string¶ Returns the entity’s name from their Name component, or the className if it doesn’t have one.
-
expect(self:
Entity, prototype: <T>): <T>¶ Expects a component, returning it or erroring if the entity does not have the component.
- Parameters:
prototype (<
T>) – The type of the component to return.
-
addRelation(
self:Entity,
relation:Relation,
target:Entity,
final?:boolean
):Entity¶ Adds a relation between this entity and another. Enforces cardinality, symmetry, and exclusivity rules.
-
removeRelation(self:
Entity, relationType:Relation, target:Entity):Entity¶ Removes a relation of a given type with a specific target.
-
removeAllRelations(self:
Entity, relationType:Relation):Entity¶ Removes all relations with the given type.
-
hasRelation(self:
Entity, relationType:Relation, target?:Entity):boolean¶ Checks whether this entity has a relation.
-
getRelations(self:
Entity, relationType:Relation):table<Entity,Relation>¶ Gets all relations of a given type.
- Parameters:
relationType (
Relation) – The relation type/class.
-
getRelation(self:
Entity, relationType:Relation):Entity?¶ Gets the first/random entity with the given relation. This is mostly useful for exclusive relations.
- Parameters:
relationType (
Relation) – The relation prototype.
Other members:
Inherited from
Object:_serializationBlacklist,adopt(),assertType(),className,deepcopy(),deserialize(),extend(),instanceOf(),is(),isInstance(),mixin(),prettyprint(),serializationBlacklist,serialize()-
components: