@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,212 @@
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 Rectangle from '../rectangle';
7
+ import Point from '../point';
8
+
9
+ /**
10
+ *
11
+ * @param a
12
+ * @param dx
13
+ * @param dy
14
+ */
15
+ export function inflate(a, dx, dy) {
16
+ a.x -= dx;
17
+ a.width += 2 * dx;
18
+ a.y -= dy;
19
+ a.height += 2 * dy;
20
+ return a;
21
+ }
22
+
23
+ /**
24
+ *
25
+ * @param a
26
+ * @param point
27
+ */
28
+ export function inflatePoint(a, point) {
29
+ return inflate(a, point.x, point.y);
30
+ }
31
+
32
+ /**
33
+ *
34
+ * @param a
35
+ * @param output
36
+ */
37
+ export function size(a, output = null) {
38
+ const result = output || new Point();
39
+ result.setTo(a.width, a.height);
40
+ return result;
41
+ }
42
+
43
+ /**
44
+ *
45
+ * @param input
46
+ * @param output
47
+ */
48
+ export function clone(input, output = null) {
49
+ const result = output || new Rectangle();
50
+ result.setTo(input.x, input.y, input.width, input.height);
51
+ return result;
52
+ }
53
+
54
+ /**
55
+ *
56
+ * @param a
57
+ * @param x
58
+ * @param y
59
+ */
60
+ export function contains(a, x, y) {
61
+ if (a.width <= 0 || a.height <= 0) {
62
+ return false;
63
+ }
64
+ return (x >= a.x && x < a.right && y >= a.y && y < a.bottom);
65
+ }
66
+
67
+ /**
68
+ *
69
+ * @param rx
70
+ * @param ry
71
+ * @param rw
72
+ * @param rh
73
+ * @param x
74
+ * @param y
75
+ */
76
+ export function containsRaw(rx, ry, rw, rh, x, y) {
77
+ return (x >= rx && x < (rx + rw) && y >= ry && y < (ry + rh));
78
+ }
79
+
80
+ /**
81
+ *
82
+ * @param a
83
+ * @param point
84
+ */
85
+ export function containsPoint(a, point) {
86
+ return contains(a, point.x, point.y);
87
+ }
88
+
89
+ /**
90
+ *
91
+ * @param a
92
+ * @param b
93
+ */
94
+ export function containsRect(a, b) {
95
+ if (a.volume > b.volume) {
96
+ return false;
97
+ }
98
+ return (a.x >= b.x && a.y >= b.y && a.right < b.right && a.bottom < b.bottom);
99
+ }
100
+
101
+ /**
102
+ *
103
+ * @param a
104
+ * @param b
105
+ */
106
+ export function equals(a, b) {
107
+ return (a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height);
108
+ }
109
+
110
+ /**
111
+ *
112
+ * @param a
113
+ * @param b
114
+ */
115
+ export function sameDimensions(a, b) {
116
+ return (a.width === b.width && a.height === b.height);
117
+ }
118
+
119
+ /**
120
+ *
121
+ * @param a
122
+ * @param b
123
+ */
124
+ export function intersects(a, b) {
125
+ if (a.width <= 0 || a.height <= 0 || b.width <= 0 || b.height <= 0) {
126
+ return false;
127
+ }
128
+ return !(a.right < b.x || a.bottom < b.y || a.x > b.right || a.y > b.bottom);
129
+ }
130
+
131
+ /**
132
+ *
133
+ * @param a
134
+ * @param b
135
+ * @param output
136
+ */
137
+ export function intersection(a, b, output = null) {
138
+ const result = output || new Rectangle();
139
+ if (intersects(a, b)) {
140
+ result.x = Math.max(a.x, b.x);
141
+ result.y = Math.max(a.y, b.y);
142
+ result.width = Math.min(a.right, b.right) - result.x;
143
+ result.height = Math.min(a.bottom, b.bottom) - result.y;
144
+ }
145
+ return result;
146
+ }
147
+
148
+ /**
149
+ *
150
+ * @param a
151
+ * @param left
152
+ * @param right
153
+ * @param top
154
+ * @param bottom
155
+ * @param tolerance
156
+ */
157
+ export function intersectsRaw(a, left, right, top, bottom, tolerance = 0) {
158
+ return !(left > a.right + tolerance || right < a.left - tolerance || top > a.bottom + tolerance || bottom < a.top - tolerance);
159
+ }
160
+
161
+ /**
162
+ *
163
+ * @param a
164
+ * @param b
165
+ * @param output
166
+ */
167
+ export function union(a, b, output = null) {
168
+ const result = output || new Rectangle();
169
+ return result.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right) - Math.min(a.left, b.left), Math.max(a.bottom, b.bottom) - Math.min(a.top, b.top));
170
+ }
171
+
172
+ /**
173
+ *
174
+ * @param points
175
+ * @param output
176
+ */
177
+ export function aabb(points, output = null) {
178
+ const result = output || new Rectangle();
179
+ let xMax = Number.NEGATIVE_INFINITY;
180
+ let xMin = Number.POSITIVE_INFINITY;
181
+ let yMax = Number.NEGATIVE_INFINITY;
182
+ let yMin = Number.POSITIVE_INFINITY;
183
+ points.forEach((point) => {
184
+ if (point.x > xMax) {
185
+ xMax = point.x;
186
+ }
187
+ if (point.x < xMin) {
188
+ xMin = point.x;
189
+ }
190
+ if (point.y > yMax) {
191
+ yMax = point.y;
192
+ }
193
+ if (point.y < yMin) {
194
+ yMin = point.y;
195
+ }
196
+ });
197
+ result.setTo(xMin, yMin, xMax - xMin, yMax - yMin);
198
+ return result;
199
+ }
200
+
201
+ /**
202
+ *
203
+ */
204
+ export function getEmptyRectangle() {
205
+ if (!window.PhaserRegistry) {
206
+ window.PhaserRegistry = {};
207
+ }
208
+ if (!window.PhaserRegistry.EMPTY_RECTANGLE) {
209
+ window.PhaserRegistry.EMPTY_RECTANGLE = new Rectangle();
210
+ }
211
+ return window.PhaserRegistry.EMPTY_RECTANGLE;
212
+ }
@@ -0,0 +1,28 @@
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 RoundedRectangle from '../rounded_rectangle';
7
+
8
+ /**
9
+ *
10
+ */
11
+ export default function () {
12
+ return true;
13
+ }
14
+
15
+ /**
16
+ *
17
+ * @param input
18
+ * @param output
19
+ */
20
+ export function clone(input, output = null) {
21
+ const result = output || new RoundedRectangle();
22
+ result.x = input.x;
23
+ result.y = input.y;
24
+ result.width = input.width;
25
+ result.height = input.height;
26
+ result.radius = input.radius;
27
+ return result;
28
+ }
@@ -0,0 +1,279 @@
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
+ export const DEG_TO_RAD = Math.PI / 180;
7
+ export const RAD_TO_DEG = 180 / Math.PI;
8
+ export const PI_2 = Math.PI * 2;
9
+
10
+ /**
11
+ *
12
+ * @param hex
13
+ */
14
+ export function hex2rgb(hex) {
15
+ return [(hex >> 16 & 0xFF) / 255, (hex >> 8 & 0xFF) / 255, (hex & 0xFF) / 255];
16
+ }
17
+
18
+ /**
19
+ *
20
+ * @param rgb
21
+ */
22
+ export function rgb2hex(rgb) {
23
+ return ((rgb[0] * 255 << 16) + (rgb[1] * 255 << 8) + rgb[2] * 255);
24
+ }
25
+
26
+ /**
27
+ *
28
+ * @param value
29
+ */
30
+ export function getNextPowerOfTwo(value) {
31
+ // see: https://en.wikipedia.org/wiki/Power_of_two#Fast_algorithm_to_check_if_a_positive_number_is_a_power_of_two
32
+ if (value > 0 && (value & (value - 1)) === 0) {
33
+ return value;
34
+ }
35
+ let result = 1;
36
+ while (result < value) {
37
+ result <<= 1;
38
+ }
39
+ return result;
40
+ }
41
+
42
+ /**
43
+ *
44
+ * @param width
45
+ * @param height
46
+ */
47
+ export function isPowerOfTwo(width, height) {
48
+ return (width > 0 && (width & (width - 1)) === 0 && height > 0 && (height & (height - 1)) === 0);
49
+ }
50
+
51
+ /**
52
+ *
53
+ * @param degrees
54
+ */
55
+ export function degToRad(degrees) {
56
+ return degrees * DEG_TO_RAD;
57
+ }
58
+
59
+ /**
60
+ *
61
+ * @param radians
62
+ */
63
+ export function radToDeg(radians) {
64
+ return radians * RAD_TO_DEG;
65
+ }
66
+
67
+ /**
68
+ *
69
+ * @param min
70
+ * @param max
71
+ */
72
+ export function between(min, max) {
73
+ return Math.floor(Math.random() * (max - min + 1) + min);
74
+ }
75
+
76
+ /**
77
+ *
78
+ * @param input
79
+ * @param gap
80
+ * @param start
81
+ */
82
+ export function snapToCeil(input, gap = 0, start = 0) {
83
+ if (gap === 0) {
84
+ return input;
85
+ }
86
+ input -= start;
87
+ input = gap * Math.ceil(input / gap);
88
+ return start + input;
89
+ }
90
+
91
+ /**
92
+ *
93
+ * @param value
94
+ * @param min
95
+ * @param max
96
+ */
97
+ export function wrap(value, min, max) {
98
+ const range = max - min;
99
+ if (range <= 0) {
100
+ return 0;
101
+ }
102
+ let result = (value - min) % range;
103
+ if (result < 0) {
104
+ result += range;
105
+ }
106
+ return result + min;
107
+ }
108
+
109
+ /**
110
+ *
111
+ * @param p0
112
+ * @param p1
113
+ * @param t
114
+ */
115
+ export function linear(p0, p1, t) {
116
+ return (p1 - p0) * t + p0;
117
+ }
118
+
119
+ /**
120
+ *
121
+ * @param a
122
+ * @param b
123
+ */
124
+ export function difference(a, b) {
125
+ return Math.abs(a - b);
126
+ }
127
+
128
+ /**
129
+ *
130
+ * @param v
131
+ * @param k
132
+ */
133
+ export function linearInterpolation(v, k) {
134
+ const m = v.length - 1;
135
+ const f = m * k;
136
+ const i = Math.floor(f);
137
+ if (k < 0) {
138
+ return linear(v[0], v[1], f);
139
+ }
140
+ if (k > 1) {
141
+ return linear(v[m], v[m - 1], m - f);
142
+ }
143
+ return linear(v[i], v[i + 1 > m ? m : i + 1], f - i);
144
+ }
145
+
146
+ /**
147
+ *
148
+ * @param x1
149
+ * @param y1
150
+ * @param x2
151
+ * @param y2
152
+ */
153
+ export function distance(x1, y1, x2, y2) {
154
+ const dx = x1 - x2;
155
+ const dy = y1 - y2;
156
+ return Math.sqrt(dx * dx + dy * dy);
157
+ }
158
+
159
+ /**
160
+ *
161
+ * @param a
162
+ * @param b
163
+ * @param tolerance
164
+ */
165
+ export function within(a, b, tolerance) {
166
+ return (Math.abs(a - b) <= tolerance);
167
+ }
168
+
169
+ /**
170
+ *
171
+ * @param a
172
+ * @param r
173
+ * @param g
174
+ * @param b
175
+ */
176
+ export function getColor32(a, r, g, b) {
177
+ return a << 24 | r << 16 | g << 8 | b;
178
+ }
179
+
180
+ /**
181
+ *
182
+ * @param r
183
+ * @param g
184
+ * @param b
185
+ */
186
+ export function getColor(r, g, b) {
187
+ return r << 16 | g << 8 | b;
188
+ }
189
+
190
+ /**
191
+ *
192
+ * @param value
193
+ * @param out
194
+ */
195
+ export function hexToColor(value, out) {
196
+ // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
197
+ value = value.replace(/^(?:#|0x)?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => r + r + g + g + b + b);
198
+ const result = /^(?:#|0x)?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(value);
199
+ if (result) {
200
+ out.r = parseInt(result[1], 16);
201
+ out.g = parseInt(result[2], 16);
202
+ out.b = parseInt(result[3], 16);
203
+ }
204
+ }
205
+
206
+ /**
207
+ *
208
+ * @param value
209
+ * @param out
210
+ */
211
+ export function webToColor(value, out) {
212
+ const result = /^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d+(?:\.\d+)?))?\s*\)$/.exec(value);
213
+ if (result) {
214
+ out.r = parseInt(result[1], 10);
215
+ out.g = parseInt(result[2], 10);
216
+ out.b = parseInt(result[3], 10);
217
+ out.a = result[4] !== undefined ? parseFloat(result[4]) : 1;
218
+ }
219
+ }
220
+
221
+ /**
222
+ *
223
+ * @param color
224
+ */
225
+ export function getRGB(color) {
226
+ if (color > 16777215) {
227
+ // The color value has an alpha component
228
+ return {
229
+ alpha: color >>> 24,
230
+ red: color >> 16 & 0xFF,
231
+ green: color >> 8 & 0xFF,
232
+ blue: color & 0xFF,
233
+ a: color >>> 24,
234
+ r: color >> 16 & 0xFF,
235
+ g: color >> 8 & 0xFF,
236
+ b: color & 0xFF,
237
+ };
238
+ }
239
+ return {
240
+ alpha: 255,
241
+ red: color >> 16 & 0xFF,
242
+ green: color >> 8 & 0xFF,
243
+ blue: color & 0xFF,
244
+ a: 255,
245
+ r: color >> 16 & 0xFF,
246
+ g: color >> 8 & 0xFF,
247
+ b: color & 0xFF,
248
+ };
249
+ }
250
+
251
+ /**
252
+ *
253
+ * @param value
254
+ * @param out
255
+ */
256
+ export function valueToColor(value, out) {
257
+ if (typeof value === 'string') {
258
+ if (value.indexOf('rgb') === 0) {
259
+ webToColor(value, out);
260
+ } else {
261
+ // `hexToColor` does not support alpha; match `createColor`.
262
+ out.a = 1;
263
+ hexToColor(value, out);
264
+ }
265
+ } else if (typeof value === 'number') {
266
+ // `getRGB` does not take optional object to modify;
267
+ // alpha is also adjusted to match `createColor`.
268
+ const tempColor = getRGB(value);
269
+ out.r = tempColor.r;
270
+ out.g = tempColor.g;
271
+ out.b = tempColor.b;
272
+ out.a = tempColor.a / 255;
273
+ }
274
+ out.rgba = 'rgba(' + out.r.toString() + ',' + out.g.toString() + ',' + out.b.toString() + ',' + out.a.toString() + ')';
275
+ out.color = getColor(out.r, out.g, out.b);
276
+ out.color32 = getColor32(out.a * 255, out.r, out.g, out.b);
277
+ return out;
278
+
279
+ }
@@ -0,0 +1,26 @@
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
+ /**
8
+ *
9
+ */
10
+ export function generateID() {
11
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
12
+ }
13
+
14
+ /**
15
+ *
16
+ */
17
+ export function generateUUID() {
18
+ return (`${generateID()}${generateID()}-${generateID()}-4${generateID().substr(0, 3)}-${generateID()}-${generateID()}${generateID()}${generateID()}`).toLowerCase();
19
+ }
20
+
21
+ /**
22
+ *
23
+ */
24
+ export function generateShaderID() {
25
+ return (`${generateID()}${generateID()}-${generateID()}`).toLowerCase();
26
+ }