phaser/v3/src/gameobjects/FactoryContainer.js

66 lines
1.4 KiB
JavaScript
Raw Normal View History

/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* The GameObject Factory is a global level container of Factory instances.
* Factories register themselves with this container.
*
* @class Phaser.GameObject.Factory
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
*/
var factories = {};
var FactoryContainer = function ()
{
console.log('FactoryContainer is alive');
this.register = function (factory)
{
if (factories.hasOwnProperty(factory.KEY))
{
console.log('Already registered', factory.KEY);
return this.getType(factory.KEY);
}
console.log('registering', factory.KEY);
factories[factory.KEY] = {
add: factory.add,
make: factory.make
};
return factory;
};
this.getType = function (key)
{
return factories[key];
};
this.load = function (dest)
{
for (var factory in factories)
{
console.log('Testing load of:', factory);
if (factories.hasOwnProperty(factory))
{
console.log('Loading', factory);
dest[factory] = factories[factory].add;
}
}
return dest;
};
return this;
};
module.exports = FactoryContainer();