@vpmedia/phaser 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/phaser.cjs.LICENSE.txt +1 -1
  2. package/dist/phaser.js.LICENSE.txt +1 -1
  3. package/package.json +2 -3
  4. package/src/index.js +99 -0
  5. package/src/phaser/core/animation.js +355 -0
  6. package/src/phaser/core/animation_manager.js +238 -0
  7. package/src/phaser/core/animation_parser.js +130 -0
  8. package/src/phaser/core/array_set.js +108 -0
  9. package/src/phaser/core/cache.js +558 -0
  10. package/src/phaser/core/const.js +106 -0
  11. package/src/phaser/core/device.js +67 -0
  12. package/src/phaser/core/device_util.js +386 -0
  13. package/src/phaser/core/dom.js +207 -0
  14. package/src/phaser/core/event_manager.js +243 -0
  15. package/src/phaser/core/factory.js +74 -0
  16. package/src/phaser/core/frame.js +75 -0
  17. package/src/phaser/core/frame_data.js +84 -0
  18. package/src/phaser/core/frame_util.js +31 -0
  19. package/src/phaser/core/game.js +412 -0
  20. package/src/phaser/core/input.js +401 -0
  21. package/src/phaser/core/input_button.js +102 -0
  22. package/src/phaser/core/input_handler.js +687 -0
  23. package/src/phaser/core/input_mouse.js +289 -0
  24. package/src/phaser/core/input_mspointer.js +197 -0
  25. package/src/phaser/core/input_pointer.js +427 -0
  26. package/src/phaser/core/input_touch.js +157 -0
  27. package/src/phaser/core/loader.js +946 -0
  28. package/src/phaser/core/loader_parser.js +105 -0
  29. package/src/phaser/core/raf.js +46 -0
  30. package/src/phaser/core/raf_fb.js +75 -0
  31. package/src/phaser/core/raf_to.js +34 -0
  32. package/src/phaser/core/scale_manager.js +806 -0
  33. package/src/phaser/core/scene.js +66 -0
  34. package/src/phaser/core/scene_manager.js +310 -0
  35. package/src/phaser/core/signal.js +175 -0
  36. package/src/phaser/core/signal_binding.js +69 -0
  37. package/src/phaser/core/sound.js +538 -0
  38. package/src/phaser/core/sound_manager.js +365 -0
  39. package/src/phaser/core/stage.js +108 -0
  40. package/src/phaser/core/time.js +203 -0
  41. package/src/phaser/core/timer.js +276 -0
  42. package/src/phaser/core/timer_event.js +21 -0
  43. package/src/phaser/core/tween.js +329 -0
  44. package/src/phaser/core/tween_data.js +258 -0
  45. package/src/phaser/core/tween_easing.js +316 -0
  46. package/src/phaser/core/tween_manager.js +185 -0
  47. package/src/phaser/core/world.js +18 -0
  48. package/src/phaser/display/bitmap_text.js +322 -0
  49. package/src/phaser/display/button.js +194 -0
  50. package/src/phaser/display/canvas/buffer.js +36 -0
  51. package/src/phaser/display/canvas/graphics.js +227 -0
  52. package/src/phaser/display/canvas/masker.js +39 -0
  53. package/src/phaser/display/canvas/pool.js +121 -0
  54. package/src/phaser/display/canvas/renderer.js +123 -0
  55. package/src/phaser/display/canvas/tinter.js +141 -0
  56. package/src/phaser/display/canvas/util.js +151 -0
  57. package/src/phaser/display/display_object.js +597 -0
  58. package/src/phaser/display/graphics.js +723 -0
  59. package/src/phaser/display/graphics_data.js +27 -0
  60. package/src/phaser/display/graphics_data_util.js +14 -0
  61. package/src/phaser/display/group.js +227 -0
  62. package/src/phaser/display/image.js +288 -0
  63. package/src/phaser/display/sprite_batch.js +15 -0
  64. package/src/phaser/display/sprite_util.js +248 -0
  65. package/src/phaser/display/text.js +1089 -0
  66. package/src/phaser/display/webgl/abstract_filter.js +25 -0
  67. package/src/phaser/display/webgl/base_texture.js +68 -0
  68. package/src/phaser/display/webgl/blend_manager.js +35 -0
  69. package/src/phaser/display/webgl/earcut.js +647 -0
  70. package/src/phaser/display/webgl/earcut_node.js +28 -0
  71. package/src/phaser/display/webgl/fast_sprite_batch.js +242 -0
  72. package/src/phaser/display/webgl/filter_manager.js +46 -0
  73. package/src/phaser/display/webgl/filter_texture.js +61 -0
  74. package/src/phaser/display/webgl/graphics.js +618 -0
  75. package/src/phaser/display/webgl/graphics_data.js +42 -0
  76. package/src/phaser/display/webgl/mask_manager.js +36 -0
  77. package/src/phaser/display/webgl/render_texture.js +81 -0
  78. package/src/phaser/display/webgl/renderer.js +234 -0
  79. package/src/phaser/display/webgl/shader/complex.js +74 -0
  80. package/src/phaser/display/webgl/shader/fast.js +97 -0
  81. package/src/phaser/display/webgl/shader/normal.js +225 -0
  82. package/src/phaser/display/webgl/shader/primitive.js +72 -0
  83. package/src/phaser/display/webgl/shader/strip.js +77 -0
  84. package/src/phaser/display/webgl/shader_manager.js +89 -0
  85. package/src/phaser/display/webgl/sprite_batch.js +320 -0
  86. package/src/phaser/display/webgl/stencil_manager.js +170 -0
  87. package/src/phaser/display/webgl/texture.js +117 -0
  88. package/src/phaser/display/webgl/texture_util.js +32 -0
  89. package/src/phaser/display/webgl/util.js +74 -0
  90. package/src/phaser/geom/circle.js +186 -0
  91. package/src/phaser/geom/ellipse.js +65 -0
  92. package/src/phaser/geom/line.js +190 -0
  93. package/src/phaser/geom/matrix.js +147 -0
  94. package/src/phaser/geom/point.js +164 -0
  95. package/src/phaser/geom/polygon.js +141 -0
  96. package/src/phaser/geom/rectangle.js +306 -0
  97. package/src/phaser/geom/rounded_rectangle.js +36 -0
  98. package/src/phaser/geom/util/circle.js +115 -0
  99. package/src/phaser/geom/util/ellipse.js +30 -0
  100. package/src/phaser/geom/util/line.js +130 -0
  101. package/src/phaser/geom/util/matrix.js +48 -0
  102. package/src/phaser/geom/util/point.js +276 -0
  103. package/src/phaser/geom/util/polygon.js +24 -0
  104. package/src/phaser/geom/util/rectangle.js +212 -0
  105. package/src/phaser/geom/util/rounded_rectangle.js +28 -0
  106. package/src/phaser/util/math.js +279 -0
  107. package/src/phaser/util/string.js +26 -0
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ /* eslint-disable class-methods-use-this */
7
+ export default class {
8
+
9
+ constructor() {
10
+ this.game = null;
11
+ this.key = '';
12
+ }
13
+
14
+ init() {
15
+ // inherit
16
+ }
17
+
18
+ preload() {
19
+ // inherit
20
+ }
21
+
22
+ loadUpdate() {
23
+ // inherit
24
+ }
25
+
26
+ loadRender() {
27
+ // inherit
28
+ }
29
+
30
+ create() {
31
+ // inherit
32
+ }
33
+
34
+ update() {
35
+ // inherit
36
+ }
37
+
38
+ preRender() {
39
+ // inherit
40
+ }
41
+
42
+ render() {
43
+ // inherit
44
+ }
45
+
46
+ resize() {
47
+ // inherit
48
+ }
49
+
50
+ paused() {
51
+ // inherit
52
+ }
53
+
54
+ resumed() {
55
+ // inherit
56
+ }
57
+
58
+ pauseUpdate() {
59
+ // inherit
60
+ }
61
+
62
+ shutdown() {
63
+ // inherit
64
+ }
65
+
66
+ }
@@ -0,0 +1,310 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ /* eslint-disable new-cap */
7
+ import Scene from './scene';
8
+ import { RENDER_CANVAS } from './const';
9
+
10
+ export default class {
11
+
12
+ constructor(game, pendingState) {
13
+ this.game = game;
14
+ this.states = {};
15
+ this._pendingState = null;
16
+ if (typeof pendingState !== 'undefined' && pendingState !== null) {
17
+ this._pendingState = pendingState;
18
+ }
19
+ this._clearWorld = false;
20
+ this._clearCache = false;
21
+ this._created = false;
22
+ this._args = [];
23
+ this.current = '';
24
+ this.onInitCallback = null;
25
+ this.onPreloadCallback = null;
26
+ this.onCreateCallback = null;
27
+ this.onUpdateCallback = null;
28
+ this.onRenderCallback = null;
29
+ this.onResizeCallback = null;
30
+ this.onPreRenderCallback = null;
31
+ this.onLoadUpdateCallback = null;
32
+ this.onLoadRenderCallback = null;
33
+ this.onPausedCallback = null;
34
+ this.onResumedCallback = null;
35
+ this.onPauseUpdateCallback = null;
36
+ this.onShutDownCallback = null;
37
+ }
38
+
39
+ boot() {
40
+ if (this._pendingState !== null && typeof this._pendingState !== 'string') {
41
+ this.add('default', this._pendingState, true);
42
+ }
43
+ }
44
+
45
+ add(key, state, autoStart = false) {
46
+ let newState = null;
47
+ if (state instanceof Scene) {
48
+ newState = state;
49
+ } else if (typeof state === 'object') {
50
+ newState = state;
51
+ newState.game = this.game;
52
+ } else if (typeof state === 'function') {
53
+ newState = new state(this.game);
54
+ }
55
+ this.states[key] = newState;
56
+ if (autoStart) {
57
+ if (this.game.isBooted) {
58
+ this.start(key);
59
+ } else {
60
+ this._pendingState = key;
61
+ }
62
+ }
63
+ return newState;
64
+ }
65
+
66
+ remove(key) {
67
+ if (this.current === key) {
68
+ this.callbackContext = null;
69
+ this.onInitCallback = null;
70
+ this.onShutDownCallback = null;
71
+ this.onPreloadCallback = null;
72
+ this.onLoadRenderCallback = null;
73
+ this.onLoadUpdateCallback = null;
74
+ this.onCreateCallback = null;
75
+ this.onUpdateCallback = null;
76
+ this.onPreRenderCallback = null;
77
+ this.onRenderCallback = null;
78
+ this.onResizeCallback = null;
79
+ this.onPausedCallback = null;
80
+ this.onResumedCallback = null;
81
+ this.onPauseUpdateCallback = null;
82
+ }
83
+ delete this.states[key];
84
+ }
85
+
86
+ start(key, clearWorld = true, clearCache = false, ...args) {
87
+ if (this.checkState(key)) {
88
+ // Place the state in the queue. It will be started the next time the game loop begins.
89
+ this._pendingState = key;
90
+ this._clearWorld = clearWorld;
91
+ this._clearCache = clearCache;
92
+ if (args && args.length > 0) {
93
+ this._args = args.slice();
94
+ }
95
+ }
96
+ }
97
+
98
+ restart(clearWorld = true, clearCache = false, ...args) {
99
+ this._pendingState = this.current;
100
+ this._clearWorld = clearWorld;
101
+ this._clearCache = clearCache;
102
+ if (args && args.length > 0) {
103
+ this._args = args.slice();
104
+ }
105
+ }
106
+
107
+ preUpdate() {
108
+ if (this._pendingState && this.game.isBooted) {
109
+ // var previousStateKey = this.current;
110
+ // Already got a state running?
111
+ this.clearCurrentState();
112
+ this.setCurrentState(this._pendingState);
113
+ this.game.world.x = 0;
114
+ this.game.world.y = 0;
115
+ if (this.current !== this._pendingState) {
116
+ return;
117
+ }
118
+ this._pendingState = null;
119
+ // If StateManager.start has been called from the init of a State that ALSO has a preload, then
120
+ // onPreloadCallback will be set, but must be ignored
121
+ if (this.onPreloadCallback) {
122
+ this.game.load.reset(true);
123
+ this.onPreloadCallback.call(this.callbackContext, this.game);
124
+ // Is the loader empty?
125
+ if (this.game.load.totalQueuedFiles() === 0 && this.game.load.totalQueuedPacks() === 0) {
126
+ this.loadComplete();
127
+ } else {
128
+ // Start the loader going as we have something in the queue
129
+ this.game.load.start();
130
+ }
131
+ } else {
132
+ // No init? Then there was nothing to load either
133
+ this.loadComplete();
134
+ }
135
+ }
136
+ }
137
+
138
+ clearCurrentState() {
139
+ if (this.current) {
140
+ if (this.onShutDownCallback) {
141
+ this.onShutDownCallback.call(this.callbackContext, this.game);
142
+ }
143
+ this.game.tweens.removeAll();
144
+ this.game.input.reset(true);
145
+ this.game.time.removeAll();
146
+ this.game.scale.reset(this._clearWorld);
147
+ if (this._clearWorld) {
148
+ this.game.world.destroy(true, true);
149
+ if (this._clearCache) {
150
+ this.game.cache.destroy();
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ checkState(key) {
157
+ if (this.states[key]) {
158
+ if (this.states[key].preload || this.states[key].create || this.states[key].update || this.states[key].render) {
159
+ return true;
160
+ }
161
+ return false;
162
+ }
163
+ return false;
164
+ }
165
+
166
+ link(key) {
167
+ this.states[key].game = this.game;
168
+ this.states[key].key = key;
169
+ }
170
+
171
+ unlink(key) {
172
+ if (this.states[key]) {
173
+ this.states[key].game = null;
174
+ }
175
+ }
176
+
177
+ setCurrentState(key) {
178
+ this.callbackContext = this.states[key];
179
+ this.link(key);
180
+ // Used when the state is set as being the current active state
181
+ this.onInitCallback = this.callbackContext.init || this.dummy;
182
+ this.onPreloadCallback = this.callbackContext.preload || null;
183
+ this.onLoadRenderCallback = this.callbackContext.loadRender || null;
184
+ this.onLoadUpdateCallback = this.callbackContext.loadUpdate || null;
185
+ this.onCreateCallback = this.callbackContext.create || null;
186
+ this.onUpdateCallback = this.callbackContext.update || null;
187
+ this.onPreRenderCallback = this.callbackContext.preRender || null;
188
+ this.onRenderCallback = this.callbackContext.render || null;
189
+ this.onResizeCallback = this.callbackContext.resize || null;
190
+ this.onPausedCallback = this.callbackContext.paused || null;
191
+ this.onResumedCallback = this.callbackContext.resumed || null;
192
+ this.onPauseUpdateCallback = this.callbackContext.pauseUpdate || null;
193
+ this.onShutDownCallback = this.callbackContext.shutdown || this.dummy;
194
+ this.current = key;
195
+ this._created = false;
196
+ this.onInitCallback.apply(this.callbackContext, this._args);
197
+ if (key === this._pendingState) {
198
+ this._args = [];
199
+ }
200
+ this.game.isKickStart = true;
201
+ }
202
+
203
+ getCurrentState() {
204
+ return this.states[this.current];
205
+ }
206
+
207
+ loadComplete() {
208
+ if (this._created === false && this.onLoadUpdateCallback) {
209
+ this.onLoadUpdateCallback.call(this.callbackContext, this.game);
210
+ }
211
+ if (this._created === false && this.onCreateCallback) {
212
+ this._created = true;
213
+ this.onCreateCallback.call(this.callbackContext, this.game);
214
+ } else {
215
+ this._created = true;
216
+ }
217
+ }
218
+
219
+ pause() {
220
+ if (this._created && this.onPausedCallback) {
221
+ this.onPausedCallback.call(this.callbackContext, this.game);
222
+ }
223
+ }
224
+
225
+ resume() {
226
+ if (this._created && this.onResumedCallback) {
227
+ this.onResumedCallback.call(this.callbackContext, this.game);
228
+ }
229
+ }
230
+
231
+ update() {
232
+ if (this._created) {
233
+ if (this.onUpdateCallback) {
234
+ this.onUpdateCallback.call(this.callbackContext, this.game);
235
+ }
236
+ } else if (this.onLoadUpdateCallback) {
237
+ this.onLoadUpdateCallback.call(this.callbackContext, this.game);
238
+ }
239
+ }
240
+
241
+ pauseUpdate() {
242
+ if (this._created) {
243
+ if (this.onPauseUpdateCallback) {
244
+ this.onPauseUpdateCallback.call(this.callbackContext, this.game);
245
+ }
246
+ } else if (this.onLoadUpdateCallback) {
247
+ this.onLoadUpdateCallback.call(this.callbackContext, this.game);
248
+ }
249
+ }
250
+
251
+ preRender(elapsedTime) {
252
+ if (this._created && this.onPreRenderCallback) {
253
+ this.onPreRenderCallback.call(this.callbackContext, this.game, elapsedTime);
254
+ }
255
+ }
256
+
257
+ resize(width, height) {
258
+ if (this.onResizeCallback) {
259
+ this.onResizeCallback.call(this.callbackContext, width, height);
260
+ }
261
+ }
262
+
263
+ render() {
264
+ if (this._created) {
265
+ if (this.onRenderCallback) {
266
+ if (this.game.renderer.type === RENDER_CANVAS) {
267
+ this.game.context.save();
268
+ this.game.context.setTransform(1, 0, 0, 1, 0, 0);
269
+ this.onRenderCallback.call(this.callbackContext, this.game);
270
+ this.game.context.restore();
271
+ } else {
272
+ this.onRenderCallback.call(this.callbackContext, this.game);
273
+ }
274
+ }
275
+ } else if (this.onLoadRenderCallback) {
276
+ this.onLoadRenderCallback.call(this.callbackContext, this.game);
277
+ }
278
+ }
279
+
280
+ destroy() {
281
+ this._clearWorld = true;
282
+ this._clearCache = true;
283
+ this.clearCurrentState();
284
+ this.callbackContext = null;
285
+ this.onInitCallback = null;
286
+ this.onShutDownCallback = null;
287
+ this.onPreloadCallback = null;
288
+ this.onLoadRenderCallback = null;
289
+ this.onLoadUpdateCallback = null;
290
+ this.onCreateCallback = null;
291
+ this.onUpdateCallback = null;
292
+ this.onRenderCallback = null;
293
+ this.onPausedCallback = null;
294
+ this.onResumedCallback = null;
295
+ this.onPauseUpdateCallback = null;
296
+ this.game = null;
297
+ this.states = {};
298
+ this._pendingState = null;
299
+ this.current = '';
300
+ }
301
+
302
+ dummy() {
303
+ // pass
304
+ }
305
+
306
+ get created() {
307
+ return this._created;
308
+ }
309
+
310
+ }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+ import SignalBinding from './signal_binding';
7
+
8
+ export default class {
9
+
10
+ constructor() {
11
+ this._bindings = null;
12
+ this._prevParams = null;
13
+ this.memorize = false;
14
+ this._shouldPropagate = true;
15
+ this.active = true;
16
+ this._boundDispatch = false;
17
+ }
18
+
19
+ validateListener(listener, fnName) {
20
+ if (typeof listener !== 'function') {
21
+ throw new Error('Signal: listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName));
22
+ }
23
+ }
24
+
25
+ _registerListener(listener, isOnce, listenerContext, priority, args) {
26
+ const prevIndex = this._indexOfListener(listener, listenerContext);
27
+ let binding;
28
+ if (prevIndex !== -1) {
29
+ binding = this._bindings[prevIndex];
30
+ if (binding.isOnce() !== isOnce) {
31
+ throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.');
32
+ }
33
+ } else {
34
+ binding = new SignalBinding(this, listener, isOnce, listenerContext, priority, args);
35
+ this._addBinding(binding);
36
+ }
37
+ if (this.memorize && this._prevParams) {
38
+ binding.execute(this._prevParams);
39
+ }
40
+ return binding;
41
+ }
42
+
43
+ _addBinding(binding) {
44
+ if (!this._bindings) {
45
+ this._bindings = [];
46
+ }
47
+ // Simplified insertion sort
48
+ let n = this._bindings.length;
49
+ do {
50
+ n -= 1;
51
+ }
52
+ while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
53
+ this._bindings.splice(n + 1, 0, binding);
54
+ }
55
+
56
+ _indexOfListener(listener, context = null) {
57
+ if (!this._bindings) {
58
+ return -1;
59
+ }
60
+ let n = this._bindings.length;
61
+ let cur;
62
+ while (n) {
63
+ n -= 1;
64
+ cur = this._bindings[n];
65
+ if (cur._listener === listener && cur.context === context) {
66
+ return n;
67
+ }
68
+ }
69
+ return -1;
70
+ }
71
+
72
+ has(listener, context) {
73
+ return this._indexOfListener(listener, context) !== -1;
74
+ }
75
+
76
+ add(listener, listenerContext, priority, ...args) {
77
+ this.validateListener(listener, 'add');
78
+ return this._registerListener(listener, false, listenerContext, priority, args);
79
+ }
80
+
81
+ addOnce(listener, listenerContext, priority, ...args) {
82
+ this.validateListener(listener, 'addOnce');
83
+ return this._registerListener(listener, true, listenerContext, priority, args);
84
+ }
85
+
86
+ remove(listener, context) {
87
+ this.validateListener(listener, 'remove');
88
+ const i = this._indexOfListener(listener, context);
89
+ if (i !== -1) {
90
+ // no reason to a SignalBinding exist if it isn't attached to a signal
91
+ this._bindings[i]._destroy();
92
+ this._bindings.splice(i, 1);
93
+ }
94
+ return listener;
95
+ }
96
+
97
+ removeAll(context = null) {
98
+ if (!this._bindings) {
99
+ return;
100
+ }
101
+ let n = this._bindings.length;
102
+ while (n) {
103
+ n -= 1;
104
+ if (context) {
105
+ if (this._bindings[n].context === context) {
106
+ this._bindings[n]._destroy();
107
+ this._bindings.splice(n, 1);
108
+ }
109
+ } else {
110
+ this._bindings[n]._destroy();
111
+ }
112
+ }
113
+ if (!context) {
114
+ this._bindings.length = 0;
115
+ }
116
+ }
117
+
118
+ getNumListeners() {
119
+ return this._bindings ? this._bindings.length : 0;
120
+ }
121
+
122
+ halt() {
123
+ this._shouldPropagate = false;
124
+ }
125
+
126
+ dispatch(...args) {
127
+ if (!this.active || !this._bindings) {
128
+ return;
129
+ }
130
+ const paramsArr = args.slice();
131
+ let n = this._bindings.length;
132
+
133
+ if (this.memorize) {
134
+ this._prevParams = paramsArr;
135
+ }
136
+ if (!n) {
137
+ // Should come after memorize
138
+ return;
139
+ }
140
+ const bindings = this._bindings.slice(); // clone array in case add/remove items during dispatch
141
+ this._shouldPropagate = true; // in case `halt` was called before dispatch or during the previous dispatch.
142
+
143
+ // execute all callbacks until end of the list or until a callback returns `false` or stops propagation
144
+ // reverse loop since listeners with higher priority will be added at the end of the list
145
+ do {
146
+ n -= 1;
147
+ }
148
+ while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
149
+ }
150
+
151
+ forget() {
152
+ if (this._prevParams) {
153
+ this._prevParams = null;
154
+ }
155
+ }
156
+
157
+ dispose() {
158
+ this.removeAll();
159
+ this.forget();
160
+ this._bindings = null;
161
+ }
162
+
163
+ toString() {
164
+ return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']';
165
+ }
166
+
167
+ get boundDispatch() {
168
+ const _this = this;
169
+ if (!this._boundDispatch) {
170
+ this._boundDispatch = (...rest) => _this.dispatch(...rest);
171
+ }
172
+ return this._boundDispatch;
173
+ }
174
+
175
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
5
+ */
6
+
7
+ export default class {
8
+
9
+ constructor(signal, listener, isOnce = false, listenerContext = null, priority = 0, args = null) {
10
+ this._signal = signal;
11
+ this._listener = listener;
12
+ this._args = args;
13
+ this._priority = priority;
14
+ this._isOnce = isOnce;
15
+ this.context = listenerContext;
16
+ this.callCount = 0;
17
+ this.active = true;
18
+ this.params = null;
19
+ }
20
+
21
+ execute(paramsArr) {
22
+ let handlerReturn;
23
+ let params;
24
+ if (this.active && !!this._listener) {
25
+ params = this.params ? this.params.concat(paramsArr) : paramsArr;
26
+ if (this._args) {
27
+ params = params.concat(this._args);
28
+ }
29
+ handlerReturn = this._listener.apply(this.context, params);
30
+ this.callCount += 1;
31
+ if (this._isOnce) {
32
+ this.detach();
33
+ }
34
+ }
35
+ return handlerReturn;
36
+
37
+ }
38
+
39
+ detach() {
40
+ return this.isBound() ? this._signal.remove(this._listener, this.context) : null;
41
+ }
42
+
43
+ isBound() {
44
+ return (!!this._signal && !!this._listener);
45
+ }
46
+
47
+ isOnce() {
48
+ return this._isOnce;
49
+ }
50
+
51
+ getListener() {
52
+ return this._listener;
53
+ }
54
+
55
+ getSignal() {
56
+ return this._signal;
57
+ }
58
+
59
+ _destroy() {
60
+ delete this._signal;
61
+ delete this._listener;
62
+ delete this.context;
63
+ }
64
+
65
+ toString() {
66
+ return '[SignalBinding isOnce:' + this._isOnce + ', isBound:' + this.isBound() + ', active:' + this.active + ']';
67
+ }
68
+
69
+ }