@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,242 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @author Mat Groves http://matgroves.com/ @Doormat23
5
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
6
+ */
7
+
8
+ // TODO: fix ++ +=1 conversion issues (when a is 0 than a++ is 0 but a+=1 is 1)
9
+
10
+ export default class {
11
+
12
+ constructor(gl) {
13
+ this.vertSize = 10;
14
+ this.maxSize = 6000; // Math.pow(2, 16) / this.vertSize;
15
+ this.size = this.maxSize;
16
+ // the total number of floats in our batch
17
+ const numVerts = this.size * 4 * this.vertSize;
18
+ // the total number of indices in our batch
19
+ const numIndices = this.maxSize * 6;
20
+ this.vertices = new Float32Array(numVerts);
21
+ this.indices = new Uint16Array(numIndices);
22
+ this.vertexBuffer = null;
23
+ this.indexBuffer = null;
24
+ this.lastIndexCount = 0;
25
+ for (let i = 0, j = 0; i < numIndices; i += 6, j += 4) {
26
+ this.indices[i + 0] = j + 0;
27
+ this.indices[i + 1] = j + 1;
28
+ this.indices[i + 2] = j + 2;
29
+ this.indices[i + 3] = j + 0;
30
+ this.indices[i + 4] = j + 2;
31
+ this.indices[i + 5] = j + 3;
32
+ }
33
+ this.drawing = false;
34
+ this.currentBatchSize = 0;
35
+ this.currentBaseTexture = null;
36
+ this.currentBlendMode = 0;
37
+ this.renderSession = null;
38
+ this.shader = null;
39
+ this.matrix = null;
40
+ this.setContext(gl);
41
+ }
42
+
43
+ setContext(gl) {
44
+ this.gl = gl;
45
+ // create a couple of buffers
46
+ this.vertexBuffer = gl.createBuffer();
47
+ this.indexBuffer = gl.createBuffer();
48
+ // 65535 is max index, so 65535 / 6 = 10922.
49
+ // upload the index data
50
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
51
+ gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, this.indices, gl.STATIC_DRAW);
52
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
53
+ gl.bufferData(gl.ARRAY_BUFFER, this.vertices, gl.DYNAMIC_DRAW);
54
+ }
55
+
56
+ begin(spriteBatch, renderSession) {
57
+ this.renderSession = renderSession;
58
+ this.shader = this.renderSession.shaderManager.fastShader;
59
+ this.matrix = spriteBatch.worldTransform.toArray(true);
60
+ this.start();
61
+ }
62
+
63
+ end() {
64
+ this.flush();
65
+ }
66
+
67
+ render(spriteBatch) {
68
+ const children = spriteBatch.children;
69
+ const sprite = children[0];
70
+ // if the uvs have not updated then no point rendering just yet!
71
+ // check texture.
72
+ if (!sprite.texture._uvs) {
73
+ return;
74
+ }
75
+ this.currentBaseTexture = sprite.texture.baseTexture;
76
+ // check blend mode
77
+ if (sprite.blendMode !== this.renderSession.blendModeManager.currentBlendMode) {
78
+ this.flush();
79
+ this.renderSession.blendModeManager.setBlendMode(sprite.blendMode);
80
+ }
81
+ for (let i = 0, j = children.length; i < j; i += 1) {
82
+ this.renderSprite(children[i]);
83
+ }
84
+ this.flush();
85
+ }
86
+
87
+ renderSprite(sprite) {
88
+ if (!sprite.visible) {
89
+ return;
90
+ }
91
+ // TODO trim??
92
+ if (sprite.texture.baseTexture !== this.currentBaseTexture && !sprite.texture.baseTexture.skipRender) {
93
+ this.flush();
94
+ this.currentBaseTexture = sprite.texture.baseTexture;
95
+ if (!sprite.texture._uvs) {
96
+ return;
97
+ }
98
+ }
99
+ const uvs = sprite.texture._uvs;
100
+ const vertices = this.vertices;
101
+ // const width = sprite.texture.frame.width;
102
+ // const height = sprite.texture.frame.height;
103
+ let w0;
104
+ let w1;
105
+ let h0;
106
+ let h1;
107
+ let index;
108
+ if (sprite.texture.trim) {
109
+ // if the sprite is trimmed then we need to add the extra space before transforming the sprite coords..
110
+ const trim = sprite.texture.trim;
111
+ w1 = trim.x - sprite.anchor.x * trim.width;
112
+ w0 = w1 + sprite.texture.crop.width;
113
+ h1 = trim.y - sprite.anchor.y * trim.height;
114
+ h0 = h1 + sprite.texture.crop.height;
115
+ } else {
116
+ w0 = (sprite.texture.frame.width) * (1 - sprite.anchor.x);
117
+ w1 = (sprite.texture.frame.width) * -sprite.anchor.x;
118
+ h0 = sprite.texture.frame.height * (1 - sprite.anchor.y);
119
+ h1 = sprite.texture.frame.height * -sprite.anchor.y;
120
+ }
121
+ index = this.currentBatchSize * 4 * this.vertSize;
122
+ index -= 1;
123
+ // xy
124
+ vertices[index += 1] = w1;
125
+ vertices[index += 1] = h1;
126
+ vertices[index += 1] = sprite.position.x;
127
+ vertices[index += 1] = sprite.position.y;
128
+ // scale
129
+ vertices[index += 1] = sprite.scale.x;
130
+ vertices[index += 1] = sprite.scale.y;
131
+ // rotation
132
+ vertices[index += 1] = sprite.rotation;
133
+ // uv
134
+ vertices[index += 1] = uvs.x0;
135
+ vertices[index += 1] = uvs.y1;
136
+ // color
137
+ vertices[index += 1] = sprite.alpha;
138
+ // xy
139
+ vertices[index += 1] = w0;
140
+ vertices[index += 1] = h1;
141
+ vertices[index += 1] = sprite.position.x;
142
+ vertices[index += 1] = sprite.position.y;
143
+ // scale
144
+ vertices[index += 1] = sprite.scale.x;
145
+ vertices[index += 1] = sprite.scale.y;
146
+ // rotation
147
+ vertices[index += 1] = sprite.rotation;
148
+ // uv
149
+ vertices[index += 1] = uvs.x1;
150
+ vertices[index += 1] = uvs.y1;
151
+ // color
152
+ vertices[index += 1] = sprite.alpha;
153
+ // xy
154
+ vertices[index += 1] = w0;
155
+ vertices[index += 1] = h0;
156
+ vertices[index += 1] = sprite.position.x;
157
+ vertices[index += 1] = sprite.position.y;
158
+ // scale
159
+ vertices[index += 1] = sprite.scale.x;
160
+ vertices[index += 1] = sprite.scale.y;
161
+ // rotation
162
+ vertices[index += 1] = sprite.rotation;
163
+ // uv
164
+ vertices[index += 1] = uvs.x2;
165
+ vertices[index += 1] = uvs.y2;
166
+ // color
167
+ vertices[index += 1] = sprite.alpha;
168
+ // xy
169
+ vertices[index += 1] = w1;
170
+ vertices[index += 1] = h0;
171
+ vertices[index += 1] = sprite.position.x;
172
+ vertices[index += 1] = sprite.position.y;
173
+ // scale
174
+ vertices[index += 1] = sprite.scale.x;
175
+ vertices[index += 1] = sprite.scale.y;
176
+ // rotation
177
+ vertices[index += 1] = sprite.rotation;
178
+ // uv
179
+ vertices[index += 1] = uvs.x3;
180
+ vertices[index += 1] = uvs.y3;
181
+ // color
182
+ vertices[index += 1] = sprite.alpha;
183
+ // increment the batch
184
+ this.currentBatchSize += 1;
185
+ if (this.currentBatchSize >= this.size) {
186
+ this.flush();
187
+ }
188
+ }
189
+
190
+ flush() {
191
+ // If the batch is length 0 then return as there is nothing to draw
192
+ if (this.currentBatchSize === 0) {
193
+ return;
194
+ }
195
+ const gl = this.gl;
196
+ // bind the current texture
197
+ if (!this.currentBaseTexture._glTextures[gl.id]) {
198
+ this.renderSession.renderer.updateTexture(this.currentBaseTexture, gl);
199
+ }
200
+ gl.bindTexture(gl.TEXTURE_2D, this.currentBaseTexture._glTextures[gl.id]);
201
+ // upload the verts to the buffer
202
+ if (this.currentBatchSize > (this.size * 0.5)) {
203
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, this.vertices);
204
+ } else {
205
+ const view = this.vertices.subarray(0, this.currentBatchSize * 4 * this.vertSize);
206
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, view);
207
+ }
208
+ // now draw those suckas!
209
+ gl.drawElements(gl.TRIANGLES, this.currentBatchSize * 6, gl.UNSIGNED_SHORT, 0);
210
+ // then reset the batch!
211
+ this.currentBatchSize = 0;
212
+ // increment the draw count
213
+ this.renderSession.drawCount += 1;
214
+ }
215
+
216
+ stop() {
217
+ this.flush();
218
+ }
219
+
220
+ start() {
221
+ const gl = this.gl;
222
+ // bind the main texture
223
+ gl.activeTexture(gl.TEXTURE0);
224
+ // bind the buffers
225
+ gl.bindBuffer(gl.ARRAY_BUFFER, this.vertexBuffer);
226
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this.indexBuffer);
227
+ // set the projection
228
+ const projection = this.renderSession.projection;
229
+ gl.uniform2f(this.shader.projectionVector, projection.x, projection.y);
230
+ // set the matrix
231
+ gl.uniformMatrix3fv(this.shader.uMatrix, false, this.matrix);
232
+ // set the pointers
233
+ const stride = this.vertSize * 4;
234
+ gl.vertexAttribPointer(this.shader.aVertexPosition, 2, gl.FLOAT, false, stride, 0);
235
+ gl.vertexAttribPointer(this.shader.aPositionCoord, 2, gl.FLOAT, false, stride, 2 * 4);
236
+ gl.vertexAttribPointer(this.shader.aScale, 2, gl.FLOAT, false, stride, 4 * 4);
237
+ gl.vertexAttribPointer(this.shader.aRotation, 1, gl.FLOAT, false, stride, 6 * 4);
238
+ gl.vertexAttribPointer(this.shader.aTextureCoord, 2, gl.FLOAT, false, stride, 7 * 4);
239
+ gl.vertexAttribPointer(this.shader.colorAttribute, 1, gl.FLOAT, false, stride, 9 * 4);
240
+ }
241
+
242
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @author Mat Groves http://matgroves.com/ @Doormat23
5
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
6
+ */
7
+
8
+ export default class {
9
+
10
+ constructor() {
11
+ this.filterStack = [];
12
+ this.offsetX = 0;
13
+ this.offsetY = 0;
14
+ }
15
+
16
+ setContext(gl) {
17
+ this.gl = gl;
18
+ this.texturePool = [];
19
+ this.initShaderBuffers();
20
+ }
21
+
22
+ begin() {
23
+ // TODO
24
+ }
25
+
26
+ pushFilter() {
27
+ // TODO
28
+ }
29
+
30
+ popFilter() {
31
+ // TODO
32
+ }
33
+
34
+ applyFilterPass() {
35
+ // TODO
36
+ }
37
+
38
+ initShaderBuffers() {
39
+ // TODO
40
+ }
41
+
42
+ destroy() {
43
+ // TODO
44
+ }
45
+
46
+ }
@@ -0,0 +1,61 @@
1
+ /**
2
+ * @author Andras Csizmadia <andras@vpmedia.hu>
3
+ * @author Richard Davey <rich@photonstorm.com>
4
+ * @author Mat Groves http://matgroves.com/ @Doormat23
5
+ * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
6
+ */
7
+ import { SCALE_LINEAR } from '../../core/const';
8
+
9
+ export default class {
10
+
11
+ constructor(gl, width, height, scaleMode) {
12
+ this.gl = gl;
13
+ this.frameBuffer = gl.createFramebuffer();
14
+ this.texture = gl.createTexture();
15
+ scaleMode = scaleMode || window.PhaserRegistry.TEXTURE_SCALE_MODE;
16
+ gl.bindTexture(gl.TEXTURE_2D, this.texture);
17
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, scaleMode === SCALE_LINEAR ? gl.LINEAR : gl.NEAREST);
18
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, scaleMode === SCALE_LINEAR ? gl.LINEAR : gl.NEAREST);
19
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
20
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
21
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer);
22
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this.frameBuffer);
23
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this.texture, 0);
24
+ // required for masking a mask??
25
+ this.renderBuffer = gl.createRenderbuffer();
26
+ gl.bindRenderbuffer(gl.RENDERBUFFER, this.renderBuffer);
27
+ gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, this.renderBuffer);
28
+ this.resize(width, height);
29
+ }
30
+
31
+ clear() {
32
+ const gl = this.gl;
33
+ gl.clearColor(0, 0, 0, 0);
34
+ gl.clear(gl.COLOR_BUFFER_BIT);
35
+ }
36
+
37
+ resize(width, height) {
38
+ if (this.width === width && this.height === height) {
39
+ return;
40
+ }
41
+ this.width = width;
42
+ this.height = height;
43
+ const gl = this.gl;
44
+ gl.bindTexture(gl.TEXTURE_2D, this.texture);
45
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
46
+ // update the stencil buffer width and height
47
+ gl.bindRenderbuffer(gl.RENDERBUFFER, this.renderBuffer);
48
+ gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_STENCIL, width, height);
49
+ }
50
+
51
+ destroy() {
52
+ const gl = this.gl;
53
+ gl.deleteFramebuffer(this.frameBuffer);
54
+ gl.deleteTexture(this.texture);
55
+ this.frameBuffer = null;
56
+ this.texture = null;
57
+ this.renderBuffer = null;
58
+ this.gl = null;
59
+ }
60
+
61
+ }