bard-legends-framework 0.9.5 → 0.9.7
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/_interfaces/index.d.ts +2 -2
- package/dist/_interfaces/index.js +2 -3
- package/dist/game-entities/attachable/attachable.d.ts +6 -6
- package/dist/game-entities/attachable/attachable.js +28 -30
- package/dist/game-entities/attachable/attachable.spec.js +129 -128
- package/dist/game-entities/attachable/attachable.store.d.ts +5 -5
- package/dist/game-entities/attachable/attachable.store.js +34 -32
- package/dist/game-entities/attachable/attachable.test.js +132 -131
- package/dist/game-entities/attachable/destroyable.d.ts +13 -13
- package/dist/game-entities/attachable/destroyable.js +64 -69
- package/dist/game-entities/attachable/helpers/decorate-actions-lib.d.ts +15 -15
- package/dist/game-entities/attachable/helpers/decorate-actions-lib.js +125 -116
- package/dist/game-entities/attachable/helpers/referance-variable.d.ts +15 -15
- package/dist/game-entities/attachable/helpers/referance-variable.js +47 -48
- package/dist/game-entities/attachable/interfaces.d.ts +6 -6
- package/dist/game-entities/attachable/interfaces.js +2 -3
- package/dist/game-entities/base/helpers/decorate-actions-lib.js +0 -1
- package/dist/game-entities/controller/controller.js +0 -1
- package/dist/game-entities/controller/controller.spec.js +128 -125
- package/dist/game-entities/entity/entity.spec.js +263 -293
- package/dist/game-entities/entity/helpers/view-creation.helper.d.ts +7 -7
- package/dist/game-entities/entity/helpers/view-creation.helper.js +48 -48
- package/dist/game-entities/scene/scene.spec.js +219 -223
- package/dist/game-entities/service/service.js +0 -4
- package/dist/game-entities/service/service.spec.js +265 -237
- package/dist/game-entities/service/service.test.js +4 -2
- package/dist/game-entities/update-loop.d.ts +18 -18
- package/dist/game-entities/update-loop.js +46 -28
- package/dist/game-entities/view/view.js +1 -1
- package/dist/game-entities/view/view.spec.js +490 -506
- package/dist/game-entities/view/view.test.js +1 -1
- package/dist/lib/animator/animations.d.ts +13 -13
- package/dist/lib/animator/animations.js +43 -40
- package/dist/lib/animator/animator.d.ts +41 -41
- package/dist/lib/animator/animator.js +194 -197
- package/dist/lib/animator/animator.spec.js +699 -612
- package/dist/lib/animator/index.js +24 -19
- package/dist/lib/libraries/animator/animations.d.ts +13 -13
- package/dist/lib/libraries/animator/animations.js +43 -40
- package/dist/lib/libraries/animator/animator.d.ts +41 -41
- package/dist/lib/libraries/animator/animator.js +194 -197
- package/dist/lib/libraries/animator/animator.spec.js +699 -612
- package/dist/lib/libraries/animator/index.js +24 -19
- package/dist/lib/libraries/path-finder/path-finder.d.ts +2 -2
- package/dist/lib/libraries/path-finder/path-finder.js +19 -20
- package/dist/lib/path-finder/path-finder.d.ts +2 -2
- package/dist/lib/path-finder/path-finder.js +19 -20
- package/dist/lib/services/keyboard/keyboard.d.ts +4 -4
- package/dist/lib/services/keyboard/keyboard.js +39 -31
- package/dist/lib/services/mouse/mouse.service.d.ts +8 -8
- package/dist/lib/services/mouse/mouse.service.js +65 -53
- package/dist/lib/services/mouse/mouser-target-focus.service.d.ts +11 -11
- package/dist/lib/services/mouse/mouser-target-focus.service.js +83 -81
- package/dist/lib/update-loop.d.ts +10 -10
- package/dist/lib/update-loop.js +35 -27
- package/dist/physics/entitity-types/immovable-physics-entity.d.ts +6 -6
- package/dist/physics/entitity-types/immovable-physics-entity.js +23 -24
- package/dist/physics/entitity-types/movable-entity.d.ts +6 -6
- package/dist/physics/entitity-types/movable-entity.js +21 -22
- package/dist/physics/entitity-types/movable-physics-entity.d.ts +14 -14
- package/dist/physics/entitity-types/movable-physics-entity.js +83 -88
- package/dist/physics/entitity-types/physics-entity.d.ts +23 -23
- package/dist/physics/entitity-types/physics-entity.js +97 -88
- package/dist/physics/helpers/closest-available-space.helper.d.ts +16 -16
- package/dist/physics/helpers/closest-available-space.helper.js +98 -96
- package/dist/physics/helpers/closest-available-space.helper.spec.js +115 -68
- package/dist/physics/helpers/p2js.helper.d.ts +3 -3
- package/dist/physics/helpers/p2js.helper.js +21 -22
- package/dist/physics/helpers/shape-factory.d.ts +9 -4
- package/dist/physics/helpers/shape-factory.js +99 -75
- package/dist/physics/libs/p2js.helper.js +1 -1
- package/dist/physics/libs/position-to-grid-position-converter.d.ts +3 -3
- package/dist/physics/libs/position-to-grid-position-converter.js +15 -13
- package/dist/physics/module//360/237/223/220services/availability-grid.service.d.ts +10 -5
- package/dist/physics/module//360/237/223/220services/availability-grid.service.js +77 -57
- package/dist/physics/module//360/237/223/220services/border.service.d.ts +2 -2
- package/dist/physics/module//360/237/223/220services/border.service.js +57 -37
- package/dist/physics/module//360/237/223/220services/collision/physics-body-group.service.js +1 -1
- package/dist/physics/module//360/237/223/220services/collisions.service.d.ts +7 -7
- package/dist/physics/module//360/237/223/220services/collisions.service.js +110 -98
- package/dist/physics/module//360/237/223/220services/debug-visuals.service.d.ts +28 -6
- package/dist/physics/module//360/237/223/220services/debug-visuals.service.js +121 -89
- package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.d.ts +15 -7
- package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.js +117 -93
- package/dist/physics/module//360/237/223/220services/explosion.service.d.ts +14 -7
- package/dist/physics/module//360/237/223/220services/explosion.service.js +102 -77
- package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.d.ts +15 -7
- package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.js +117 -93
- package/dist/physics/module//360/237/223/220services/explosions/explosion.service.d.ts +14 -7
- package/dist/physics/module//360/237/223/220services/explosions/explosion.service.js +102 -77
- package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.d.ts +3 -3
- package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.js +71 -67
- package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.d.ts +3 -3
- package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.js +71 -67
- package/dist/physics/module//360/237/223/220services/impact/eliptic-explosion.service.js +1 -1
- package/dist/physics/module//360/237/223/220services/materials.service.d.ts +16 -11
- package/dist/physics/module//360/237/223/220services/materials.service.js +118 -108
- package/dist/physics/module//360/237/223/220services/path-finder.service.d.ts +19 -8
- package/dist/physics/module//360/237/223/220services/path-finder.service.js +121 -82
- package/dist/physics/module//360/237/223/220services/physics-world.service.d.ts +30 -15
- package/dist/physics/module//360/237/223/220services/physics-world.service.js +122 -100
- package/dist/physics/module//360/237/223/220services/ray-casting.service.d.ts +3 -3
- package/dist/physics/module//360/237/223/220services/ray-casting.service.js +87 -86
- package/dist/physics/module//360/237/223/220services/shape-creation.service.d.ts +9 -4
- package/dist/physics/module//360/237/223/220services/shape-creation.service.js +113 -84
- package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js +2 -1
- package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.d.ts +8 -8
- package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.js +32 -33
- package/dist/physics/physics-world.d.ts +50 -34
- package/dist/physics/physics-world.js +142 -133
- package/dist/physics/sub-elements/available-spaces/helpers/availability-grid.helper.d.ts +3 -3
- package/dist/physics/sub-elements/available-spaces/helpers/availability-grid.helper.js +15 -13
- package/dist/physics/sub-elements/available-spaces/physics-availability-grid.d.ts +9 -9
- package/dist/physics/sub-elements/available-spaces/physics-availability-grid.js +82 -77
- package/dist/physics/sub-elements/available-spaces/physics-available-spaces.d.ts +18 -14
- package/dist/physics/sub-elements/available-spaces/physics-available-spaces.js +91 -79
- package/dist/physics/sub-elements/collisions/contact-equation-orginiser.d.ts +11 -11
- package/dist/physics/sub-elements/collisions/contact-equation-orginiser.js +84 -76
- package/dist/physics/sub-elements/collisions/physics-collision.d.ts +7 -7
- package/dist/physics/sub-elements/collisions/physics-collision.js +43 -44
- package/dist/physics/sub-elements/elements/physics-body-groups.d.ts +11 -11
- package/dist/physics/sub-elements/elements/physics-body-groups.js +54 -54
- package/dist/physics/sub-elements/elements/physics-materials.d.ts +15 -10
- package/dist/physics/sub-elements/elements/physics-materials.js +101 -100
- package/dist/physics/sub-elements/elements/physics-world-borders.d.ts +3 -3
- package/dist/physics/sub-elements/elements/physics-world-borders.js +69 -45
- package/dist/physics/sub-elements/physics-body-groups.d.ts +8 -8
- package/dist/physics/sub-elements/physics-body-groups.js +41 -42
- package/dist/physics/sub-elements/physics-collision.d.ts +16 -16
- package/dist/physics/sub-elements/physics-collision.js +141 -121
- package/dist/physics/sub-elements/physics-materials.d.ts +15 -10
- package/dist/physics/sub-elements/physics-materials.js +101 -100
- package/dist/physics/sub-elements/physics-world-borders.d.ts +2 -2
- package/dist/physics/sub-elements/physics-world-borders.js +25 -26
- package/dist/physics/sub-elements/raycasting/physics-body-explosion-hit.d.ts +15 -11
- package/dist/physics/sub-elements/raycasting/physics-body-explosion-hit.js +59 -59
- package/dist/physics/sub-elements/raycasting/physics-explosion.d.ts +13 -6
- package/dist/physics/sub-elements/raycasting/physics-explosion.js +108 -73
- package/dist/physics/sub-elements/raycasting/ray-cast.d.ts +19 -19
- package/dist/physics/sub-elements/raycasting/ray-cast.js +93 -98
- package/dist/pixi/display-object/components/filters.d.ts +18 -18
- package/dist/pixi/display-object/components/filters.js +106 -81
- package/dist/pixi/display-object/components/glow-effect.d.ts +8 -8
- package/dist/pixi/display-object/components/glow-effect.js +33 -36
- package/dist/pixi/display-object/components/glow-filter.d.ts +8 -8
- package/dist/pixi/display-object/components/glow-filter.js +33 -36
- package/dist/pixi/display-object/container-attributes.js +1 -1
- package/dist/pixi/display-object/display-object-attributes.d.ts +41 -41
- package/dist/pixi/display-object/display-object-attributes.js +148 -150
- package/dist/pixi/display-object/display-object.d.ts +17 -17
- package/dist/pixi/display-object/display-object.js +79 -75
- package/dist/pixi/display-object/filters/base-filters/alpha-primer-color.filter.d.ts +9 -4
- package/dist/pixi/display-object/filters/base-filters/alpha-primer-color.filter.js +89 -77
- package/dist/pixi/display-object/filters/base-filters/blur.filter.js +30 -30
- package/dist/pixi/display-object/filters/base-filters/contrast-filter.d.ts +9 -4
- package/dist/pixi/display-object/filters/base-filters/contrast-filter.js +62 -53
- package/dist/pixi/display-object/filters/base-filters/expand-with-alpha-color.d.ts +10 -5
- package/dist/pixi/display-object/filters/base-filters/expand-with-alpha-color.js +93 -81
- package/dist/pixi/display-object/filters/base-filters/expand-with-color-gradient.d.ts +12 -7
- package/dist/pixi/display-object/filters/base-filters/expand-with-color-gradient.js +120 -109
- package/dist/pixi/display-object/filters/base-filters/expand-with-color.d.ts +10 -5
- package/dist/pixi/display-object/filters/base-filters/expand-with-color.filter.js +32 -32
- package/dist/pixi/display-object/filters/base-filters/expand-with-color.js +92 -85
- package/dist/pixi/display-object/filters/templates/checking-neighbors.template.js +28 -28
- package/dist/pixi/display-object/filters/templates/plane.template.js +20 -20
- package/dist/pixi/display-object/filters.js +20 -4
- package/dist/pixi/display-object/objects/components/filters.d.ts +18 -18
- package/dist/pixi/display-object/objects/components/filters.js +106 -81
- package/dist/pixi/display-object/objects/container.d.ts +2 -2
- package/dist/pixi/display-object/objects/container.js +39 -30
- package/dist/pixi/display-object/objects/graphics.d.ts +28 -28
- package/dist/pixi/display-object/objects/graphics.js +218 -202
- package/dist/pixi/display-object/objects/helpers/filters.d.ts +25 -25
- package/dist/pixi/display-object/objects/helpers/filters.js +150 -124
- package/dist/pixi/display-object/objects/helpers/glow-sprite-generator.d.ts +7 -7
- package/dist/pixi/display-object/objects/helpers/glow-sprite-generator.js +114 -95
- package/dist/pixi/display-object/objects/premade-objects/sprite-with-glowing-shapes.d.ts +5 -5
- package/dist/pixi/display-object/objects/premade-objects/sprite-with-glowing-shapes.js +81 -57
- package/dist/pixi/display-object/objects/sprite.d.ts +43 -43
- package/dist/pixi/display-object/objects/sprite.js +248 -233
- package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.js +1 -1
- package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.test.js +9 -9
- package/dist/pixi/display-object/objects/text/helpers/rich-text-to-plane-text.d.ts +1 -1
- package/dist/pixi/display-object/objects/text.d.ts +25 -25
- package/dist/pixi/display-object/objects/text.js +111 -102
- package/dist/pixi/display-object/premade-objects/sprite-with-glowing-shapes.d.ts +13 -9
- package/dist/pixi/display-object/premade-objects/sprite-with-glowing-shapes.js +96 -67
- package/dist/pixi/game.d.ts +1 -1
- package/dist/pixi/game.js +2 -2
- package/dist/pixi/helpers/glow-sprite-generator.d.ts +6 -6
- package/dist/pixi/helpers/glow-sprite-generator.js +99 -84
- package/dist/pixi/helpers/pixi-container.helper.d.ts +1 -1
- package/dist/pixi/helpers/pixi-container.helper.js +10 -8
- package/dist/pixi/helpers/screen-position-to-stage.helper.d.ts +1 -1
- package/dist/pixi/helpers/screen-position-to-stage.helper.js +12 -12
- package/dist/pixi/helpers/screen-position-to-stage.helper.test.js +174 -79
- package/dist/pixi/modules/CAMERA/index.d.ts +1 -1
- package/dist/pixi/modules/CAMERA/index.js +3 -3
- package/dist/services/keyboard/keyboard.d.ts +4 -4
- package/dist/services/keyboard/keyboard.js +39 -31
- package/dist/services/mouse/mouse.service.d.ts +8 -8
- package/dist/services/mouse/mouse.service.js +65 -53
- package/dist/services/mouse/mouser-target-focus.service.d.ts +11 -11
- package/dist/services/mouse/mouser-target-focus.service.js +83 -81
- package/dist/utilities/libraries/animator/animating-content/state-animation.d.ts +29 -26
- package/dist/utilities/libraries/animator/animating-content/state-animation.js +159 -165
- package/dist/utilities/libraries/animator/animating-content/state-animation.test.js +386 -375
- package/dist/utilities/libraries/animator/animator.spec.js +765 -656
- package/dist/utilities/libraries/binary-heap/binary-heap.d.ts +11 -11
- package/dist/utilities/libraries/binary-heap/binary-heap.js +79 -81
- package/dist/utilities/libraries/data-structures/binary-heap/binary-heap.d.ts +11 -11
- package/dist/utilities/libraries/data-structures/binary-heap/binary-heap.js +79 -81
- package/dist/utilities/libraries/data-structures/grid/grid.d.ts +35 -31
- package/dist/utilities/libraries/data-structures/grid/grid.js +128 -117
- package/dist/utilities/libraries/data-structures/grid/grid.spec.js +176 -138
- package/dist/utilities/libraries/data-structures/grid/grid.test.js +218 -141
- package/dist/utilities/libraries/data-structures/grid/position-to-grid-position-converter.d.ts +3 -3
- package/dist/utilities/libraries/data-structures/grid/position-to-grid-position-converter.js +15 -13
- package/dist/utilities/libraries/data-structures/queue/queue.d.ts +21 -21
- package/dist/utilities/libraries/data-structures/queue/queue.js +63 -66
- package/dist/utilities/libraries/data-structures/queue/queue.test.js +54 -55
- package/dist/utilities/libraries/grid-algorithms/closest-available-space/closest-available-space.helper.spec.js +122 -68
- package/dist/utilities/libraries/grid-algorithms/path-finder/path-finder.spec.js +140 -135
- package/dist/utilities/libraries/grid-algorithms/vector-field-path-finder/vector-field-path-finder.spec.js +293 -229
- package/dist/utilities/libraries/path-finder/path-finder.d.ts +7 -7
- package/dist/utilities/libraries/path-finder/path-finder.js +113 -109
- package/dist/utilities/libraries/path-finder/path-finder.spec.js +131 -106
- package/dist/utilities/services/keyboard/keyboard.d.ts +4 -4
- package/dist/utilities/services/keyboard/keyboard.js +42 -34
- package/dist/utilities/services/mouse/helpers/mouse-position.helper.d.ts +1 -1
- package/dist/utilities/services/mouse/helpers/mouse-position.helper.js +12 -12
- package/dist/utilities/services/mouse/helpers/mouse-position.helper.test.js +168 -73
- package/dist/utilities/services/mouse/mouse-target-focus.service.d.ts +15 -15
- package/dist/utilities/services/mouse/mouse-target-focus.service.js +79 -76
- package/dist/utilities/services/mouse/mouse.service.d.ts +9 -9
- package/dist/utilities/services/mouse/mouse.service.js +86 -72
- package/dist/utilities/services/mouse/mouser-target-focus.service.d.ts +11 -11
- package/dist/utilities/services/mouse/mouser-target-focus.service.js +83 -81
- package/package.json +6 -12
|
@@ -1,122 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
2
|
exports.Grid = void 0;
|
|
4
|
-
const helpers_lib_1 = require(
|
|
5
|
-
const NEIGHBORS = [
|
|
6
|
-
|
|
3
|
+
const helpers_lib_1 = require('helpers-lib');
|
|
4
|
+
const NEIGHBORS = [
|
|
5
|
+
new helpers_lib_1.Vector(-1, 0),
|
|
6
|
+
new helpers_lib_1.Vector(0, -1),
|
|
7
|
+
new helpers_lib_1.Vector(0, 1),
|
|
8
|
+
new helpers_lib_1.Vector(1, 0)
|
|
9
|
+
];
|
|
10
|
+
const DIAGONALS = [
|
|
11
|
+
new helpers_lib_1.Vector(-1, -1),
|
|
12
|
+
new helpers_lib_1.Vector(-1, 1),
|
|
13
|
+
new helpers_lib_1.Vector(1, -1),
|
|
14
|
+
new helpers_lib_1.Vector(1, 1)
|
|
15
|
+
];
|
|
7
16
|
const NEIGHBORS_INCLUDING_DIAGONALS = [...NEIGHBORS, ...DIAGONALS];
|
|
8
17
|
class Grid {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
18
|
+
static createByValues(values) {
|
|
19
|
+
const width = values[0].length;
|
|
20
|
+
values.forEach(row => {
|
|
21
|
+
if (row.length !== width) {
|
|
22
|
+
throw new Error(`Grid: All rows must have the same length. Expected: ${width}, got: ${row.length}`);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return new Grid(values);
|
|
26
|
+
}
|
|
27
|
+
static createNew(size, defaultValue) {
|
|
28
|
+
const values = Array(Math.floor(size.y))
|
|
29
|
+
.fill(undefined)
|
|
30
|
+
.map(() => Array(Math.floor(size.x)).fill(defaultValue));
|
|
31
|
+
return new Grid(values);
|
|
32
|
+
}
|
|
33
|
+
static getNeighborDirections(options) {
|
|
34
|
+
return options?.includeDiagonals ? NEIGHBORS_INCLUDING_DIAGONALS : NEIGHBORS;
|
|
35
|
+
}
|
|
36
|
+
static getDiagonalNeighborDirections() {
|
|
37
|
+
return DIAGONALS;
|
|
38
|
+
}
|
|
39
|
+
static vectorToNeighborDirection(vector, options) {
|
|
40
|
+
const roundedVector = vector.normalize().round();
|
|
41
|
+
if (!options?.includeDiagonals && roundedVector.x !== 0 && roundedVector.y !== 0) {
|
|
42
|
+
if (helpers_lib_1.Random.chance(0.5)) {
|
|
43
|
+
return new helpers_lib_1.Vector(0, roundedVector.y);
|
|
44
|
+
} else {
|
|
45
|
+
return new helpers_lib_1.Vector(roundedVector.x, 0);
|
|
46
|
+
}
|
|
47
|
+
} else {
|
|
48
|
+
return new helpers_lib_1.Vector(roundedVector.x, roundedVector.y);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
get size() {
|
|
52
|
+
return this._size;
|
|
53
|
+
}
|
|
54
|
+
get width() {
|
|
55
|
+
return this._size.x;
|
|
56
|
+
}
|
|
57
|
+
get height() {
|
|
58
|
+
return this._size.y;
|
|
59
|
+
}
|
|
60
|
+
constructor(values) {
|
|
61
|
+
this._size = new helpers_lib_1.Vector(values[0].length, values.length);
|
|
62
|
+
this._grid = values;
|
|
63
|
+
}
|
|
64
|
+
has(position) {
|
|
65
|
+
return this.isPointWithinBounds(position) && this.get(position) !== undefined;
|
|
66
|
+
}
|
|
67
|
+
get(position) {
|
|
68
|
+
return this._grid[position.y][position.x];
|
|
69
|
+
}
|
|
70
|
+
set(position, value) {
|
|
71
|
+
if (!this.isPointWithinBounds(position)) {
|
|
72
|
+
throw new Error(`Grid: Point is outside of the grid: point: "${position}", grid-size: "${this._size}"`);
|
|
73
|
+
}
|
|
74
|
+
this._grid[position.y][position.x] = value;
|
|
75
|
+
}
|
|
76
|
+
safeSetArea(area, value) {
|
|
77
|
+
area = this.cropPartsOutsideOfTheGrid(area);
|
|
78
|
+
this.setArea(area, value);
|
|
79
|
+
}
|
|
80
|
+
setArea(area, value) {
|
|
81
|
+
if (!this.isAreaWithinBounds(area)) {
|
|
82
|
+
throw new Error(
|
|
83
|
+
`Grid: Area is outside of the grid: area: "${JSON.stringify(area)}", grid-size: "${JSON.stringify(this._size)}"`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
for (let y = area.topLeft.y; y <= area.bottomRight.y && y < this._grid.length; y++) {
|
|
87
|
+
for (let x = area.topLeft.x; x <= area.bottomRight.x && x < this._grid[y].length; x++) {
|
|
88
|
+
this._grid[y][x] = value;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
forEach(callback) {
|
|
93
|
+
this._grid.forEach((row, y) => row.forEach((value, x) => callback(value, new helpers_lib_1.Vector(x, y))));
|
|
94
|
+
}
|
|
95
|
+
map(callback) {
|
|
96
|
+
const newValues = this._grid.map((row, y) => row.map((value, x) => callback(value, new helpers_lib_1.Vector(x, y))));
|
|
97
|
+
return new Grid(newValues);
|
|
98
|
+
}
|
|
99
|
+
isAreaWithinBounds(area) {
|
|
100
|
+
return this.isPointWithinBounds(area.topLeft) && this.isPointWithinBounds(area.bottomRight);
|
|
101
|
+
}
|
|
102
|
+
isPointWithinBounds(point) {
|
|
103
|
+
return point.x >= 0 && point.y >= 0 && point.x < this._size.x && point.y < this._size.y;
|
|
104
|
+
}
|
|
105
|
+
cropPartsOutsideOfTheGrid(area) {
|
|
106
|
+
const topLeft = this.movePositionInsideGrid(area.topLeft);
|
|
107
|
+
const bottomRight = this.movePositionInsideGrid(area.bottomRight);
|
|
108
|
+
return new helpers_lib_1.Rectangle(topLeft, bottomRight);
|
|
109
|
+
}
|
|
110
|
+
moveAreaInsideGrid(area) {
|
|
111
|
+
const topLeft = this.movePositionInsideGrid(area.topLeft);
|
|
112
|
+
const bottomRight = this.movePositionInsideGrid(area.bottomRight);
|
|
113
|
+
return new helpers_lib_1.Rectangle(topLeft, bottomRight);
|
|
114
|
+
}
|
|
115
|
+
movePositionInsideGrid(point) {
|
|
116
|
+
const x = Math.max(0, Math.min(this._size.x - 1, point.x));
|
|
117
|
+
const y = Math.max(0, Math.min(this._size.y - 1, point.y));
|
|
118
|
+
return new helpers_lib_1.Vector(x, y);
|
|
119
|
+
}
|
|
120
|
+
getNeighborPositions(position, options = { includeDiagonals: false }) {
|
|
121
|
+
const neighbors = options.includeDiagonals ? NEIGHBORS_INCLUDING_DIAGONALS : NEIGHBORS;
|
|
122
|
+
return neighbors
|
|
123
|
+
.map(neighborDirection => new helpers_lib_1.Vector(position.x + neighborDirection.x, position.y + neighborDirection.y))
|
|
124
|
+
.filter(neighborPosition => this.isPointWithinBounds(neighborPosition));
|
|
125
|
+
}
|
|
126
|
+
getDiagonalNeighborPositions(position) {
|
|
127
|
+
return DIAGONALS.map(
|
|
128
|
+
neighborDirection => new helpers_lib_1.Vector(position.x + neighborDirection.x, position.y + neighborDirection.y)
|
|
129
|
+
).filter(neighborPosition => this.isPointWithinBounds(neighborPosition));
|
|
130
|
+
}
|
|
120
131
|
}
|
|
121
132
|
exports.Grid = Grid;
|
|
122
|
-
//# sourceMappingURL=grid.js.map
|
|
133
|
+
//# sourceMappingURL=grid.js.map
|
|
@@ -1,140 +1,178 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const grid_1 = require("./grid");
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const helpers_lib_1 = require('helpers-lib');
|
|
3
|
+
const vitest_1 = require('vitest');
|
|
4
|
+
const grid_1 = require('./grid');
|
|
6
5
|
(0, vitest_1.describe)('Grid', () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(0, vitest_1.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
(0, vitest_1.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
78
|
-
(0, vitest_1.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
(0, vitest_1.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
6
|
+
let grid;
|
|
7
|
+
(0, vitest_1.beforeEach)(() => {
|
|
8
|
+
grid = grid_1.Grid.createNew({ x: 3, y: 3 }, true);
|
|
9
|
+
});
|
|
10
|
+
(0, vitest_1.test)('should be defined', () => {
|
|
11
|
+
(0, vitest_1.expect)(grid).toBeDefined();
|
|
12
|
+
});
|
|
13
|
+
(0, vitest_1.test)('should set and get values', () => {
|
|
14
|
+
grid.setArea({ topLeft: { x: 0, y: 0 }, bottomRight: { x: 1, y: 1 } }, false);
|
|
15
|
+
(0, vitest_1.expect)(grid.get({ x: 0, y: 0 })).toBeFalsy();
|
|
16
|
+
(0, vitest_1.expect)(grid.get({ x: 0, y: 1 })).toBeFalsy();
|
|
17
|
+
(0, vitest_1.expect)(grid.get({ x: 1, y: 0 })).toBeFalsy();
|
|
18
|
+
(0, vitest_1.expect)(grid.get({ x: 1, y: 1 })).toBeFalsy();
|
|
19
|
+
});
|
|
20
|
+
(0, vitest_1.test)('should throw an error if area is outside of the grid', () => {
|
|
21
|
+
(0, vitest_1.expect)(() => grid.setArea({ topLeft: { x: 0, y: 0 }, bottomRight: { x: 3, y: 3 } }, false)).toThrow();
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.test)('should crop area outside of the grid 1', () => {
|
|
24
|
+
(0, vitest_1.expect)(
|
|
25
|
+
grid.cropPartsOutsideOfTheGrid({
|
|
26
|
+
topLeft: { x: -1, y: -1 },
|
|
27
|
+
bottomRight: { x: 3, y: 3 }
|
|
28
|
+
})
|
|
29
|
+
).toEqual({
|
|
30
|
+
topLeft: { x: 0, y: 0 },
|
|
31
|
+
bottomRight: { x: 2, y: 2 }
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
(0, vitest_1.test)('should crop area outside of the grid 2', () => {
|
|
35
|
+
(0, vitest_1.expect)(
|
|
36
|
+
grid.cropPartsOutsideOfTheGrid({
|
|
37
|
+
topLeft: { x: 3, y: 3 },
|
|
38
|
+
bottomRight: { x: 4, y: 4 }
|
|
39
|
+
})
|
|
40
|
+
).toEqual({
|
|
41
|
+
topLeft: { x: 2, y: 2 },
|
|
42
|
+
bottomRight: { x: 2, y: 2 }
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.test)('should crop area outside of the grid 2', () => {
|
|
46
|
+
(0, vitest_1.expect)(
|
|
47
|
+
grid.cropPartsOutsideOfTheGrid({
|
|
48
|
+
topLeft: { x: -1, y: -1 },
|
|
49
|
+
bottomRight: { x: -1, y: -1 }
|
|
50
|
+
})
|
|
51
|
+
).toEqual({
|
|
52
|
+
topLeft: { x: 0, y: 0 },
|
|
53
|
+
bottomRight: { x: 0, y: 0 }
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
(0, vitest_1.test)('should check if area is within bounds', () => {
|
|
57
|
+
(0, vitest_1.expect)(
|
|
58
|
+
grid.isAreaWithinBounds({
|
|
59
|
+
topLeft: { x: 0, y: 0 },
|
|
60
|
+
bottomRight: { x: 1, y: 1 }
|
|
61
|
+
})
|
|
62
|
+
).toBeTruthy();
|
|
63
|
+
(0, vitest_1.expect)(
|
|
64
|
+
grid.isAreaWithinBounds({
|
|
65
|
+
topLeft: { x: 0, y: 0 },
|
|
66
|
+
bottomRight: { x: 3, y: 3 }
|
|
67
|
+
})
|
|
68
|
+
).toBeFalsy();
|
|
69
|
+
});
|
|
70
|
+
(0, vitest_1.test)('should check if point is within bounds', () => {
|
|
71
|
+
(0, vitest_1.expect)(grid.isPointWithinBounds({ x: 0, y: 0 })).toBeTruthy();
|
|
72
|
+
(0, vitest_1.expect)(grid.isPointWithinBounds({ x: 1, y: 1 })).toBeTruthy();
|
|
73
|
+
(0, vitest_1.expect)(grid.isPointWithinBounds({ x: 3, y: 3 })).toBeFalsy();
|
|
74
|
+
});
|
|
75
|
+
(0, vitest_1.test)('should set area within bounds', () => {
|
|
76
|
+
grid.safeSetArea({ topLeft: { x: 0, y: 0 }, bottomRight: { x: 3, y: 3 } }, false);
|
|
77
|
+
(0, vitest_1.expect)(grid.get({ x: 0, y: 0 })).toBeFalsy();
|
|
78
|
+
(0, vitest_1.expect)(grid.get({ x: 0, y: 1 })).toBeFalsy();
|
|
79
|
+
(0, vitest_1.expect)(grid.get({ x: 1, y: 0 })).toBeFalsy();
|
|
80
|
+
(0, vitest_1.expect)(grid.get({ x: 1, y: 1 })).toBeFalsy();
|
|
81
|
+
});
|
|
82
|
+
(0, vitest_1.test)('should return neighbor positions only adjacent', () => {
|
|
83
|
+
(0, vitest_1.expect)(grid.getNeighborPositions({ x: 1, y: 1 })).toEqual([
|
|
84
|
+
{ x: 0, y: 1 },
|
|
85
|
+
{ x: 1, y: 0 },
|
|
86
|
+
{ x: 1, y: 2 },
|
|
87
|
+
{ x: 2, y: 1 }
|
|
88
|
+
]);
|
|
89
|
+
});
|
|
90
|
+
(0, vitest_1.test)('should return neighbor positions with diagonals', () => {
|
|
91
|
+
(0, vitest_1.expect)(grid.getNeighborPositions({ x: 1, y: 1 }, { includeDiagonals: true })).toEqual([
|
|
92
|
+
{ x: 0, y: 1 },
|
|
93
|
+
{ x: 1, y: 0 },
|
|
94
|
+
{ x: 1, y: 2 },
|
|
95
|
+
{ x: 2, y: 1 },
|
|
96
|
+
{ x: 0, y: 0 },
|
|
97
|
+
{ x: 0, y: 2 },
|
|
98
|
+
{ x: 2, y: 0 },
|
|
99
|
+
{ x: 2, y: 2 }
|
|
100
|
+
]);
|
|
101
|
+
});
|
|
102
|
+
(0, vitest_1.test)('should return neighbor positions only adjacent at the edge', () => {
|
|
103
|
+
(0, vitest_1.expect)(grid.getNeighborPositions({ x: 2, y: 2 })).toEqual([
|
|
104
|
+
{ x: 1, y: 2 },
|
|
105
|
+
{ x: 2, y: 1 }
|
|
106
|
+
]);
|
|
107
|
+
});
|
|
108
|
+
(0, vitest_1.test)('should return neighbor positions at the edge with diagonals', () => {
|
|
109
|
+
(0, vitest_1.expect)(grid.getNeighborPositions({ x: 0, y: 0 }, { includeDiagonals: true })).toEqual([
|
|
110
|
+
{ x: 0, y: 1 },
|
|
111
|
+
{ x: 1, y: 0 },
|
|
112
|
+
{ x: 1, y: 1 }
|
|
113
|
+
]);
|
|
114
|
+
});
|
|
115
|
+
(0, vitest_1.test)('should iterate over all values', () => {
|
|
116
|
+
grid.setArea({ topLeft: { x: 1, y: 0 }, bottomRight: { x: 1, y: 1 } }, false);
|
|
117
|
+
const values = [];
|
|
118
|
+
grid.forEach((value, position) => values.push({ value, position }));
|
|
119
|
+
(0, vitest_1.expect)(values).toEqual([
|
|
120
|
+
{ value: true, position: { x: 0, y: 0 } },
|
|
121
|
+
{ value: false, position: { x: 1, y: 0 } },
|
|
122
|
+
{ value: true, position: { x: 2, y: 0 } },
|
|
123
|
+
{ value: true, position: { x: 0, y: 1 } },
|
|
124
|
+
{ value: false, position: { x: 1, y: 1 } },
|
|
125
|
+
{ value: true, position: { x: 2, y: 1 } },
|
|
126
|
+
{ value: true, position: { x: 0, y: 2 } },
|
|
127
|
+
{ value: true, position: { x: 1, y: 2 } },
|
|
128
|
+
{ value: true, position: { x: 2, y: 2 } }
|
|
129
|
+
]);
|
|
130
|
+
});
|
|
131
|
+
(0, vitest_1.test)('should map over all values', () => {
|
|
132
|
+
grid.setArea({ topLeft: { x: 1, y: 0 }, bottomRight: { x: 1, y: 1 } }, false);
|
|
133
|
+
const newGrid = grid.map((value, position) => (position.x + position.y) * (value ? 1 : -1));
|
|
134
|
+
(0, vitest_1.expect)(newGrid.get({ x: 0, y: 0 })).toBe(0);
|
|
135
|
+
(0, vitest_1.expect)(newGrid.get({ x: 1, y: 0 })).toBe(-1);
|
|
136
|
+
(0, vitest_1.expect)(newGrid.get({ x: 2, y: 0 })).toBe(2);
|
|
137
|
+
(0, vitest_1.expect)(newGrid.get({ x: 0, y: 1 })).toBe(1);
|
|
138
|
+
(0, vitest_1.expect)(newGrid.get({ x: 1, y: 1 })).toBe(-2);
|
|
139
|
+
(0, vitest_1.expect)(newGrid.get({ x: 2, y: 1 })).toBe(3);
|
|
140
|
+
(0, vitest_1.expect)(newGrid.get({ x: 0, y: 2 })).toBe(2);
|
|
141
|
+
(0, vitest_1.expect)(newGrid.get({ x: 1, y: 2 })).toBe(3);
|
|
142
|
+
(0, vitest_1.expect)(newGrid.get({ x: 2, y: 2 })).toBe(4);
|
|
143
|
+
(0, vitest_1.expect)(newGrid.size).toEqual({ x: 3, y: 3 });
|
|
144
|
+
});
|
|
145
|
+
(0, vitest_1.test)('should find the neighbor direction from a vector', () => {
|
|
146
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: 0, y: 1 })).toEqual({ x: 0, y: 1 });
|
|
147
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: 1, y: 0 })).toEqual({ x: 1, y: 0 });
|
|
148
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: 0, y: -1 })).toEqual({ x: 0, y: -1 });
|
|
149
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: -1, y: 0 })).toEqual({ x: -1, y: 0 });
|
|
150
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: 0.5, y: 2 })).toEqual({ x: 0, y: 1 });
|
|
151
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: 2, y: -0.5 })).toEqual({ x: 1, y: 0 });
|
|
152
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: 0.5, y: -2 })).toEqual({ x: 0, y: -1 });
|
|
153
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: -2, y: -0.5 })).toEqual({ x: -1, y: 0 });
|
|
154
|
+
const middle = grid_1.Grid.vectorToNeighborDirection({ x: 1, y: 1 });
|
|
155
|
+
(0, vitest_1.expect)(
|
|
156
|
+
helpers_lib_1.Vector.isEqual(middle, { x: 0, y: 1 }) || helpers_lib_1.Vector.isEqual(middle, { x: 1, y: 0 })
|
|
157
|
+
).toBeTruthy();
|
|
158
|
+
});
|
|
159
|
+
(0, vitest_1.test)('should find the neighbor direction with diagonals from a vector', () => {
|
|
160
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: 0, y: 1 }, { includeDiagonals: true })).toEqual({
|
|
161
|
+
x: 0,
|
|
162
|
+
y: 1
|
|
163
|
+
});
|
|
164
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: 1, y: 1 }, { includeDiagonals: true })).toEqual({
|
|
165
|
+
x: 1,
|
|
166
|
+
y: 1
|
|
167
|
+
});
|
|
168
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: -1, y: -1 }, { includeDiagonals: true })).toEqual({
|
|
169
|
+
x: -1,
|
|
170
|
+
y: -1
|
|
171
|
+
});
|
|
172
|
+
(0, vitest_1.expect)(grid_1.Grid.vectorToNeighborDirection({ x: 2, y: 1 }, { includeDiagonals: true })).toEqual({
|
|
173
|
+
x: 1,
|
|
174
|
+
y: 0
|
|
175
|
+
});
|
|
176
|
+
});
|
|
139
177
|
});
|
|
140
|
-
//# sourceMappingURL=grid.spec.js.map
|
|
178
|
+
//# sourceMappingURL=grid.spec.js.map
|