EntitiesInterface
in
An entity is nothing more then just a number on which components are attached indexed to.
Table of Contents
Methods
- attach() : T
- Attaches the given component to the given entity
- components() : array<class-string, object>
- Returns an array of all components for the given entity
- create() : int
- Creates an entity and returns its ID
- destroy() : void
- Destroyes an entity by its ID
- detach() : void
- Dettaches a component by class its class name
- detachAll() : void
- Dettaches all components from the given entity
- first() : T|null
- Returns the first component of the given class name
- firstWith() : int|null
- Returns the first entity that has the given component
- get() : T
- Returns a component for the given entity ! Warning: This method does no error checking and assumes you made sure the component needs to actually exist!
- getSingleton() : T
- Returns a singleton component from the entity registry
- has() : bool
- Returns boolean if an entity has a component
- hasSingleton() : bool
- Returns boolean if a singleton component exists
- list() : array<string|int, int>
- listComponents() : array<int, object>
- Returns an array of components for the given component class name.
- listWith() : array<string|int, int>
- registerComponent() : void
- Prepares internal data structures for the given component
- removeSingleton() : void
- Removes a singleton component from the entity registry
- setSingleton() : T
- Stores a singleton component in the entity registy
- tryGet() : T|null
- Returns a component for the given entity or null if it does not exist
- valid() : bool
- Returns boolean if the given entity ID is a valid one
- view() : Generator<int, T>
- Iterates over all available components of the given class name
- viewWith() : Generator<int, array<string|int, object>>
- Iterates over all entities having the given components and will pass the components as arguments to the callback Please note that the order is important, choose the "rarest" component first as this will be used to iterate and filter the entities.
Methods
attach()
Attaches the given component to the given entity
public
attach(int $entity, T $component) : T
Parameters
- $entity : int
-
The entitiy ID of the component to be attached
- $component : T
Tags
Return values
Tcomponents()
Returns an array of all components for the given entity
public
components(int $entity) : array<class-string, object>
Parameters
- $entity : int
-
The entitiy ID of the component
Return values
array<class-string, object>create()
Creates an entity and returns its ID
public
create() : int
Return values
intdestroy()
Destroyes an entity by its ID
public
destroy(int $entity) : void
Parameters
- $entity : int
detach()
Dettaches a component by class its class name
public
detach(int $entity, class-string $componentClassName) : void
Parameters
- $entity : int
-
The entitiy ID of the component to be detached
- $componentClassName : class-string
detachAll()
Dettaches all components from the given entity
public
detachAll(int $entity) : void
Parameters
- $entity : int
-
The entitiy ID of the component to be detached
first()
Returns the first component of the given class name
public
first(T> $componentClassName) : T|null
Parameters
- $componentClassName : T>
Tags
Return values
T|nullfirstWith()
Returns the first entity that has the given component
public
firstWith(class-string $componentClassName) : int|null
Parameters
- $componentClassName : class-string
Return values
int|nullget()
Returns a component for the given entity ! Warning: This method does no error checking and assumes you made sure the component needs to actually exist!
public
get(int $entity, T> $componentClassName) : T
Parameters
- $entity : int
-
The entitiy ID of the component to be retrieved
- $componentClassName : T>
Tags
Return values
TgetSingleton()
Returns a singleton component from the entity registry
public
getSingleton(T> $componentClassName) : T
Parameters
- $componentClassName : T>
Tags
Return values
Thas()
Returns boolean if an entity has a component
public
has(int $entity, class-string $componentClassName) : bool
Parameters
- $entity : int
-
The entitiy ID of the component
- $componentClassName : class-string
Return values
boolhasSingleton()
Returns boolean if a singleton component exists
public
hasSingleton(T> $componentClassName) : bool
Parameters
- $componentClassName : T>
Tags
Return values
boollist()
public
list(class-string $componentClassName) : array<string|int, int>
Parameters
- $componentClassName : class-string
Return values
array<string|int, int>listComponents()
Returns an array of components for the given component class name.
public
listComponents(class-string $componentClassName) : array<int, object>
In most cases you want to use the view method instead.
Parameters
- $componentClassName : class-string
Return values
array<int, object>listWith()
public
listWith(class-string ...$componentClassNames) : array<string|int, int>
Parameters
- $componentClassNames : class-string
Return values
array<string|int, int>registerComponent()
Prepares internal data structures for the given component
public
registerComponent(class-string $componentClassName) : void
Parameters
- $componentClassName : class-string
removeSingleton()
Removes a singleton component from the entity registry
public
removeSingleton(T> $componentClassName) : void
Parameters
- $componentClassName : T>
Tags
setSingleton()
Stores a singleton component in the entity registy
public
setSingleton(T $component) : T
Parameters
- $component : T
Tags
Return values
TtryGet()
Returns a component for the given entity or null if it does not exist
public
tryGet(int $entity, T> $componentClassName) : T|null
Parameters
- $entity : int
-
The entitiy ID of the component to be retrieved
- $componentClassName : T>
Tags
Return values
T|nullvalid()
Returns boolean if the given entity ID is a valid one
public
valid(int $entity) : bool
Parameters
- $entity : int
Return values
boolview()
Iterates over all available components of the given class name
public
view(T> $componentClassName) : Generator<int, T>
Parameters
- $componentClassName : T>
Tags
Return values
Generator<int, T>viewWith()
Iterates over all entities having the given components and will pass the components as arguments to the callback Please note that the order is important, choose the "rarest" component first as this will be used to iterate and filter the entities.
public
viewWith(class-string ...$componentClassNames) : Generator<int, array<string|int, object>>
Parameters
- $componentClassNames : class-string