var Class = require('../utils/Class'); var plugins = { } ; var PluginManager = new Class({ initialize: function PluginManager(game){ this.game = game; game.events.once('boot', this.boot, this); } , boot: function (){ } , installGlobal: function (sys, globalPlugins){ var game = sys.game; var scene = sys.scene; var map = sys.settings.map; for (var i = 0; i < (_AN_Read_length('length', globalPlugins)); i++ ){ var pluginKey = globalPlugins[i]; sys[pluginKey] = game[pluginKey]; if (map.hasOwnProperty(pluginKey)) { scene[map[pluginKey]] = sys[pluginKey]; } } } , installLocal: function (sys, scenePlugins){ var scene = sys.scene; var map = sys.settings.map; var isBooted = sys.settings.isBooted; for (var i = 0; i < (_AN_Read_length('length', scenePlugins)); i++ ){ var pluginKey = scenePlugins[i]; var source = plugins[pluginKey]; var plugin = new source.plugin(scene); sys[source.mapping] = plugin; if (map.hasOwnProperty(source.mapping)) { scene[map[source.mapping]] = plugin; } if (isBooted) { plugin.boot(); } } } , remove: function (key){ delete plugins[key]; } , destroy: function (){ plugins = { } ; } } ); PluginManager.register = function (key, plugin, mapping){ plugins[key] = { plugin: plugin, mapping: mapping} ; } ; module.exports = PluginManager;