Home Reference Source
import EntitySystem from 'oxygen-core/systems/EntitySystem'
public class | source

EntitySystem

Extends:

System → EntitySystem

Manages entities on scene.

Example:

const system = new EntitySystem();
class Hello extends Component { constructor() { this.hello = null; } onAction(name) { console.log(name); } }
system.registerComponent('Hello', () => new Hello());
system.root = system.buildEntity({ name: 'hey', components: { Hello: { hello: 'world' } } });
system.updateTransforms();
system.performAction('hi');

Constructor Summary

Public Constructor
public

constructor(triggerEvents: boolean)

Constructor.

Member Summary

Public Members
public get
public set
public get

Method Summary

Public Methods
public

buildEntity(data: *): Entity

Build entity from JSON data.

public

createComponent(typename: string, properties: *): Component

Create component instnace by it's type name and apply properties to it.

public

Destructor (dispose internal resources).

public

performAction(name: string, args: *)

Perform action on root entity.

public

registerComponent(typename: string, componentConstructor: Function)

Register new component factory.

public

Unregister component factory.

public

Update entities transforms.

Inherited Summary

From class System
public static get
public static get

systems: *

public static

Dispose and remove all registered systems.

public static

get(typename: string): System | null

Returns system instance of given type name.

public static

register(typename: string, system: System): System

Register new system instance under given name.

public static

unregister(typename: string): System

Unregister given system.

public

Destructor (disposes all internal resources).

public

Event called after system gets registered.

public

Event called before system gets unregistered.

Public Constructors

public constructor(triggerEvents: boolean) source

Constructor.

Params:

NameTypeAttributeDescription
triggerEvents boolean

Tells if system should trigger events.

Public Members

public get root: Entity | null source

public set root: Entity | null source

public get triggerEvents: boolean source

Public Methods

public buildEntity(data: *): Entity source

Build entity from JSON data.

Params:

NameTypeAttributeDescription
data *

JSON representation of serialized entity data.

Return:

Entity

Entity instance.

Example:

class Hello extends Component { constructor() { this.hello = null; } }
system.registerComponent('Hello', () => new Hello());
const entity = system.buildEntity({ name: 'hey', components: { Hello: { hello: 'world' } } });
const hello = entity.getComponent('Hello');
console.log(hello.hello);

public createComponent(typename: string, properties: *): Component source

Create component instnace by it's type name and apply properties to it.

Params:

NameTypeAttributeDescription
typename string

Component type name.

properties *

Object with key-value pairs of component properties.

Return:

Component

Component instance.

Example:

class Hello extends Component { constructor() { this.hello = null; } }
system.registerComponent('Hello', () => new Hello());
const hello = system.createComponent('Hello', { hello: 'world' });
console.log(hello.hello);

public dispose() source

Destructor (dispose internal resources).

Override:

System#dispose

Example:

system.dispose();
system = null;

public performAction(name: string, args: *) source

Perform action on root entity. Actions are events that are performed by entity components and are passed down to it's children.

Params:

NameTypeAttributeDescription
name string

action name.

args *

Action arguments.

Example:

class Hi extends Component { onAction(name, what) { if (name === 'hi') console.log(what); } }
system.registerComponent('Hi', () => new Hi());
system.root = system.buildEntity({ components: { Hi: {} } });
system.performAction('hi', 'hello');

public registerComponent(typename: string, componentConstructor: Function) source

Register new component factory.

Params:

NameTypeAttributeDescription
typename string

Component type name.

componentConstructor Function

Component factory function (it should return new instance of component).

Example:

class MyComponent extends Component { static factory() { return new MyComponent(); } }
system.registerComponent('MyComponent', MyComponent.factory);

public unregisterComponent(typename: string) source

Unregister component factory.

Params:

NameTypeAttributeDescription
typename string

Component type name.

Example:

system.unregisterComponent('MyComponent');

public updateTransforms() source

Update entities transforms.