@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,248 @@
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 { getTintedTexture } from './canvas/tinter';
7
+ import { getIdentityMatrix } from '../geom/util/matrix';
8
+ import { SCALE_LINEAR } from '../core/const';
9
+
10
+ /**
11
+ *
12
+ * @param target
13
+ * @param texture
14
+ * @param destroyBase
15
+ */
16
+ export function setTexture(target, texture, destroyBase = false) {
17
+ if (destroyBase) {
18
+ target.texture.baseTexture.destroy();
19
+ }
20
+ target.texture.baseTexture.skipRender = false;
21
+ target.texture = texture;
22
+ target.texture.valid = true;
23
+ target.cachedTint = -1;
24
+ }
25
+
26
+ /**
27
+ *
28
+ * @param target
29
+ * @param matrix
30
+ */
31
+ export function getBounds(target, matrix = null) {
32
+ // TODO verify
33
+ if (target.currentBounds) {
34
+ return target.currentBounds;
35
+ }
36
+ const width = target.texture.frame.width;
37
+ const height = target.texture.frame.height;
38
+ let w0 = width * (1 - target.anchor.x);
39
+ let w1 = width * -target.anchor.x;
40
+ let h0 = height * (1 - target.anchor.y);
41
+ let h1 = height * -target.anchor.y;
42
+ const worldTransform = matrix || target.worldTransform;
43
+ let a = worldTransform.a;
44
+ const b = worldTransform.b;
45
+ const c = worldTransform.c;
46
+ let d = worldTransform.d;
47
+ const tx = worldTransform.tx;
48
+ const ty = worldTransform.ty;
49
+ let maxX = -Infinity;
50
+ let maxY = -Infinity;
51
+ let minX = Infinity;
52
+ let minY = Infinity;
53
+ if (b === 0 && c === 0) {
54
+ // scale may be negative!
55
+ if (a < 0) {
56
+ a *= -1;
57
+ const temp = w0;
58
+ w0 = -w1;
59
+ w1 = -temp;
60
+ }
61
+ if (d < 0) {
62
+ d *= -1;
63
+ const temp = h0;
64
+ h0 = -h1;
65
+ h1 = -temp;
66
+ }
67
+ // this means there is no rotation going on right? RIGHT?
68
+ // if thats the case then we can avoid checking the bound values! yay
69
+ minX = a * w1 + tx;
70
+ maxX = a * w0 + tx;
71
+ minY = d * h1 + ty;
72
+ maxY = d * h0 + ty;
73
+ } else {
74
+ const x1 = a * w1 + c * h1 + tx;
75
+ const y1 = d * h1 + b * w1 + ty;
76
+ const x2 = a * w0 + c * h1 + tx;
77
+ const y2 = d * h1 + b * w0 + ty;
78
+ const x3 = a * w0 + c * h0 + tx;
79
+ const y3 = d * h0 + b * w0 + ty;
80
+ const x4 = a * w1 + c * h0 + tx;
81
+ const y4 = d * h0 + b * w1 + ty;
82
+ minX = x1 < minX ? x1 : minX;
83
+ minX = x2 < minX ? x2 : minX;
84
+ minX = x3 < minX ? x3 : minX;
85
+ minX = x4 < minX ? x4 : minX;
86
+ minY = y1 < minY ? y1 : minY;
87
+ minY = y2 < minY ? y2 : minY;
88
+ minY = y3 < minY ? y3 : minY;
89
+ minY = y4 < minY ? y4 : minY;
90
+ maxX = x1 > maxX ? x1 : maxX;
91
+ maxX = x2 > maxX ? x2 : maxX;
92
+ maxX = x3 > maxX ? x3 : maxX;
93
+ maxX = x4 > maxX ? x4 : maxX;
94
+ maxY = y1 > maxY ? y1 : maxY;
95
+ maxY = y2 > maxY ? y2 : maxY;
96
+ maxY = y3 > maxY ? y3 : maxY;
97
+ maxY = y4 > maxY ? y4 : maxY;
98
+ }
99
+ const bounds = target.cachedBounds;
100
+ bounds.x = minX;
101
+ bounds.width = maxX - minX;
102
+ bounds.y = minY;
103
+ bounds.height = maxY - minY;
104
+ target.currentBounds = bounds;
105
+ return bounds;
106
+ }
107
+
108
+ /**
109
+ *
110
+ * @param target
111
+ */
112
+ export function getLocalBounds(target) {
113
+ const matrixCache = target.worldTransform;
114
+ target.worldTransform = getIdentityMatrix();
115
+ let i;
116
+ for (i = 0; i < target.children.length; i += 1) {
117
+ target.children[i].updateTransform();
118
+ }
119
+ const bounds = target.getBounds();
120
+ target.worldTransform = matrixCache;
121
+ for (i = 0; i < target.children.length; i += 1) {
122
+ target.children[i].updateTransform();
123
+ }
124
+ return bounds;
125
+ }
126
+
127
+ /**
128
+ *
129
+ * @param target
130
+ * @param renderSession
131
+ * @param matrix
132
+ */
133
+ export function renderWebGL(target, renderSession, matrix) {
134
+ // if the sprite is not visible or the alpha is 0 then no need to render this element
135
+ if (!target.visible || target.alpha <= 0 || !target.renderable) {
136
+ return;
137
+ }
138
+ // They provided an alternative rendering matrix, so use it
139
+ let wt = target.worldTransform;
140
+ if (matrix) {
141
+ wt = matrix;
142
+ }
143
+ // A quick check to see if this element has a mask or a filter.
144
+ if (target._mask || target._filters) {
145
+ const spriteBatch = renderSession.spriteBatch;
146
+ // push filter first as we need to ensure the stencil buffer is correct for any masking
147
+ if (target._filters) {
148
+ spriteBatch.flush();
149
+ renderSession.filterManager.pushFilter(target._filterBlock);
150
+ }
151
+ if (target._mask) {
152
+ spriteBatch.stop();
153
+ renderSession.maskManager.pushMask(target.mask, renderSession);
154
+ spriteBatch.start();
155
+ }
156
+ // add this sprite to the batch
157
+ spriteBatch.render(target);
158
+ // now loop through the children and make sure they get rendered
159
+ for (let i = 0; i < target.children.length; i += 1) {
160
+ target.children[i].renderWebGL(renderSession);
161
+ }
162
+ // time to stop the sprite batch as either a mask element or a filter draw will happen next
163
+ spriteBatch.stop();
164
+ if (target._mask) renderSession.maskManager.popMask(target._mask, renderSession);
165
+ if (target._filters) renderSession.filterManager.popFilter();
166
+ spriteBatch.start();
167
+ } else {
168
+ renderSession.spriteBatch.render(target);
169
+ // Render children!
170
+ for (let i = 0; i < target.children.length; i += 1) {
171
+ target.children[i].renderWebGL(renderSession, wt);
172
+ }
173
+ }
174
+ }
175
+
176
+ /**
177
+ *
178
+ * @param target
179
+ * @param renderSession
180
+ * @param matrix
181
+ */
182
+ export function renderCanvas(target, renderSession, matrix) {
183
+ // If the sprite is not visible or the alpha is 0 then no need to render this element
184
+ if (!target.visible || target.alpha === 0 || !target.renderable || target.texture.crop.width <= 0 || target.texture.crop.height <= 0) {
185
+ return;
186
+ }
187
+ let wt = target.worldTransform;
188
+ // If they provided an alternative rendering matrix then use it
189
+ if (matrix) {
190
+ wt = matrix;
191
+ }
192
+ if (target.blendMode !== renderSession.currentBlendMode) {
193
+ renderSession.currentBlendMode = target.blendMode;
194
+ renderSession.context.globalCompositeOperation = window.PhaserRegistry.blendModesCanvas[renderSession.currentBlendMode];
195
+ }
196
+ if (target._mask) {
197
+ renderSession.maskManager.pushMask(target._mask, renderSession);
198
+ }
199
+ // Ignore null sources
200
+ if (target.texture.valid) {
201
+ const resolution = target.texture.baseTexture.resolution / renderSession.resolution;
202
+ renderSession.context.globalAlpha = target.worldAlpha;
203
+
204
+ // If smoothingEnabled is supported and we need to change the smoothing property for this texture
205
+ if (renderSession.smoothProperty && renderSession.scaleMode !== target.texture.baseTexture.scaleMode) {
206
+ renderSession.scaleMode = target.texture.baseTexture.scaleMode;
207
+ renderSession.context[renderSession.smoothProperty] = (renderSession.scaleMode === SCALE_LINEAR);
208
+ }
209
+ // If the texture is trimmed we offset by the trim x/y, otherwise we use the frame dimensions
210
+ let dx = (target.texture.trim) ? target.texture.trim.x - target.anchor.x * target.texture.trim.width : target.anchor.x * -target.texture.frame.width;
211
+ let dy = (target.texture.trim) ? target.texture.trim.y - target.anchor.y * target.texture.trim.height : target.anchor.y * -target.texture.frame.height;
212
+ const tx = (wt.tx * renderSession.resolution) + renderSession.shakeX;
213
+ const ty = (wt.ty * renderSession.resolution) + renderSession.shakeY;
214
+ // Allow for pixel rounding
215
+ if (renderSession.roundPixels) {
216
+ renderSession.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx | 0, ty | 0);
217
+ dx |= 0;
218
+ dy |= 0;
219
+ } else {
220
+ renderSession.context.setTransform(wt.a, wt.b, wt.c, wt.d, tx, ty);
221
+ }
222
+ let cw = target.texture.crop.width;
223
+ let ch = target.texture.crop.height;
224
+ dx /= resolution;
225
+ dy /= resolution;
226
+ if (target.tint !== 0xFFFFFF) {
227
+ if (target.texture.requiresReTint || target.cachedTint !== target.tint) {
228
+ target.tintedTexture = getTintedTexture(target, target.tint);
229
+ target.cachedTint = target.tint;
230
+ target.texture.requiresReTint = false;
231
+ }
232
+ renderSession.context.drawImage(target.tintedTexture, 0, 0, cw, ch, dx, dy, cw / resolution, ch / resolution);
233
+ } else {
234
+ const cx = target.texture.crop.x;
235
+ const cy = target.texture.crop.y;
236
+ // https://github.com/photonstorm/phaser-ce/pull/61
237
+ cw = Math.floor(cw);
238
+ ch = Math.floor(ch);
239
+ renderSession.context.drawImage(target.texture.baseTexture.source, cx, cy, cw, ch, dx, dy, cw / resolution, ch / resolution);
240
+ }
241
+ }
242
+ for (let i = 0; i < target.children.length; i += 1) {
243
+ target.children[i].renderCanvas(renderSession);
244
+ }
245
+ if (target._mask) {
246
+ renderSession.maskManager.popMask(renderSession);
247
+ }
248
+ }