mirror of
https://github.com/photonstorm/phaser
synced 2024-12-20 01:55:45 +00:00
61 lines
1.3 KiB
JavaScript
61 lines
1.3 KiB
JavaScript
|
|
/**
|
|
* The GameObject Factory is a global level container of Factory instances.
|
|
* Factories register themselves with this container (when required)
|
|
*
|
|
* @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);
|
|
}
|
|
else
|
|
{
|
|
// 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, isFactory)
|
|
{
|
|
for (var factory in factories)
|
|
{
|
|
if (factories.hasOwnProperty(factory))
|
|
{
|
|
// console.log('Loading', factory);
|
|
|
|
dest[factory] = (isFactory) ? factories[factory].add : factories[factory].make;
|
|
}
|
|
}
|
|
|
|
return dest;
|
|
};
|
|
|
|
return this;
|
|
};
|
|
|
|
module.exports = FactoryContainer();
|