@vpmedia/phaser 1.112.0 → 1.114.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.
Files changed (296) hide show
  1. package/dist/index.js +1261 -1314
  2. package/dist/index.js.map +1 -1
  3. package/dist/phaser/core/animation.d.ts +14 -10
  4. package/dist/phaser/core/animation.d.ts.map +1 -1
  5. package/dist/phaser/core/animation_manager.d.ts +10 -8
  6. package/dist/phaser/core/animation_manager.d.ts.map +1 -1
  7. package/dist/phaser/core/animation_parser.d.ts +5 -4
  8. package/dist/phaser/core/animation_parser.d.ts.map +1 -1
  9. package/dist/phaser/core/array_set.d.ts.map +1 -1
  10. package/dist/phaser/core/cache.d.ts +4 -3
  11. package/dist/phaser/core/cache.d.ts.map +1 -1
  12. package/dist/phaser/core/const.d.ts.map +1 -1
  13. package/dist/phaser/core/device.d.ts.map +1 -1
  14. package/dist/phaser/core/device_util.d.ts.map +1 -1
  15. package/dist/phaser/core/dom.d.ts +3 -2
  16. package/dist/phaser/core/dom.d.ts.map +1 -1
  17. package/dist/phaser/core/event_manager.d.ts.map +1 -1
  18. package/dist/phaser/core/factory.d.ts +1 -1
  19. package/dist/phaser/core/factory.d.ts.map +1 -1
  20. package/dist/phaser/core/frame.d.ts.map +1 -1
  21. package/dist/phaser/core/frame_data.d.ts.map +1 -1
  22. package/dist/phaser/core/game.d.ts.map +1 -1
  23. package/dist/phaser/core/input.d.ts +8 -6
  24. package/dist/phaser/core/input.d.ts.map +1 -1
  25. package/dist/phaser/core/input_handler.d.ts +40 -30
  26. package/dist/phaser/core/input_handler.d.ts.map +1 -1
  27. package/dist/phaser/core/input_mouse.d.ts +3 -2
  28. package/dist/phaser/core/input_mouse.d.ts.map +1 -1
  29. package/dist/phaser/core/input_mspointer.d.ts +3 -2
  30. package/dist/phaser/core/input_mspointer.d.ts.map +1 -1
  31. package/dist/phaser/core/input_pointer.d.ts +6 -4
  32. package/dist/phaser/core/input_pointer.d.ts.map +1 -1
  33. package/dist/phaser/core/input_touch.d.ts +3 -2
  34. package/dist/phaser/core/input_touch.d.ts.map +1 -1
  35. package/dist/phaser/core/loader.d.ts +4 -3
  36. package/dist/phaser/core/loader.d.ts.map +1 -1
  37. package/dist/phaser/core/loader_parser.d.ts +9 -8
  38. package/dist/phaser/core/loader_parser.d.ts.map +1 -1
  39. package/dist/phaser/core/raf.d.ts +3 -2
  40. package/dist/phaser/core/raf.d.ts.map +1 -1
  41. package/dist/phaser/core/registry.d.ts +7 -0
  42. package/dist/phaser/core/registry.d.ts.map +1 -0
  43. package/dist/phaser/core/scale_manager.d.ts +1 -1
  44. package/dist/phaser/core/scale_manager.d.ts.map +1 -1
  45. package/dist/phaser/core/scene.d.ts +0 -1
  46. package/dist/phaser/core/scene.d.ts.map +1 -1
  47. package/dist/phaser/core/scene_manager.d.ts +1 -1
  48. package/dist/phaser/core/scene_manager.d.ts.map +1 -1
  49. package/dist/phaser/core/signal.d.ts +0 -1
  50. package/dist/phaser/core/signal.d.ts.map +1 -1
  51. package/dist/phaser/core/signal_binding.d.ts +4 -3
  52. package/dist/phaser/core/signal_binding.d.ts.map +1 -1
  53. package/dist/phaser/core/sound.d.ts +6 -4
  54. package/dist/phaser/core/sound.d.ts.map +1 -1
  55. package/dist/phaser/core/sound_manager.d.ts +3 -2
  56. package/dist/phaser/core/sound_manager.d.ts.map +1 -1
  57. package/dist/phaser/core/sound_sprite.d.ts +5 -4
  58. package/dist/phaser/core/sound_sprite.d.ts.map +1 -1
  59. package/dist/phaser/core/stage.d.ts +3 -2
  60. package/dist/phaser/core/stage.d.ts.map +1 -1
  61. package/dist/phaser/core/time.d.ts +1 -1
  62. package/dist/phaser/core/time.d.ts.map +1 -1
  63. package/dist/phaser/core/timer.d.ts +1 -1
  64. package/dist/phaser/core/timer.d.ts.map +1 -1
  65. package/dist/phaser/core/timer_event.d.ts.map +1 -1
  66. package/dist/phaser/core/tween.d.ts +10 -7
  67. package/dist/phaser/core/tween.d.ts.map +1 -1
  68. package/dist/phaser/core/tween_data.d.ts +3 -2
  69. package/dist/phaser/core/tween_data.d.ts.map +1 -1
  70. package/dist/phaser/core/tween_easing.d.ts.map +1 -1
  71. package/dist/phaser/core/tween_manager.d.ts +3 -2
  72. package/dist/phaser/core/tween_manager.d.ts.map +1 -1
  73. package/dist/phaser/core/world.d.ts +3 -2
  74. package/dist/phaser/core/world.d.ts.map +1 -1
  75. package/dist/phaser/display/bitmap_text.d.ts +3 -2
  76. package/dist/phaser/display/bitmap_text.d.ts.map +1 -1
  77. package/dist/phaser/display/button.d.ts +3 -2
  78. package/dist/phaser/display/button.d.ts.map +1 -1
  79. package/dist/phaser/display/canvas/buffer.d.ts.map +1 -1
  80. package/dist/phaser/display/canvas/graphics.d.ts +7 -6
  81. package/dist/phaser/display/canvas/graphics.d.ts.map +1 -1
  82. package/dist/phaser/display/canvas/pool.d.ts +2 -2
  83. package/dist/phaser/display/canvas/pool.d.ts.map +1 -1
  84. package/dist/phaser/display/canvas/renderer.d.ts +10 -8
  85. package/dist/phaser/display/canvas/renderer.d.ts.map +1 -1
  86. package/dist/phaser/display/canvas/tinter.d.ts +3 -2
  87. package/dist/phaser/display/canvas/tinter.d.ts.map +1 -1
  88. package/dist/phaser/display/canvas/util.d.ts +2 -2
  89. package/dist/phaser/display/canvas/util.d.ts.map +1 -1
  90. package/dist/phaser/display/display_object.d.ts +14 -12
  91. package/dist/phaser/display/display_object.d.ts.map +1 -1
  92. package/dist/phaser/display/graphics.d.ts +8 -5
  93. package/dist/phaser/display/graphics.d.ts.map +1 -1
  94. package/dist/phaser/display/graphics_data.d.ts.map +1 -1
  95. package/dist/phaser/display/graphics_data_util.d.ts.map +1 -1
  96. package/dist/phaser/display/group.d.ts +4 -3
  97. package/dist/phaser/display/group.d.ts.map +1 -1
  98. package/dist/phaser/display/image.d.ts +13 -10
  99. package/dist/phaser/display/image.d.ts.map +1 -1
  100. package/dist/phaser/display/sprite_batch.d.ts +3 -2
  101. package/dist/phaser/display/sprite_batch.d.ts.map +1 -1
  102. package/dist/phaser/display/sprite_util.d.ts +18 -15
  103. package/dist/phaser/display/sprite_util.d.ts.map +1 -1
  104. package/dist/phaser/display/text.d.ts +12 -10
  105. package/dist/phaser/display/text.d.ts.map +1 -1
  106. package/dist/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  107. package/dist/phaser/display/webgl/base_texture.d.ts.map +1 -1
  108. package/dist/phaser/display/webgl/blend_manager.d.ts +0 -1
  109. package/dist/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  110. package/dist/phaser/display/webgl/earcut.d.ts +1 -1
  111. package/dist/phaser/display/webgl/earcut.d.ts.map +1 -1
  112. package/dist/phaser/display/webgl/earcut_node.d.ts.map +1 -1
  113. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts +4 -3
  114. package/dist/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  115. package/dist/phaser/display/webgl/filter_manager.d.ts +2 -1
  116. package/dist/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  117. package/dist/phaser/display/webgl/filter_texture.d.ts +2 -1
  118. package/dist/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  119. package/dist/phaser/display/webgl/graphics.d.ts +7 -6
  120. package/dist/phaser/display/webgl/graphics.d.ts.map +1 -1
  121. package/dist/phaser/display/webgl/graphics_data.d.ts +2 -1
  122. package/dist/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  123. package/dist/phaser/display/webgl/render_texture.d.ts +4 -2
  124. package/dist/phaser/display/webgl/render_texture.d.ts.map +1 -1
  125. package/dist/phaser/display/webgl/renderer.d.ts +16 -11
  126. package/dist/phaser/display/webgl/renderer.d.ts.map +1 -1
  127. package/dist/phaser/display/webgl/shader/complex.d.ts +16 -6
  128. package/dist/phaser/display/webgl/shader/complex.d.ts.map +1 -1
  129. package/dist/phaser/display/webgl/shader/fast.d.ts +19 -7
  130. package/dist/phaser/display/webgl/shader/fast.d.ts.map +1 -1
  131. package/dist/phaser/display/webgl/shader/normal.d.ts +33 -12
  132. package/dist/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  133. package/dist/phaser/display/webgl/shader/primitive.d.ts +15 -6
  134. package/dist/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
  135. package/dist/phaser/display/webgl/shader/strip.d.ts +15 -6
  136. package/dist/phaser/display/webgl/shader/strip.d.ts.map +1 -1
  137. package/dist/phaser/display/webgl/shader_manager.d.ts +16 -11
  138. package/dist/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  139. package/dist/phaser/display/webgl/sprite_batch.d.ts +29 -20
  140. package/dist/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  141. package/dist/phaser/display/webgl/stencil_manager.d.ts +12 -10
  142. package/dist/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  143. package/dist/phaser/display/webgl/texture.d.ts +3 -2
  144. package/dist/phaser/display/webgl/texture.d.ts.map +1 -1
  145. package/dist/phaser/display/webgl/texture_util.d.ts.map +1 -1
  146. package/dist/phaser/display/webgl/util.d.ts.map +1 -1
  147. package/dist/phaser/geom/circle.d.ts +4 -1
  148. package/dist/phaser/geom/circle.d.ts.map +1 -1
  149. package/dist/phaser/geom/ellipse.d.ts.map +1 -1
  150. package/dist/phaser/geom/line.d.ts +1 -1
  151. package/dist/phaser/geom/line.d.ts.map +1 -1
  152. package/dist/phaser/geom/matrix.d.ts.map +1 -1
  153. package/dist/phaser/geom/point.d.ts.map +1 -1
  154. package/dist/phaser/geom/polygon.d.ts.map +1 -1
  155. package/dist/phaser/geom/rectangle.d.ts.map +1 -1
  156. package/dist/phaser/geom/rounded_rectangle.d.ts.map +1 -1
  157. package/dist/phaser/geom/util/circle.d.ts.map +1 -1
  158. package/dist/phaser/geom/util/ellipse.d.ts +3 -2
  159. package/dist/phaser/geom/util/ellipse.d.ts.map +1 -1
  160. package/dist/phaser/geom/util/line.d.ts.map +1 -1
  161. package/dist/phaser/geom/util/matrix.d.ts +2 -2
  162. package/dist/phaser/geom/util/matrix.d.ts.map +1 -1
  163. package/dist/phaser/geom/util/point.d.ts.map +1 -1
  164. package/dist/phaser/geom/util/rectangle.d.ts +1 -1
  165. package/dist/phaser/geom/util/rectangle.d.ts.map +1 -1
  166. package/dist/phaser/util/math.d.ts.map +1 -1
  167. package/package.json +5 -5
  168. package/src/phaser/core/animation.ts +64 -60
  169. package/src/phaser/core/animation_manager.ts +50 -53
  170. package/src/phaser/core/animation_parser.ts +9 -9
  171. package/src/phaser/core/array_set.ts +16 -17
  172. package/src/phaser/core/cache.ts +92 -93
  173. package/src/phaser/core/const.ts +1 -1
  174. package/src/phaser/core/device.ts +24 -29
  175. package/src/phaser/core/device_util.ts +22 -26
  176. package/src/phaser/core/dom.ts +54 -65
  177. package/src/phaser/core/event_manager.ts +64 -94
  178. package/src/phaser/core/factory.ts +14 -14
  179. package/src/phaser/core/frame.ts +28 -28
  180. package/src/phaser/core/frame_data.test.ts +100 -0
  181. package/src/phaser/core/frame_data.ts +24 -24
  182. package/src/phaser/core/frame_util.ts +2 -2
  183. package/src/phaser/core/game.ts +47 -48
  184. package/src/phaser/core/input.ts +104 -110
  185. package/src/phaser/core/input_handler.test.ts +113 -0
  186. package/src/phaser/core/input_handler.ts +199 -218
  187. package/src/phaser/core/input_mouse.ts +71 -54
  188. package/src/phaser/core/input_mspointer.ts +52 -39
  189. package/src/phaser/core/input_pointer.ts +81 -80
  190. package/src/phaser/core/input_touch.ts +49 -36
  191. package/src/phaser/core/loader.ts +173 -152
  192. package/src/phaser/core/loader_parser.ts +39 -57
  193. package/src/phaser/core/raf.ts +8 -7
  194. package/src/phaser/core/registry.test.ts +31 -0
  195. package/src/phaser/core/registry.ts +9 -0
  196. package/src/phaser/core/scale_manager.ts +156 -152
  197. package/src/phaser/core/scene.ts +9 -13
  198. package/src/phaser/core/scene_manager.ts +47 -47
  199. package/src/phaser/core/signal.test.ts +4 -4
  200. package/src/phaser/core/signal.ts +41 -52
  201. package/src/phaser/core/signal_binding.ts +26 -25
  202. package/src/phaser/core/signal_dispatch.test.ts +180 -0
  203. package/src/phaser/core/sound.ts +75 -83
  204. package/src/phaser/core/sound_manager.ts +52 -51
  205. package/src/phaser/core/sound_sprite.ts +17 -16
  206. package/src/phaser/core/stage.ts +25 -24
  207. package/src/phaser/core/time.ts +52 -52
  208. package/src/phaser/core/timer.test.ts +187 -0
  209. package/src/phaser/core/timer.ts +82 -69
  210. package/src/phaser/core/timer_event.ts +10 -10
  211. package/src/phaser/core/tween.ts +90 -93
  212. package/src/phaser/core/tween_data.ts +45 -51
  213. package/src/phaser/core/tween_easing.test.ts +106 -0
  214. package/src/phaser/core/tween_easing.ts +151 -123
  215. package/src/phaser/core/tween_manager.ts +19 -18
  216. package/src/phaser/core/world.ts +4 -3
  217. package/src/phaser/display/bitmap_text.ts +56 -64
  218. package/src/phaser/display/button.ts +33 -32
  219. package/src/phaser/display/canvas/buffer.ts +8 -8
  220. package/src/phaser/display/canvas/graphics.ts +36 -37
  221. package/src/phaser/display/canvas/masker.ts +2 -2
  222. package/src/phaser/display/canvas/pool.test.ts +106 -0
  223. package/src/phaser/display/canvas/pool.ts +25 -27
  224. package/src/phaser/display/canvas/renderer.ts +32 -31
  225. package/src/phaser/display/canvas/tinter.ts +25 -25
  226. package/src/phaser/display/canvas/util.ts +7 -10
  227. package/src/phaser/display/display_object.ts +114 -118
  228. package/src/phaser/display/graphics.ts +121 -119
  229. package/src/phaser/display/graphics_data.ts +12 -12
  230. package/src/phaser/display/graphics_data_util.ts +2 -3
  231. package/src/phaser/display/group.ts +50 -57
  232. package/src/phaser/display/image.ts +55 -52
  233. package/src/phaser/display/sprite_batch.ts +3 -2
  234. package/src/phaser/display/sprite_util.ts +48 -54
  235. package/src/phaser/display/text.test.ts +110 -0
  236. package/src/phaser/display/text.ts +199 -204
  237. package/src/phaser/display/webgl/abstract_filter.ts +9 -9
  238. package/src/phaser/display/webgl/base_texture.ts +21 -24
  239. package/src/phaser/display/webgl/blend_manager.ts +6 -10
  240. package/src/phaser/display/webgl/earcut.ts +73 -37
  241. package/src/phaser/display/webgl/earcut_node.ts +10 -10
  242. package/src/phaser/display/webgl/fast_sprite_batch.ts +34 -34
  243. package/src/phaser/display/webgl/filter_manager.ts +13 -12
  244. package/src/phaser/display/webgl/filter_texture.ts +14 -13
  245. package/src/phaser/display/webgl/graphics.ts +51 -57
  246. package/src/phaser/display/webgl/graphics_data.ts +15 -14
  247. package/src/phaser/display/webgl/mask_manager.ts +2 -2
  248. package/src/phaser/display/webgl/render_texture.ts +26 -25
  249. package/src/phaser/display/webgl/renderer.ts +57 -62
  250. package/src/phaser/display/webgl/shader/complex.ts +28 -12
  251. package/src/phaser/display/webgl/shader/fast.ts +30 -12
  252. package/src/phaser/display/webgl/shader/normal.ts +70 -57
  253. package/src/phaser/display/webgl/shader/primitive.ts +26 -11
  254. package/src/phaser/display/webgl/shader/shader.test.ts +148 -0
  255. package/src/phaser/display/webgl/shader/strip.ts +27 -12
  256. package/src/phaser/display/webgl/shader_manager.test.ts +124 -0
  257. package/src/phaser/display/webgl/shader_manager.ts +26 -34
  258. package/src/phaser/display/webgl/sprite_batch.ts +67 -61
  259. package/src/phaser/display/webgl/stencil_manager.ts +23 -34
  260. package/src/phaser/display/webgl/texture.ts +43 -50
  261. package/src/phaser/display/webgl/texture_util.ts +2 -3
  262. package/src/phaser/display/webgl/util.ts +26 -25
  263. package/src/phaser/geom/circle.test.ts +2 -3
  264. package/src/phaser/geom/circle.ts +36 -36
  265. package/src/phaser/geom/ellipse.test.ts +73 -71
  266. package/src/phaser/geom/ellipse.ts +14 -14
  267. package/src/phaser/geom/line.test.ts +5 -5
  268. package/src/phaser/geom/line.ts +35 -35
  269. package/src/phaser/geom/matrix.test.ts +1 -1
  270. package/src/phaser/geom/matrix.ts +27 -27
  271. package/src/phaser/geom/point.test.ts +1 -2
  272. package/src/phaser/geom/point.ts +35 -35
  273. package/src/phaser/geom/polygon.test.ts +82 -0
  274. package/src/phaser/geom/polygon.ts +16 -16
  275. package/src/phaser/geom/rectangle.test.ts +14 -14
  276. package/src/phaser/geom/rectangle.ts +83 -75
  277. package/src/phaser/geom/rounded_rectangle.test.ts +1 -7
  278. package/src/phaser/geom/rounded_rectangle.ts +9 -9
  279. package/src/phaser/geom/util/circle.test.ts +25 -23
  280. package/src/phaser/geom/util/circle.ts +9 -18
  281. package/src/phaser/geom/util/ellipse.test.ts +7 -5
  282. package/src/phaser/geom/util/ellipse.ts +3 -2
  283. package/src/phaser/geom/util/line.test.ts +10 -8
  284. package/src/phaser/geom/util/line.ts +6 -16
  285. package/src/phaser/geom/util/matrix.test.ts +20 -18
  286. package/src/phaser/geom/util/matrix.ts +8 -15
  287. package/src/phaser/geom/util/point.test.ts +8 -6
  288. package/src/phaser/geom/util/point.ts +24 -28
  289. package/src/phaser/geom/util/polygon.test.ts +12 -10
  290. package/src/phaser/geom/util/polygon.ts +2 -2
  291. package/src/phaser/geom/util/rectangle.test.ts +10 -8
  292. package/src/phaser/geom/util/rectangle.ts +18 -37
  293. package/src/phaser/geom/util/rounded_rectangle.test.ts +11 -9
  294. package/src/phaser/geom/util/rounded_rectangle.ts +1 -1
  295. package/src/phaser/util/math.test.ts +11 -11
  296. package/src/phaser/util/math.ts +29 -46
@@ -1,11 +1,12 @@
1
1
  import { SCALE_LINEAR } from '../../core/const.js';
2
2
 
3
3
  export class FilterTexture {
4
- [key: string]: any;
5
- gl!: any;
6
- frameBuffer!: any;
7
- texture!: any;
8
- renderBuffer!: any;
4
+ public width!: number;
5
+ public height!: number;
6
+ public gl!: any;
7
+ public frameBuffer!: any;
8
+ public texture!: any;
9
+ public renderBuffer!: any;
9
10
  /**
10
11
  * Creates a new FilterTexture instance.
11
12
  * @param {WebGLRenderingContext} gl - The WebGL rendering context.
@@ -13,11 +14,11 @@ export class FilterTexture {
13
14
  * @param {number} height - The height of the filter texture.
14
15
  * @param {number} scaleMode - The scale mode to use.
15
16
  */
16
- constructor(gl: WebGLRenderingContext, width: number, height: number, scaleMode: number) {
17
+ public constructor(gl: WebGLRenderingContext, width: number, height: number, scaleMode: number) {
17
18
  this.gl = gl;
18
19
  this.frameBuffer = gl.createFramebuffer();
19
20
  this.texture = gl.createTexture();
20
- scaleMode = scaleMode || window.PhaserRegistry.TEXTURE_SCALE_MODE;
21
+ scaleMode = scaleMode || globalThis.PhaserRegistry.TEXTURE_SCALE_MODE;
21
22
  gl.bindTexture(gl.TEXTURE_2D, this.texture);
22
23
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, scaleMode === SCALE_LINEAR ? gl.LINEAR : gl.NEAREST);
23
24
  gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, scaleMode === SCALE_LINEAR ? gl.LINEAR : gl.NEAREST);
@@ -36,8 +37,8 @@ export class FilterTexture {
36
37
  /**
37
38
  * Destroys this filter texture and cleans up resources.
38
39
  */
39
- clear() {
40
- const gl = this.gl;
40
+ public clear() {
41
+ const { gl } = this;
41
42
  gl.clearColor(0, 0, 0, 0);
42
43
  gl.clear(gl.COLOR_BUFFER_BIT);
43
44
  }
@@ -47,13 +48,13 @@ export class FilterTexture {
47
48
  * @param {number} width - The new width of the filter texture.
48
49
  * @param {number} height - The new height of the filter texture.
49
50
  */
50
- resize(width: number, height: number) {
51
+ public resize(width: number, height: number) {
51
52
  if (this.width === width && this.height === height) {
52
53
  return;
53
54
  }
54
55
  this.width = width;
55
56
  this.height = height;
56
- const gl = this.gl;
57
+ const { gl } = this;
57
58
  gl.bindTexture(gl.TEXTURE_2D, this.texture);
58
59
  gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
59
60
  // update the stencil buffer width and height
@@ -64,8 +65,8 @@ export class FilterTexture {
64
65
  /**
65
66
  * Updates the resolution of this filter texture.
66
67
  */
67
- destroy() {
68
- const gl = this.gl;
68
+ public destroy() {
69
+ const { gl } = this;
69
70
  gl.deleteFramebuffer(this.frameBuffer);
70
71
  gl.deleteTexture(this.texture);
71
72
  this.frameBuffer = null;
@@ -4,16 +4,15 @@ import { hex2rgb } from '../../util/math.js';
4
4
  import { triangulate } from './earcut.js';
5
5
  import { GraphicsData } from './graphics_data.js';
6
6
  import type { IdentifiedWebGLRenderingContext } from './util.js';
7
+ import type { Graphics } from '../graphics.js';
7
8
 
8
9
  /**
9
10
  * Updates the graphics data for WebGL rendering.
10
11
  * @returns {number} The number of vertices in the graphics data.
11
12
  */
12
13
  export const getStencilBufferLimit = () => {
13
- if (!window.PhaserRegistry.stencilBufferLimit) {
14
- window.PhaserRegistry.stencilBufferLimit = 6;
15
- }
16
- return window.PhaserRegistry.stencilBufferLimit;
14
+ globalThis.PhaserRegistry.stencilBufferLimit ??= 6;
15
+ return globalThis.PhaserRegistry.stencilBufferLimit;
17
16
  };
18
17
 
19
18
  /**
@@ -21,10 +20,8 @@ export const getStencilBufferLimit = () => {
21
20
  * @returns {object[]} The graphics data array.
22
21
  */
23
22
  export const getGraphicsDataPool = () => {
24
- if (!window.PhaserRegistry.graphicsDataPool) {
25
- window.PhaserRegistry.graphicsDataPool = [];
26
- }
27
- return window.PhaserRegistry.graphicsDataPool;
23
+ globalThis.PhaserRegistry.graphicsDataPool ??= [];
24
+ return globalThis.PhaserRegistry.graphicsDataPool;
28
25
  };
29
26
 
30
27
  /**
@@ -35,14 +32,14 @@ export const getGraphicsDataPool = () => {
35
32
  */
36
33
  export const switchMode = (webGL: any, type: number) => {
37
34
  let webGLData;
38
- if (!webGL.data.length) {
39
- webGLData = getGraphicsDataPool().pop() || new GraphicsData(webGL.gl);
35
+ if (webGL.data.length === 0) {
36
+ webGLData = getGraphicsDataPool().pop() ?? new GraphicsData(webGL.gl);
40
37
  webGLData.mode = type;
41
38
  webGL.data.push(webGLData);
42
39
  } else {
43
- webGLData = webGL.data[webGL.data.length - 1];
40
+ webGLData = webGL.data.at(-1);
44
41
  if (webGLData.mode !== type || type === 1) {
45
- webGLData = getGraphicsDataPool().pop() || new GraphicsData(webGL.gl);
42
+ webGLData = getGraphicsDataPool().pop() ?? new GraphicsData(webGL.gl);
46
43
  webGLData.mode = type;
47
44
  webGL.data.push(webGLData);
48
45
  }
@@ -59,7 +56,7 @@ export const switchMode = (webGL: any, type: number) => {
59
56
  export const buildLine = (graphicsData: any, webGLData: GraphicsData) => {
60
57
  // TODO OPTIMISE!
61
58
  let i = 0;
62
- let points = graphicsData.points;
59
+ let { points } = graphicsData;
63
60
  if (points.length === 0) {
64
61
  return;
65
62
  }
@@ -71,21 +68,21 @@ export const buildLine = (graphicsData: any, webGLData: GraphicsData) => {
71
68
  }
72
69
  // get first and last point.. figure out the middle!
73
70
  const firstPoint = new Point(points[0], points[1]);
74
- let lastPoint = new Point(points[points.length - 2], points[points.length - 1]);
71
+ let lastPoint = new Point(points.at(-2), points.at(-1));
75
72
  // if the first point is the last point - gonna have issues :)
76
73
  if (firstPoint.x === lastPoint.x && firstPoint.y === lastPoint.y) {
77
74
  // need to clone as we are going to slightly modify the shape..
78
- points = points.slice();
75
+ points = [...points];
79
76
  points.pop();
80
77
  points.pop();
81
- lastPoint = new Point(points[points.length - 2], points[points.length - 1]);
78
+ lastPoint = new Point(points.at(-2), points.at(-1));
82
79
  const midPointX = lastPoint.x + (firstPoint.x - lastPoint.x) * 0.5;
83
80
  const midPointY = lastPoint.y + (firstPoint.y - lastPoint.y) * 0.5;
84
81
  points.unshift(midPointX, midPointY);
85
82
  points.push(midPointX, midPointY);
86
83
  }
87
84
  const verts = webGLData.points;
88
- const indices = webGLData.indices;
85
+ const { indices } = webGLData;
89
86
  const length = points.length / 2;
90
87
  let indexCount = points.length;
91
88
  let indexStart = verts.length / 6;
@@ -226,10 +223,10 @@ export const buildRectangle = (graphicsData: any, webGLData: GraphicsData) => {
226
223
  // need to convert points to a nice regular data
227
224
  //
228
225
  const rectData = graphicsData.shape;
229
- const x = rectData.x;
230
- const y = rectData.y;
231
- const width = rectData.width;
232
- const height = rectData.height;
226
+ const { x } = rectData;
227
+ const { y } = rectData;
228
+ const { width } = rectData;
229
+ const { height } = rectData;
233
230
 
234
231
  if (graphicsData.fill) {
235
232
  const color = hex2rgb(graphicsData.fillColor);
@@ -238,7 +235,7 @@ export const buildRectangle = (graphicsData: any, webGLData: GraphicsData) => {
238
235
  const g = color[1] * alpha;
239
236
  const b = color[2] * alpha;
240
237
  const verts = webGLData.points;
241
- const indices = webGLData.indices;
238
+ const { indices } = webGLData;
242
239
  const vertPos = verts.length / 6;
243
240
  // start
244
241
  verts.push(x, y);
@@ -313,11 +310,11 @@ export const quadraticBezierCurve = (
313
310
  */
314
311
  export const buildRoundedRectangle = (graphicsData: any, webGLData: GraphicsData) => {
315
312
  const rrectData = graphicsData.shape;
316
- const x = rrectData.x;
317
- const y = rrectData.y;
318
- const width = rrectData.width;
319
- const height = rrectData.height;
320
- const radius = rrectData.radius;
313
+ const { x } = rrectData;
314
+ const { y } = rrectData;
315
+ const { width } = rrectData;
316
+ const { height } = rrectData;
317
+ const { radius } = rrectData;
321
318
  let recPoints = [];
322
319
  recPoints.push(x, y + radius);
323
320
  recPoints = recPoints.concat(quadraticBezierCurve(x, y + height - radius, x, y + height, x + radius, y + height));
@@ -333,15 +330,15 @@ export const buildRoundedRectangle = (graphicsData: any, webGLData: GraphicsData
333
330
  const g = color[1] * alpha;
334
331
  const b = color[2] * alpha;
335
332
  const verts = webGLData.points;
336
- const indices = webGLData.indices;
333
+ const { indices } = webGLData;
337
334
  const vecPos = verts.length / 6;
338
335
  const triangles = triangulate(recPoints, null, 2);
339
336
  for (let i = 0; i < triangles.length; i += 3) {
340
- indices.push(triangles[i] + vecPos);
341
- indices.push(triangles[i] + vecPos);
342
- indices.push(triangles[i + 1] + vecPos);
343
- indices.push(triangles[i + 2] + vecPos);
344
- indices.push(triangles[i + 2] + vecPos);
337
+ indices.push(triangles[i]! + vecPos);
338
+ indices.push(triangles[i]! + vecPos);
339
+ indices.push(triangles[i + 1]! + vecPos);
340
+ indices.push(triangles[i + 2]! + vecPos);
341
+ indices.push(triangles[i + 2]! + vecPos);
345
342
  }
346
343
  for (let i = 0; i < recPoints.length; i += 2) {
347
344
  // TODO verify
@@ -364,8 +361,8 @@ export const buildRoundedRectangle = (graphicsData: any, webGLData: GraphicsData
364
361
  export const buildCircle = (graphicsData: any, webGLData: GraphicsData) => {
365
362
  // need to convert points to a nice regular data
366
363
  const circleData = graphicsData.shape;
367
- const x = circleData.x;
368
- const y = circleData.y;
364
+ const { x } = circleData;
365
+ const { y } = circleData;
369
366
  let width;
370
367
  let height;
371
368
  // TODO - bit hacky??
@@ -385,7 +382,7 @@ export const buildCircle = (graphicsData: any, webGLData: GraphicsData) => {
385
382
  const g = color[1] * alpha;
386
383
  const b = color[2] * alpha;
387
384
  const verts = webGLData.points;
388
- const indices = webGLData.indices;
385
+ const { indices } = webGLData;
389
386
  let vecPos = verts.length / 6;
390
387
  indices.push(vecPos);
391
388
  for (let i = 0; i < totalSegs + 1; i += 1) {
@@ -414,12 +411,12 @@ export const buildCircle = (graphicsData: any, webGLData: GraphicsData) => {
414
411
  */
415
412
  export const buildComplexPoly = (graphicsData: any, webGLData: GraphicsData) => {
416
413
  // TODO - no need to copy this as it gets turned into a Float32Array anyways..
417
- const points = graphicsData.points.slice();
414
+ const points = [...graphicsData.points];
418
415
  if (points.length < 6) {
419
416
  return;
420
417
  }
421
418
  // get first and last point.. figure out the middle!
422
- const indices = webGLData.indices;
419
+ const { indices } = webGLData;
423
420
  webGLData.points = points;
424
421
  webGLData.alpha = graphicsData.fillAlpha;
425
422
  webGLData.color = hex2rgb(graphicsData.fillColor);
@@ -458,13 +455,13 @@ export const buildComplexPoly = (graphicsData: any, webGLData: GraphicsData) =>
458
455
  * @returns {boolean} TBD.
459
456
  */
460
457
  export const buildPoly = (graphicsData: any, webGLData: GraphicsData) => {
461
- const points = graphicsData.points;
458
+ const { points } = graphicsData;
462
459
  if (points.length < 6) {
463
460
  return false;
464
461
  }
465
462
  // get first and last point.. figure out the middle!
466
463
  const verts = webGLData.points;
467
- const indices = webGLData.indices;
464
+ const { indices } = webGLData;
468
465
  const length = points.length / 2;
469
466
  // sort color
470
467
  const color = hex2rgb(graphicsData.fillColor);
@@ -478,11 +475,11 @@ export const buildPoly = (graphicsData: any, webGLData: GraphicsData) => {
478
475
  }
479
476
  const vertPos = verts.length / 6;
480
477
  for (let i = 0; i < triangles.length; i += 3) {
481
- indices.push(triangles[i] + vertPos);
482
- indices.push(triangles[i] + vertPos);
483
- indices.push(triangles[i + 1] + vertPos);
484
- indices.push(triangles[i + 2] + vertPos);
485
- indices.push(triangles[i + 2] + vertPos);
478
+ indices.push(triangles[i]! + vertPos);
479
+ indices.push(triangles[i]! + vertPos);
480
+ indices.push(triangles[i + 1]! + vertPos);
481
+ indices.push(triangles[i + 2]! + vertPos);
482
+ indices.push(triangles[i + 2]! + vertPos);
486
483
  }
487
484
  for (let i = 0; i < length; i += 1) {
488
485
  verts.push(points[i * 2], points[i * 2 + 1], r, g, b, alpha);
@@ -492,10 +489,10 @@ export const buildPoly = (graphicsData: any, webGLData: GraphicsData) => {
492
489
 
493
490
  /**
494
491
  * TBD.
495
- * @param {import('../graphics.js').Graphics} graphics - The graphics object to update.
492
+ * @param {Graphics} graphics - The graphics object to update.
496
493
  * @param {WebGLRenderingContext & { id: number }} gl - The WebGL rendering context.
497
494
  */
498
- export const updateGraphics = (graphics: import('../graphics.js').Graphics, gl: IdentifiedWebGLRenderingContext) => {
495
+ export const updateGraphics = (graphics: Graphics, gl: IdentifiedWebGLRenderingContext) => {
499
496
  const stencilBufferLimit = getStencilBufferLimit();
500
497
  // get the contexts graphics object
501
498
  let webGL = graphics._webGL[gl.id];
@@ -528,13 +525,10 @@ export const updateGraphics = (graphics: import('../graphics.js').Graphics, gl:
528
525
  const data = graphics.graphicsData[i];
529
526
  if (data.type === GEOM_POLYGON) {
530
527
  // need to add the points the the graphics object..
531
- data.points = data.shape.points.slice();
528
+ data.points = [...data.shape.points];
532
529
  if (data.shape.closed) {
533
530
  // close the poly if the value is true!
534
- if (
535
- data.points[0] !== data.points[data.points.length - 2] ||
536
- data.points[1] !== data.points[data.points.length - 1]
537
- ) {
531
+ if (data.points[0] !== data.points.at(-2) || data.points[1] !== data.points.at(-1)) {
538
532
  data.points.push(data.points[0], data.points[1]);
539
533
  }
540
534
  }
@@ -581,13 +575,13 @@ export const updateGraphics = (graphics: import('../graphics.js').Graphics, gl:
581
575
 
582
576
  /**
583
577
  * Updates the graphics data for WebGL rendering.
584
- * @param {import('../graphics.js').Graphics} graphics - The graphics object to update.
578
+ * @param {Graphics} graphics - The graphics object to update.
585
579
  * @param {object} renderSession - The rendering session.
586
580
  */
587
- export const renderGraphics = (graphics: import('../graphics.js').Graphics, renderSession: any) => {
588
- const gl = renderSession.gl;
589
- const projection = renderSession.projection;
590
- const offset = renderSession.offset;
581
+ export const renderGraphics = (graphics: Graphics, renderSession: any) => {
582
+ const { gl } = renderSession;
583
+ const { projection } = renderSession;
584
+ const { offset } = renderSession;
591
585
  let shader = renderSession.shaderManager.primitiveShader;
592
586
  let webGLData;
593
587
  if (graphics.dirty) {
@@ -1,19 +1,20 @@
1
1
  export class GraphicsData {
2
- [key: string]: any;
3
- gl!: any;
4
- color!: any;
5
- points!: any;
6
- indices!: any;
7
- buffer!: any;
8
- indexBuffer!: any;
9
- mode!: any;
10
- alpha!: any;
11
- dirty!: any;
2
+ public glPoints!: Float32Array | null;
3
+ public glIndicies!: Uint16Array | null;
4
+ public gl!: any;
5
+ public color!: any;
6
+ public points!: any;
7
+ public indices!: any;
8
+ public buffer!: any;
9
+ public indexBuffer!: any;
10
+ public mode!: any;
11
+ public alpha!: any;
12
+ public dirty!: any;
12
13
  /**
13
14
  * Creates a new GraphicsData instance.
14
15
  * @param {WebGLRenderingContext} gl - The WebGL rendering context.
15
16
  */
16
- constructor(gl: WebGLRenderingContext) {
17
+ public constructor(gl: WebGLRenderingContext) {
17
18
  this.gl = gl;
18
19
  // TODO does this need to be split before uploading??
19
20
  this.color = [0, 0, 0]; // color split!
@@ -29,7 +30,7 @@ export class GraphicsData {
29
30
  /**
30
31
  * Destroys this graphics data and cleans up resources.
31
32
  */
32
- reset() {
33
+ public reset() {
33
34
  this.points = [];
34
35
  this.indices = [];
35
36
  this.glPoints = null;
@@ -39,8 +40,8 @@ export class GraphicsData {
39
40
  /**
40
41
  * Updates the graphics data for WebGL rendering.
41
42
  */
42
- upload() {
43
- const gl = this.gl;
43
+ public upload() {
44
+ const { gl } = this;
44
45
  // this.lastIndex = graphics.graphicsData.length;
45
46
  this.glPoints = new Float32Array(this.points);
46
47
  gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
@@ -6,7 +6,7 @@ import { updateGraphics } from './graphics.js';
6
6
  * @param {object} renderSession - The rendering session.
7
7
  */
8
8
  export const pushMask = (maskData: any, renderSession: any) => {
9
- const gl = renderSession.gl;
9
+ const { gl } = renderSession;
10
10
  if (maskData.dirty) {
11
11
  updateGraphics(maskData, gl);
12
12
  }
@@ -26,7 +26,7 @@ export const pushMask = (maskData: any, renderSession: any) => {
26
26
  * @param {object} renderSession - The rendering session.
27
27
  */
28
28
  export const popMask = (maskData: any, renderSession: any) => {
29
- const gl = renderSession.gl;
29
+ const { gl } = renderSession;
30
30
  if (
31
31
  maskData._webGL[gl.id] === undefined ||
32
32
  maskData._webGL[gl.id].data === undefined ||
@@ -5,43 +5,45 @@ import { CanvasBuffer } from '../canvas/buffer.js';
5
5
  import { BaseTexture } from './base_texture.js';
6
6
  import { FilterTexture } from './filter_texture.js';
7
7
  import { Texture } from './texture.js';
8
+ import type { WebGLRenderer } from './renderer.js';
9
+ import type { CanvasRenderer } from '../canvas/renderer.js';
8
10
 
9
11
  export class RenderTexture extends Texture {
10
12
  [key: string]: any;
11
- declare width: any;
12
- declare height: any;
13
- resolution!: any;
14
- declare frame: any;
15
- declare crop: any;
16
- renderer!: any;
17
- textureBuffer!: any;
18
- render!: any;
19
- projection!: any;
20
- declare valid: any;
13
+ declare public width: any;
14
+ declare public height: any;
15
+ public resolution!: any;
16
+ declare public frame: any;
17
+ declare public crop: any;
18
+ public renderer!: any;
19
+ public textureBuffer!: any;
20
+ public render!: any;
21
+ public projection!: any;
22
+ declare public valid: any;
21
23
  /**
22
24
  * Creates a new RenderTexture instance.
23
25
  * @param {number} width - The width of the render texture.
24
26
  * @param {number} height - The height of the render texture.
25
- * @param {import('./renderer.js').WebGLRenderer|import('../canvas/renderer.js').CanvasRenderer} renderer - The renderer to use.
27
+ * @param {WebGLRenderer|CanvasRenderer} renderer - The renderer to use.
26
28
  * @param {number} scaleMode - The scale mode to use.
27
29
  * @param {number} resolution - The resolution to use.
28
30
  */
29
- constructor(
31
+ public constructor(
30
32
  width: number,
31
33
  height: number,
32
- renderer: import('./renderer.js').WebGLRenderer | import('../canvas/renderer.js').CanvasRenderer,
34
+ renderer: WebGLRenderer | CanvasRenderer,
33
35
  scaleMode: number,
34
- resolution: number = 1
36
+ resolution = 1
35
37
  ) {
36
38
  const w = width || 100;
37
39
  const h = height || 100;
38
40
  const res = resolution || 1;
39
- const baseTexture = new BaseTexture(null, scaleMode || window.PhaserRegistry.TEXTURE_SCALE_MODE);
41
+ const baseTexture = new BaseTexture(null, scaleMode || globalThis.PhaserRegistry.TEXTURE_SCALE_MODE);
40
42
  baseTexture.width = width * res;
41
43
  baseTexture.height = height * res;
42
44
  baseTexture._glTextures = [];
43
45
  baseTexture.resolution = res;
44
- baseTexture.scaleMode = scaleMode || window.PhaserRegistry.TEXTURE_SCALE_MODE;
46
+ baseTexture.scaleMode = scaleMode || globalThis.PhaserRegistry.TEXTURE_SCALE_MODE;
45
47
  baseTexture.hasLoaded = true;
46
48
  super(baseTexture, new Rectangle(0, 0, w * res, h * res));
47
49
  this.width = w;
@@ -51,8 +53,7 @@ export class RenderTexture extends Texture {
51
53
  this.crop = new Rectangle(0, 0, this.width * this.resolution, this.height * this.resolution);
52
54
  this.renderer = renderer;
53
55
  if (this.renderer.type === RENDER_WEBGL) {
54
- // @ts-ignore
55
- const gl = this.renderer.gl;
56
+ const { gl } = this.renderer;
56
57
  this.baseTexture._dirty[gl.id] = false;
57
58
  this.textureBuffer = new FilterTexture(gl, this.width, this.height, this.baseTexture.scaleMode);
58
59
  this.baseTexture._glTextures[gl.id] = this.textureBuffer.texture;
@@ -70,28 +71,28 @@ export class RenderTexture extends Texture {
70
71
  /**
71
72
  * Destroys this render texture and cleans up resources.
72
73
  */
73
- resize() {
74
+ public resize() {
74
75
  // TODO
75
76
  }
76
77
 
77
78
  /**
78
79
  * Updates the size of this render texture.
79
80
  */
80
- clear() {
81
+ public clear() {
81
82
  // TODO
82
83
  }
83
84
 
84
85
  /**
85
86
  * Updates the resolution of this render texture.
86
87
  */
87
- renderWebGL() {
88
+ public renderWebGL() {
88
89
  // TODO
89
90
  }
90
91
 
91
92
  /**
92
93
  * Updates the scale mode of this render texture.
93
94
  */
94
- renderCanvas() {
95
+ public renderCanvas() {
95
96
  // TODO
96
97
  }
97
98
 
@@ -99,7 +100,7 @@ export class RenderTexture extends Texture {
99
100
  * Gets the HTML image element for this render texture.
100
101
  * @returns {HTMLImageElement} The HTML image element.
101
102
  */
102
- getImage() {
103
+ public getImage() {
103
104
  const image = new Image();
104
105
  image.src = this.getBase64();
105
106
  return image;
@@ -109,7 +110,7 @@ export class RenderTexture extends Texture {
109
110
  * Gets the base64 string representation of this render texture.
110
111
  * @returns {string} The base64 string representation.
111
112
  */
112
- getBase64() {
113
+ public getBase64() {
113
114
  return this.getCanvas()?.toDataURL() ?? '';
114
115
  }
115
116
 
@@ -117,7 +118,7 @@ export class RenderTexture extends Texture {
117
118
  * Gets the canvas element for this render texture.
118
119
  * @returns {HTMLCanvasElement} The canvas element.
119
120
  */
120
- getCanvas(): HTMLCanvasElement | null {
121
+ public getCanvas(): HTMLCanvasElement | null {
121
122
  // TODO
122
123
  return null;
123
124
  }