ComponentHandler

ComponentHandler

Base class for component handlers. All different types of components that an entity
can have need to have a registered component handler. To handle a new type of component,
create a class that inherits from this class, and override {_prepare}, {_create}, {update} and {remove}
as needed ({update} must be overridden). In your class, call @_register('yourComponentType') to _register
the handler with the loader.

Constructor

new ComponentHandler(world, getConfig, updateObject, loadObject)

Parameters:
Name Type Description
world World

The sumerian world

getConfig function

The config loader function. See DynamicLoader#_loadRef.

updateObject function

The handler function. See DynamicLoader#_updateObject.

loadObject function

The object loader function. See DynamicLoader#_loadObject.

Methods

(static) _registerClass(type, klass)

Register a handler for a component type. Called in the class body of subclasses.

Parameters:
Name Type Description
type string
klass Class

the class to register for this component type

(static) getHandler(type) → {Class}

Get a handler class for the specified type of component. The type can be e.g. 'camera', 'transform', etc.
The type name should not end with "Component".

Parameters:
Name Type Description
type string

update(entity, config, options) → {Promise}

Update engine component object based on the config. Should be overridden in subclasses.
This method is called by #{EntityHandler} to load new component configs into the engine.

Parameters:
Name Type Description
entity Entity

The entity on which this component should be added.

config Object
options Object