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 22:28:29 +00:00
|
|
|
install: function (scene, globalPlugins, localPlugins)
|
2018-01-16 02:08:04 +00:00
|
|
|
{
|
2018-01-16 22:28:29 +00:00
|
|
|
var i;
|
|
|
|
var pluginKey;
|
2018-01-16 02:08:04 +00:00
|
|
|
var sys = scene.sys;
|
|
|
|
|
2018-01-16 22:28:29 +00:00
|
|
|
for (var i = 0; i < globalPlugins.length; i++)
|
2018-01-16 02:08:04 +00:00
|
|
|
{
|
2018-01-16 22:28:29 +00:00
|
|
|
pluginKey = globalPlugins[i];
|
2018-01-16 02:08:04 +00:00
|
|
|
|
2018-01-16 22:28:29 +00:00
|
|
|
sys.scene[pluginKey] = sys[pluginKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < localPlugins.length; i++)
|
|
|
|
{
|
|
|
|
pluginKey = localPlugins[i];
|
|
|
|
|
|
|
|
// console.log('installing', p);
|
2018-01-16 02:08:04 +00:00
|
|
|
|
2018-01-16 22:28:29 +00:00
|
|
|
if (plugins[pluginKey])
|
2018-01-16 02:08:04 +00:00
|
|
|
{
|
|
|
|
// Install a local reference inside of Systems
|
2018-01-16 22:28:29 +00:00
|
|
|
sys[pluginKey] = new plugins[pluginKey](scene);
|
2018-01-16 02:08:04 +00:00
|
|
|
}
|
|
|
|
}
|
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 22:28:29 +00:00
|
|
|
// console.log('PluginManager.register', key);
|
2018-01-16 02:08:04 +00:00
|
|
|
};
|
2018-01-09 01:30:10 +00:00
|
|
|
|
|
|
|
module.exports = PluginManager;
|