Skip to content

Commit 69dbe38

Browse files
committed
Scene.Systems keeps track of it's booted, so plugins know how to respond to the boot event (or not). You can now also load a plugin into a Scene at runtime.
1 parent 3bb6099 commit 69dbe38

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

src/plugins/PluginManager.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var PluginManager = new Class({
77
initialize:
88

99
// The PluginManager is global and belongs to the Game instance, not a Scene.
10-
function PluginManager (game, config)
10+
function PluginManager (game)
1111
{
1212
this.game = game;
1313

@@ -45,6 +45,7 @@ var PluginManager = new Class({
4545
{
4646
var scene = sys.scene;
4747
var map = sys.settings.map;
48+
var isBooted = sys.settings.isBooted;
4849

4950
for (var i = 0; i < scenePlugins.length; i++)
5051
{
@@ -53,13 +54,21 @@ var PluginManager = new Class({
5354
var source = plugins[pluginKey];
5455

5556
// console.log('PluginManager.local', pluginKey, 'to', source.mapping);
57+
58+
var plugin = new source.plugin(scene);
5659

57-
sys[source.mapping] = new source.plugin(scene);
60+
sys[source.mapping] = plugin;
5861

5962
// Scene level injection
6063
if (map.hasOwnProperty(source.mapping))
6164
{
62-
scene[map[source.mapping]] = sys[source.mapping];
65+
scene[map[source.mapping]] = plugin;
66+
}
67+
68+
// Scene is already booted, usually because this method is being called at run-time, so boot the plugin
69+
if (isBooted)
70+
{
71+
plugin.boot();
6372
}
6473
}
6574
},

src/scene/Settings.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ var Settings = {
2727
active: GetValue(config, 'active', false),
2828
visible: GetValue(config, 'visible', true),
2929

30+
isBooted: false,
31+
3032
// Loader payload array
3133

3234
data: {},

src/scene/Systems.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
var Class = require('../utils/Class');
22
var CoreScenePlugins = require('../CoreScenePlugins');
3-
var EventEmitter = require('eventemitter3');
4-
var GetFastValue = require('../utils/object/GetFastValue');
53
var GetPhysicsPlugins = require('./GetPhysicsPlugins');
64
var GetScenePlugins = require('./GetScenePlugins');
75
var GlobalPlugins = require('../GlobalPlugins');
@@ -47,8 +45,6 @@ var Systems = new Class({
4745

4846
init: function (game)
4947
{
50-
var scene = this.scene;
51-
5248
this.game = game;
5349

5450
game.plugins.installGlobal(this, GlobalPlugins);
@@ -60,6 +56,18 @@ var Systems = new Class({
6056
game.plugins.installLocal(this, GetPhysicsPlugins(this));
6157

6258
this.events.emit('boot', this);
59+
60+
this.settings.isBooted = true;
61+
},
62+
63+
install: function (plugin)
64+
{
65+
if (!Array.isArray(plugin))
66+
{
67+
plugin = [ plugin ];
68+
}
69+
70+
this.game.plugins.installLocal(this, plugin);
6371
},
6472

6573
step: function (time, delta)

0 commit comments

Comments
 (0)