UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

46 lines (36 loc) 1.09 kB
//TODO consider making more abstract and using as a ViewFactory elsewhere import { assert } from "../../../src/core/assert.js"; class ComponentControlFactory { /** * * @constructor */ constructor() { this.controllerTypes = {}; } /** * * @param {string} componentTypeName * @param {function} factory * @returns {ComponentControlFactory} */ register(componentTypeName, factory) { assert.equal(typeof factory, 'function'); assert.equal(typeof componentTypeName, 'string'); this.controllerTypes[componentTypeName] = factory; return this; } /** * * @param {string} componentTypeName * @returns {object} instance of a controller for given component type */ create(componentTypeName) { const factory = this.controllerTypes[componentTypeName]; return factory(); } exists(typeName) { return this.controllerTypes.hasOwnProperty(typeName); } } export default ComponentControlFactory;