@vpmedia/phaser 1.15.0 → 1.17.0
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.
- package/README.md +3 -3
- package/package.json +6 -5
- package/src/index.js +15 -18
- package/src/phaser/core/animation.js +114 -6
- package/src/phaser/core/animation_manager.js +102 -10
- package/src/phaser/core/animation_parser.js +6 -19
- package/src/phaser/core/array_set.js +59 -5
- package/src/phaser/core/cache.js +307 -6
- package/src/phaser/core/const.js +107 -4
- package/src/phaser/core/device.js +3 -6
- package/src/phaser/core/device_util.js +3 -16
- package/src/phaser/core/dom.js +127 -29
- package/src/phaser/core/event_manager.js +128 -6
- package/src/phaser/core/factory.js +69 -34
- package/src/phaser/core/frame.js +43 -6
- package/src/phaser/core/frame_data.js +55 -5
- package/src/phaser/core/frame_util.js +7 -12
- package/src/phaser/core/game.js +35 -7
- package/src/phaser/core/input.js +133 -17
- package/src/phaser/core/input_handler.js +243 -43
- package/src/phaser/core/input_mouse.js +70 -5
- package/src/phaser/core/input_mspointer.js +40 -9
- package/src/phaser/core/input_pointer.js +88 -17
- package/src/phaser/core/input_touch.js +42 -5
- package/src/phaser/core/loader.js +303 -101
- package/src/phaser/core/loader_parser.js +2 -10
- package/src/phaser/core/raf.js +16 -5
- package/src/phaser/core/scale_manager.js +204 -39
- package/src/phaser/core/scene.js +24 -5
- package/src/phaser/core/scene_manager.js +81 -11
- package/src/phaser/core/signal.js +88 -11
- package/src/phaser/core/signal_binding.js +35 -15
- package/src/phaser/core/sound.js +99 -10
- package/src/phaser/core/sound_manager.js +89 -13
- package/src/phaser/core/sound_sprite.js +20 -5
- package/src/phaser/core/stage.js +43 -7
- package/src/phaser/core/time.js +67 -5
- package/src/phaser/core/timer.js +107 -30
- package/src/phaser/core/timer_event.js +11 -6
- package/src/phaser/core/tween.js +124 -30
- package/src/phaser/core/tween_data.js +42 -18
- package/src/phaser/core/tween_easing.js +1 -8
- package/src/phaser/core/tween_manager.js +47 -5
- package/src/phaser/core/world.js +9 -6
- package/src/phaser/display/bitmap_text.js +91 -10
- package/src/phaser/display/button.js +63 -12
- package/src/phaser/display/canvas/buffer.js +16 -6
- package/src/phaser/display/canvas/graphics.js +1 -13
- package/src/phaser/display/canvas/masker.js +0 -6
- package/src/phaser/display/canvas/pool.js +0 -7
- package/src/phaser/display/canvas/renderer.js +28 -8
- package/src/phaser/display/canvas/tinter.js +4 -43
- package/src/phaser/display/canvas/util.js +0 -6
- package/src/phaser/display/display_object.js +192 -20
- package/src/phaser/display/graphics.js +161 -26
- package/src/phaser/display/graphics_data.js +14 -6
- package/src/phaser/display/graphics_data_util.js +2 -8
- package/src/phaser/display/group.js +82 -9
- package/src/phaser/display/image.js +87 -9
- package/src/phaser/display/sprite_batch.js +3 -8
- package/src/phaser/display/sprite_util.js +3 -23
- package/src/phaser/display/text.js +331 -31
- package/src/phaser/display/webgl/abstract_filter.js +8 -7
- package/src/phaser/display/webgl/base_texture.js +20 -12
- package/src/phaser/display/webgl/blend_manager.js +14 -7
- package/src/phaser/display/webgl/earcut.js +4 -23
- package/src/phaser/display/webgl/earcut_node.js +6 -7
- package/src/phaser/display/webgl/fast_sprite_batch.js +34 -11
- package/src/phaser/display/webgl/filter_manager.js +25 -7
- package/src/phaser/display/webgl/filter_texture.js +21 -22
- package/src/phaser/display/webgl/graphics.js +5 -28
- package/src/phaser/display/webgl/graphics_data.js +10 -7
- package/src/phaser/display/webgl/mask_manager.js +0 -6
- package/src/phaser/display/webgl/render_texture.js +33 -21
- package/src/phaser/display/webgl/renderer.js +38 -11
- package/src/phaser/display/webgl/shader/complex.js +10 -6
- package/src/phaser/display/webgl/shader/fast.js +10 -6
- package/src/phaser/display/webgl/shader/normal.js +23 -32
- package/src/phaser/display/webgl/shader/primitive.js +10 -6
- package/src/phaser/display/webgl/shader/strip.js +10 -6
- package/src/phaser/display/webgl/shader_manager.js +18 -6
- package/src/phaser/display/webgl/sprite_batch.js +41 -8
- package/src/phaser/display/webgl/stencil_manager.js +28 -6
- package/src/phaser/display/webgl/texture.js +28 -15
- package/src/phaser/display/webgl/texture_util.js +0 -6
- package/src/phaser/display/webgl/util.js +0 -7
- package/src/phaser/geom/circle.js +123 -18
- package/src/phaser/geom/ellipse.js +39 -18
- package/src/phaser/geom/line.js +148 -16
- package/src/phaser/geom/matrix.js +73 -6
- package/src/phaser/geom/point.js +152 -6
- package/src/phaser/geom/polygon.js +42 -14
- package/src/phaser/geom/rectangle.js +233 -6
- package/src/phaser/geom/rounded_rectangle.js +10 -6
- package/src/phaser/geom/util/circle.js +3 -9
- package/src/phaser/geom/util/ellipse.js +0 -7
- package/src/phaser/geom/util/line.js +5 -14
- package/src/phaser/geom/util/matrix.js +1 -7
- package/src/phaser/geom/util/point.js +0 -6
- package/src/phaser/geom/util/polygon.js +1 -7
- package/src/phaser/geom/util/rectangle.js +1 -7
- package/src/phaser/geom/util/rounded_rectangle.js +1 -7
- package/src/phaser/util/math.js +3 -21
- package/types/index.d.ts +2 -1
- package/types/index.d.ts.map +1 -1
- package/types/phaser/core/animation.d.ts +126 -13
- package/types/phaser/core/animation.d.ts.map +1 -1
- package/types/phaser/core/animation_manager.d.ts +121 -19
- package/types/phaser/core/animation_manager.d.ts.map +1 -1
- package/types/phaser/core/animation_parser.d.ts +6 -5
- package/types/phaser/core/animation_parser.d.ts.map +1 -1
- package/types/phaser/core/array_set.d.ts +67 -13
- package/types/phaser/core/array_set.d.ts.map +1 -1
- package/types/phaser/core/cache.d.ts +365 -69
- package/types/phaser/core/cache.d.ts.map +1 -1
- package/types/phaser/core/const.d.ts +143 -40
- package/types/phaser/core/const.d.ts.map +1 -1
- package/types/phaser/core/device.d.ts +0 -5
- package/types/phaser/core/device.d.ts.map +1 -1
- package/types/phaser/core/device_util.d.ts +1 -1
- package/types/phaser/core/device_util.d.ts.map +1 -1
- package/types/phaser/core/dom.d.ts +119 -0
- package/types/phaser/core/dom.d.ts.map +1 -1
- package/types/phaser/core/event_manager.d.ts +127 -0
- package/types/phaser/core/event_manager.d.ts.map +1 -1
- package/types/phaser/core/factory.d.ts +75 -8
- package/types/phaser/core/factory.d.ts.map +1 -1
- package/types/phaser/core/frame.d.ts +64 -21
- package/types/phaser/core/frame.d.ts.map +1 -1
- package/types/phaser/core/frame_data.d.ts +61 -9
- package/types/phaser/core/frame_data.d.ts.map +1 -1
- package/types/phaser/core/frame_util.d.ts +10 -8
- package/types/phaser/core/frame_util.d.ts.map +1 -1
- package/types/phaser/core/game.d.ts +40 -6
- package/types/phaser/core/game.d.ts.map +1 -1
- package/types/phaser/core/input.d.ts +143 -15
- package/types/phaser/core/input.d.ts.map +1 -1
- package/types/phaser/core/input_handler.d.ts +258 -25
- package/types/phaser/core/input_handler.d.ts.map +1 -1
- package/types/phaser/core/input_mouse.d.ts +62 -14
- package/types/phaser/core/input_mouse.d.ts.map +1 -1
- package/types/phaser/core/input_mspointer.d.ts +51 -17
- package/types/phaser/core/input_mspointer.d.ts.map +1 -1
- package/types/phaser/core/input_pointer.d.ts +99 -14
- package/types/phaser/core/input_pointer.d.ts.map +1 -1
- package/types/phaser/core/input_touch.d.ts +53 -16
- package/types/phaser/core/input_touch.d.ts.map +1 -1
- package/types/phaser/core/loader.d.ts +299 -28
- package/types/phaser/core/loader.d.ts.map +1 -1
- package/types/phaser/core/loader_parser.d.ts.map +1 -1
- package/types/phaser/core/raf.d.ts +19 -9
- package/types/phaser/core/raf.d.ts.map +1 -1
- package/types/phaser/core/scale_manager.d.ts +208 -13
- package/types/phaser/core/scale_manager.d.ts.map +1 -1
- package/types/phaser/core/scene.d.ts +21 -5
- package/types/phaser/core/scene.d.ts.map +1 -1
- package/types/phaser/core/scene_manager.d.ts +90 -10
- package/types/phaser/core/scene_manager.d.ts.map +1 -1
- package/types/phaser/core/signal.d.ts +93 -9
- package/types/phaser/core/signal.d.ts.map +1 -1
- package/types/phaser/core/signal_binding.d.ts +34 -5
- package/types/phaser/core/signal_binding.d.ts.map +1 -1
- package/types/phaser/core/sound.d.ts +111 -14
- package/types/phaser/core/sound.d.ts.map +1 -1
- package/types/phaser/core/sound_manager.d.ts +97 -11
- package/types/phaser/core/sound_manager.d.ts.map +1 -1
- package/types/phaser/core/sound_sprite.d.ts +22 -8
- package/types/phaser/core/sound_sprite.d.ts.map +1 -1
- package/types/phaser/core/stage.d.ts +32 -3
- package/types/phaser/core/stage.d.ts.map +1 -1
- package/types/phaser/core/time.d.ts +73 -6
- package/types/phaser/core/time.d.ts.map +1 -1
- package/types/phaser/core/timer.d.ts +108 -7
- package/types/phaser/core/timer.d.ts.map +1 -1
- package/types/phaser/core/timer_event.d.ts +13 -7
- package/types/phaser/core/timer_event.d.ts.map +1 -1
- package/types/phaser/core/tween.d.ts +124 -4
- package/types/phaser/core/tween.d.ts.map +1 -1
- package/types/phaser/core/tween_data.d.ts +41 -2
- package/types/phaser/core/tween_data.d.ts.map +1 -1
- package/types/phaser/core/tween_easing.d.ts +0 -5
- package/types/phaser/core/tween_easing.d.ts.map +1 -1
- package/types/phaser/core/tween_manager.d.ts +49 -2
- package/types/phaser/core/tween_manager.d.ts.map +1 -1
- package/types/phaser/core/world.d.ts +9 -1
- package/types/phaser/core/world.d.ts.map +1 -1
- package/types/phaser/display/bitmap_text.d.ts +84 -7
- package/types/phaser/display/bitmap_text.d.ts.map +1 -1
- package/types/phaser/display/button.d.ts +65 -8
- package/types/phaser/display/button.d.ts.map +1 -1
- package/types/phaser/display/canvas/buffer.d.ts +20 -4
- package/types/phaser/display/canvas/buffer.d.ts.map +1 -1
- package/types/phaser/display/canvas/graphics.d.ts.map +1 -1
- package/types/phaser/display/canvas/masker.d.ts.map +1 -1
- package/types/phaser/display/canvas/pool.d.ts +0 -6
- package/types/phaser/display/canvas/pool.d.ts.map +1 -1
- package/types/phaser/display/canvas/renderer.d.ts +29 -2
- package/types/phaser/display/canvas/renderer.d.ts.map +1 -1
- package/types/phaser/display/canvas/tinter.d.ts.map +1 -1
- package/types/phaser/display/canvas/util.d.ts.map +1 -1
- package/types/phaser/display/display_object.d.ts +195 -8
- package/types/phaser/display/display_object.d.ts.map +1 -1
- package/types/phaser/display/graphics.d.ts +132 -6
- package/types/phaser/display/graphics.d.ts.map +1 -1
- package/types/phaser/display/graphics_data.d.ts +15 -1
- package/types/phaser/display/graphics_data.d.ts.map +1 -1
- package/types/phaser/display/graphics_data_util.d.ts +3 -2
- package/types/phaser/display/graphics_data_util.d.ts.map +1 -1
- package/types/phaser/display/group.d.ts +80 -10
- package/types/phaser/display/group.d.ts.map +1 -1
- package/types/phaser/display/image.d.ts +72 -6
- package/types/phaser/display/image.d.ts.map +1 -1
- package/types/phaser/display/sprite_batch.d.ts +4 -3
- package/types/phaser/display/sprite_batch.d.ts.map +1 -1
- package/types/phaser/display/sprite_util.d.ts.map +1 -1
- package/types/phaser/display/text.d.ts +366 -46
- package/types/phaser/display/text.d.ts.map +1 -1
- package/types/phaser/display/webgl/abstract_filter.d.ts +8 -6
- package/types/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
- package/types/phaser/display/webgl/base_texture.d.ts +20 -1
- package/types/phaser/display/webgl/base_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/blend_manager.d.ts +11 -6
- package/types/phaser/display/webgl/blend_manager.d.ts.map +1 -1
- package/types/phaser/display/webgl/earcut.d.ts.map +1 -1
- package/types/phaser/display/webgl/earcut_node.d.ts +9 -9
- package/types/phaser/display/webgl/earcut_node.d.ts.map +1 -1
- package/types/phaser/display/webgl/fast_sprite_batch.d.ts +33 -6
- package/types/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
- package/types/phaser/display/webgl/filter_manager.d.ts +22 -6
- package/types/phaser/display/webgl/filter_manager.d.ts.map +1 -1
- package/types/phaser/display/webgl/filter_texture.d.ts +21 -3
- package/types/phaser/display/webgl/filter_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/graphics.d.ts.map +1 -1
- package/types/phaser/display/webgl/graphics_data.d.ts +10 -6
- package/types/phaser/display/webgl/graphics_data.d.ts.map +1 -1
- package/types/phaser/display/webgl/mask_manager.d.ts.map +1 -1
- package/types/phaser/display/webgl/render_texture.d.ts +30 -3
- package/types/phaser/display/webgl/render_texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/renderer.d.ts +41 -4
- package/types/phaser/display/webgl/renderer.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/complex.d.ts +10 -0
- package/types/phaser/display/webgl/shader/complex.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/fast.d.ts +10 -0
- package/types/phaser/display/webgl/shader/fast.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/normal.d.ts +20 -0
- package/types/phaser/display/webgl/shader/normal.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/primitive.d.ts +10 -0
- package/types/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader/strip.d.ts +10 -0
- package/types/phaser/display/webgl/shader/strip.d.ts.map +1 -1
- package/types/phaser/display/webgl/shader_manager.d.ts +15 -0
- package/types/phaser/display/webgl/shader_manager.d.ts.map +1 -1
- package/types/phaser/display/webgl/sprite_batch.d.ts +37 -0
- package/types/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
- package/types/phaser/display/webgl/stencil_manager.d.ts +25 -0
- package/types/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
- package/types/phaser/display/webgl/texture.d.ts +21 -0
- package/types/phaser/display/webgl/texture.d.ts.map +1 -1
- package/types/phaser/display/webgl/texture_util.d.ts.map +1 -1
- package/types/phaser/display/webgl/util.d.ts +0 -6
- package/types/phaser/display/webgl/util.d.ts.map +1 -1
- package/types/phaser/geom/circle.d.ts +131 -9
- package/types/phaser/geom/circle.d.ts.map +1 -1
- package/types/phaser/geom/ellipse.d.ts +43 -5
- package/types/phaser/geom/ellipse.d.ts.map +1 -1
- package/types/phaser/geom/line.d.ts +159 -13
- package/types/phaser/geom/line.d.ts.map +1 -1
- package/types/phaser/geom/matrix.d.ts +85 -11
- package/types/phaser/geom/matrix.d.ts.map +1 -1
- package/types/phaser/geom/point.d.ts +170 -18
- package/types/phaser/geom/point.d.ts.map +1 -1
- package/types/phaser/geom/polygon.d.ts +45 -5
- package/types/phaser/geom/polygon.d.ts.map +1 -1
- package/types/phaser/geom/rectangle.d.ts +253 -20
- package/types/phaser/geom/rectangle.d.ts.map +1 -1
- package/types/phaser/geom/rounded_rectangle.d.ts +11 -1
- package/types/phaser/geom/rounded_rectangle.d.ts.map +1 -1
- package/types/phaser/geom/util/circle.d.ts +3 -3
- package/types/phaser/geom/util/circle.d.ts.map +1 -1
- package/types/phaser/geom/util/ellipse.d.ts +0 -6
- package/types/phaser/geom/util/ellipse.d.ts.map +1 -1
- package/types/phaser/geom/util/line.d.ts +5 -5
- package/types/phaser/geom/util/line.d.ts.map +1 -1
- package/types/phaser/geom/util/matrix.d.ts.map +1 -1
- package/types/phaser/geom/util/point.d.ts.map +1 -1
- package/types/phaser/geom/util/polygon.d.ts.map +1 -1
- package/types/phaser/geom/util/rectangle.d.ts.map +1 -1
- package/types/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
- package/types/phaser/util/math.d.ts +0 -5
- package/types/phaser/util/math.d.ts.map +1 -1
package/src/phaser/core/game.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module core/game
|
|
3
|
-
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
4
|
-
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
5
|
-
* @author Richard Davey <rich@photonstorm.com>
|
|
6
|
-
*/
|
|
7
1
|
import { CanvasRenderer } from '../display/canvas/renderer';
|
|
8
2
|
import { WebGLRenderer } from '../display/webgl/renderer';
|
|
9
|
-
import { Signal } from
|
|
3
|
+
import { Signal } from './signal';
|
|
10
4
|
import { Loader } from './loader';
|
|
11
5
|
import { Cache } from './cache';
|
|
12
6
|
import { Input } from './input';
|
|
@@ -25,6 +19,10 @@ import { create, removeFromDOM, addToDOM, setTouchAction } from '../display/canv
|
|
|
25
19
|
import { initialize, checkOS } from './device_util';
|
|
26
20
|
|
|
27
21
|
export class Game {
|
|
22
|
+
/**
|
|
23
|
+
* TBD.
|
|
24
|
+
* @param {object} gameConfig - TBD.
|
|
25
|
+
*/
|
|
28
26
|
constructor(gameConfig = {}) {
|
|
29
27
|
if (!window.PhaserRegistry) {
|
|
30
28
|
window.PhaserRegistry = {};
|
|
@@ -72,6 +70,9 @@ export class Game {
|
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
|
|
73
|
+
/**
|
|
74
|
+
* TBD.
|
|
75
|
+
*/
|
|
75
76
|
boot() {
|
|
76
77
|
if (this.isBooted) {
|
|
77
78
|
return;
|
|
@@ -105,6 +106,9 @@ export class Game {
|
|
|
105
106
|
this.onBoot.dispatch(this);
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
/**
|
|
110
|
+
* TBD.
|
|
111
|
+
*/
|
|
108
112
|
initRenderer() {
|
|
109
113
|
if (this.config.canvas) {
|
|
110
114
|
this.canvas = this.config.canvas;
|
|
@@ -165,6 +169,12 @@ export class Game {
|
|
|
165
169
|
setTouchAction(this.canvas);
|
|
166
170
|
}
|
|
167
171
|
|
|
172
|
+
/**
|
|
173
|
+
* TBD.
|
|
174
|
+
* @param {object} config - TBD.
|
|
175
|
+
* @param {string} key - TBD.
|
|
176
|
+
* @param {*} defaultValue - TBD.
|
|
177
|
+
*/
|
|
168
178
|
parseConfigElement(config, key, defaultValue) {
|
|
169
179
|
if (config[key] !== undefined) {
|
|
170
180
|
this.config[key] = config[key];
|
|
@@ -173,6 +183,10 @@ export class Game {
|
|
|
173
183
|
}
|
|
174
184
|
}
|
|
175
185
|
|
|
186
|
+
/**
|
|
187
|
+
* TBD.
|
|
188
|
+
* @param {object} config - TBD.
|
|
189
|
+
*/
|
|
176
190
|
parseConfig(config) {
|
|
177
191
|
this.parseConfigElement(config, 'width', 800);
|
|
178
192
|
this.parseConfigElement(config, 'height', 600);
|
|
@@ -205,6 +219,10 @@ export class Game {
|
|
|
205
219
|
this.state = new SceneManager(this, state);
|
|
206
220
|
}
|
|
207
221
|
|
|
222
|
+
/**
|
|
223
|
+
* TBD.
|
|
224
|
+
* @param {Event} event - TBD.
|
|
225
|
+
*/
|
|
208
226
|
contextLost(event) {
|
|
209
227
|
event.preventDefault();
|
|
210
228
|
if (this.renderer) {
|
|
@@ -212,6 +230,9 @@ export class Game {
|
|
|
212
230
|
}
|
|
213
231
|
}
|
|
214
232
|
|
|
233
|
+
/**
|
|
234
|
+
* TBD.
|
|
235
|
+
*/
|
|
215
236
|
contextRestored() {
|
|
216
237
|
this.renderer.initContext();
|
|
217
238
|
// this.cache.clearGLTextures();
|
|
@@ -220,6 +241,10 @@ export class Game {
|
|
|
220
241
|
}
|
|
221
242
|
}
|
|
222
243
|
|
|
244
|
+
/**
|
|
245
|
+
* TBD.
|
|
246
|
+
* @param {number} time - TBD.
|
|
247
|
+
*/
|
|
223
248
|
update(time) {
|
|
224
249
|
this.time.update(time);
|
|
225
250
|
if (!this.isPaused) {
|
|
@@ -240,6 +265,9 @@ export class Game {
|
|
|
240
265
|
this.renderer.render(this.stage);
|
|
241
266
|
}
|
|
242
267
|
|
|
268
|
+
/**
|
|
269
|
+
* TBD.
|
|
270
|
+
*/
|
|
243
271
|
destroy() {
|
|
244
272
|
this.isPaused = true;
|
|
245
273
|
|
package/src/phaser/core/input.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
|
|
3
|
-
* @author Andras Csizmadia <andras@vpmedia.hu>
|
|
4
|
-
* @author Richard Davey <rich@photonstorm.com>
|
|
5
|
-
*/
|
|
6
1
|
import { ArraySet } from './array_set';
|
|
7
|
-
import { Graphics } from
|
|
2
|
+
import { Graphics } from '../display/graphics';
|
|
8
3
|
import { Image } from '../display/image';
|
|
9
|
-
import { Signal } from
|
|
4
|
+
import { Signal } from './signal';
|
|
10
5
|
import { Point } from '../geom/point';
|
|
11
|
-
import { Circle } from
|
|
6
|
+
import { Circle } from '../geom/circle';
|
|
12
7
|
import { Mouse } from './input_mouse';
|
|
13
8
|
import { MSPointer } from './input_mspointer';
|
|
14
9
|
import { Pointer } from './input_pointer';
|
|
15
10
|
import { Touch } from './input_touch';
|
|
16
11
|
import { POINTER_CURSOR, POINTER_CONTACT, MOUSE_TOUCH_COMBINE } from './const';
|
|
17
12
|
import { create, remove } from '../display/canvas/pool';
|
|
13
|
+
import { Game } from './game';
|
|
18
14
|
|
|
19
15
|
const MAX_POINTERS = 10;
|
|
20
16
|
|
|
21
17
|
export class Input {
|
|
18
|
+
/**
|
|
19
|
+
* TBD.
|
|
20
|
+
* @param {Game} game - TBD.
|
|
21
|
+
*/
|
|
22
22
|
constructor(game) {
|
|
23
23
|
this.game = game;
|
|
24
24
|
this.hitCanvas = null;
|
|
@@ -73,6 +73,9 @@ export class Input {
|
|
|
73
73
|
this._y = 0;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
+
/**
|
|
77
|
+
* TBD.
|
|
78
|
+
*/
|
|
76
79
|
boot() {
|
|
77
80
|
this.mousePointer = new Pointer(this.game, 0, POINTER_CURSOR);
|
|
78
81
|
this.addPointer();
|
|
@@ -104,6 +107,9 @@ export class Input {
|
|
|
104
107
|
this.game.canvas.addEventListener('click', this._onClickTrampoline, false);
|
|
105
108
|
}
|
|
106
109
|
|
|
110
|
+
/**
|
|
111
|
+
* TBD.
|
|
112
|
+
*/
|
|
107
113
|
destroy() {
|
|
108
114
|
this.mouse.stop();
|
|
109
115
|
if (this.game.device.mspointer) {
|
|
@@ -116,29 +122,45 @@ export class Input {
|
|
|
116
122
|
this.game.canvas.removeEventListener('click', this._onClickTrampoline);
|
|
117
123
|
}
|
|
118
124
|
|
|
125
|
+
/**
|
|
126
|
+
* TBD.
|
|
127
|
+
* @param {Function} callback - TBD.
|
|
128
|
+
* @param context - TBD.
|
|
129
|
+
*/
|
|
119
130
|
setInteractiveCandidateHandler(callback, context) {
|
|
120
131
|
this.customCandidateHandler = callback;
|
|
121
132
|
this.customCandidateHandlerContext = context;
|
|
122
133
|
}
|
|
123
134
|
|
|
135
|
+
/**
|
|
136
|
+
* TBD.
|
|
137
|
+
* @param {Function} callback - TBD.
|
|
138
|
+
* @param context - TBD.
|
|
139
|
+
*/
|
|
124
140
|
addMoveCallback(callback, context) {
|
|
125
141
|
this.moveCallbacks.push({ callback, context });
|
|
126
142
|
}
|
|
127
143
|
|
|
144
|
+
/**
|
|
145
|
+
* TBD.
|
|
146
|
+
* @param {Function} callback - TBD.
|
|
147
|
+
* @param context - TBD.
|
|
148
|
+
*/
|
|
128
149
|
deleteMoveCallback(callback, context) {
|
|
129
150
|
let i = this.moveCallbacks.length;
|
|
130
151
|
while (i) {
|
|
131
152
|
i -= 1;
|
|
132
|
-
if (
|
|
133
|
-
this.moveCallbacks[i].callback === callback &&
|
|
134
|
-
this.moveCallbacks[i].context === context
|
|
135
|
-
) {
|
|
153
|
+
if (this.moveCallbacks[i].callback === callback && this.moveCallbacks[i].context === context) {
|
|
136
154
|
this.moveCallbacks.splice(i, 1);
|
|
137
155
|
return;
|
|
138
156
|
}
|
|
139
157
|
}
|
|
140
158
|
}
|
|
141
159
|
|
|
160
|
+
/**
|
|
161
|
+
* TBD.
|
|
162
|
+
* @returns {Pointer} TBD.
|
|
163
|
+
*/
|
|
142
164
|
addPointer() {
|
|
143
165
|
if (this.pointers.length >= MAX_POINTERS) {
|
|
144
166
|
console.warn('Input.addPointer: Maximum limit of ' + MAX_POINTERS + ' pointers reached.');
|
|
@@ -151,6 +173,9 @@ export class Input {
|
|
|
151
173
|
return pointer;
|
|
152
174
|
}
|
|
153
175
|
|
|
176
|
+
/**
|
|
177
|
+
* TBD.
|
|
178
|
+
*/
|
|
154
179
|
update() {
|
|
155
180
|
if (this.pollRate > 0 && this._pollCounter < this.pollRate) {
|
|
156
181
|
this._pollCounter += 1;
|
|
@@ -166,6 +191,10 @@ export class Input {
|
|
|
166
191
|
this._pollCounter = 0;
|
|
167
192
|
}
|
|
168
193
|
|
|
194
|
+
/**
|
|
195
|
+
* TBD.
|
|
196
|
+
* @param {boolean} hard - TBD.
|
|
197
|
+
*/
|
|
169
198
|
reset(hard = false) {
|
|
170
199
|
if (!this.game.isBooted || this.resetLocked) {
|
|
171
200
|
return;
|
|
@@ -191,11 +220,21 @@ export class Input {
|
|
|
191
220
|
this._pollCounter = 0;
|
|
192
221
|
}
|
|
193
222
|
|
|
223
|
+
/**
|
|
224
|
+
* TBD.
|
|
225
|
+
* @param {number} x - TBD.
|
|
226
|
+
* @param {number} y - TBD.
|
|
227
|
+
*/
|
|
194
228
|
resetSpeed(x, y) {
|
|
195
229
|
this._oldPosition.setTo(x, y);
|
|
196
230
|
this.speed.setTo(0, 0);
|
|
197
231
|
}
|
|
198
232
|
|
|
233
|
+
/**
|
|
234
|
+
* TBD.
|
|
235
|
+
* @param {MouseEvent|TouchEvent|PointerEvent} event - TBD.
|
|
236
|
+
* @returns {Pointer} TBD.
|
|
237
|
+
*/
|
|
199
238
|
startPointer(event) {
|
|
200
239
|
if (this.maxPointers >= 0 && this.countActivePointers(this.maxPointers) >= this.maxPointers) {
|
|
201
240
|
return null;
|
|
@@ -215,6 +254,11 @@ export class Input {
|
|
|
215
254
|
return null;
|
|
216
255
|
}
|
|
217
256
|
|
|
257
|
+
/**
|
|
258
|
+
* TBD.
|
|
259
|
+
* @param {MouseEvent|TouchEvent|PointerEvent} event - TBD.
|
|
260
|
+
* @returns {Pointer} TBD.
|
|
261
|
+
*/
|
|
218
262
|
updatePointer(event) {
|
|
219
263
|
if (this.pointer1.active && this.pointer1.identifier === event.identifier) {
|
|
220
264
|
return this.pointer1.move(event);
|
|
@@ -231,6 +275,11 @@ export class Input {
|
|
|
231
275
|
return null;
|
|
232
276
|
}
|
|
233
277
|
|
|
278
|
+
/**
|
|
279
|
+
* TBD.
|
|
280
|
+
* @param {MouseEvent|TouchEvent|PointerEvent} event - TBD.
|
|
281
|
+
* @returns {Pointer} TBD.
|
|
282
|
+
*/
|
|
234
283
|
stopPointer(event) {
|
|
235
284
|
if (this.pointer1.active && this.pointer1.identifier === event.identifier) {
|
|
236
285
|
return this.pointer1.stop(event);
|
|
@@ -247,6 +296,11 @@ export class Input {
|
|
|
247
296
|
return null;
|
|
248
297
|
}
|
|
249
298
|
|
|
299
|
+
/**
|
|
300
|
+
* TBD.
|
|
301
|
+
* @param limit - TBD.
|
|
302
|
+
* @returns {number} TBD.
|
|
303
|
+
*/
|
|
250
304
|
countActivePointers(limit = this.pointers.length) {
|
|
251
305
|
let count = limit;
|
|
252
306
|
for (let i = 0; i < this.pointers.length && count > 0; i += 1) {
|
|
@@ -258,6 +312,11 @@ export class Input {
|
|
|
258
312
|
return limit - count;
|
|
259
313
|
}
|
|
260
314
|
|
|
315
|
+
/**
|
|
316
|
+
* TBD.
|
|
317
|
+
* @param {boolean} isActive - TBD.
|
|
318
|
+
* @returns {Pointer} TBD.
|
|
319
|
+
*/
|
|
261
320
|
getPointer(isActive = false) {
|
|
262
321
|
for (let i = 0; i < this.pointers.length; i += 1) {
|
|
263
322
|
const pointer = this.pointers[i];
|
|
@@ -268,6 +327,11 @@ export class Input {
|
|
|
268
327
|
return null;
|
|
269
328
|
}
|
|
270
329
|
|
|
330
|
+
/**
|
|
331
|
+
* TBD.
|
|
332
|
+
* @param identifier - TBD.
|
|
333
|
+
* @returns {Pointer} TBD.
|
|
334
|
+
*/
|
|
271
335
|
getPointerFromIdentifier(identifier) {
|
|
272
336
|
for (let i = 0; i < this.pointers.length; i += 1) {
|
|
273
337
|
const pointer = this.pointers[i];
|
|
@@ -279,6 +343,11 @@ export class Input {
|
|
|
279
343
|
return null;
|
|
280
344
|
}
|
|
281
345
|
|
|
346
|
+
/**
|
|
347
|
+
* TBD.
|
|
348
|
+
* @param pointerId - TBD.
|
|
349
|
+
* @returns {Pointer} TBD.
|
|
350
|
+
*/
|
|
282
351
|
getPointerFromId(pointerId) {
|
|
283
352
|
for (let i = 0; i < this.pointers.length; i += 1) {
|
|
284
353
|
const pointer = this.pointers[i];
|
|
@@ -290,6 +359,13 @@ export class Input {
|
|
|
290
359
|
return null;
|
|
291
360
|
}
|
|
292
361
|
|
|
362
|
+
/**
|
|
363
|
+
* TBD.
|
|
364
|
+
* @param displayObject - TBD.
|
|
365
|
+
* @param pointer - TBD.
|
|
366
|
+
* @param output - TBD.
|
|
367
|
+
* @returns {Point} TBD.
|
|
368
|
+
*/
|
|
293
369
|
getLocalPosition(displayObject, pointer, output = null) {
|
|
294
370
|
const result = output || new Point();
|
|
295
371
|
const wt = displayObject.worldTransform;
|
|
@@ -300,6 +376,13 @@ export class Input {
|
|
|
300
376
|
);
|
|
301
377
|
}
|
|
302
378
|
|
|
379
|
+
/**
|
|
380
|
+
* TBD.
|
|
381
|
+
* @param displayObject - TBD.
|
|
382
|
+
* @param pointer - TBD.
|
|
383
|
+
* @param localPoint - TBD.
|
|
384
|
+
* @returns {boolean} TBD.
|
|
385
|
+
*/
|
|
303
386
|
hitTest(displayObject, pointer, localPoint) {
|
|
304
387
|
if (!displayObject.worldVisible) {
|
|
305
388
|
return false;
|
|
@@ -321,11 +404,7 @@ export class Input {
|
|
|
321
404
|
} else if (displayObject instanceof Graphics) {
|
|
322
405
|
for (let i = 0; i < displayObject.graphicsData.length; i += 1) {
|
|
323
406
|
const data = displayObject.graphicsData[i];
|
|
324
|
-
if (
|
|
325
|
-
data.fill &&
|
|
326
|
-
data.shape &&
|
|
327
|
-
data.shape.contains(this._localPoint.x, this._localPoint.y)
|
|
328
|
-
) {
|
|
407
|
+
if (data.fill && data.shape && data.shape.contains(this._localPoint.x, this._localPoint.y)) {
|
|
329
408
|
// Only deal with fills..
|
|
330
409
|
return true;
|
|
331
410
|
}
|
|
@@ -340,42 +419,79 @@ export class Input {
|
|
|
340
419
|
return false;
|
|
341
420
|
}
|
|
342
421
|
|
|
422
|
+
/**
|
|
423
|
+
* TBD.
|
|
424
|
+
*/
|
|
343
425
|
onClickTrampoline() {
|
|
344
426
|
this.activePointer.processClickTrampolines();
|
|
345
427
|
}
|
|
346
428
|
|
|
429
|
+
/**
|
|
430
|
+
* TBD.
|
|
431
|
+
* @returns {number} TBD.
|
|
432
|
+
*/
|
|
347
433
|
get x() {
|
|
348
434
|
return this._x;
|
|
349
435
|
}
|
|
350
436
|
|
|
437
|
+
/**
|
|
438
|
+
* TBD.
|
|
439
|
+
*/
|
|
351
440
|
set x(value) {
|
|
352
441
|
this._x = Math.floor(value);
|
|
353
442
|
}
|
|
354
443
|
|
|
444
|
+
/**
|
|
445
|
+
* TBD.
|
|
446
|
+
* @returns {number} TBD.
|
|
447
|
+
*/
|
|
355
448
|
get y() {
|
|
356
449
|
return this._y;
|
|
357
450
|
}
|
|
358
451
|
|
|
452
|
+
/**
|
|
453
|
+
* TBD.
|
|
454
|
+
*/
|
|
359
455
|
set y(value) {
|
|
360
456
|
this._y = Math.floor(value);
|
|
361
457
|
}
|
|
362
458
|
|
|
459
|
+
/**
|
|
460
|
+
* TBD.
|
|
461
|
+
* @returns {boolean} TBD.
|
|
462
|
+
*/
|
|
363
463
|
get pollLocked() {
|
|
364
464
|
return this.pollRate > 0 && this._pollCounter < this.pollRate;
|
|
365
465
|
}
|
|
366
466
|
|
|
467
|
+
/**
|
|
468
|
+
* TBD.
|
|
469
|
+
* @returns {number} TBD.
|
|
470
|
+
*/
|
|
367
471
|
get totalInactivePointers() {
|
|
368
472
|
return this.pointers.length - this.countActivePointers();
|
|
369
473
|
}
|
|
370
474
|
|
|
475
|
+
/**
|
|
476
|
+
* TBD.
|
|
477
|
+
* @returns {number} TBD.
|
|
478
|
+
*/
|
|
371
479
|
get totalActivePointers() {
|
|
372
480
|
return this.countActivePointers();
|
|
373
481
|
}
|
|
374
482
|
|
|
483
|
+
/**
|
|
484
|
+
* TBD.
|
|
485
|
+
* @returns {number} TBD.
|
|
486
|
+
*/
|
|
375
487
|
get worldX() {
|
|
376
488
|
return this.x;
|
|
377
489
|
}
|
|
378
490
|
|
|
491
|
+
/**
|
|
492
|
+
* TBD.
|
|
493
|
+
* @returns {number} TBD.
|
|
494
|
+
*/
|
|
379
495
|
get worldY() {
|
|
380
496
|
return this.y;
|
|
381
497
|
}
|