Skip to content

Commit 2340a32

Browse files
committed
Added callback wrappers
1 parent 6024720 commit 2340a32

3 files changed

Lines changed: 60 additions & 12 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'f20e3110-5d2c-11e7-9a51-cfbdba7f8363'
2+
build: '63bf21d0-5d40-11e7-b1c8-175ac06dc855'
33
};
44
module.exports = CHECKSUM;

v3/src/state/GlobalStateManager.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,7 @@ GlobalStateManager.prototype = {
420420
return;
421421
}
422422

423-
state.sys.settings.active = true;
424-
425-
state.sys.settings.data = data;
423+
state.sys.start(data);
426424

427425
var loader = state.sys.load;
428426

@@ -572,7 +570,27 @@ GlobalStateManager.prototype = {
572570
swap: function (from, to)
573571
{
574572
this.sleep(from);
575-
this.start(to);
573+
574+
if (this.isSleeping(to))
575+
{
576+
this.wake(to);
577+
}
578+
else
579+
{
580+
this.start(to);
581+
}
582+
},
583+
584+
isSleeping: function (key)
585+
{
586+
var entry = this.getActiveState(key);
587+
588+
if (entry)
589+
{
590+
return (!entry.state.sys.settings.active && !entry.state.sys.settings.visible);
591+
}
592+
593+
return false;
576594
},
577595

578596
stop: function (key)

v3/src/state/Systems.js

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var Systems = function (state, config)
4545
this.stateManager;
4646
this.time;
4747
this.tweens;
48-
// this.updates;
48+
this.updates;
4949

5050
// State properties
5151
this.children;
@@ -83,7 +83,7 @@ Systems.prototype = {
8383
this.stateManager = new StateManager(this.state, game);
8484
this.time = new Clock(this.state);
8585
this.tweens = new TweenManager(this.state);
86-
// this.updates = new UpdateManager(this.state);
86+
this.updates = new UpdateManager(this.state);
8787

8888
this.inject();
8989
},
@@ -163,7 +163,10 @@ Systems.prototype = {
163163

164164
this.settings.active = false;
165165

166-
// Notify the State callback or dispatch an event
166+
if (this.state.pause)
167+
{
168+
this.state.pause.call(this.state);
169+
}
167170
},
168171

169172
resume: function ()
@@ -172,7 +175,10 @@ Systems.prototype = {
172175

173176
this.settings.active = true;
174177

175-
// Notify the State callback or dispatch an event
178+
if (this.state.resume)
179+
{
180+
this.state.resume.call(this.state);
181+
}
176182
},
177183

178184
sleep: function ()
@@ -182,7 +188,10 @@ Systems.prototype = {
182188
this.settings.active = false;
183189
this.settings.visible = false;
184190

185-
// Notify the State callback or dispatch an event
191+
if (this.state.sleep)
192+
{
193+
this.state.sleep.call(this.state);
194+
}
186195
},
187196

188197
wake: function ()
@@ -192,14 +201,28 @@ Systems.prototype = {
192201
this.settings.active = true;
193202
this.settings.visible = true;
194203

195-
// Notify the State callback or dispatch an event
204+
if (this.state.wake)
205+
{
206+
this.state.wake.call(this.state);
207+
}
208+
},
209+
210+
start: function (data)
211+
{
212+
// Was started by the GlobalStateManager
213+
214+
this.settings.data = data;
215+
216+
this.settings.active = true;
217+
this.settings.visible = true;
196218
},
197219

198220
shutdown: function ()
199221
{
200222
// Was stopped by the GlobalStateManager
201223

202224
this.settings.active = false;
225+
this.settings.visible = false;
203226

204227
// If all State level managers followed the same pattern then we could just iterate
205228
// the map and call shutdown on all of them, same for destroy
@@ -212,7 +235,10 @@ Systems.prototype = {
212235
this.time.shutdown();
213236
this.tweens.shutdown();
214237

215-
this.state.shutdown.call(this.state);
238+
if (this.state.shutdown)
239+
{
240+
this.state.shutdown.call(this.state);
241+
}
216242
},
217243

218244
// Game level nuke
@@ -224,6 +250,10 @@ Systems.prototype = {
224250
this.tweens.destroy();
225251

226252
// etc
253+
if (this.state.destroy)
254+
{
255+
this.state.destroy.call(this.state);
256+
}
227257
}
228258
};
229259

0 commit comments

Comments
 (0)