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