UNPKG

gibbon.js

Version:

Actor/Component system for use with pixi.js.

59 lines 1.6 kB
/** * A Factory creates full GameObject instances from keys. */ export default class Factory { /** * @property {PIXI.renderer} renderer - game renderer to pre-render objects to textures. */ get renderer() { return this._game.renderer; } /** * @property {Gibbon.Game} game */ get game() { return this._game; } /** * @property {Gibbon.Engine} engine */ get engine() { return this.game.engine; } /** * @property {PIXI.Rectangle} viewRect */ get viewRect() { return this._game.screen; } builds; _game; /** * * @param {Gibbon.Game} game */ constructor(game) { this._game = game; this.builds = new Map(); } /** * Associates a key with the given creator function, binding it to this factory * instance. * @param {string} key * @param {Function} func * @param {?object} data - data to pass as first argument to create function. * @returns {Factory} this. */ addCreator(key, creator, data) { if (data) { creator = creator.bind(this, data); } this.builds.set(key, creator); return this; } /** * Create a GameObject from the given key. * @param {string} key * @returns {GameObject} Object created. */ create(key, ...args) { let build = this.builds.get(key); if (build) { return build.apply(this, args); } return null; } } //# sourceMappingURL=factory.js.map