-
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.
-
relationships:
table
<Relationship
,table
<Entity
,Relationship
>>¶
-
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.
-
addRelationship(
self:Entity
,
relationship:Relationship
,
target:Entity
,
final?:boolean
):Entity
¶ Adds a relationship between this entity and another. Enforces cardinality, symmetry, and exclusivity rules.
- Parameters:
relationship (
Relationship
) – The relationship instance to add.target (
Entity
) – The target entity of the relationship.final? (
boolean
) – If true this add is part of a symmetry and we shouldn’t attempt again.
-
removeRelationship(
self:Entity
,
relationshipType:Relationship
,
target:Entity
):Entity
¶ Removes a relationship of a given type with a specific target.
- Parameters:
relationshipType (
Relationship
) – The relationship type/class (not an instance).target (
Entity
) – The target entity of the relationship.
-
removeAllRelationships(self:
Entity
, relationshipType:Relationship
):Entity
¶
-
hasRelationship(
self:Entity
,
relationshipType:Relationship
,
target:Entity
):boolean
¶ Checks whether this entity has a relationship of a given type with a specific target.
- Parameters:
relationshipType (
Relationship
) – The relationship type/class.target (
Entity
) – The target entity to check for.
-
getRelationships(self:
Entity
, relationshipType:Relationship
):table
<Entity
,Relationship
>¶ Gets all relationships of a given type.
- Parameters:
relationshipType (
Relationship
) – The relationship type/class.
Other members:
Inherited from
Object
:_serializationBlacklist
,adopt()
,assertType()
,className
,deserialize()
,extend()
,instanceOf()
,is()
,isInstance()
,mixin()
,prettyprint()
,serializationBlacklist
,serialize()
-
components: