VISU - PHP Game Framework

EntitiesInterface

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
template
Return values
T

components()

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
int

destroy()

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
template
Return values
T|null

firstWith()

Returns the first entity that has the given component

public firstWith(class-string $componentClassName) : int|null
Parameters
$componentClassName : class-string
Return values
int|null

get()

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
template
Return values
T

getSingleton()

Returns a singleton component from the entity registry

public getSingleton(T> $componentClassName) : T
Parameters
$componentClassName : T>
Tags
template
Return values
T

has()

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
bool

hasSingleton()

Returns boolean if a singleton component exists

public hasSingleton(T> $componentClassName) : bool
Parameters
$componentClassName : T>
Tags
template
Return values
bool

list()

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
template

setSingleton()

Stores a singleton component in the entity registy

public setSingleton(T $component) : T
Parameters
$component : T
Tags
template
Return values
T

tryGet()

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
template
Return values
T|null

valid()

Returns boolean if the given entity ID is a valid one

public valid(int $entity) : bool
Parameters
$entity : int
Return values
bool

view()

Iterates over all available components of the given class name

public view(T> $componentClassName) : Generator<int, T>
Parameters
$componentClassName : T>
Tags
template
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
Return values
Generator<int, array<string|int, object>>

        
On this page

Search results