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.

This commit is contained in:
Richard Davey 2018-01-18 13:59:32 +00:00
parent 3bb6099c6d
commit 69dbe38c9f
3 changed files with 26 additions and 7 deletions

View file

@ -7,7 +7,7 @@ var PluginManager = new Class({
initialize:
// The PluginManager is global and belongs to the Game instance, not a Scene.
function PluginManager (game, config)
function PluginManager (game)
{
this.game = game;
@ -45,6 +45,7 @@ var PluginManager = new Class({
{
var scene = sys.scene;
var map = sys.settings.map;
var isBooted = sys.settings.isBooted;
for (var i = 0; i < scenePlugins.length; i++)
{
@ -53,13 +54,21 @@ var PluginManager = new Class({
var source = plugins[pluginKey];
// console.log('PluginManager.local', pluginKey, 'to', source.mapping);
var plugin = new source.plugin(scene);
sys[source.mapping] = new source.plugin(scene);
sys[source.mapping] = plugin;
// Scene level injection
if (map.hasOwnProperty(source.mapping))
{
scene[map[source.mapping]] = sys[source.mapping];
scene[map[source.mapping]] = plugin;
}
// Scene is already booted, usually because this method is being called at run-time, so boot the plugin
if (isBooted)
{
plugin.boot();
}
}
},

View file

@ -27,6 +27,8 @@ var Settings = {
active: GetValue(config, 'active', false),
visible: GetValue(config, 'visible', true),
isBooted: false,
// Loader payload array
data: {},

View file

@ -1,7 +1,5 @@
var Class = require('../utils/Class');
var CoreScenePlugins = require('../CoreScenePlugins');
var EventEmitter = require('eventemitter3');
var GetFastValue = require('../utils/object/GetFastValue');
var GetPhysicsPlugins = require('./GetPhysicsPlugins');
var GetScenePlugins = require('./GetScenePlugins');
var GlobalPlugins = require('../GlobalPlugins');
@ -47,8 +45,6 @@ var Systems = new Class({
init: function (game)
{
var scene = this.scene;
this.game = game;
game.plugins.installGlobal(this, GlobalPlugins);
@ -60,6 +56,18 @@ var Systems = new Class({
game.plugins.installLocal(this, GetPhysicsPlugins(this));
this.events.emit('boot', this);
this.settings.isBooted = true;
},
install: function (plugin)
{
if (!Array.isArray(plugin))
{
plugin = [ plugin ];
}
this.game.plugins.installLocal(this, plugin);
},
step: function (time, delta)