bard-legends-framework 0.11.0 → 0.12.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 (258) hide show
  1. package/dist/actions-performance.test.d.ts +1 -0
  2. package/dist/actions-performance.test.js +83 -0
  3. package/dist/game-entities/controller/controller.d.ts +2 -2
  4. package/dist/game-entities/controller/controller.js +8 -8
  5. package/dist/game-entities/controller/controller.test.js +2 -2
  6. package/dist/game-entities/entity/entity.d.ts +7 -7
  7. package/dist/game-entities/entity/entity.js +18 -12
  8. package/dist/game-entities/entity/entity.test.js +93 -30
  9. package/dist/game-entities/entity/helpers/entity-store.helper.d.ts +3 -3
  10. package/dist/game-entities/entity/helpers/entity-store.helper.js +12 -12
  11. package/dist/game-entities/entity/helpers/entity-store.helper.test.js +11 -11
  12. package/dist/game-entities/entity/helpers/entity-views.helper.d.ts +6 -6
  13. package/dist/game-entities/entity/helpers/entity-views.helper.js +25 -22
  14. package/dist/game-entities/entity/singleton-entity.test.js +9 -4
  15. package/dist/game-entities/hard-reset.d.ts +5 -0
  16. package/dist/game-entities/hard-reset.js +14 -0
  17. package/dist/game-entities/index.d.ts +1 -1
  18. package/dist/game-entities/index.js +3 -3
  19. package/dist/game-entities/scene/scene.d.ts +13 -13
  20. package/dist/game-entities/scene/scene.js +41 -46
  21. package/dist/game-entities/scene/scene.test.js +95 -37
  22. package/dist/game-entities/service/service.d.ts +1 -4
  23. package/dist/game-entities/service/service.js +12 -13
  24. package/dist/game-entities/service/service.test.js +33 -12
  25. package/dist/game-entities/unit-test.helper.js +1 -1
  26. package/dist/game-entities/update-cycle.d.ts +7 -17
  27. package/dist/game-entities/update-cycle.js +25 -19
  28. package/dist/game-entities/view/view.d.ts +6 -6
  29. package/dist/game-entities/view/view.js +15 -21
  30. package/dist/game-entities/view/view.test.js +40 -9
  31. package/dist/physics/entity-types/immovable-physics-entity.d.ts +1 -1
  32. package/dist/physics/entity-types/immovable-physics-entity.js +4 -4
  33. package/dist/physics/entity-types/movable-entity.d.ts +1 -1
  34. package/dist/physics/entity-types/movable-entity.js +2 -2
  35. package/dist/physics/entity-types/movable-physics-entity.d.ts +8 -8
  36. package/dist/physics/entity-types/movable-physics-entity.js +27 -27
  37. package/dist/physics/entity-types/physics-entity.d.ts +10 -14
  38. package/dist/physics/entity-types/physics-entity.js +27 -26
  39. package/dist/physics/interfaces.d.ts +6 -6
  40. package/dist/physics/interfaces.js +4 -4
  41. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics-internal.controller.d.ts +16 -16
  42. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics-internal.controller.js +22 -22
  43. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.d.ts +19 -19
  44. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.js +30 -30
  45. package/dist/physics/module//342/232/234/357/270/217gateways/dtos/requests.dto.d.ts +3 -3
  46. package/dist/physics/module//342/232/234/357/270/217gateways/physics-internal.gateway.d.ts +10 -10
  47. package/dist/physics/module//342/232/234/357/270/217gateways/physics-internal.gateway.js +16 -16
  48. package/dist/physics/module//342/232/234/357/270/217gateways/physics.gateway.d.ts +10 -10
  49. package/dist/physics/module//342/232/234/357/270/217gateways/physics.gateway.js +18 -18
  50. package/dist/physics/module//360/237/223/220services/collision/collisions.service.d.ts +5 -5
  51. package/dist/physics/module//360/237/223/220services/collision/collisions.service.js +17 -17
  52. package/dist/physics/module//360/237/223/220services/collision/hit-test.service.d.ts +4 -4
  53. package/dist/physics/module//360/237/223/220services/collision/hit-test.service.js +11 -11
  54. package/dist/physics/module//360/237/223/220services/collision/physics-body-group.service.d.ts +2 -2
  55. package/dist/physics/module//360/237/223/220services/collision/physics-body-group.service.js +4 -4
  56. package/dist/physics/module//360/237/223/220services/creation/border.service.d.ts +2 -2
  57. package/dist/physics/module//360/237/223/220services/creation/border.service.js +9 -9
  58. package/dist/physics/module//360/237/223/220services/creation/materials.service.d.ts +7 -7
  59. package/dist/physics/module//360/237/223/220services/creation/materials.service.js +17 -17
  60. package/dist/physics/module//360/237/223/220services/creation/physics-world.service.d.ts +11 -11
  61. package/dist/physics/module//360/237/223/220services/creation/physics-world.service.js +27 -26
  62. package/dist/physics/module//360/237/223/220services/creation/shape-creation.service.d.ts +4 -4
  63. package/dist/physics/module//360/237/223/220services/creation/shape-creation.service.js +13 -13
  64. package/dist/physics/module//360/237/223/220services/impact/eliptic-explosion.service.d.ts +9 -9
  65. package/dist/physics/module//360/237/223/220services/impact/eliptic-explosion.service.js +19 -19
  66. package/dist/physics/module//360/237/223/220services/impact/explosion.service.d.ts +9 -9
  67. package/dist/physics/module//360/237/223/220services/impact/explosion.service.js +20 -20
  68. package/dist/physics/module//360/237/223/220services/impact/ray-cast-hit-converter.d.ts +1 -1
  69. package/dist/physics/module//360/237/223/220services/impact/ray-cast-hit-converter.js +4 -4
  70. package/dist/physics/module//360/237/223/220services/path-finding/availability-grid-cache.service.d.ts +2 -2
  71. package/dist/physics/module//360/237/223/220services/path-finding/availability-grid-cache.service.js +3 -3
  72. package/dist/physics/module//360/237/223/220services/path-finding/availability-grid.service.d.ts +5 -5
  73. package/dist/physics/module//360/237/223/220services/path-finding/availability-grid.service.js +12 -12
  74. package/dist/physics/module//360/237/223/220services/path-finding/path-finder.service.d.ts +4 -4
  75. package/dist/physics/module//360/237/223/220services/path-finding/path-finder.service.js +12 -12
  76. package/dist/physics/module//360/237/223/220services/query/physics-query.service.d.ts +4 -4
  77. package/dist/physics/module//360/237/223/220services/query/physics-query.service.js +4 -4
  78. package/dist/physics/module//360/237/223/220services/ray-casting/ray-casting.service.d.ts +1 -4
  79. package/dist/physics/module//360/237/223/220services/ray-casting/ray-casting.service.js +7 -15
  80. package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.d.ts +9 -9
  81. package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js +43 -42
  82. package/dist/physics/module//360/237/247/212entities/border.entity.d.ts +1 -1
  83. package/dist/physics/module//360/237/247/212entities/border.entity.js +3 -3
  84. package/dist/pixi/components/display-object-array.d.ts +5 -5
  85. package/dist/pixi/components/display-object-array.js +14 -14
  86. package/dist/pixi/components/helpers/smooth-scroller.d.ts +7 -7
  87. package/dist/pixi/components/helpers/smooth-scroller.js +23 -23
  88. package/dist/pixi/components/helpers/smooth-scroller.test.js +14 -14
  89. package/dist/pixi/components/menu/menu-entity.d.ts +14 -0
  90. package/dist/pixi/components/menu/menu-entity.js +48 -0
  91. package/dist/pixi/components/menu/menu.ui.d.ts +23 -0
  92. package/dist/pixi/components/menu/menu.ui.js +97 -0
  93. package/dist/pixi/components/mouse-wheel-listener.ui.d.ts +2 -2
  94. package/dist/pixi/components/mouse-wheel-listener.ui.js +11 -11
  95. package/dist/pixi/components/scroll-area.ui.d.ts +1 -1
  96. package/dist/pixi/components/scroll-area.ui.js +9 -9
  97. package/dist/pixi/components/scroll-mask.ui.d.ts +9 -8
  98. package/dist/pixi/components/scroll-mask.ui.js +25 -24
  99. package/dist/pixi/display-object/container-attributes.d.ts +24 -25
  100. package/dist/pixi/display-object/container-attributes.js +26 -26
  101. package/dist/pixi/display-object/container.d.ts +3 -3
  102. package/dist/pixi/display-object/container.js +2 -2
  103. package/dist/pixi/display-object/filters/base-filters/blur.filter.d.ts +9 -9
  104. package/dist/pixi/display-object/filters/base-filters/blur.filter.js +25 -25
  105. package/dist/pixi/display-object/filters/base-filters/expand-with-color.filter.d.ts +7 -7
  106. package/dist/pixi/display-object/filters/base-filters/expand-with-color.filter.js +17 -17
  107. package/dist/pixi/display-object/filters/composite-filters/glow-filter.d.ts +6 -6
  108. package/dist/pixi/display-object/filters/composite-filters/glow-filter.js +10 -11
  109. package/dist/pixi/display-object/filters/helpers/gaussian-values.helper.d.ts +2 -2
  110. package/dist/pixi/display-object/filters/helpers/gaussian-values.helper.js +5 -5
  111. package/dist/pixi/display-object/filters/templates/checking-neighbors.template.d.ts +5 -5
  112. package/dist/pixi/display-object/filters/templates/checking-neighbors.template.js +8 -8
  113. package/dist/pixi/display-object/filters/templates/plane.template.d.ts +5 -5
  114. package/dist/pixi/display-object/filters/templates/plane.template.js +7 -7
  115. package/dist/pixi/display-object/filters.d.ts +7 -7
  116. package/dist/pixi/display-object/filters.js +34 -34
  117. package/dist/pixi/display-object/index.d.ts +1 -1
  118. package/dist/pixi/display-object/objects/graphics/graphics.d.ts +9 -9
  119. package/dist/pixi/display-object/objects/graphics/graphics.js +25 -25
  120. package/dist/pixi/display-object/objects/placeholder.d.ts +1 -1
  121. package/dist/pixi/display-object/objects/placeholder.js +7 -7
  122. package/dist/pixi/display-object/objects/sprite/glow-sprite-generator.d.ts +9 -9
  123. package/dist/pixi/display-object/objects/sprite/glow-sprite-generator.js +26 -25
  124. package/dist/pixi/display-object/objects/sprite/sprite.d.ts +10 -9
  125. package/dist/pixi/display-object/objects/sprite/sprite.js +62 -53
  126. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/pixi-text-style-converter.d.ts +4 -3
  127. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.d.ts +6 -6
  128. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.js +16 -16
  129. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.test.js +28 -28
  130. package/dist/pixi/display-object/objects/text/helpers/process-steps/2-wrapping-text/consistent-space-text-wrapper.d.ts +1 -1
  131. package/dist/pixi/display-object/objects/text/helpers/process-steps/2-wrapping-text/consistent-space-text-wrapper.js +3 -3
  132. package/dist/pixi/display-object/objects/text/helpers/process-steps/2-wrapping-text/rich-text-typewriter.d.ts +17 -17
  133. package/dist/pixi/display-object/objects/text/helpers/process-steps/2-wrapping-text/rich-text-typewriter.js +62 -62
  134. package/dist/pixi/display-object/objects/text/helpers/process-steps/2-wrapping-text/rich-text-typewriter.test.js +2 -2
  135. package/dist/pixi/display-object/objects/text/helpers/process-steps/3-data-out-converter/rich-text-data-out-converter.d.ts +3 -3
  136. package/dist/pixi/display-object/objects/text/helpers/process-steps/3-data-out-converter/rich-text-data-out-converter.js +6 -6
  137. package/dist/pixi/display-object/objects/text/helpers/process-steps/3-data-out-converter/rich-text-data-out-converter.test.js +12 -12
  138. package/dist/pixi/display-object/objects/text/helpers/rich-text-to-plane-text.d.ts +2 -2
  139. package/dist/pixi/display-object/objects/text/helpers/rich-text-to-plane-text.test.js +5 -5
  140. package/dist/pixi/display-object/objects/text/rich-text.d.ts +0 -1
  141. package/dist/pixi/display-object/objects/text/rich-text.js +0 -1
  142. package/dist/pixi/display-object/objects/text/text.d.ts +9 -10
  143. package/dist/pixi/display-object/objects/text/text.js +34 -35
  144. package/dist/pixi/game.d.ts +20 -15
  145. package/dist/pixi/game.js +40 -35
  146. package/dist/pixi/helpers/game-assets.d.ts +5 -5
  147. package/dist/pixi/helpers/game-assets.js +14 -11
  148. package/dist/pixi/helpers/position-conversion.helper.d.ts +4 -4
  149. package/dist/pixi/helpers/position-conversion.helper.js +3 -3
  150. package/dist/pixi/index.d.ts +3 -37
  151. package/dist/pixi/index.js +6 -22
  152. package/dist/pixi/modules/CAMERA/camera.d.ts +5 -4
  153. package/dist/pixi/modules/CAMERA/camera.js +9 -9
  154. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/camera-view.gateway.d.ts +3 -2
  155. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/camera-view.gateway.js +1 -1
  156. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/controllers/camera-view.controller.d.ts +3 -2
  157. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/controllers/camera-view.controller.js +5 -5
  158. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/controllers/camera.controller.d.ts +3 -3
  159. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/controllers/camera.controller.js +7 -7
  160. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/dtos/requests.dto.d.ts +8 -8
  161. package/dist/pixi/modules/CAMERA//342/232/234/357/270/217gateways/dtos/requests.dto.js +8 -8
  162. package/dist/pixi/modules/CAMERA//360/237/223/220services/camera.service.d.ts +2 -2
  163. package/dist/pixi/modules/CAMERA//360/237/223/220services/camera.service.js +12 -12
  164. package/dist/pixi/modules/CAMERA//360/237/247/251views/camera.view.d.ts +17 -16
  165. package/dist/pixi/modules/CAMERA//360/237/247/251views/camera.view.js +49 -48
  166. package/dist/pixi/pixi-definitions.d.ts +38 -0
  167. package/dist/pixi/pixi-definitions.js +37 -0
  168. package/dist/pixi/services/keyboard/keyboard.d.ts +2 -2
  169. package/dist/pixi/services/keyboard/keyboard.js +9 -9
  170. package/dist/pixi/services/mouse/mouse-target-focus.service.d.ts +10 -10
  171. package/dist/pixi/services/mouse/mouse-target-focus.service.js +28 -28
  172. package/dist/pixi/services/mouse/mouse.service.d.ts +1 -1
  173. package/dist/pixi/services/mouse/mouse.service.js +5 -5
  174. package/dist/utilities/animator/animating-content/fade-in-content.test.d.ts +1 -0
  175. package/dist/utilities/animator/animating-content/fade-in-content.test.js +10 -0
  176. package/dist/utilities/animator/animating-content/slide-in-content.test.d.ts +1 -0
  177. package/dist/utilities/animator/animating-content/slide-in-content.test.js +10 -0
  178. package/dist/utilities/animator/animations.d.ts +14 -6
  179. package/dist/utilities/animator/animations.js +15 -11
  180. package/dist/utilities/animator/animator/animator.d.ts +44 -0
  181. package/dist/utilities/animator/animator/animator.js +234 -0
  182. package/dist/utilities/animator/animator/animator.memory-leak.test.d.ts +1 -0
  183. package/dist/utilities/animator/animator/animator.memory-leak.test.js +73 -0
  184. package/dist/utilities/animator/animator/animator.performance.test.d.ts +1 -0
  185. package/dist/utilities/animator/animator/animator.performance.test.js +116 -0
  186. package/dist/utilities/animator/animator/animator.test.d.ts +1 -0
  187. package/dist/utilities/animator/animator/animator.test.js +1046 -0
  188. package/dist/utilities/animator/animator.d.ts +2 -3
  189. package/dist/utilities/animator/animator.js +66 -59
  190. package/dist/utilities/animator/animator.performance.test.d.ts +1 -0
  191. package/dist/utilities/animator/animator.performance.test.js +46 -0
  192. package/dist/utilities/animator/animator.test.js +89 -28
  193. package/dist/utilities/animator/animator2/animator.d.ts +42 -0
  194. package/dist/utilities/animator/animator2/animator.js +222 -0
  195. package/dist/utilities/animator/animator2/animator.memory-leak.test.d.ts +1 -0
  196. package/dist/utilities/animator/animator2/animator.memory-leak.test.js +73 -0
  197. package/dist/utilities/animator/animator2/animator.performance.test.d.ts +1 -0
  198. package/dist/utilities/animator/animator2/animator.performance.test.js +65 -0
  199. package/dist/utilities/animator/animator2/animator.test.d.ts +1 -0
  200. package/dist/utilities/animator/animator2/animator.test.js +1007 -0
  201. package/dist/utilities/animator/animator_old/animator.d.ts +60 -0
  202. package/dist/utilities/animator/animator_old/animator.js +337 -0
  203. package/dist/utilities/animator/animator_old/animator.performance.test.d.ts +1 -0
  204. package/dist/utilities/animator/animator_old/animator.performance.test.js +121 -0
  205. package/dist/utilities/animator/animator_old/animator.test.d.ts +1 -0
  206. package/dist/utilities/animator/animator_old/animator.test.js +996 -0
  207. package/dist/utilities/animator/content-animations/fade-in/fade-in-content.d.ts +18 -0
  208. package/dist/utilities/animator/content-animations/fade-in/fade-in-content.js +37 -0
  209. package/dist/utilities/animator/content-animations/fade-in/fade-in-content.test.d.ts +1 -0
  210. package/dist/utilities/animator/content-animations/fade-in/fade-in-content.test.js +10 -0
  211. package/dist/utilities/animator/content-animations/fade-in/fade-in-state-animation.d.ts +38 -0
  212. package/dist/utilities/animator/content-animations/fade-in/fade-in-state-animation.js +208 -0
  213. package/dist/utilities/animator/content-animations/fade-in/fade-in-state-animation.test.d.ts +1 -0
  214. package/dist/utilities/animator/content-animations/fade-in/fade-in-state-animation.test.js +439 -0
  215. package/dist/utilities/animator/content-animations/slide/slide-in-content.d.ts +41 -0
  216. package/dist/utilities/animator/content-animations/slide/slide-in-content.js +107 -0
  217. package/dist/utilities/animator/content-animations/slide/slide-in-content.test.d.ts +1 -0
  218. package/dist/utilities/animator/content-animations/slide/slide-in-content.test.js +10 -0
  219. package/dist/utilities/animator/content-animations/slide/slide-state-animation.d.ts +24 -0
  220. package/dist/utilities/animator/content-animations/slide/slide-state-animation.js +138 -0
  221. package/dist/utilities/animator/content-animations/slide/slide-state-animation.test.d.ts +1 -0
  222. package/dist/utilities/animator/content-animations/slide/slide-state-animation.test.js +307 -0
  223. package/dist/utilities/animator/content-animations/slide/state-animation.d.ts +37 -0
  224. package/dist/utilities/animator/content-animations/slide/state-animation.js +170 -0
  225. package/dist/utilities/animator/content-animations/slide/state-animation.test.d.ts +1 -0
  226. package/dist/utilities/animator/content-animations/slide/state-animation.test.js +340 -0
  227. package/dist/utilities/animator/index.d.ts +6 -6
  228. package/dist/utilities/animator/index.js +6 -6
  229. package/dist/utilities/animator/state-animation/fade-in/fade-in-content.d.ts +18 -0
  230. package/dist/utilities/animator/state-animation/fade-in/fade-in-content.js +37 -0
  231. package/dist/utilities/animator/state-animation/fade-in/fade-in-content.test.d.ts +1 -0
  232. package/dist/utilities/animator/state-animation/fade-in/fade-in-content.test.js +10 -0
  233. package/dist/utilities/animator/state-animation/fade-in/fade-in-state-animation.d.ts +32 -0
  234. package/dist/utilities/animator/state-animation/fade-in/fade-in-state-animation.js +168 -0
  235. package/dist/utilities/animator/state-animation/fade-in/fade-in-state-animation.test.d.ts +1 -0
  236. package/dist/utilities/animator/state-animation/fade-in/fade-in-state-animation.test.js +431 -0
  237. package/dist/utilities/animator/state-animation/slide/slide-in-content.d.ts +37 -0
  238. package/dist/utilities/animator/state-animation/slide/slide-in-content.js +100 -0
  239. package/dist/utilities/animator/state-animation/slide/slide-in-content.test.d.ts +1 -0
  240. package/dist/utilities/animator/state-animation/slide/slide-in-content.test.js +10 -0
  241. package/dist/utilities/animator/state-animation/slide/slide-state-animation.d.ts +24 -0
  242. package/dist/utilities/animator/state-animation/slide/slide-state-animation.js +130 -0
  243. package/dist/utilities/animator/state-animation/slide/slide-state-animation.test.d.ts +1 -0
  244. package/dist/utilities/animator/state-animation/slide/slide-state-animation.test.js +301 -0
  245. package/dist/utilities/animator/state-animation/slide-state-animation.test.js +30 -30
  246. package/dist/utilities/animator/state-animation/state-animation.js +7 -7
  247. package/dist/utilities/animator/state-animation/state-animation.test.js +24 -24
  248. package/dist/utilities/animator/state-animation/visit-disappear-state-animation.test.js +30 -30
  249. package/dist/utilities/data-structures/vector-set/vector-set.d.ts +1 -1
  250. package/dist/utilities/data-structures/vector-set/vector-set.js +5 -5
  251. package/dist/utilities/grid-algorithms/closest-available-space/closest-available-space.helper.d.ts +1 -1
  252. package/dist/utilities/grid-algorithms/closest-available-space/closest-available-space.helper.js +5 -5
  253. package/dist/utilities/grid-algorithms/path-finder/path-finder.js +21 -21
  254. package/dist/utilities/grid-algorithms/path-finder/path-finder.test.js +9 -9
  255. package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.d.ts +14 -14
  256. package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.js +43 -43
  257. package/dist/utilities/grid-algorithms/vector-field-path-finder/vector-field-path-finder.test.js +21 -21
  258. package/package.json +7 -5
@@ -0,0 +1,996 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const actions_lib_1 = require("actions-lib");
4
+ const vitest_1 = require("vitest");
5
+ const game_entities_1 = require("../../../game-entities");
6
+ const animations_1 = require("../animations");
7
+ const animator_1 = require("./animator");
8
+ (0, vitest_1.describe)('ANIMATOR', () => {
9
+ (0, vitest_1.describe)('Setup', () => {
10
+ (0, vitest_1.test)('constructor should throw error if target is not an object', () => {
11
+ let obj = 'string';
12
+ (0, vitest_1.expect)(() => {
13
+ new animator_1.Animator(obj, 'x').attachToRoot();
14
+ }).toThrow('Animator: target is not an object! Target: "string"');
15
+ });
16
+ (0, vitest_1.test)('constructor should throw error if target does not have all target properties', () => {
17
+ let obj = { x: 1, y: 2, z: 3 };
18
+ (0, vitest_1.expect)(() => {
19
+ new animator_1.Animator(obj, ['x', 't']).attachToRoot();
20
+ }).toThrow('Animator: target does not have property. Target property: "t"');
21
+ });
22
+ (0, vitest_1.test)('constructor should throw error if target property is not a number', () => {
23
+ let obj = { x: 'fail' };
24
+ (0, vitest_1.expect)(() => {
25
+ new animator_1.Animator(obj, ['x']).attachToRoot();
26
+ }).toThrow('Animator: target property is not a number. Target property: "x"');
27
+ });
28
+ (0, vitest_1.test)('animate should throw error if non effected property tried to animate', () => {
29
+ (0, vitest_1.expect)(() => {
30
+ let obj = { x: 0, y: 0 };
31
+ let animator = new animator_1.Animator(obj, ['x', 't']).attachToRoot();
32
+ animator.animate({ x: 5, y: 5 });
33
+ }).toThrow('Animator: target does not have property. Target property: "t"');
34
+ });
35
+ (0, vitest_1.test)('should throw error if multiple animators decorate the same property', () => {
36
+ (0, vitest_1.expect)(() => {
37
+ let obj = { x: 0 };
38
+ new animator_1.Animator(obj, 'x').attachToRoot();
39
+ new animator_1.Animator(obj, 'x').attachToRoot();
40
+ }).toThrow(`Animator: target property is already animated! Target: "{\n "x": 0\n}", Property: "x"`);
41
+ });
42
+ (0, vitest_1.test)('setting multiple update callbacks should throw error', () => {
43
+ (0, vitest_1.expect)(() => {
44
+ let obj = { x: 0 };
45
+ new animator_1.Animator(obj, 'x')
46
+ .onChange(() => { })
47
+ .onChange(() => { })
48
+ .attachToRoot();
49
+ }).toThrow('Animator: onChangeCallback is already set!');
50
+ });
51
+ });
52
+ (0, vitest_1.describe)('Animate', () => {
53
+ (0, vitest_1.test)('animate should not change the value before the update ticks', () => {
54
+ let obj = { x: 0 };
55
+ let animator = new animator_1.Animator(obj, 'x').attachToRoot();
56
+ animator.animate({ x: 5 }).attachToRoot();
57
+ (0, vitest_1.expect)(obj.x).toEqual(0);
58
+ });
59
+ (0, vitest_1.test)('animate should not take action if the target value is the same', () => {
60
+ let obj = { x: 0 };
61
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4 }).attachToRoot();
62
+ animator.animate({ x: 0 }).attachToRoot();
63
+ animator['update'](1);
64
+ (0, vitest_1.expect)(obj.x).toEqual(0);
65
+ (0, vitest_1.expect)(animator.animating).toEqual(false);
66
+ });
67
+ (0, vitest_1.test)('animate should take action if the target value is the same and the animation is loop', () => {
68
+ let obj = { x: 0 };
69
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, loop: true }).attachToRoot();
70
+ animator.animate({ x: 0 }).attachToRoot();
71
+ animator['update'](1);
72
+ (0, vitest_1.expect)(obj.x).toEqual(0);
73
+ (0, vitest_1.expect)(animator.animating).toEqual(true);
74
+ });
75
+ (0, vitest_1.test)('animate to target in lineer', () => {
76
+ let obj = { x: 0 };
77
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: animations_1.Animations.lineer }).attachToRoot();
78
+ animator.animate({ x: 4 }).attachToRoot();
79
+ animator['update'](1);
80
+ (0, vitest_1.expect)(obj.x).toEqual(1);
81
+ animator['update'](1);
82
+ (0, vitest_1.expect)(obj.x).toEqual(2);
83
+ animator['update'](1);
84
+ (0, vitest_1.expect)(obj.x).toEqual(3);
85
+ animator['update'](1);
86
+ (0, vitest_1.expect)(obj.x).toEqual(4);
87
+ });
88
+ (0, vitest_1.test)('animate to target with overriden duration', () => {
89
+ let obj = { x: 0 };
90
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: animations_1.Animations.lineer }).attachToRoot();
91
+ animator.animate({ x: 4 }, { duration: 2 }).attachToRoot();
92
+ animator['update'](1);
93
+ (0, vitest_1.expect)(obj.x).toEqual(2);
94
+ });
95
+ (0, vitest_1.test)('animate to target with overriden instant duration', () => {
96
+ let obj = { x: 0 };
97
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: animations_1.Animations.lineer }).attachToRoot();
98
+ animator.animate({ x: 4 }, { duration: 0 }).attachToRoot();
99
+ animator['update'](1);
100
+ (0, vitest_1.expect)(obj.x).toEqual(4);
101
+ });
102
+ (0, vitest_1.test)('animate only one property should not effect the other', () => {
103
+ let obj = { x: 0, y: 0 };
104
+ let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: animations_1.Animations.lineer }).attachToRoot();
105
+ animator.animate({ x: 4 }).attachToRoot();
106
+ animator['update'](1);
107
+ (0, vitest_1.expect)(obj).toEqual({ x: 1, y: 0 });
108
+ animator['update'](1);
109
+ (0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
110
+ animator['update'](1);
111
+ (0, vitest_1.expect)(obj).toEqual({ x: 3, y: 0 });
112
+ animator['update'](1);
113
+ (0, vitest_1.expect)(obj).toEqual({ x: 4, y: 0 });
114
+ });
115
+ (0, vitest_1.test)('animate with custom values should override the default settings', () => {
116
+ let obj = { x: 0 };
117
+ let animator = new animator_1.Animator(obj, 'x', { duration: 10, animation: animations_1.Animations.lineer }).attachToRoot();
118
+ animator.animate({ x: 10 }, { duration: 4, animation: animations_1.Animations.easeInOut }).attachToRoot();
119
+ animator['update'](1);
120
+ (0, vitest_1.expect)(obj).toEqual({ x: 1.25 });
121
+ animator['update'](1);
122
+ (0, vitest_1.expect)(obj).toEqual({ x: 5 });
123
+ animator['update'](1);
124
+ (0, vitest_1.expect)(obj).toEqual({ x: 8.75 });
125
+ animator['update'](1);
126
+ (0, vitest_1.expect)(obj).toEqual({ x: 10 });
127
+ });
128
+ (0, vitest_1.test)('animate to target in easeInOut starting from zero', () => {
129
+ let obj = { x: 0 };
130
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: animations_1.Animations.easeInOut }).attachToRoot();
131
+ animator.animate({ x: 10 }).attachToRoot();
132
+ animator['update'](1);
133
+ (0, vitest_1.expect)(obj.x).toEqual(1.25);
134
+ animator['update'](1);
135
+ (0, vitest_1.expect)(obj.x).toEqual(5);
136
+ animator['update'](1);
137
+ (0, vitest_1.expect)(obj.x).toEqual(8.75);
138
+ animator['update'](1);
139
+ (0, vitest_1.expect)(obj.x).toEqual(10);
140
+ });
141
+ (0, vitest_1.test)('animate to target in easeInOut starting from different value than zero', () => {
142
+ let obj = { x: 10 };
143
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: animations_1.Animations.easeInOut }).attachToRoot();
144
+ animator.animate({ x: 20 }).attachToRoot();
145
+ animator['update'](1);
146
+ (0, vitest_1.expect)(obj.x).toEqual(11.25);
147
+ animator['update'](1);
148
+ (0, vitest_1.expect)(obj.x).toEqual(15);
149
+ animator['update'](1);
150
+ (0, vitest_1.expect)(obj.x).toEqual(18.75);
151
+ animator['update'](1);
152
+ (0, vitest_1.expect)(obj.x).toEqual(20);
153
+ });
154
+ (0, vitest_1.test)('animate to target and return back', () => {
155
+ let obj = { x: 0 };
156
+ let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: animations_1.Animations.lineer }).attachToRoot();
157
+ animator.animate({ x: 4 }).attachToRoot();
158
+ animator['update'](1);
159
+ animator.animate({ x: 0 }).attachToRoot();
160
+ animator['update'](1);
161
+ (0, vitest_1.expect)(obj.x).toEqual(0);
162
+ });
163
+ (0, vitest_1.test)('animate onChange callbacks', () => {
164
+ let obj = { x: 0 };
165
+ let valueFromOnStep = 0;
166
+ let onStepCallCount = 0;
167
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: animations_1.Animations.easeInOut })
168
+ .onChange(item => {
169
+ valueFromOnStep = item.x;
170
+ onStepCallCount++;
171
+ })
172
+ .attachToRoot();
173
+ animator.animate({ x: 10 }).attachToRoot();
174
+ (0, vitest_1.expect)(valueFromOnStep).toEqual(0);
175
+ (0, vitest_1.expect)(onStepCallCount).toEqual(0);
176
+ animator['update'](1);
177
+ (0, vitest_1.expect)(onStepCallCount).toEqual(1);
178
+ (0, vitest_1.expect)(valueFromOnStep).toEqual(1.25);
179
+ animator['update'](1);
180
+ (0, vitest_1.expect)(onStepCallCount).toEqual(2);
181
+ (0, vitest_1.expect)(valueFromOnStep).toEqual(5);
182
+ animator['update'](1);
183
+ (0, vitest_1.expect)(onStepCallCount).toEqual(3);
184
+ (0, vitest_1.expect)(valueFromOnStep).toEqual(8.75);
185
+ animator['update'](1);
186
+ (0, vitest_1.expect)(onStepCallCount).toEqual(4);
187
+ (0, vitest_1.expect)(valueFromOnStep).toEqual(10);
188
+ animator['update'](1);
189
+ animator['update'](1);
190
+ animator['update'](1);
191
+ (0, vitest_1.expect)(onStepCallCount).toEqual(4);
192
+ });
193
+ (0, vitest_1.test)('animate onChange should not be triggered before starting the animation', () => {
194
+ let onStepCallCount = 0;
195
+ let animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 4, animation: animations_1.Animations.easeInOut })
196
+ .onChange(() => {
197
+ onStepCallCount++;
198
+ })
199
+ .attachToRoot();
200
+ animator['update'](1);
201
+ (0, vitest_1.expect)(onStepCallCount).toEqual(0);
202
+ });
203
+ (0, vitest_1.test)('animation complete promise', () => {
204
+ let obj = { x: 0 };
205
+ let completed = false;
206
+ let animator = new animator_1.Animator(obj, 'x').attachToRoot();
207
+ animator
208
+ .animate({ x: 1 }, { duration: 2 })
209
+ .tap(() => {
210
+ completed = true;
211
+ })
212
+ .attachToRoot();
213
+ (0, vitest_1.expect)(completed).toBeFalsy();
214
+ animator['update'](1);
215
+ (0, vitest_1.expect)(completed).toBeFalsy();
216
+ animator['update'](1);
217
+ (0, vitest_1.expect)(completed).toBeTruthy();
218
+ });
219
+ (0, vitest_1.test)('animate getter/setter property', () => {
220
+ class Foo {
221
+ constructor() {
222
+ this._x = 10;
223
+ }
224
+ get x() {
225
+ return this._x;
226
+ }
227
+ set x(value) {
228
+ this._x = value;
229
+ }
230
+ }
231
+ let obj = new Foo();
232
+ let animator = new animator_1.Animator(obj, ['x'], { duration: 4, animation: animations_1.Animations.easeInOut }).attachToRoot();
233
+ animator.animate({ x: 20 }).attachToRoot();
234
+ animator['update'](1);
235
+ (0, vitest_1.expect)(obj.x).toEqual(11.25);
236
+ animator['update'](1);
237
+ (0, vitest_1.expect)(obj.x).toEqual(15);
238
+ animator['update'](1);
239
+ (0, vitest_1.expect)(obj.x).toEqual(18.75);
240
+ animator['update'](1);
241
+ (0, vitest_1.expect)(obj.x).toEqual(20);
242
+ });
243
+ (0, vitest_1.test)('is animating should return true if it is animating', () => {
244
+ let animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 1, animation: animations_1.Animations.lineer }).attachToRoot();
245
+ animator.animate({ x: 1 }).attachToRoot();
246
+ (0, vitest_1.expect)(animator.animating).toBeTruthy();
247
+ });
248
+ (0, vitest_1.test)('is animating should return false if it is not animating', () => {
249
+ let obj = { x: 0 };
250
+ let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: animations_1.Animations.lineer }).attachToRoot();
251
+ (0, vitest_1.expect)(animator.animating).toBeFalsy();
252
+ animator.animate({ x: 1 }).attachToRoot();
253
+ animator['update'](1);
254
+ (0, vitest_1.expect)(animator.animating).toBeFalsy();
255
+ });
256
+ });
257
+ (0, vitest_1.describe)('Animation Cycle Changes', () => {
258
+ (0, vitest_1.test)('pause animations should halt the progress', () => {
259
+ let obj = { x: 0 };
260
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: animations_1.Animations.lineer }).attachToRoot();
261
+ animator.animate({ x: 4 }).attachToRoot();
262
+ animator['update'](1);
263
+ (0, vitest_1.expect)(obj).toEqual({ x: 1 });
264
+ animator['update'](1);
265
+ (0, vitest_1.expect)(obj).toEqual({ x: 2 });
266
+ animator.pauseAnimations();
267
+ animator['update'](1);
268
+ (0, vitest_1.expect)(obj).toEqual({ x: 2 });
269
+ animator['update'](1);
270
+ (0, vitest_1.expect)(obj).toEqual({ x: 2 });
271
+ animator.resumeAnimations();
272
+ animator['update'](1);
273
+ (0, vitest_1.expect)(obj).toEqual({ x: 3 });
274
+ animator['update'](1);
275
+ (0, vitest_1.expect)(obj).toEqual({ x: 4 });
276
+ });
277
+ (0, vitest_1.test)('new animations should not proceed while the animations are paused', () => {
278
+ let obj = { x: 0 };
279
+ let animator = new animator_1.Animator(obj, 'x', { duration: 2, animation: animations_1.Animations.lineer }).attachToRoot();
280
+ animator.pauseAnimations();
281
+ animator.animate({ x: 2 }).attachToRoot();
282
+ animator['update'](1);
283
+ (0, vitest_1.expect)(obj).toEqual({ x: 0 });
284
+ animator['update'](1);
285
+ (0, vitest_1.expect)(obj).toEqual({ x: 0 });
286
+ animator.resumeAnimations();
287
+ animator['update'](1);
288
+ (0, vitest_1.expect)(obj).toEqual({ x: 1 });
289
+ animator['update'](1);
290
+ (0, vitest_1.expect)(obj).toEqual({ x: 2 });
291
+ });
292
+ (0, vitest_1.test)('animation loop', () => {
293
+ let obj = { x: 0 };
294
+ let animator = new animator_1.Animator(obj, 'x', { duration: 2, animation: animations_1.Animations.lineer, loop: true }).attachToRoot();
295
+ animator.animate({ x: 2 }, { duration: 2 }).attachToRoot();
296
+ animator['update'](1);
297
+ (0, vitest_1.expect)(obj.x).toEqual(1);
298
+ animator['update'](1);
299
+ (0, vitest_1.expect)(obj.x).toEqual(0);
300
+ animator['update'](1);
301
+ (0, vitest_1.expect)(obj.x).toEqual(1);
302
+ animator['update'](0.8);
303
+ (0, vitest_1.expect)(obj.x).toEqual(1.8);
304
+ animator['update'](0.7);
305
+ (0, vitest_1.expect)(obj.x).toEqual(0.5);
306
+ });
307
+ });
308
+ (0, vitest_1.describe)('Set', () => {
309
+ (0, vitest_1.test)('it should throw error if it is animating', () => {
310
+ let animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 1 }).attachToRoot();
311
+ animator.animate({ x: 1 }).attachToRoot();
312
+ (0, vitest_1.expect)(() => {
313
+ animator.set({ x: 0 });
314
+ }).toThrow();
315
+ });
316
+ (0, vitest_1.test)('it should throw error if the property is not valid', () => {
317
+ let animator = new animator_1.Animator({ x: 0 }, 'x').attachToRoot();
318
+ (0, vitest_1.expect)(() => {
319
+ animator.set({ t: 0 });
320
+ }).toThrow();
321
+ });
322
+ (0, vitest_1.test)('it should change the original value', () => {
323
+ let obj = { x: 0, y: 1, z: 2 };
324
+ let animator = new animator_1.Animator(obj, ['x', 'y', 'z']).attachToRoot();
325
+ animator.set({ x: 3, y: 4 });
326
+ (0, vitest_1.expect)(obj).toEqual({ x: 3, y: 4, z: 2 });
327
+ });
328
+ (0, vitest_1.test)('it should trigger onChange', () => {
329
+ let obj = { x: 0 };
330
+ let valueFromOnStep = 0;
331
+ let onStepCallCount = 0;
332
+ let animator = new animator_1.Animator(obj, 'x')
333
+ .onChange(item => {
334
+ valueFromOnStep = item.x;
335
+ onStepCallCount++;
336
+ })
337
+ .attachToRoot();
338
+ animator.set({ x: 1 });
339
+ (0, vitest_1.expect)(valueFromOnStep).toEqual(1);
340
+ (0, vitest_1.expect)(onStepCallCount).toEqual(1);
341
+ });
342
+ (0, vitest_1.test)('it should not trigger onChange if the value is the same', () => {
343
+ let obj = { x: 0 };
344
+ let onStepCallCount = 0;
345
+ let animator = new animator_1.Animator(obj, 'x')
346
+ .onChange(() => {
347
+ onStepCallCount++;
348
+ })
349
+ .attachToRoot();
350
+ animator.set({ x: 0 });
351
+ (0, vitest_1.expect)(onStepCallCount).toEqual(0);
352
+ });
353
+ });
354
+ (0, vitest_1.describe)('Reanimate', () => {
355
+ (0, vitest_1.test)('re-animation handling option throw error should throw error', () => {
356
+ let obj = { x: 0 };
357
+ let animator = new animator_1.Animator(obj, 'x', {
358
+ duration: 4,
359
+ reAnimateHandling: animator_1.ReAnimateHandlingType.throwError
360
+ }).attachToRoot();
361
+ animator.animate({ x: 1 }).attachToRoot();
362
+ (0, vitest_1.expect)(() => animator.animate({ x: 0 }).attachToRoot()).toThrow('Animator: property is already being animated. Property: "x"');
363
+ animator['update'](1);
364
+ (0, vitest_1.expect)(() => animator.animate({ x: 0 }).attachToRoot()).toThrow('Animator: property is already being animated. Property: "x"');
365
+ animator['update'](3);
366
+ (0, vitest_1.expect)(() => animator.animate({ x: 0 }).attachToRoot()).not.toThrow('Animator: property is already being animated. Property: "x"');
367
+ });
368
+ (0, vitest_1.test)('re-animation handling option ignore should ignore new animation', () => {
369
+ let obj = { x: 0 };
370
+ let animator = new animator_1.Animator(obj, 'x', {
371
+ duration: 1,
372
+ reAnimateHandling: animator_1.ReAnimateHandlingType.ignoreNewAnimation
373
+ }).attachToRoot();
374
+ animator.animate({ x: 1 }).attachToRoot();
375
+ animator.animate({ x: 2 }).attachToRoot();
376
+ animator['update'](1);
377
+ (0, vitest_1.expect)(obj.x).toEqual(1);
378
+ });
379
+ (0, vitest_1.test)('re-animation handling option ignore should ignore multiple property animation', () => {
380
+ let obj = { x: 0, y: 0 };
381
+ let animator = new animator_1.Animator(obj, ['x', 'y'], {
382
+ duration: 1,
383
+ reAnimateHandling: animator_1.ReAnimateHandlingType.ignoreNewAnimation
384
+ }).attachToRoot();
385
+ animator.animate({ x: 1 }).attachToRoot();
386
+ animator.animate({ x: 2, y: 1 }).attachToRoot();
387
+ animator['update'](1);
388
+ (0, vitest_1.expect)(obj).toEqual({ x: 1, y: 1 });
389
+ });
390
+ (0, vitest_1.test)('animate switch after finishes to a different animation type should not throw error', () => {
391
+ let obj = { x: 1 };
392
+ let animator = new animator_1.Animator(obj, 'x', { duration: 1 }).attachToRoot();
393
+ animator.animate({ x: 0 }, { animation: animations_1.Animations.lineer }).attachToRoot();
394
+ animator['update'](1);
395
+ (0, vitest_1.expect)(obj.x).toEqual(0);
396
+ animator.animate({ x: 10 }, { duration: 4, animation: animations_1.Animations.easeInOut }).attachToRoot();
397
+ animator['update'](1);
398
+ (0, vitest_1.expect)(obj.x).toEqual(1.25);
399
+ animator['update'](1);
400
+ (0, vitest_1.expect)(obj.x).toEqual(5);
401
+ animator['update'](1);
402
+ (0, vitest_1.expect)(obj.x).toEqual(8.75);
403
+ animator['update'](1);
404
+ (0, vitest_1.expect)(obj.x).toEqual(10);
405
+ });
406
+ (0, vitest_1.test)('re-animation handling option canceling should cancel the ongoing animation', () => {
407
+ let obj = { x: 0 };
408
+ let animator = new animator_1.Animator(obj, 'x', {
409
+ duration: 1,
410
+ reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious
411
+ }).attachToRoot();
412
+ animator.animate({ x: 1 }).attachToRoot();
413
+ animator.animate({ x: 2 }).attachToRoot();
414
+ animator['update'](1);
415
+ (0, vitest_1.expect)(obj.x).toEqual(2);
416
+ });
417
+ (0, vitest_1.test)('re-animation handling option canceling should cancel the ongoing multiple property animation', () => {
418
+ let obj = { x: 0, y: 0 };
419
+ let animator = new animator_1.Animator(obj, ['x', 'y'], {
420
+ duration: 1,
421
+ reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious
422
+ }).attachToRoot();
423
+ animator.animate({ x: 1 }).attachToRoot();
424
+ animator.animate({ x: 2, y: 1 }).attachToRoot();
425
+ animator['update'](1);
426
+ (0, vitest_1.expect)(obj).toEqual({ x: 2, y: 1 });
427
+ });
428
+ (0, vitest_1.test)('re-animation handling option canceling should cancel the animation with keeping the current value', () => {
429
+ let obj = { x: 0 };
430
+ let animator = new animator_1.Animator(obj, 'x', {
431
+ duration: 2,
432
+ reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious
433
+ }).attachToRoot();
434
+ animator.animate({ x: 2 }).attachToRoot();
435
+ animator['update'](1);
436
+ animator.animate({ x: 3 }).attachToRoot();
437
+ (0, vitest_1.expect)(obj.x).toEqual(1);
438
+ animator['update'](1);
439
+ (0, vitest_1.expect)(obj.x).toEqual(2);
440
+ animator['update'](1);
441
+ (0, vitest_1.expect)(obj.x).toEqual(3);
442
+ });
443
+ (0, vitest_1.test)('reanimate ignore new animation', () => {
444
+ let obj = { x: 0 };
445
+ let animator = new animator_1.Animator(obj, 'x', {
446
+ duration: 4,
447
+ animation: animations_1.Animations.lineer,
448
+ reAnimateHandling: animator_1.ReAnimateHandlingType.ignoreNewAnimation
449
+ }).attachToRoot();
450
+ animator.animate({ x: 1 }).attachToRoot();
451
+ animator['update'](1);
452
+ (0, vitest_1.expect)(obj.x).toEqual(0.25);
453
+ animator.animate({ x: 0 }).attachToRoot();
454
+ animator['update'](1);
455
+ (0, vitest_1.expect)(obj.x).toEqual(0.5);
456
+ });
457
+ (0, vitest_1.test)('reanimate start new animation', () => {
458
+ let obj = { x: 0 };
459
+ let animator = new animator_1.Animator(obj, 'x', {
460
+ duration: 4,
461
+ animation: animations_1.Animations.lineer,
462
+ reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious,
463
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
464
+ }).attachToRoot();
465
+ animator.animate({ x: 1 }).attachToRoot();
466
+ animator['update'](1);
467
+ (0, vitest_1.expect)(obj.x).toEqual(0.25);
468
+ animator.animate({ x: 0 }).attachToRoot();
469
+ animator['update'](1);
470
+ (0, vitest_1.expect)(obj.x).toEqual(0.1875);
471
+ });
472
+ (0, vitest_1.test)('reanimation triggered completion destroys the object should not make the new animation to throw error', async () => {
473
+ class AnimationObject extends actions_lib_1.Attachable {
474
+ constructor() {
475
+ super(...arguments);
476
+ this.scale = 1;
477
+ }
478
+ }
479
+ let object = new AnimationObject().attachToRoot();
480
+ let animator = new animator_1.Animator(object, 'scale', {
481
+ duration: 4,
482
+ reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious,
483
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
484
+ }).attach(object);
485
+ let completed1 = false;
486
+ let completed2 = false;
487
+ animator
488
+ .animate({ scale: 2 })
489
+ .tap(() => {
490
+ completed1 = true;
491
+ object.destroy();
492
+ })
493
+ .attachToRoot();
494
+ animator
495
+ .animate({ scale: 3 })
496
+ .tap(() => {
497
+ completed2 = true;
498
+ })
499
+ .attach(object);
500
+ (0, vitest_1.expect)(completed1).toBeTruthy();
501
+ (0, vitest_1.expect)(completed2).toBeFalsy();
502
+ });
503
+ (0, vitest_1.test)('reanimation triggered completion animates the same property should not interfier with the new animation', async () => {
504
+ class AnimationObject extends actions_lib_1.Attachable {
505
+ constructor() {
506
+ super(...arguments);
507
+ this.scale = 1;
508
+ }
509
+ }
510
+ let object = new AnimationObject().attachToRoot();
511
+ let animator = new animator_1.Animator(object, 'scale', {
512
+ duration: 4,
513
+ reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious,
514
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
515
+ }).attach(object);
516
+ let animation1Complete = false;
517
+ let completed1 = false;
518
+ let completed2 = false;
519
+ animator
520
+ .animate({ scale: 2 })
521
+ .asyncMap(() => {
522
+ animation1Complete = true;
523
+ return animator.animate({ scale: 1 });
524
+ })
525
+ .tap(() => {
526
+ completed1 = true;
527
+ object.destroy();
528
+ })
529
+ .attachToRoot();
530
+ animator['update'](1);
531
+ animator
532
+ .animate({ scale: 1 })
533
+ .tap(() => {
534
+ completed2 = true;
535
+ })
536
+ .attach(object);
537
+ (0, vitest_1.expect)(animation1Complete).toBeTruthy();
538
+ (0, vitest_1.expect)(completed1).toBeFalsy();
539
+ (0, vitest_1.expect)(completed2).toBeTruthy();
540
+ animator['update'](4);
541
+ (0, vitest_1.expect)(animation1Complete).toBeTruthy();
542
+ (0, vitest_1.expect)(completed1).toBeTruthy();
543
+ (0, vitest_1.expect)(completed2).toBeTruthy();
544
+ });
545
+ });
546
+ (0, vitest_1.describe)('Complete Animations', () => {
547
+ (0, vitest_1.test)('when animation is done it should respect the complete animaitons option', () => {
548
+ let obj = { x: 0 };
549
+ let animator = new animator_1.Animator(obj, 'x', {
550
+ duration: 1,
551
+ animation: animations_1.Animations.lineer,
552
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
553
+ }).attachToRoot();
554
+ animator.animate({ x: 1 }).attachToRoot();
555
+ animator['update'](1);
556
+ (0, vitest_1.expect)(obj.x).toEqual(0);
557
+ });
558
+ (0, vitest_1.test)('complete animations should finalize the ongoing animation', () => {
559
+ let obj = { x: 0 };
560
+ let completed = false;
561
+ let animator = new animator_1.Animator(obj, 'x').attachToRoot();
562
+ animator
563
+ .animate({ x: 1 }, { duration: 4 })
564
+ .tap(() => {
565
+ completed = true;
566
+ })
567
+ .attachToRoot();
568
+ animator['update'](1);
569
+ (0, vitest_1.expect)(completed).toBeFalsy();
570
+ animator.completeAnimations();
571
+ (0, vitest_1.expect)(completed).toBeTruthy();
572
+ });
573
+ (0, vitest_1.test)('complete animations should finalize the all ongoing animations', () => {
574
+ let completed1 = false;
575
+ let completed2 = false;
576
+ let obj = { x: 0, y: 0 };
577
+ let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: animations_1.Animations.easeInOut }).attachToRoot();
578
+ animator
579
+ .animate({ y: 10 }, { loop: true })
580
+ .tap(() => {
581
+ completed1 = true;
582
+ })
583
+ .attachToRoot();
584
+ animator['update'](1);
585
+ animator
586
+ .animate({ x: 10 })
587
+ .tap(() => {
588
+ completed2 = true;
589
+ })
590
+ .attachToRoot();
591
+ animator['update'](1);
592
+ (0, vitest_1.expect)(completed1).toBeFalsy();
593
+ (0, vitest_1.expect)(completed2).toBeFalsy();
594
+ animator.completeAnimations();
595
+ (0, vitest_1.expect)(completed1).toBeTruthy();
596
+ (0, vitest_1.expect)(completed2).toBeTruthy();
597
+ });
598
+ (0, vitest_1.test)('complete animations stay in current state', () => {
599
+ let obj = { x: 0 };
600
+ let animator = new animator_1.Animator(obj, 'x').attachToRoot();
601
+ animator
602
+ .animate({ x: 4 }, {
603
+ duration: 4,
604
+ animation: animations_1.Animations.lineer,
605
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
606
+ })
607
+ .attachToRoot();
608
+ animator['update'](1);
609
+ (0, vitest_1.expect)(obj.x).toEqual(1);
610
+ animator.completeAnimations();
611
+ animator['update'](1);
612
+ (0, vitest_1.expect)(obj.x).toEqual(1);
613
+ });
614
+ (0, vitest_1.test)('complete animations jump to end', () => {
615
+ let obj = { x: 0 };
616
+ let animator = new animator_1.Animator(obj, 'x').attachToRoot();
617
+ animator
618
+ .animate({ x: 4 }, {
619
+ duration: 4,
620
+ animation: animations_1.Animations.lineer,
621
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
622
+ })
623
+ .attachToRoot();
624
+ animator['update'](1);
625
+ (0, vitest_1.expect)(obj.x).toEqual(1);
626
+ animator.completeAnimations();
627
+ animator['update'](1);
628
+ (0, vitest_1.expect)(obj.x).toEqual(4);
629
+ });
630
+ (0, vitest_1.test)('complete animations return to original', () => {
631
+ let obj = { x: 0 };
632
+ let animator = new animator_1.Animator(obj, 'x').attachToRoot();
633
+ animator
634
+ .animate({ x: 4 }, {
635
+ duration: 4,
636
+ animation: animations_1.Animations.lineer,
637
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
638
+ })
639
+ .attachToRoot();
640
+ animator['update'](1);
641
+ (0, vitest_1.expect)(obj.x).toEqual(1);
642
+ animator.completeAnimations();
643
+ animator['update'](1);
644
+ (0, vitest_1.expect)(obj.x).toEqual(0);
645
+ });
646
+ (0, vitest_1.test)('complete animations options overriden in animate', () => {
647
+ let obj = { x: 0 };
648
+ let animator = new animator_1.Animator(obj, 'x', {
649
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
650
+ }).attachToRoot();
651
+ animator
652
+ .animate({ x: 4 }, {
653
+ duration: 4,
654
+ animation: animations_1.Animations.lineer,
655
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
656
+ })
657
+ .attachToRoot();
658
+ animator['update'](1);
659
+ (0, vitest_1.expect)(obj.x).toEqual(1);
660
+ animator.completeAnimations();
661
+ animator['update'](1);
662
+ (0, vitest_1.expect)(obj.x).toEqual(4);
663
+ });
664
+ (0, vitest_1.test)('complete animations options overriden in complete animations funciton', () => {
665
+ let obj = { x: 0 };
666
+ let animator = new animator_1.Animator(obj, 'x', {
667
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
668
+ }).attachToRoot();
669
+ animator
670
+ .animate({ x: 4 }, {
671
+ duration: 4,
672
+ animation: animations_1.Animations.lineer,
673
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd
674
+ })
675
+ .attachToRoot();
676
+ animator['update'](1);
677
+ (0, vitest_1.expect)(obj.x).toEqual(1);
678
+ animator.completeAnimations(animator_1.CompleteAnimationsHandlingType.stayInCurrentState);
679
+ animator['update'](1);
680
+ (0, vitest_1.expect)(obj.x).toEqual(1);
681
+ });
682
+ (0, vitest_1.test)('complete animations should not trigger onChange at stay in current state', () => {
683
+ let obj = { x: 0 };
684
+ let heap = [];
685
+ let animator = new animator_1.Animator(obj, 'x', {
686
+ duration: 4,
687
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
688
+ })
689
+ .onChange(value => heap.push(value.x))
690
+ .attachToRoot();
691
+ animator.animate({ x: 1 }).attachToRoot();
692
+ animator['update'](1);
693
+ heap = [];
694
+ animator.completeAnimations();
695
+ (0, vitest_1.expect)(heap).toEqual([]);
696
+ });
697
+ (0, vitest_1.test)('complete animations should trigger onChange jump to end', () => {
698
+ let obj = { x: 0 };
699
+ let heap = [];
700
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.jumpToEnd })
701
+ .onChange(value => heap.push(value.x))
702
+ .attachToRoot();
703
+ animator.animate({ x: 1 }).attachToRoot();
704
+ animator['update'](1);
705
+ heap = [];
706
+ animator.completeAnimations();
707
+ (0, vitest_1.expect)(heap).toEqual([1]);
708
+ });
709
+ (0, vitest_1.test)('complete animations should trigger onChange return to original', () => {
710
+ let obj = { x: 0 };
711
+ let heap = [];
712
+ let animator = new animator_1.Animator(obj, 'x', {
713
+ duration: 4,
714
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.returnToOriginal
715
+ })
716
+ .onChange(value => heap.push(value.x))
717
+ .attachToRoot();
718
+ animator.animate({ x: 1 }).attachToRoot();
719
+ animator['update'](1);
720
+ heap = [];
721
+ animator.completeAnimations();
722
+ (0, vitest_1.expect)(heap).toEqual([0]);
723
+ });
724
+ (0, vitest_1.test)('complete animations should not trigger on change if it is not animating', () => {
725
+ let completed = false;
726
+ let animator = new animator_1.Animator({ x: 0 }, 'x')
727
+ .onChange(() => {
728
+ completed = true;
729
+ })
730
+ .attachToRoot();
731
+ animator.completeAnimations();
732
+ (0, vitest_1.expect)(completed).toBeFalsy();
733
+ });
734
+ (0, vitest_1.test)('complete animations should not trigger on change if the value change is already triggered', () => {
735
+ let obj = { x: 0 };
736
+ let heap = [];
737
+ let animator = new animator_1.Animator(obj, 'x', { duration: 2 }).onChange(value => heap.push(value.x)).attachToRoot();
738
+ animator.animate({ x: 1 }).attachToRoot();
739
+ animator['update'](1);
740
+ animator.completeAnimations();
741
+ (0, vitest_1.expect)(heap).toEqual([0.5]);
742
+ });
743
+ (0, vitest_1.test)('complete animations options should take effect with set', () => {
744
+ let obj = { x: 0 };
745
+ let animator = new animator_1.Animator(obj, 'x', {
746
+ duration: 4,
747
+ animation: animations_1.Animations.lineer,
748
+ reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious
749
+ }).attachToRoot();
750
+ animator.animate({ x: 4 }).attachToRoot();
751
+ animator['update'](1);
752
+ (0, vitest_1.expect)(obj.x).toEqual(1);
753
+ animator.set({ x: 1 });
754
+ animator['update'](1);
755
+ (0, vitest_1.expect)(obj.x).toEqual(1);
756
+ });
757
+ });
758
+ (0, vitest_1.describe)('Compete Callback', () => {
759
+ (0, vitest_1.test)('complete callback should trigger when the animation is done', () => {
760
+ let obj = { x: 0 };
761
+ let completed = false;
762
+ let animator = new animator_1.Animator(obj, 'x', { duration: 1 }).onComplete(() => (completed = true)).attachToRoot();
763
+ animator.animate({ x: 1 }).attachToRoot();
764
+ animator['update'](1);
765
+ (0, vitest_1.expect)(completed).toBeTruthy();
766
+ });
767
+ (0, vitest_1.test)('complete callback should trigger on reanimation', () => {
768
+ let obj = { x: 0 };
769
+ let heap = [];
770
+ let animator = new animator_1.Animator(obj, 'x', {
771
+ duration: 2,
772
+ reAnimateHandling: animator_1.ReAnimateHandlingType.completePrevious,
773
+ completeAnimationsHandling: animator_1.CompleteAnimationsHandlingType.stayInCurrentState
774
+ })
775
+ .onComplete((key, value) => heap.push(value))
776
+ .attachToRoot();
777
+ animator.animate({ x: 1 }).attachToRoot();
778
+ animator['update'](1);
779
+ (0, vitest_1.expect)(heap).toEqual([]);
780
+ animator.animate({ x: 2 }).attachToRoot();
781
+ animator['update'](1);
782
+ (0, vitest_1.expect)(heap).toEqual([0.5]);
783
+ animator['update'](1);
784
+ (0, vitest_1.expect)(heap).toEqual([0.5, 2]);
785
+ });
786
+ (0, vitest_1.test)('complete callback should not trigger when the animation is not done', () => {
787
+ let completed = false;
788
+ let animator = new animator_1.Animator({ x: 0 }, 'x', { duration: 1 }).onComplete(() => (completed = true)).attachToRoot();
789
+ animator.animate({ x: 1 }).attachToRoot();
790
+ (0, vitest_1.expect)(completed).toBeFalsy();
791
+ });
792
+ (0, vitest_1.test)('re-animate should take action in complete callback', () => {
793
+ let obj = { x: 0 };
794
+ let animator = new animator_1.Animator(obj, 'x', { duration: 2 }).attachToRoot();
795
+ animator.onComplete(() => {
796
+ animator.animate({ x: 0 }).attachToRoot();
797
+ });
798
+ animator.animate({ x: 1 }).attachToRoot();
799
+ animator['update'](2);
800
+ (0, vitest_1.expect)(obj.x).toEqual(1);
801
+ animator['update'](1);
802
+ (0, vitest_1.expect)(obj.x).toEqual(0.5);
803
+ });
804
+ });
805
+ (0, vitest_1.describe)('Mixing Different Configurations', () => {
806
+ (0, vitest_1.test)('animate multiple properties without mixing animation type', () => {
807
+ let obj = { x: 0, y: 10 };
808
+ let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: animations_1.Animations.easeInOut }).attachToRoot();
809
+ animator.animate({ x: 10, y: 0 }).attachToRoot();
810
+ animator['update'](1);
811
+ (0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 8.75 });
812
+ animator['update'](1);
813
+ (0, vitest_1.expect)(obj).toEqual({ x: 5, y: 5 });
814
+ animator['update'](1);
815
+ (0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 1.25 });
816
+ animator['update'](1);
817
+ (0, vitest_1.expect)(obj).toEqual({ x: 10, y: 0 });
818
+ });
819
+ (0, vitest_1.test)('animate multiple properties with mixing animation type', () => {
820
+ let obj = { x: 0, y: 4 };
821
+ let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4 }).attachToRoot();
822
+ animator.animate({ x: 10 }, { animation: animations_1.Animations.easeInOut }).attachToRoot();
823
+ animator.animate({ y: 0 }, { animation: animations_1.Animations.lineer }).attachToRoot();
824
+ animator['update'](1);
825
+ (0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 3 });
826
+ animator['update'](1);
827
+ (0, vitest_1.expect)(obj).toEqual({ x: 5, y: 2 });
828
+ animator['update'](1);
829
+ (0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 1 });
830
+ animator['update'](1);
831
+ (0, vitest_1.expect)(obj).toEqual({ x: 10, y: 0 });
832
+ });
833
+ (0, vitest_1.test)('animate multiple properties async', () => {
834
+ let obj = { x: 0, y: 0 };
835
+ let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: animations_1.Animations.easeInOut }).attachToRoot();
836
+ animator.animate({ y: 10 }).attachToRoot();
837
+ animator['update'](1);
838
+ (0, vitest_1.expect)(obj).toEqual({ x: 0, y: 1.25 });
839
+ animator.animate({ x: 10 }).attachToRoot();
840
+ animator['update'](1);
841
+ (0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 5 });
842
+ animator['update'](1);
843
+ (0, vitest_1.expect)(obj).toEqual({ x: 5, y: 8.75 });
844
+ animator['update'](1);
845
+ (0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 10 });
846
+ animator['update'](1);
847
+ (0, vitest_1.expect)(obj).toEqual({ x: 10, y: 10 });
848
+ });
849
+ (0, vitest_1.test)('animate multiple properties mixed with loop', () => {
850
+ let obj = { x: 0, y: 0 };
851
+ let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: animations_1.Animations.easeInOut }).attachToRoot();
852
+ animator.animate({ y: 10 }, { loop: true }).attachToRoot();
853
+ animator['update'](1);
854
+ (0, vitest_1.expect)(obj).toEqual({ x: 0, y: 1.25 });
855
+ animator.animate({ x: 10 }).attachToRoot();
856
+ animator['update'](1);
857
+ (0, vitest_1.expect)(obj).toEqual({ x: 1.25, y: 5 });
858
+ animator['update'](1);
859
+ (0, vitest_1.expect)(obj).toEqual({ x: 5, y: 8.75 });
860
+ animator['update'](1);
861
+ (0, vitest_1.expect)(obj).toEqual({ x: 8.75, y: 0 });
862
+ animator['update'](1);
863
+ (0, vitest_1.expect)(obj).toEqual({ x: 10, y: 1.25 });
864
+ animator['update'](1);
865
+ (0, vitest_1.expect)(obj).toEqual({ x: 10, y: 5 });
866
+ });
867
+ (0, vitest_1.test)('animate multiple properties complete promise', () => {
868
+ let completed1 = false;
869
+ let completed2 = false;
870
+ let obj = { x: 0, y: 0 };
871
+ let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4 }).attachToRoot();
872
+ animator
873
+ .animate({ y: 10 })
874
+ .tap(() => {
875
+ completed1 = true;
876
+ })
877
+ .attachToRoot();
878
+ animator['update'](1);
879
+ animator
880
+ .animate({ x: 10 })
881
+ .tap(() => {
882
+ completed2 = true;
883
+ })
884
+ .attachToRoot();
885
+ animator['update'](2);
886
+ (0, vitest_1.expect)(completed1).toBeFalsy();
887
+ (0, vitest_1.expect)(completed2).toBeFalsy();
888
+ animator['update'](1);
889
+ (0, vitest_1.expect)(completed1).toBeTruthy();
890
+ (0, vitest_1.expect)(completed2).toBeFalsy();
891
+ animator['update'](1);
892
+ (0, vitest_1.expect)(completed1).toBeTruthy();
893
+ (0, vitest_1.expect)(completed2).toBeTruthy();
894
+ });
895
+ (0, vitest_1.test)('pause animations with mixed commands', () => {
896
+ let obj = { x: 0, y: 0 };
897
+ let animator = new animator_1.Animator(obj, ['x', 'y'], { duration: 4, animation: animations_1.Animations.lineer }).attachToRoot();
898
+ animator.resumeAnimations();
899
+ animator.animate({ x: 4 }).attachToRoot();
900
+ animator['update'](1);
901
+ (0, vitest_1.expect)(obj).toEqual({ x: 1, y: 0 });
902
+ animator['update'](1);
903
+ (0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
904
+ animator.pauseAnimations();
905
+ animator['update'](1);
906
+ (0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
907
+ animator.pauseAnimations();
908
+ animator.animate({ y: 4 }).attachToRoot();
909
+ animator['update'](1);
910
+ (0, vitest_1.expect)(obj).toEqual({ x: 2, y: 0 });
911
+ animator.resumeAnimations();
912
+ animator['update'](1);
913
+ (0, vitest_1.expect)(obj).toEqual({ x: 3, y: 1 });
914
+ animator.resumeAnimations();
915
+ animator['update'](1);
916
+ (0, vitest_1.expect)(obj).toEqual({ x: 4, y: 2 });
917
+ });
918
+ });
919
+ (0, vitest_1.describe)('Update Cycle', () => {
920
+ (0, vitest_1.test)('testing with update cycle', () => {
921
+ let obj = { x: 0 };
922
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: animations_1.Animations.lineer }).attachToRoot();
923
+ animator.animate({ x: 4 }).attachToRoot();
924
+ game_entities_1.UpdateCycle.triggerUpdateTick(1);
925
+ (0, vitest_1.expect)(obj.x).toEqual(1);
926
+ game_entities_1.UpdateCycle.triggerUpdateTick(1);
927
+ (0, vitest_1.expect)(obj.x).toEqual(2);
928
+ game_entities_1.UpdateCycle.triggerUpdateTick(1);
929
+ (0, vitest_1.expect)(obj.x).toEqual(3);
930
+ game_entities_1.UpdateCycle.triggerUpdateTick(1);
931
+ (0, vitest_1.expect)(obj.x).toEqual(4);
932
+ });
933
+ });
934
+ (0, vitest_1.describe)('Destroyed Animator', () => {
935
+ (0, vitest_1.test)('destroyed animator should not animate', () => {
936
+ let obj = { x: 0 };
937
+ let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: animations_1.Animations.lineer }).attachToRoot();
938
+ animator.destroy();
939
+ game_entities_1.UpdateCycle.triggerUpdateTick(1);
940
+ animator.animate({ x: 1 }).attachToRoot();
941
+ game_entities_1.UpdateCycle.triggerUpdateTick(1);
942
+ (0, vitest_1.expect)(obj.x).toEqual(0);
943
+ });
944
+ (0, vitest_1.test)('after destroy animation should not trigger complete', () => {
945
+ let obj = { x: 0 };
946
+ let animator = new animator_1.Animator(obj, 'x', { duration: 1, animation: animations_1.Animations.lineer }).attachToRoot();
947
+ let animation = animator.animate({ x: 1 });
948
+ animator.destroy();
949
+ let triggered = false;
950
+ animation
951
+ .tap(() => {
952
+ triggered = true;
953
+ })
954
+ .attachToRoot();
955
+ game_entities_1.UpdateCycle.triggerUpdateTick(1);
956
+ (0, vitest_1.expect)(triggered).toBeFalsy();
957
+ });
958
+ (0, vitest_1.test)('destroying animator should destroy the animation that attached to that animator', () => {
959
+ let obj = { x: 0 };
960
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: animations_1.Animations.lineer }).attachToRoot();
961
+ animator.animate({ x: 4 }).attach(animator);
962
+ animator['update'](1);
963
+ (0, vitest_1.expect)(obj.x).toEqual(1);
964
+ animator['update'](1);
965
+ (0, vitest_1.expect)(obj.x).toEqual(2);
966
+ animator['update'](1);
967
+ (0, vitest_1.expect)(obj.x).toEqual(3);
968
+ animator.destroy();
969
+ animator['update'](1);
970
+ animator['update'](1);
971
+ animator['update'](1);
972
+ (0, vitest_1.expect)(obj.x).toEqual(3);
973
+ });
974
+ (0, vitest_1.test)('animation sequence destroys the animator that it is being attached to', () => {
975
+ let obj = { x: 0 };
976
+ let animator = new animator_1.Animator(obj, 'x', { duration: 4, animation: animations_1.Animations.lineer }).attachToRoot();
977
+ animator
978
+ .animate({ x: 4 })
979
+ .tap(() => animator.destroy())
980
+ .attach(animator);
981
+ animator['update'](1);
982
+ (0, vitest_1.expect)(obj.x).toEqual(1);
983
+ (0, vitest_1.expect)(animator.destroyed).toBeFalsy();
984
+ animator['update'](1);
985
+ (0, vitest_1.expect)(obj.x).toEqual(2);
986
+ (0, vitest_1.expect)(animator.destroyed).toBeFalsy();
987
+ animator['update'](1);
988
+ (0, vitest_1.expect)(obj.x).toEqual(3);
989
+ (0, vitest_1.expect)(animator.destroyed).toBeFalsy();
990
+ animator['update'](1);
991
+ (0, vitest_1.expect)(obj.x).toEqual(4);
992
+ (0, vitest_1.expect)(animator.destroyed).toBeTruthy();
993
+ });
994
+ });
995
+ });
996
+ //# sourceMappingURL=animator.test.js.map