2016-11-29 10:46:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The GameObject Factory is a global level container of Factory instances.
|
2016-11-29 15:25:14 +00:00
|
|
|
* Factories register themselves with this container (when required)
|
2016-11-29 10:46:35 +00:00
|
|
|
*
|
|
|
|
* @class Phaser.GameObject.Factory
|
|
|
|
* @constructor
|
|
|
|
* @param {Phaser.Game} game - A reference to the currently running game.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var factories = {};
|
|
|
|
|
|
|
|
var FactoryContainer = function ()
|
|
|
|
{
|
2016-12-07 01:13:17 +00:00
|
|
|
// console.log('FactoryContainer is alive');
|
2016-11-29 10:46:35 +00:00
|
|
|
|
|
|
|
this.register = function (factory)
|
|
|
|
{
|
|
|
|
if (factories.hasOwnProperty(factory.KEY))
|
|
|
|
{
|
2016-12-07 01:13:17 +00:00
|
|
|
// console.log('Already registered', factory.KEY);
|
2016-11-29 10:46:35 +00:00
|
|
|
|
|
|
|
return this.getType(factory.KEY);
|
|
|
|
}
|
|
|
|
|
2016-12-07 01:13:17 +00:00
|
|
|
// console.log('registering', factory.KEY);
|
2016-11-29 10:46:35 +00:00
|
|
|
|
|
|
|
factories[factory.KEY] = {
|
|
|
|
add: factory.add,
|
|
|
|
make: factory.make
|
|
|
|
};
|
|
|
|
|
|
|
|
return factory;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getType = function (key)
|
|
|
|
{
|
|
|
|
return factories[key];
|
|
|
|
};
|
|
|
|
|
2016-11-29 11:06:14 +00:00
|
|
|
this.load = function (dest, isFactory)
|
2016-11-29 10:46:35 +00:00
|
|
|
{
|
|
|
|
for (var factory in factories)
|
|
|
|
{
|
|
|
|
if (factories.hasOwnProperty(factory))
|
|
|
|
{
|
2016-11-29 11:06:14 +00:00
|
|
|
// console.log('Loading', factory);
|
|
|
|
|
|
|
|
dest[factory] = (isFactory) ? factories[factory].add : factories[factory].make;
|
2016-11-29 10:46:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
};
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = FactoryContainer();
|