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