Skip to content

Commit 92e62b9

Browse files
committed
Updated PluginManager to support installation and injection of global and local plugins
1 parent c8d859c commit 92e62b9

1 file changed

Lines changed: 40 additions & 16 deletions

File tree

src/plugins/PluginManager.js

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,56 @@ var PluginManager = new Class({
1010
function PluginManager (game, config)
1111
{
1212
this.game = game;
13+
14+
game.events.once('boot', this.boot, this);
1315
},
1416

1517
boot: function ()
1618
{
1719
},
1820

19-
install: function (scene, globalPlugins, localPlugins)
21+
installGlobal: function (sys, globalPlugins)
2022
{
21-
var i;
22-
var pluginKey;
23-
var sys = scene.sys;
23+
var game = sys.game;
24+
var scene = sys.scene;
25+
var map = sys.settings.map;
2426

27+
// Reference the GlobalPlugins from Game into Scene.Systems
2528
for (var i = 0; i < globalPlugins.length; i++)
2629
{
27-
pluginKey = globalPlugins[i];
30+
var pluginKey = globalPlugins[i];
31+
32+
// console.log('PluginManager.global', pluginKey);
2833

29-
sys.scene[pluginKey] = sys[pluginKey];
34+
sys[pluginKey] = game[pluginKey];
35+
36+
// Scene level injection
37+
if (map.hasOwnProperty(pluginKey))
38+
{
39+
scene[map[pluginKey]] = sys[pluginKey];
40+
}
3041
}
42+
},
3143

32-
for (var i = 0; i < localPlugins.length; i++)
44+
installLocal: function (sys, scenePlugins)
45+
{
46+
var scene = sys.scene;
47+
var map = sys.settings.map;
48+
49+
for (var i = 0; i < scenePlugins.length; i++)
3350
{
34-
pluginKey = localPlugins[i];
51+
var pluginKey = scenePlugins[i];
52+
53+
var source = plugins[pluginKey];
54+
55+
// console.log('PluginManager.local', pluginKey, 'to', source.mapping);
3556

36-
if (plugins[pluginKey])
37-
{
38-
// console.log('installing', pluginKey);
57+
sys[source.mapping] = new source.plugin(scene);
3958

40-
// Install a local reference inside of Systems
41-
sys[pluginKey] = new plugins[pluginKey](scene);
59+
// Scene level injection
60+
if (map.hasOwnProperty(source.mapping))
61+
{
62+
scene[map[source.mapping]] = sys[source.mapping];
4263
}
4364
}
4465
},
@@ -56,12 +77,15 @@ var PluginManager = new Class({
5677
});
5778

5879
// Static method called directly by the Plugins
80+
// Key is a reference used to get the plugin from the plugins object (i.e. InputPlugin)
81+
// Plugin is the object to instantiate to create the plugin
82+
// Mapping is what the plugin is injected into the Scene.Systems as (i.e. input)
5983

60-
PluginManager.register = function (key, plugin)
84+
PluginManager.register = function (key, plugin, mapping)
6185
{
62-
plugins[key] = plugin;
86+
plugins[key] = { plugin: plugin, mapping: mapping };
6387

64-
// console.log('PluginManager.register', key);
88+
// console.log('PluginManager.register', key, mapping);
6589
};
6690

6791
module.exports = PluginManager;

0 commit comments

Comments
 (0)