Skip to content

Commit c8d859c

Browse files
committed
Systems now does everything based on events and config files, no more creation of its own plugins
1 parent 43d7e0f commit c8d859c

3 files changed

Lines changed: 74 additions & 71 deletions

File tree

src/scene/GetPhysicsPlugins.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
var GetFastValue = require('../utils/object/GetFastValue');
2+
3+
var GetPhysicsPlugins = function (sys)
4+
{
5+
var defaultSystem = sys.game.config.defaultPhysicsSystem;
6+
var sceneSystems = GetFastValue(sys.settings, 'physics', false);
7+
8+
if (!defaultSystem && !sceneSystems)
9+
{
10+
// No default physics system or systems in this scene
11+
return;
12+
}
13+
14+
// Let's build the systems array
15+
var output = [];
16+
17+
if (defaultSystem)
18+
{
19+
output.push(defaultSystem + 'Physics');
20+
}
21+
22+
if (sceneSystems)
23+
{
24+
for (var key in sceneSystems)
25+
{
26+
key = key.concat('Physics');
27+
28+
if (output.indexOf(key) === -1)
29+
{
30+
output.push(key);
31+
}
32+
}
33+
}
34+
35+
// An array of Physics systems to start for this Scene
36+
return output;
37+
};
38+
39+
module.exports = GetPhysicsPlugins;

src/scene/GetScenePlugins.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var GetFastValue = require('../utils/object/GetFastValue');
2+
3+
var GetScenePlugins = function (sys)
4+
{
5+
var defaultPlugins = sys.game.config.defaultPlugins;
6+
var scenePlugins = GetFastValue(sys.settings, 'plugins', false);
7+
8+
// Scene Plugins always override Default Plugins
9+
if (Array.isArray(scenePlugins))
10+
{
11+
return scenePlugins;
12+
}
13+
else if (defaultPlugins)
14+
{
15+
return defaultPlugins;
16+
}
17+
else
18+
{
19+
// No default plugins or plugins in this scene
20+
return [];
21+
}
22+
};
23+
24+
module.exports = GetScenePlugins;

src/scene/Systems.js

Lines changed: 11 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
var Class = require('../utils/Class');
2+
var CoreScenePlugins = require('../CoreScenePlugins');
23
var EventEmitter = require('eventemitter3');
34
var GetFastValue = require('../utils/object/GetFastValue');
4-
var ScenePlugin = require('./ScenePlugin');
5+
var GetPhysicsPlugins = require('./GetPhysicsPlugins');
6+
var GetScenePlugins = require('./GetScenePlugins');
7+
var GlobalPlugins = require('../GlobalPlugins');
58
var Settings = require('./Settings');
69

710
var Systems = new Class({
@@ -23,23 +26,22 @@ var Systems = new Class({
2326
this.canvas;
2427
this.context;
2528

26-
// Global Systems - these are global managers (belonging to Game)
29+
// Global Systems - these are single-instance global managers that belong to Game
2730

2831
this.anims;
2932
this.cache;
3033
this.registry;
3134
this.sound;
3235
this.textures;
3336

34-
// These are core Scene plugins, needed by lots of the global systems (and each other)
37+
// Core Plugins - these are non-optional Scene plugins, needed by lots of the other systems
3538

3639
this.add;
3740
this.cameras;
3841
this.displayList;
3942
this.events;
4043
this.make;
41-
this.sceneManager;
42-
this.time;
44+
this.scenePlugin;
4345
this.updateList;
4446
},
4547

@@ -49,79 +51,17 @@ var Systems = new Class({
4951

5052
this.game = game;
5153

52-
// Global Systems - these are global managers (belonging to Game)
54+
game.plugins.installGlobal(this, GlobalPlugins);
5355

54-
this.anims = game.anims;
55-
this.cache = game.cache;
56-
this.registry = game.registry;
57-
this.sound = game.sound;
58-
this.textures = game.textures;
56+
game.plugins.installLocal(this, CoreScenePlugins);
5957

60-
// These are core Scene plugins, needed by lots of the global systems (and each other)
58+
game.plugins.installLocal(this, GetScenePlugins(this));
6159

62-
this.events = new EventEmitter();
63-
64-
game.plugins.install(scene,
65-
[ 'anims', 'cache', 'registry', 'sound', 'textures' ],
66-
[ 'displayList', 'updateList', 'sceneManager', 'time', 'cameras', 'add', 'make', 'load', 'tweens', 'input' ]
67-
);
68-
69-
var physics = this.getPhysicsSystem();
70-
71-
if (physics)
72-
{
73-
game.plugins.install(scene, [], physics);
74-
}
60+
game.plugins.installLocal(this, GetPhysicsPlugins(this));
7561

7662
this.events.emit('boot', this);
7763
},
7864

79-
getPhysicsSystem: function ()
80-
{
81-
var defaultSystem = this.game.config.defaultPhysicsSystem;
82-
var sceneSystems = GetFastValue(this.settings, 'physics', false);
83-
84-
if (!defaultSystem && !sceneSystems)
85-
{
86-
// No default physics system or systems in this scene
87-
return;
88-
}
89-
90-
// Let's build the systems array
91-
var output = [];
92-
93-
if (defaultSystem)
94-
{
95-
output.push(defaultSystem + 'Physics');
96-
}
97-
98-
if (sceneSystems)
99-
{
100-
for (var key in sceneSystems)
101-
{
102-
key = key.concat('Physics');
103-
104-
if (output.indexOf(key) === -1)
105-
{
106-
output.push(key);
107-
}
108-
}
109-
}
110-
111-
// An array of Physics systems to start for this Scene
112-
return output;
113-
},
114-
115-
inject: function (plugin)
116-
{
117-
var map = this.settings.map;
118-
119-
if (plugin.mapping && map.hasOwnProperty(plugin.mapping))
120-
{
121-
this.scene[plugin.mapping] = plugin;
122-
}
123-
},
124-
12565
step: function (time, delta)
12666
{
12767
this.events.emit('preupdate', time, delta);

0 commit comments

Comments
 (0)