@@ -15,7 +15,7 @@ var Settings = require('./Settings');
1515var TweenManager = require ( '../../tweens/manager/TweenManager' ) ;
1616var UpdateList = require ( '../plugins/UpdateList' ) ;
1717
18- // var PluginManager = require('../../plugins/PluginManager ');
18+ var TestPlugin = require ( '../../plugins/TestPlugin ' ) ;
1919
2020var Systems = new Class ( {
2121
@@ -31,7 +31,7 @@ var Systems = new Class({
3131
3232 this . settings = Settings . create ( config ) ;
3333
34- // Set by the GlobalSceneManager - a reference to the game canvas / context
34+ // Set by the GlobalSceneManager - a reference to the Scene canvas / context
3535
3636 this . canvas ;
3737 this . context ;
@@ -46,25 +46,14 @@ var Systems = new Class({
4646
4747 // These are core Scene plugins, needed by lots of the global systems (and each other)
4848
49+ this . add ;
4950 this . cameras ;
5051 this . displayList ;
5152 this . events ;
53+ this . make ;
5254 this . sceneManager ;
5355 this . time ;
5456 this . updateList ;
55-
56- // Optional Scene plugins - not referenced by core systems, can be overridden with user code
57-
58- // this.plugins;
59-
60- this . add ;
61- this . data ;
62- this . dataStore ;
63- this . inputManager ;
64- this . load ;
65- this . make ;
66- this . physicsManager ;
67- this . tweens ;
6857 } ,
6958
7059 init : function ( game )
@@ -83,36 +72,42 @@ var Systems = new Class({
8372
8473 // These are core Scene plugins, needed by lots of the global systems (and each other)
8574
86- this . cameras = new CameraManager ( scene ) ;
87- this . displayList = new DisplayList ( scene ) ;
8875 this . events = new EventEmitter ( ) ;
89- this . sceneManager = new SceneManager ( scene ) ;
90- this . time = new Clock ( scene ) ;
91- this . updateList = new UpdateList ( scene ) ;
76+
77+ game . plugins . install ( scene , [ 'displayList' , 'updateList' , 'sceneManager' , 'time' , 'cameras' , 'add' , 'make' ] ) ;
9278
9379 // Optional Scene plugins - not referenced by core systems, can be overridden with user code
9480
95- this . add = new GameObjectFactory ( scene ) ;
81+ // game.plugins.install(scene, [ , 'test' ]);
82+
9683 this . data = new Data ( scene ) ;
9784 this . dataStore = new DataStore ( scene ) ;
9885 this . inputManager = new InputManager ( scene ) ;
9986 this . load = new Loader ( scene ) ;
100- this . make = new GameObjectCreator ( scene ) ;
10187 this . physicsManager = new PhysicsManager ( scene ) ;
10288 this . tweens = new TweenManager ( scene ) ;
10389
104- // this.plugins = new PluginManager(scene);
105-
10690 // Sometimes the managers need access to a system created after them
107- this . add . boot ( this ) ;
108- this . make . boot ( this ) ;
91+
92+ this . events . emit ( 'boot' , this ) ;
93+
10994 this . inputManager . boot ( ) ;
11095 this . physicsManager . boot ( ) ;
11196
112- this . inject ( ) ;
97+ this . inject2 ( ) ;
98+ } ,
99+
100+ inject : function ( plugin )
101+ {
102+ var map = this . settings . map ;
103+
104+ if ( plugin . mapping && map . hasOwnProperty ( plugin . mapping ) )
105+ {
106+ this . scene [ plugin . mapping ] = plugin ;
107+ }
113108 } ,
114109
115- inject : function ( )
110+ inject2 : function ( )
116111 {
117112 var map = this . settings . map ;
118113
@@ -130,31 +125,30 @@ var Systems = new Class({
130125 step : function ( time , delta )
131126 {
132127 // Are there any pending SceneManager actions?
128+ // This plugin is a special case, as it can literally modify this Scene, so we update it directly.
133129 this . sceneManager . update ( ) ;
134130
135131 if ( ! this . settings . active )
136132 {
137133 return ;
138134 }
139135
140- // Move these into local arrays, so you can control which systems are registered here and their
141- // execution order
136+ this . events . emit ( 'preupdate' , time , delta ) ;
142137
143- this . updateList . begin ( time ) ;
144- this . time . begin ( time ) ;
145138 this . tweens . begin ( time ) ;
146139 this . inputManager . begin ( time ) ;
147140
141+ this . events . emit ( 'update' , time , delta ) ;
142+
148143 this . physicsManager . update ( time , delta ) ;
149144
150- this . updateList . update ( time , delta ) ;
151- this . time . update ( time , delta ) ;
152145 this . tweens . update ( time , delta ) ;
153- this . cameras . update ( time , delta ) ;
154146 this . inputManager . update ( time , delta ) ;
155147
156148 this . scene . update . call ( this . scene , time , delta ) ;
157149
150+ this . events . emit ( 'postupdate' , time , delta ) ;
151+
158152 this . physicsManager . postUpdate ( ) ;
159153 } ,
160154
@@ -252,9 +246,11 @@ var Systems = new Class({
252246 this . settings . active = false ;
253247 this . settings . visible = false ;
254248
255- this . displayList . shutdown ( ) ;
256- this . updateList . shutdown ( ) ;
257- this . time . shutdown ( ) ;
249+ this . events . emit ( 'shutdown' , this ) ;
250+
251+ // this.displayList.shutdown();
252+ // this.updateList.shutdown();
253+ // this.time.shutdown();
258254 this . tweens . shutdown ( ) ;
259255 this . physicsManager . shutdown ( ) ;
260256
@@ -267,8 +263,10 @@ var Systems = new Class({
267263 // TODO: Game level nuke
268264 destroy : function ( )
269265 {
266+ this . events . emit ( 'destroy' , this ) ;
267+
270268 this . add . destroy ( ) ;
271- this . time . destroy ( ) ;
269+ // this.time.destroy();
272270 this . tweens . destroy ( ) ;
273271 this . physicsManager . destroy ( ) ;
274272
0 commit comments