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 ()
|
|
|
|
{
|
|
|
|
this.register = function (factory)
|
|
|
|
{
|
|
|
|
if (factories.hasOwnProperty(factory.KEY))
|
|
|
|
{
|
|
|
|
return this.getType(factory.KEY);
|
|
|
|
}
|
2017-02-07 21:49:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
factories[factory.KEY] = {
|
|
|
|
add: factory.add,
|
|
|
|
make: factory.make
|
|
|
|
};
|
2016-11-29 10:46:35 +00:00
|
|
|
|
2017-02-07 21:49:25 +00:00
|
|
|
return factory;
|
|
|
|
}
|
2016-11-29 10:46:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
dest[factory] = (isFactory) ? factories[factory].add : factories[factory].make;
|
2016-11-29 10:46:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
};
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = FactoryContainer();
|