2018-01-09 01:30:10 +00:00
|
|
|
var Class = require('../utils/Class');
|
2018-01-16 02:08:04 +00:00
|
|
|
|
|
|
|
var plugins = {};
|
2018-01-09 01:30:10 +00:00
|
|
|
|
|
|
|
var PluginManager = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2018-01-16 02:08:04 +00:00
|
|
|
// The PluginManager is global and belongs to the Game instance, not a Scene.
|
|
|
|
function PluginManager (game, config)
|
2018-01-09 01:30:10 +00:00
|
|
|
{
|
2018-01-16 02:08:04 +00:00
|
|
|
this.game = game;
|
|
|
|
},
|
|
|
|
|
|
|
|
boot: function ()
|
|
|
|
{
|
|
|
|
},
|
2018-01-09 01:30:10 +00:00
|
|
|
|
2018-01-16 02:08:04 +00:00
|
|
|
install: function (scene, config)
|
|
|
|
{
|
|
|
|
var sys = scene.sys;
|
|
|
|
|
|
|
|
for (var i = 0; i < config.length; i++)
|
|
|
|
{
|
|
|
|
var p = config[i];
|
|
|
|
|
|
|
|
console.log('installing', p);
|
|
|
|
|
|
|
|
if (plugins[p])
|
|
|
|
{
|
|
|
|
// Install a local reference inside of Systems
|
|
|
|
sys[p] = new plugins[p](scene);
|
|
|
|
}
|
|
|
|
}
|
2018-01-09 01:30:10 +00:00
|
|
|
},
|
|
|
|
|
2018-01-16 02:08:04 +00:00
|
|
|
remove: function (key)
|
|
|
|
{
|
|
|
|
delete plugins[key];
|
|
|
|
},
|
2018-01-09 01:30:10 +00:00
|
|
|
|
2018-01-16 02:08:04 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
plugins = {};
|
|
|
|
}
|
2018-01-09 01:30:10 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-01-16 02:08:04 +00:00
|
|
|
// Static method called directly by the Plugins
|
|
|
|
|
|
|
|
PluginManager.register = function (key, plugin)
|
|
|
|
{
|
|
|
|
plugins[key] = plugin;
|
2018-01-09 01:30:10 +00:00
|
|
|
|
2018-01-16 02:08:04 +00:00
|
|
|
console.log('PluginManager.register', key);
|
|
|
|
};
|
2018-01-09 01:30:10 +00:00
|
|
|
|
|
|
|
module.exports = PluginManager;
|