forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateManager.js
More file actions
199 lines (146 loc) · 4.2 KB
/
Copy pathStateManager.js
File metadata and controls
199 lines (146 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
var Class = require('../utils/Class');
// A proxy class to the Global State Manager
var StateManager = new Class({
initialize:
function StateManager (state, game)
{
// The State that owns this plugin
this.state = state;
this.settings = state.sys.settings;
this.key = state.sys.settings.key;
// GlobalStateManager
this.manager = game.state;
// Private
this._queue = [];
},
update: function ()
{
var len = this._queue.length;
if (len === 0)
{
return;
}
var manager = this.manager;
// Process the queue
for (var i = 0; i < len; i++)
{
var action = this._queue[i];
switch (action.type)
{
case 'start':
manager.stop(this.key);
manager.start(action.key, action.data);
break;
case 'launch':
manager.start(action.key, action.data);
break;
case 'pause':
manager.pause(action.key);
break;
case 'resume':
manager.resume(action.key);
break;
case 'stop':
manager.stop(action.key);
break;
case 'swap':
manager.swap(this.key, action.key);
break;
case 'sleep':
manager.sleep(action.key);
break;
case 'wake':
manager.wake(action.key);
break;
}
}
this._queue.length = 0;
},
// Shutdown this State and run the given one
start: function (key, data)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'start', key: key, data: data });
return this;
},
// Launch the given State and run it in parallel with this one
launch: function (key, data)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'launch', key: key, data: data });
return this;
},
// Pause the State - this stops the update step from happening but it still renders
pause: function (key)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'pause', key: key });
return this;
},
// Resume the State - starts the update loop again
resume: function (key)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'resume', key: key });
return this;
},
// Makes the State sleep (no update, no render) but doesn't shutdown
sleep: function (key)
{
this._queue.push({ type: 'sleep', key: key });
return this;
},
// Makes the State wake-up (starts update and render)
wake: function (key)
{
this._queue.push({ type: 'wake', key: key });
return this;
},
// Makes this State sleep then starts the State given
swap: function (key)
{
this._queue.push({ type: 'swap', key: key });
return this;
},
// Shutdown the State, clearing display list, timers, etc
stop: function (key)
{
if (key === undefined) { key = this.key; }
this._queue.push({ type: 'stop', key: key });
return this;
},
setVisible: function (value)
{
this.settings.visible = value;
return this;
},
moveUp: function ()
{
this._queue.push({ type: 'moveUp' });
},
moveDown: function ()
{
this._queue.push({ type: 'moveDown' });
},
bringToTop: function ()
{
this._queue.push({ type: 'bringToTop' });
},
sendToBack: function ()
{
this._queue.push({ type: 'sendToBack' });
},
get: function (key)
{
return this.manager.getState(key);
},
transitionTo: function (key, duration)
{
},
isActive: function (key)
{
if (key === undefined) { key = this.key; }
return this.manager.isActive(key);
}
});
module.exports = StateManager;