@vpmedia/phaser 1.15.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/README.md +3 -3
  2. package/package.json +6 -5
  3. package/src/index.js +15 -18
  4. package/src/phaser/core/animation.js +114 -6
  5. package/src/phaser/core/animation_manager.js +102 -10
  6. package/src/phaser/core/animation_parser.js +6 -19
  7. package/src/phaser/core/array_set.js +59 -5
  8. package/src/phaser/core/cache.js +307 -6
  9. package/src/phaser/core/const.js +107 -4
  10. package/src/phaser/core/device.js +3 -6
  11. package/src/phaser/core/device_util.js +3 -16
  12. package/src/phaser/core/dom.js +127 -29
  13. package/src/phaser/core/event_manager.js +128 -6
  14. package/src/phaser/core/factory.js +69 -34
  15. package/src/phaser/core/frame.js +43 -6
  16. package/src/phaser/core/frame_data.js +55 -5
  17. package/src/phaser/core/frame_util.js +7 -12
  18. package/src/phaser/core/game.js +35 -7
  19. package/src/phaser/core/input.js +133 -17
  20. package/src/phaser/core/input_handler.js +243 -43
  21. package/src/phaser/core/input_mouse.js +70 -5
  22. package/src/phaser/core/input_mspointer.js +40 -9
  23. package/src/phaser/core/input_pointer.js +88 -17
  24. package/src/phaser/core/input_touch.js +42 -5
  25. package/src/phaser/core/loader.js +303 -101
  26. package/src/phaser/core/loader_parser.js +2 -10
  27. package/src/phaser/core/raf.js +16 -5
  28. package/src/phaser/core/scale_manager.js +204 -39
  29. package/src/phaser/core/scene.js +24 -5
  30. package/src/phaser/core/scene_manager.js +81 -11
  31. package/src/phaser/core/signal.js +88 -11
  32. package/src/phaser/core/signal_binding.js +35 -15
  33. package/src/phaser/core/sound.js +99 -10
  34. package/src/phaser/core/sound_manager.js +89 -13
  35. package/src/phaser/core/sound_sprite.js +20 -5
  36. package/src/phaser/core/stage.js +43 -7
  37. package/src/phaser/core/time.js +67 -5
  38. package/src/phaser/core/timer.js +107 -30
  39. package/src/phaser/core/timer_event.js +11 -6
  40. package/src/phaser/core/tween.js +124 -30
  41. package/src/phaser/core/tween_data.js +42 -18
  42. package/src/phaser/core/tween_easing.js +1 -8
  43. package/src/phaser/core/tween_manager.js +47 -5
  44. package/src/phaser/core/world.js +9 -6
  45. package/src/phaser/display/bitmap_text.js +91 -10
  46. package/src/phaser/display/button.js +63 -12
  47. package/src/phaser/display/canvas/buffer.js +16 -6
  48. package/src/phaser/display/canvas/graphics.js +1 -13
  49. package/src/phaser/display/canvas/masker.js +0 -6
  50. package/src/phaser/display/canvas/pool.js +0 -7
  51. package/src/phaser/display/canvas/renderer.js +28 -8
  52. package/src/phaser/display/canvas/tinter.js +4 -43
  53. package/src/phaser/display/canvas/util.js +0 -6
  54. package/src/phaser/display/display_object.js +192 -20
  55. package/src/phaser/display/graphics.js +161 -26
  56. package/src/phaser/display/graphics_data.js +14 -6
  57. package/src/phaser/display/graphics_data_util.js +2 -8
  58. package/src/phaser/display/group.js +82 -9
  59. package/src/phaser/display/image.js +87 -9
  60. package/src/phaser/display/sprite_batch.js +3 -8
  61. package/src/phaser/display/sprite_util.js +3 -23
  62. package/src/phaser/display/text.js +331 -31
  63. package/src/phaser/display/webgl/abstract_filter.js +8 -7
  64. package/src/phaser/display/webgl/base_texture.js +20 -12
  65. package/src/phaser/display/webgl/blend_manager.js +14 -7
  66. package/src/phaser/display/webgl/earcut.js +4 -23
  67. package/src/phaser/display/webgl/earcut_node.js +6 -7
  68. package/src/phaser/display/webgl/fast_sprite_batch.js +34 -11
  69. package/src/phaser/display/webgl/filter_manager.js +25 -7
  70. package/src/phaser/display/webgl/filter_texture.js +21 -22
  71. package/src/phaser/display/webgl/graphics.js +5 -28
  72. package/src/phaser/display/webgl/graphics_data.js +10 -7
  73. package/src/phaser/display/webgl/mask_manager.js +0 -6
  74. package/src/phaser/display/webgl/render_texture.js +33 -21
  75. package/src/phaser/display/webgl/renderer.js +38 -11
  76. package/src/phaser/display/webgl/shader/complex.js +10 -6
  77. package/src/phaser/display/webgl/shader/fast.js +10 -6
  78. package/src/phaser/display/webgl/shader/normal.js +23 -32
  79. package/src/phaser/display/webgl/shader/primitive.js +10 -6
  80. package/src/phaser/display/webgl/shader/strip.js +10 -6
  81. package/src/phaser/display/webgl/shader_manager.js +18 -6
  82. package/src/phaser/display/webgl/sprite_batch.js +41 -8
  83. package/src/phaser/display/webgl/stencil_manager.js +28 -6
  84. package/src/phaser/display/webgl/texture.js +28 -15
  85. package/src/phaser/display/webgl/texture_util.js +0 -6
  86. package/src/phaser/display/webgl/util.js +0 -7
  87. package/src/phaser/geom/circle.js +123 -18
  88. package/src/phaser/geom/ellipse.js +39 -18
  89. package/src/phaser/geom/line.js +148 -16
  90. package/src/phaser/geom/matrix.js +73 -6
  91. package/src/phaser/geom/point.js +152 -6
  92. package/src/phaser/geom/polygon.js +42 -14
  93. package/src/phaser/geom/rectangle.js +233 -6
  94. package/src/phaser/geom/rounded_rectangle.js +10 -6
  95. package/src/phaser/geom/util/circle.js +3 -9
  96. package/src/phaser/geom/util/ellipse.js +0 -7
  97. package/src/phaser/geom/util/line.js +5 -14
  98. package/src/phaser/geom/util/matrix.js +1 -7
  99. package/src/phaser/geom/util/point.js +0 -6
  100. package/src/phaser/geom/util/polygon.js +1 -7
  101. package/src/phaser/geom/util/rectangle.js +1 -7
  102. package/src/phaser/geom/util/rounded_rectangle.js +1 -7
  103. package/src/phaser/util/math.js +3 -21
  104. package/types/index.d.ts +2 -1
  105. package/types/index.d.ts.map +1 -1
  106. package/types/phaser/core/animation.d.ts +126 -13
  107. package/types/phaser/core/animation.d.ts.map +1 -1
  108. package/types/phaser/core/animation_manager.d.ts +121 -19
  109. package/types/phaser/core/animation_manager.d.ts.map +1 -1
  110. package/types/phaser/core/animation_parser.d.ts +6 -5
  111. package/types/phaser/core/animation_parser.d.ts.map +1 -1
  112. package/types/phaser/core/array_set.d.ts +67 -13
  113. package/types/phaser/core/array_set.d.ts.map +1 -1
  114. package/types/phaser/core/cache.d.ts +365 -69
  115. package/types/phaser/core/cache.d.ts.map +1 -1
  116. package/types/phaser/core/const.d.ts +143 -40
  117. package/types/phaser/core/const.d.ts.map +1 -1
  118. package/types/phaser/core/device.d.ts +0 -5
  119. package/types/phaser/core/device.d.ts.map +1 -1
  120. package/types/phaser/core/device_util.d.ts +1 -1
  121. package/types/phaser/core/device_util.d.ts.map +1 -1
  122. package/types/phaser/core/dom.d.ts +119 -0
  123. package/types/phaser/core/dom.d.ts.map +1 -1
  124. package/types/phaser/core/event_manager.d.ts +127 -0
  125. package/types/phaser/core/event_manager.d.ts.map +1 -1
  126. package/types/phaser/core/factory.d.ts +75 -8
  127. package/types/phaser/core/factory.d.ts.map +1 -1
  128. package/types/phaser/core/frame.d.ts +64 -21
  129. package/types/phaser/core/frame.d.ts.map +1 -1
  130. package/types/phaser/core/frame_data.d.ts +61 -9
  131. package/types/phaser/core/frame_data.d.ts.map +1 -1
  132. package/types/phaser/core/frame_util.d.ts +10 -8
  133. package/types/phaser/core/frame_util.d.ts.map +1 -1
  134. package/types/phaser/core/game.d.ts +40 -6
  135. package/types/phaser/core/game.d.ts.map +1 -1
  136. package/types/phaser/core/input.d.ts +143 -15
  137. package/types/phaser/core/input.d.ts.map +1 -1
  138. package/types/phaser/core/input_handler.d.ts +258 -25
  139. package/types/phaser/core/input_handler.d.ts.map +1 -1
  140. package/types/phaser/core/input_mouse.d.ts +62 -14
  141. package/types/phaser/core/input_mouse.d.ts.map +1 -1
  142. package/types/phaser/core/input_mspointer.d.ts +51 -17
  143. package/types/phaser/core/input_mspointer.d.ts.map +1 -1
  144. package/types/phaser/core/input_pointer.d.ts +99 -14
  145. package/types/phaser/core/input_pointer.d.ts.map +1 -1
  146. package/types/phaser/core/input_touch.d.ts +53 -16
  147. package/types/phaser/core/input_touch.d.ts.map +1 -1
  148. package/types/phaser/core/loader.d.ts +299 -28
  149. package/types/phaser/core/loader.d.ts.map +1 -1
  150. package/types/phaser/core/loader_parser.d.ts.map +1 -1
  151. package/types/phaser/core/raf.d.ts +19 -9
  152. package/types/phaser/core/raf.d.ts.map +1 -1
  153. package/types/phaser/core/scale_manager.d.ts +208 -13
  154. package/types/phaser/core/scale_manager.d.ts.map +1 -1
  155. package/types/phaser/core/scene.d.ts +21 -5
  156. package/types/phaser/core/scene.d.ts.map +1 -1
  157. package/types/phaser/core/scene_manager.d.ts +90 -10
  158. package/types/phaser/core/scene_manager.d.ts.map +1 -1
  159. package/types/phaser/core/signal.d.ts +93 -9
  160. package/types/phaser/core/signal.d.ts.map +1 -1
  161. package/types/phaser/core/signal_binding.d.ts +34 -5
  162. package/types/phaser/core/signal_binding.d.ts.map +1 -1
  163. package/types/phaser/core/sound.d.ts +111 -14
  164. package/types/phaser/core/sound.d.ts.map +1 -1
  165. package/types/phaser/core/sound_manager.d.ts +97 -11
  166. package/types/phaser/core/sound_manager.d.ts.map +1 -1
  167. package/types/phaser/core/sound_sprite.d.ts +22 -8
  168. package/types/phaser/core/sound_sprite.d.ts.map +1 -1
  169. package/types/phaser/core/stage.d.ts +32 -3
  170. package/types/phaser/core/stage.d.ts.map +1 -1
  171. package/types/phaser/core/time.d.ts +73 -6
  172. package/types/phaser/core/time.d.ts.map +1 -1
  173. package/types/phaser/core/timer.d.ts +108 -7
  174. package/types/phaser/core/timer.d.ts.map +1 -1
  175. package/types/phaser/core/timer_event.d.ts +13 -7
  176. package/types/phaser/core/timer_event.d.ts.map +1 -1
  177. package/types/phaser/core/tween.d.ts +124 -4
  178. package/types/phaser/core/tween.d.ts.map +1 -1
  179. package/types/phaser/core/tween_data.d.ts +41 -2
  180. package/types/phaser/core/tween_data.d.ts.map +1 -1
  181. package/types/phaser/core/tween_easing.d.ts +0 -5
  182. package/types/phaser/core/tween_easing.d.ts.map +1 -1
  183. package/types/phaser/core/tween_manager.d.ts +49 -2
  184. package/types/phaser/core/tween_manager.d.ts.map +1 -1
  185. package/types/phaser/core/world.d.ts +9 -1
  186. package/types/phaser/core/world.d.ts.map +1 -1
  187. package/types/phaser/display/bitmap_text.d.ts +84 -7
  188. package/types/phaser/display/bitmap_text.d.ts.map +1 -1
  189. package/types/phaser/display/button.d.ts +65 -8
  190. package/types/phaser/display/button.d.ts.map +1 -1
  191. package/types/phaser/display/canvas/buffer.d.ts +20 -4
  192. package/types/phaser/display/canvas/buffer.d.ts.map +1 -1
  193. package/types/phaser/display/canvas/graphics.d.ts.map +1 -1
  194. package/types/phaser/display/canvas/masker.d.ts.map +1 -1
  195. package/types/phaser/display/canvas/pool.d.ts +0 -6
  196. package/types/phaser/display/canvas/pool.d.ts.map +1 -1
  197. package/types/phaser/display/canvas/renderer.d.ts +29 -2
  198. package/types/phaser/display/canvas/renderer.d.ts.map +1 -1
  199. package/types/phaser/display/canvas/tinter.d.ts.map +1 -1
  200. package/types/phaser/display/canvas/util.d.ts.map +1 -1
  201. package/types/phaser/display/display_object.d.ts +195 -8
  202. package/types/phaser/display/display_object.d.ts.map +1 -1
  203. package/types/phaser/display/graphics.d.ts +132 -6
  204. package/types/phaser/display/graphics.d.ts.map +1 -1
  205. package/types/phaser/display/graphics_data.d.ts +15 -1
  206. package/types/phaser/display/graphics_data.d.ts.map +1 -1
  207. package/types/phaser/display/graphics_data_util.d.ts +3 -2
  208. package/types/phaser/display/graphics_data_util.d.ts.map +1 -1
  209. package/types/phaser/display/group.d.ts +80 -10
  210. package/types/phaser/display/group.d.ts.map +1 -1
  211. package/types/phaser/display/image.d.ts +72 -6
  212. package/types/phaser/display/image.d.ts.map +1 -1
  213. package/types/phaser/display/sprite_batch.d.ts +4 -3
  214. package/types/phaser/display/sprite_batch.d.ts.map +1 -1
  215. package/types/phaser/display/sprite_util.d.ts.map +1 -1
  216. package/types/phaser/display/text.d.ts +366 -46
  217. package/types/phaser/display/text.d.ts.map +1 -1
  218. package/types/phaser/display/webgl/abstract_filter.d.ts +8 -6
  219. package/types/phaser/display/webgl/abstract_filter.d.ts.map +1 -1
  220. package/types/phaser/display/webgl/base_texture.d.ts +20 -1
  221. package/types/phaser/display/webgl/base_texture.d.ts.map +1 -1
  222. package/types/phaser/display/webgl/blend_manager.d.ts +11 -6
  223. package/types/phaser/display/webgl/blend_manager.d.ts.map +1 -1
  224. package/types/phaser/display/webgl/earcut.d.ts.map +1 -1
  225. package/types/phaser/display/webgl/earcut_node.d.ts +9 -9
  226. package/types/phaser/display/webgl/earcut_node.d.ts.map +1 -1
  227. package/types/phaser/display/webgl/fast_sprite_batch.d.ts +33 -6
  228. package/types/phaser/display/webgl/fast_sprite_batch.d.ts.map +1 -1
  229. package/types/phaser/display/webgl/filter_manager.d.ts +22 -6
  230. package/types/phaser/display/webgl/filter_manager.d.ts.map +1 -1
  231. package/types/phaser/display/webgl/filter_texture.d.ts +21 -3
  232. package/types/phaser/display/webgl/filter_texture.d.ts.map +1 -1
  233. package/types/phaser/display/webgl/graphics.d.ts.map +1 -1
  234. package/types/phaser/display/webgl/graphics_data.d.ts +10 -6
  235. package/types/phaser/display/webgl/graphics_data.d.ts.map +1 -1
  236. package/types/phaser/display/webgl/mask_manager.d.ts.map +1 -1
  237. package/types/phaser/display/webgl/render_texture.d.ts +30 -3
  238. package/types/phaser/display/webgl/render_texture.d.ts.map +1 -1
  239. package/types/phaser/display/webgl/renderer.d.ts +41 -4
  240. package/types/phaser/display/webgl/renderer.d.ts.map +1 -1
  241. package/types/phaser/display/webgl/shader/complex.d.ts +10 -0
  242. package/types/phaser/display/webgl/shader/complex.d.ts.map +1 -1
  243. package/types/phaser/display/webgl/shader/fast.d.ts +10 -0
  244. package/types/phaser/display/webgl/shader/fast.d.ts.map +1 -1
  245. package/types/phaser/display/webgl/shader/normal.d.ts +20 -0
  246. package/types/phaser/display/webgl/shader/normal.d.ts.map +1 -1
  247. package/types/phaser/display/webgl/shader/primitive.d.ts +10 -0
  248. package/types/phaser/display/webgl/shader/primitive.d.ts.map +1 -1
  249. package/types/phaser/display/webgl/shader/strip.d.ts +10 -0
  250. package/types/phaser/display/webgl/shader/strip.d.ts.map +1 -1
  251. package/types/phaser/display/webgl/shader_manager.d.ts +15 -0
  252. package/types/phaser/display/webgl/shader_manager.d.ts.map +1 -1
  253. package/types/phaser/display/webgl/sprite_batch.d.ts +37 -0
  254. package/types/phaser/display/webgl/sprite_batch.d.ts.map +1 -1
  255. package/types/phaser/display/webgl/stencil_manager.d.ts +25 -0
  256. package/types/phaser/display/webgl/stencil_manager.d.ts.map +1 -1
  257. package/types/phaser/display/webgl/texture.d.ts +21 -0
  258. package/types/phaser/display/webgl/texture.d.ts.map +1 -1
  259. package/types/phaser/display/webgl/texture_util.d.ts.map +1 -1
  260. package/types/phaser/display/webgl/util.d.ts +0 -6
  261. package/types/phaser/display/webgl/util.d.ts.map +1 -1
  262. package/types/phaser/geom/circle.d.ts +131 -9
  263. package/types/phaser/geom/circle.d.ts.map +1 -1
  264. package/types/phaser/geom/ellipse.d.ts +43 -5
  265. package/types/phaser/geom/ellipse.d.ts.map +1 -1
  266. package/types/phaser/geom/line.d.ts +159 -13
  267. package/types/phaser/geom/line.d.ts.map +1 -1
  268. package/types/phaser/geom/matrix.d.ts +85 -11
  269. package/types/phaser/geom/matrix.d.ts.map +1 -1
  270. package/types/phaser/geom/point.d.ts +170 -18
  271. package/types/phaser/geom/point.d.ts.map +1 -1
  272. package/types/phaser/geom/polygon.d.ts +45 -5
  273. package/types/phaser/geom/polygon.d.ts.map +1 -1
  274. package/types/phaser/geom/rectangle.d.ts +253 -20
  275. package/types/phaser/geom/rectangle.d.ts.map +1 -1
  276. package/types/phaser/geom/rounded_rectangle.d.ts +11 -1
  277. package/types/phaser/geom/rounded_rectangle.d.ts.map +1 -1
  278. package/types/phaser/geom/util/circle.d.ts +3 -3
  279. package/types/phaser/geom/util/circle.d.ts.map +1 -1
  280. package/types/phaser/geom/util/ellipse.d.ts +0 -6
  281. package/types/phaser/geom/util/ellipse.d.ts.map +1 -1
  282. package/types/phaser/geom/util/line.d.ts +5 -5
  283. package/types/phaser/geom/util/line.d.ts.map +1 -1
  284. package/types/phaser/geom/util/matrix.d.ts.map +1 -1
  285. package/types/phaser/geom/util/point.d.ts.map +1 -1
  286. package/types/phaser/geom/util/polygon.d.ts.map +1 -1
  287. package/types/phaser/geom/util/rectangle.d.ts.map +1 -1
  288. package/types/phaser/geom/util/rounded_rectangle.d.ts.map +1 -1
  289. package/types/phaser/util/math.d.ts +0 -5
  290. package/types/phaser/util/math.d.ts.map +1 -1
@@ -1,11 +1,11 @@
1
- /**
2
- * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
3
- * @author Andras Csizmadia <andras@vpmedia.hu>
4
- * @author Richard Davey <rich@photonstorm.com>
5
- */
1
+ import { Game } from './game';
6
2
  import { Timer } from './timer';
7
3
 
8
4
  export class Time {
5
+ /**
6
+ * TBD.
7
+ * @param {Game} game - TBD.
8
+ */
9
9
  constructor(game) {
10
10
  this.game = game;
11
11
  this.time = 0;
@@ -36,6 +36,9 @@ export class Time {
36
36
  this._timers = [];
37
37
  }
38
38
 
39
+ /**
40
+ * TBD.
41
+ */
39
42
  boot() {
40
43
  this._started = Date.now();
41
44
  this.time = Date.now();
@@ -43,17 +46,30 @@ export class Time {
43
46
  this.timeExpected = this.time;
44
47
  }
45
48
 
49
+ /**
50
+ * TBD.
51
+ * @param {Timer} timer - TBD.
52
+ * @returns {Timer} TBD.
53
+ */
46
54
  add(timer) {
47
55
  this._timers.push(timer);
48
56
  return timer;
49
57
  }
50
58
 
59
+ /**
60
+ * TBD.
61
+ * @param {boolean} autoDestroy - TBD.
62
+ * @returns {Timer} TBD.
63
+ */
51
64
  create(autoDestroy = true) {
52
65
  const timer = new Timer(this.game, autoDestroy);
53
66
  this._timers.push(timer);
54
67
  return timer;
55
68
  }
56
69
 
70
+ /**
71
+ * TBD.
72
+ */
57
73
  removeAll() {
58
74
  for (let i = 0; i < this._timers.length; i += 1) {
59
75
  this._timers[i].destroy();
@@ -62,6 +78,9 @@ export class Time {
62
78
  this.events.removeAll();
63
79
  }
64
80
 
81
+ /**
82
+ * TBD.
83
+ */
65
84
  refresh() {
66
85
  const previousDateNow = this.time;
67
86
  // this.time always holds a Date.now value
@@ -70,6 +89,10 @@ export class Time {
70
89
  this.elapsedMS = this.time - previousDateNow;
71
90
  }
72
91
 
92
+ /**
93
+ * TBD.
94
+ * @param {number} time - TBD.
95
+ */
73
96
  update(time) {
74
97
  const previousDateNow = this.time;
75
98
  // this.time always holds a Date.now value
@@ -96,6 +119,9 @@ export class Time {
96
119
  }
97
120
  }
98
121
 
122
+ /**
123
+ * TBD.
124
+ */
99
125
  updateTimers() {
100
126
  let i = 0;
101
127
  let len = this._timers.length;
@@ -110,6 +136,9 @@ export class Time {
110
136
  }
111
137
  }
112
138
 
139
+ /**
140
+ * TBD.
141
+ */
113
142
  updateAdvancedTiming() {
114
143
  // count the number of time.update calls
115
144
  this._frameCount += 1;
@@ -133,6 +162,9 @@ export class Time {
133
162
  }
134
163
  }
135
164
 
165
+ /**
166
+ * TBD.
167
+ */
136
168
  gamePaused() {
137
169
  this._pauseStarted = Date.now();
138
170
  this.events.pause();
@@ -143,6 +175,9 @@ export class Time {
143
175
  }
144
176
  }
145
177
 
178
+ /**
179
+ * TBD.
180
+ */
146
181
  gameResumed() {
147
182
  this.time = Date.now();
148
183
  this.pauseDuration = this.time - this._pauseStarted;
@@ -154,31 +189,58 @@ export class Time {
154
189
  }
155
190
  }
156
191
 
192
+ /**
193
+ * TBD.
194
+ * @returns {number} TBD.
195
+ */
157
196
  totalElapsedSeconds() {
158
197
  return (this.time - this._started) * 0.001;
159
198
  }
160
199
 
200
+ /**
201
+ * TBD.
202
+ * @param {number} since - TBD.
203
+ * @returns {number} TBD.
204
+ */
161
205
  elapsedSince(since) {
162
206
  return this.time - since;
163
207
  }
164
208
 
209
+ /**
210
+ * TBD.
211
+ * @param {number} since - TBD.
212
+ * @returns {number} TBD.
213
+ */
165
214
  elapsedSecondsSince(since) {
166
215
  return (this.time - since) * 0.001;
167
216
  }
168
217
 
218
+ /**
219
+ * TBD.
220
+ */
169
221
  reset() {
170
222
  this._started = this.time;
171
223
  this.removeAll();
172
224
  }
173
225
 
226
+ /**
227
+ * TBD.
228
+ */
174
229
  destroy() {
175
230
  this.reset();
176
231
  }
177
232
 
233
+ /**
234
+ * TBD.
235
+ * @returns {number} TBD.
236
+ */
178
237
  get desiredFps() {
179
238
  return this._desiredFps;
180
239
  }
181
240
 
241
+ /**
242
+ * TBD.
243
+ */
182
244
  set desiredFps(value) {
183
245
  this._desiredFps = value;
184
246
  this.desiredFpsMult = 1.0 / value;
@@ -1,12 +1,13 @@
1
- /**
2
- * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
3
- * @author Andras Csizmadia <andras@vpmedia.hu>
4
- * @author Richard Davey <rich@photonstorm.com>
5
- */
6
- import { Signal } from './signal';
1
+ import { Game } from './game';
2
+ import { Signal } from './signal';
7
3
  import { TimerEvent } from './timer_event';
8
4
 
9
5
  export class Timer {
6
+ /**
7
+ * TBD.
8
+ * @param {Game} game - TBD.
9
+ * @param {boolean} autoDestroy - TBD.
10
+ */
10
11
  constructor(game, autoDestroy = false) {
11
12
  this.game = game;
12
13
  this.running = false;
@@ -30,6 +31,15 @@ export class Timer {
30
31
  this._newTick = 0;
31
32
  }
32
33
 
34
+ /**
35
+ * TBD.
36
+ * @param delay - TBD.
37
+ * @param loop
38
+ * @param repeatCount
39
+ * @param {Function} callback - TBD.
40
+ * @param callbackContext
41
+ * @param args - TBD.
42
+ */
33
43
  create(delay, loop, repeatCount, callback, callbackContext, args) {
34
44
  const roundedDelay = Math.round(delay);
35
45
  let tick = roundedDelay;
@@ -38,34 +48,51 @@ export class Timer {
38
48
  } else {
39
49
  tick += this._now;
40
50
  }
41
- const event = new TimerEvent(
42
- this,
43
- roundedDelay,
44
- tick,
45
- repeatCount,
46
- loop,
47
- callback,
48
- callbackContext,
49
- args
50
- );
51
+ const event = new TimerEvent(this, roundedDelay, tick, repeatCount, loop, callback, callbackContext, args);
51
52
  this.events.push(event);
52
53
  this.order();
53
54
  this.expired = false;
54
55
  return event;
55
56
  }
56
57
 
58
+ /**
59
+ * TBD.
60
+ * @param delay - TBD.
61
+ * @param {Function} callback - TBD.
62
+ * @param callbackContext
63
+ * @param {...any} args
64
+ */
57
65
  add(delay, callback, callbackContext, ...args) {
58
66
  return this.create(delay, false, 0, callback, callbackContext, args);
59
67
  }
60
68
 
69
+ /**
70
+ * TBD.
71
+ * @param delay - TBD.
72
+ * @param repeatCount
73
+ * @param {Function} callback - TBD.
74
+ * @param callbackContext
75
+ * @param {...any} args
76
+ */
61
77
  repeat(delay, repeatCount, callback, callbackContext, ...args) {
62
78
  return this.create(delay, false, repeatCount, callback, callbackContext, args);
63
79
  }
64
80
 
81
+ /**
82
+ * TBD.
83
+ * @param delay - TBD.
84
+ * @param {Function} callback - TBD.
85
+ * @param callbackContext
86
+ * @param {...any} args
87
+ */
65
88
  loop(delay, callback, callbackContext, ...args) {
66
89
  return this.create(delay, true, 0, callback, callbackContext, args);
67
90
  }
68
91
 
92
+ /**
93
+ * TBD.
94
+ * @param delay - TBD.
95
+ */
69
96
  start(delay) {
70
97
  if (this.running) {
71
98
  return;
@@ -77,6 +104,10 @@ export class Timer {
77
104
  }
78
105
  }
79
106
 
107
+ /**
108
+ * TBD.
109
+ * @param clearEvents
110
+ */
80
111
  stop(clearEvents = true) {
81
112
  this.running = false;
82
113
  if (clearEvents) {
@@ -84,6 +115,10 @@ export class Timer {
84
115
  }
85
116
  }
86
117
 
118
+ /**
119
+ * TBD.
120
+ * @param {Event} event - TBD.
121
+ */
87
122
  remove(event) {
88
123
  for (let i = 0; i < this.events.length; i += 1) {
89
124
  if (this.events[i] === event) {
@@ -94,6 +129,9 @@ export class Timer {
94
129
  return false;
95
130
  }
96
131
 
132
+ /**
133
+ * TBD.
134
+ */
97
135
  order() {
98
136
  if (this.events.length > 0) {
99
137
  // Sort the events so the one with the lowest tick is first
@@ -102,6 +140,11 @@ export class Timer {
102
140
  }
103
141
  }
104
142
 
143
+ /**
144
+ * TBD.
145
+ * @param a - TBD.
146
+ * @param b - TBD.
147
+ */
105
148
  sortHandler(a, b) {
106
149
  if (a.tick < b.tick) {
107
150
  return -1;
@@ -111,6 +154,9 @@ export class Timer {
111
154
  return 0;
112
155
  }
113
156
 
157
+ /**
158
+ * TBD.
159
+ */
114
160
  clearPendingEvents() {
115
161
  this._i = this.events.length;
116
162
  while (this._i) {
@@ -123,6 +169,10 @@ export class Timer {
123
169
  this._i = 0;
124
170
  }
125
171
 
172
+ /**
173
+ * TBD.
174
+ * @param time - TBD.
175
+ */
126
176
  update(time) {
127
177
  if (this.paused) {
128
178
  return true;
@@ -143,31 +193,21 @@ export class Timer {
143
193
  while (this._i < this._len && this.running) {
144
194
  if (this._now >= this.events[this._i].tick && !this.events[this._i].pendingDelete) {
145
195
  // (now + delay) - (time difference from last tick to now)
146
- this._newTick =
147
- this._now + this.events[this._i].delay - (this._now - this.events[this._i].tick);
196
+ this._newTick = this._now + this.events[this._i].delay - (this._now - this.events[this._i].tick);
148
197
  if (this._newTick < 0) {
149
198
  this._newTick = this._now + this.events[this._i].delay;
150
199
  }
151
200
  if (this.events[this._i].loop === true) {
152
201
  this.events[this._i].tick = this._newTick;
153
- this.events[this._i].callback.apply(
154
- this.events[this._i].callbackContext,
155
- this.events[this._i].args
156
- );
202
+ this.events[this._i].callback.apply(this.events[this._i].callbackContext, this.events[this._i].args);
157
203
  } else if (this.events[this._i].repeatCount > 0) {
158
204
  this.events[this._i].repeatCount -= 1;
159
205
  this.events[this._i].tick = this._newTick;
160
- this.events[this._i].callback.apply(
161
- this.events[this._i].callbackContext,
162
- this.events[this._i].args
163
- );
206
+ this.events[this._i].callback.apply(this.events[this._i].callbackContext, this.events[this._i].args);
164
207
  } else {
165
208
  this._marked += 1;
166
209
  this.events[this._i].pendingDelete = true;
167
- this.events[this._i].callback.apply(
168
- this.events[this._i].callbackContext,
169
- this.events[this._i].args
170
- );
210
+ this.events[this._i].callback.apply(this.events[this._i].callbackContext, this.events[this._i].args);
171
211
  }
172
212
  this._i += 1;
173
213
  } else {
@@ -188,6 +228,9 @@ export class Timer {
188
228
  return true;
189
229
  }
190
230
 
231
+ /**
232
+ * TBD.
233
+ */
191
234
  pause() {
192
235
  if (!this.running) {
193
236
  return;
@@ -200,6 +243,9 @@ export class Timer {
200
243
  this.paused = true;
201
244
  }
202
245
 
246
+ /**
247
+ * TBD.
248
+ */
203
249
  _pause() {
204
250
  if (this.paused || !this.running) {
205
251
  return;
@@ -208,6 +254,10 @@ export class Timer {
208
254
  this.paused = true;
209
255
  }
210
256
 
257
+ /**
258
+ * TBD.
259
+ * @param baseTime - TBD.
260
+ */
211
261
  adjustEvents(baseTime) {
212
262
  for (let i = 0; i < this.events.length; i += 1) {
213
263
  if (!this.events[i].pendingDelete) {
@@ -228,6 +278,9 @@ export class Timer {
228
278
  }
229
279
  }
230
280
 
281
+ /**
282
+ * TBD.
283
+ */
231
284
  resume() {
232
285
  if (!this.paused) {
233
286
  return;
@@ -240,6 +293,9 @@ export class Timer {
240
293
  this._codePaused = false;
241
294
  }
242
295
 
296
+ /**
297
+ * TBD.
298
+ */
243
299
  _resume() {
244
300
  if (this._codePaused) {
245
301
  return;
@@ -247,6 +303,9 @@ export class Timer {
247
303
  this.resume();
248
304
  }
249
305
 
306
+ /**
307
+ * TBD.
308
+ */
250
309
  removeAll() {
251
310
  this.onComplete.removeAll();
252
311
  this.events.length = 0;
@@ -254,6 +313,9 @@ export class Timer {
254
313
  this._i = 0;
255
314
  }
256
315
 
316
+ /**
317
+ * TBD.
318
+ */
257
319
  destroy() {
258
320
  this.onComplete.removeAll();
259
321
  this.running = false;
@@ -262,10 +324,16 @@ export class Timer {
262
324
  this._i = 0;
263
325
  }
264
326
 
327
+ /**
328
+ * TBD.
329
+ */
265
330
  get next() {
266
331
  return this.nextTick;
267
332
  }
268
333
 
334
+ /**
335
+ * TBD.
336
+ */
269
337
  get duration() {
270
338
  if (this.running && this.nextTick > this._now) {
271
339
  return this.nextTick - this._now;
@@ -273,10 +341,16 @@ export class Timer {
273
341
  return 0;
274
342
  }
275
343
 
344
+ /**
345
+ * TBD.
346
+ */
276
347
  get length() {
277
348
  return this.events.length;
278
349
  }
279
350
 
351
+ /**
352
+ * TBD.
353
+ */
280
354
  get ms() {
281
355
  if (this.running) {
282
356
  return this._now - this._started - this._pauseTotal;
@@ -284,6 +358,9 @@ export class Timer {
284
358
  return 0;
285
359
  }
286
360
 
361
+ /**
362
+ * TBD.
363
+ */
287
364
  get seconds() {
288
365
  if (this.running) {
289
366
  return this.ms * 0.001;
@@ -1,10 +1,15 @@
1
- /**
2
- * @copyright Copyright (c) 2018-present Richard Davey, Photon Storm Ltd., Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)
3
- * @author Andras Csizmadia <andras@vpmedia.hu>
4
- * @author Richard Davey <rich@photonstorm.com>
5
- */
6
-
7
1
  export class TimerEvent {
2
+ /**
3
+ * TBD.
4
+ * @param timer - TBD.
5
+ * @param delay - TBD.
6
+ * @param tick - TBD.
7
+ * @param repeatCount - TBD.
8
+ * @param loop - TBD.
9
+ * @param {Function} callback - TBD.
10
+ * @param {object} callbackContext - TBD.
11
+ * @param args - TBD.
12
+ */
8
13
  constructor(timer, delay, tick, repeatCount, loop, callback, callbackContext, args) {
9
14
  this.timer = timer;
10
15
  this.delay = delay;