bard-legends-framework 0.9.6 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) 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.d.ts +4 -1
  21. package/dist/game-entities/entity/entity.js +5 -5
  22. package/dist/game-entities/entity/entity.spec.js +263 -293
  23. package/dist/game-entities/entity/helpers/view-creation.helper.d.ts +7 -7
  24. package/dist/game-entities/entity/helpers/view-creation.helper.js +48 -48
  25. package/dist/game-entities/scene/scene.spec.js +219 -223
  26. package/dist/game-entities/service/service.js +0 -4
  27. package/dist/game-entities/service/service.spec.js +265 -237
  28. package/dist/game-entities/service/service.test.js +4 -2
  29. package/dist/game-entities/update-loop.d.ts +18 -18
  30. package/dist/game-entities/update-loop.js +46 -28
  31. package/dist/game-entities/view/view.spec.js +490 -506
  32. package/dist/game-entities/view/view.test.js +1 -1
  33. package/dist/lib/animator/animations.d.ts +13 -13
  34. package/dist/lib/animator/animations.js +43 -40
  35. package/dist/lib/animator/animator.d.ts +41 -41
  36. package/dist/lib/animator/animator.js +194 -197
  37. package/dist/lib/animator/animator.spec.js +699 -612
  38. package/dist/lib/animator/index.js +24 -19
  39. package/dist/lib/libraries/animator/animations.d.ts +13 -13
  40. package/dist/lib/libraries/animator/animations.js +43 -40
  41. package/dist/lib/libraries/animator/animator.d.ts +41 -41
  42. package/dist/lib/libraries/animator/animator.js +194 -197
  43. package/dist/lib/libraries/animator/animator.spec.js +699 -612
  44. package/dist/lib/libraries/animator/index.js +24 -19
  45. package/dist/lib/libraries/path-finder/path-finder.d.ts +2 -2
  46. package/dist/lib/libraries/path-finder/path-finder.js +19 -20
  47. package/dist/lib/path-finder/path-finder.d.ts +2 -2
  48. package/dist/lib/path-finder/path-finder.js +19 -20
  49. package/dist/lib/services/keyboard/keyboard.d.ts +4 -4
  50. package/dist/lib/services/keyboard/keyboard.js +39 -31
  51. package/dist/lib/services/mouse/mouse.service.d.ts +8 -8
  52. package/dist/lib/services/mouse/mouse.service.js +65 -53
  53. package/dist/lib/services/mouse/mouser-target-focus.service.d.ts +11 -11
  54. package/dist/lib/services/mouse/mouser-target-focus.service.js +83 -81
  55. package/dist/lib/update-loop.d.ts +10 -10
  56. package/dist/lib/update-loop.js +35 -27
  57. package/dist/physics/entitity-types/immovable-physics-entity.d.ts +6 -6
  58. package/dist/physics/entitity-types/immovable-physics-entity.js +23 -24
  59. package/dist/physics/entitity-types/movable-entity.d.ts +6 -6
  60. package/dist/physics/entitity-types/movable-entity.js +21 -22
  61. package/dist/physics/entitity-types/movable-physics-entity.d.ts +14 -14
  62. package/dist/physics/entitity-types/movable-physics-entity.js +83 -88
  63. package/dist/physics/entitity-types/physics-entity.d.ts +23 -23
  64. package/dist/physics/entitity-types/physics-entity.js +97 -88
  65. package/dist/physics/helpers/closest-available-space.helper.d.ts +16 -16
  66. package/dist/physics/helpers/closest-available-space.helper.js +98 -96
  67. package/dist/physics/helpers/closest-available-space.helper.spec.js +115 -68
  68. package/dist/physics/helpers/p2js.helper.d.ts +3 -3
  69. package/dist/physics/helpers/p2js.helper.js +21 -22
  70. package/dist/physics/helpers/shape-factory.d.ts +9 -4
  71. package/dist/physics/helpers/shape-factory.js +99 -75
  72. package/dist/physics/libs/p2js.helper.js +1 -1
  73. package/dist/physics/libs/position-to-grid-position-converter.d.ts +3 -3
  74. package/dist/physics/libs/position-to-grid-position-converter.js +15 -13
  75. package/dist/physics/module//360/237/223/220services/availability-grid.service.d.ts +10 -5
  76. package/dist/physics/module//360/237/223/220services/availability-grid.service.js +77 -57
  77. package/dist/physics/module//360/237/223/220services/border.service.d.ts +2 -2
  78. package/dist/physics/module//360/237/223/220services/border.service.js +57 -37
  79. package/dist/physics/module//360/237/223/220services/collision/physics-body-group.service.js +1 -1
  80. package/dist/physics/module//360/237/223/220services/collisions.service.d.ts +7 -7
  81. package/dist/physics/module//360/237/223/220services/collisions.service.js +110 -98
  82. package/dist/physics/module//360/237/223/220services/debug-visuals.service.d.ts +28 -6
  83. package/dist/physics/module//360/237/223/220services/debug-visuals.service.js +121 -89
  84. package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.d.ts +15 -7
  85. package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.js +117 -93
  86. package/dist/physics/module//360/237/223/220services/explosion.service.d.ts +14 -7
  87. package/dist/physics/module//360/237/223/220services/explosion.service.js +102 -77
  88. package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.d.ts +15 -7
  89. package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.js +117 -93
  90. package/dist/physics/module//360/237/223/220services/explosions/explosion.service.d.ts +14 -7
  91. package/dist/physics/module//360/237/223/220services/explosions/explosion.service.js +102 -77
  92. package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.d.ts +3 -3
  93. package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.js +71 -67
  94. package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.d.ts +3 -3
  95. package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.js +71 -67
  96. package/dist/physics/module//360/237/223/220services/impact/eliptic-explosion.service.js +1 -1
  97. package/dist/physics/module//360/237/223/220services/materials.service.d.ts +16 -11
  98. package/dist/physics/module//360/237/223/220services/materials.service.js +118 -108
  99. package/dist/physics/module//360/237/223/220services/path-finder.service.d.ts +19 -8
  100. package/dist/physics/module//360/237/223/220services/path-finder.service.js +121 -82
  101. package/dist/physics/module//360/237/223/220services/physics-world.service.d.ts +30 -15
  102. package/dist/physics/module//360/237/223/220services/physics-world.service.js +122 -100
  103. package/dist/physics/module//360/237/223/220services/ray-casting.service.d.ts +3 -3
  104. package/dist/physics/module//360/237/223/220services/ray-casting.service.js +87 -86
  105. package/dist/physics/module//360/237/223/220services/shape-creation.service.d.ts +9 -4
  106. package/dist/physics/module//360/237/223/220services/shape-creation.service.js +113 -84
  107. package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js +2 -1
  108. package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.d.ts +8 -8
  109. package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.js +32 -33
  110. package/dist/physics/physics-world.d.ts +50 -34
  111. package/dist/physics/physics-world.js +142 -133
  112. package/dist/physics/sub-elements/available-spaces/helpers/availability-grid.helper.d.ts +3 -3
  113. package/dist/physics/sub-elements/available-spaces/helpers/availability-grid.helper.js +15 -13
  114. package/dist/physics/sub-elements/available-spaces/physics-availability-grid.d.ts +9 -9
  115. package/dist/physics/sub-elements/available-spaces/physics-availability-grid.js +82 -77
  116. package/dist/physics/sub-elements/available-spaces/physics-available-spaces.d.ts +18 -14
  117. package/dist/physics/sub-elements/available-spaces/physics-available-spaces.js +91 -79
  118. package/dist/physics/sub-elements/collisions/contact-equation-orginiser.d.ts +11 -11
  119. package/dist/physics/sub-elements/collisions/contact-equation-orginiser.js +84 -76
  120. package/dist/physics/sub-elements/collisions/physics-collision.d.ts +7 -7
  121. package/dist/physics/sub-elements/collisions/physics-collision.js +43 -44
  122. package/dist/physics/sub-elements/elements/physics-body-groups.d.ts +11 -11
  123. package/dist/physics/sub-elements/elements/physics-body-groups.js +54 -54
  124. package/dist/physics/sub-elements/elements/physics-materials.d.ts +15 -10
  125. package/dist/physics/sub-elements/elements/physics-materials.js +101 -100
  126. package/dist/physics/sub-elements/elements/physics-world-borders.d.ts +3 -3
  127. package/dist/physics/sub-elements/elements/physics-world-borders.js +69 -45
  128. package/dist/physics/sub-elements/physics-body-groups.d.ts +8 -8
  129. package/dist/physics/sub-elements/physics-body-groups.js +41 -42
  130. package/dist/physics/sub-elements/physics-collision.d.ts +16 -16
  131. package/dist/physics/sub-elements/physics-collision.js +141 -121
  132. package/dist/physics/sub-elements/physics-materials.d.ts +15 -10
  133. package/dist/physics/sub-elements/physics-materials.js +101 -100
  134. package/dist/physics/sub-elements/physics-world-borders.d.ts +2 -2
  135. package/dist/physics/sub-elements/physics-world-borders.js +25 -26
  136. package/dist/physics/sub-elements/raycasting/physics-body-explosion-hit.d.ts +15 -11
  137. package/dist/physics/sub-elements/raycasting/physics-body-explosion-hit.js +59 -59
  138. package/dist/physics/sub-elements/raycasting/physics-explosion.d.ts +13 -6
  139. package/dist/physics/sub-elements/raycasting/physics-explosion.js +108 -73
  140. package/dist/physics/sub-elements/raycasting/ray-cast.d.ts +19 -19
  141. package/dist/physics/sub-elements/raycasting/ray-cast.js +93 -98
  142. package/dist/pixi/display-object/components/filters.d.ts +18 -18
  143. package/dist/pixi/display-object/components/filters.js +106 -81
  144. package/dist/pixi/display-object/components/glow-effect.d.ts +8 -8
  145. package/dist/pixi/display-object/components/glow-effect.js +33 -36
  146. package/dist/pixi/display-object/components/glow-filter.d.ts +8 -8
  147. package/dist/pixi/display-object/components/glow-filter.js +33 -36
  148. package/dist/pixi/display-object/container-attributes.js +1 -1
  149. package/dist/pixi/display-object/display-object-attributes.d.ts +41 -41
  150. package/dist/pixi/display-object/display-object-attributes.js +148 -150
  151. package/dist/pixi/display-object/display-object.d.ts +17 -17
  152. package/dist/pixi/display-object/display-object.js +79 -75
  153. package/dist/pixi/display-object/filters/base-filters/alpha-primer-color.filter.d.ts +9 -4
  154. package/dist/pixi/display-object/filters/base-filters/alpha-primer-color.filter.js +89 -77
  155. package/dist/pixi/display-object/filters/base-filters/blur.filter.js +30 -30
  156. package/dist/pixi/display-object/filters/base-filters/contrast-filter.d.ts +9 -4
  157. package/dist/pixi/display-object/filters/base-filters/contrast-filter.js +62 -53
  158. package/dist/pixi/display-object/filters/base-filters/expand-with-alpha-color.d.ts +10 -5
  159. package/dist/pixi/display-object/filters/base-filters/expand-with-alpha-color.js +93 -81
  160. package/dist/pixi/display-object/filters/base-filters/expand-with-color-gradient.d.ts +12 -7
  161. package/dist/pixi/display-object/filters/base-filters/expand-with-color-gradient.js +120 -109
  162. package/dist/pixi/display-object/filters/base-filters/expand-with-color.d.ts +10 -5
  163. package/dist/pixi/display-object/filters/base-filters/expand-with-color.filter.js +32 -32
  164. package/dist/pixi/display-object/filters/base-filters/expand-with-color.js +92 -85
  165. package/dist/pixi/display-object/filters/templates/checking-neighbors.template.js +28 -28
  166. package/dist/pixi/display-object/filters/templates/plane.template.js +20 -20
  167. package/dist/pixi/display-object/filters.js +20 -4
  168. package/dist/pixi/display-object/objects/components/filters.d.ts +18 -18
  169. package/dist/pixi/display-object/objects/components/filters.js +106 -81
  170. package/dist/pixi/display-object/objects/container.d.ts +2 -2
  171. package/dist/pixi/display-object/objects/container.js +39 -30
  172. package/dist/pixi/display-object/objects/graphics.d.ts +28 -28
  173. package/dist/pixi/display-object/objects/graphics.js +218 -202
  174. package/dist/pixi/display-object/objects/helpers/filters.d.ts +25 -25
  175. package/dist/pixi/display-object/objects/helpers/filters.js +150 -124
  176. package/dist/pixi/display-object/objects/helpers/glow-sprite-generator.d.ts +7 -7
  177. package/dist/pixi/display-object/objects/helpers/glow-sprite-generator.js +114 -95
  178. package/dist/pixi/display-object/objects/premade-objects/sprite-with-glowing-shapes.d.ts +5 -5
  179. package/dist/pixi/display-object/objects/premade-objects/sprite-with-glowing-shapes.js +81 -57
  180. package/dist/pixi/display-object/objects/sprite.d.ts +43 -43
  181. package/dist/pixi/display-object/objects/sprite.js +248 -233
  182. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.js +1 -1
  183. package/dist/pixi/display-object/objects/text/helpers/process-steps/1-data-in-converter/rich-text-data-in-converter.test.js +9 -9
  184. package/dist/pixi/display-object/objects/text/helpers/rich-text-to-plane-text.d.ts +1 -1
  185. package/dist/pixi/display-object/objects/text.d.ts +25 -25
  186. package/dist/pixi/display-object/objects/text.js +111 -102
  187. package/dist/pixi/display-object/premade-objects/sprite-with-glowing-shapes.d.ts +13 -9
  188. package/dist/pixi/display-object/premade-objects/sprite-with-glowing-shapes.js +96 -67
  189. package/dist/pixi/game.d.ts +1 -1
  190. package/dist/pixi/game.js +2 -2
  191. package/dist/pixi/helpers/glow-sprite-generator.d.ts +6 -6
  192. package/dist/pixi/helpers/glow-sprite-generator.js +99 -84
  193. package/dist/pixi/helpers/pixi-container.helper.d.ts +1 -1
  194. package/dist/pixi/helpers/pixi-container.helper.js +10 -8
  195. package/dist/pixi/helpers/screen-position-to-stage.helper.d.ts +1 -1
  196. package/dist/pixi/helpers/screen-position-to-stage.helper.js +12 -12
  197. package/dist/pixi/helpers/screen-position-to-stage.helper.test.js +174 -79
  198. package/dist/pixi/modules/CAMERA/index.d.ts +1 -1
  199. package/dist/pixi/modules/CAMERA/index.js +3 -3
  200. package/dist/pixi/modules/CAMERA//360/237/247/212entities/camera.entity.js +1 -1
  201. package/dist/services/keyboard/keyboard.d.ts +4 -4
  202. package/dist/services/keyboard/keyboard.js +39 -31
  203. package/dist/services/mouse/mouse.service.d.ts +8 -8
  204. package/dist/services/mouse/mouse.service.js +65 -53
  205. package/dist/services/mouse/mouser-target-focus.service.d.ts +11 -11
  206. package/dist/services/mouse/mouser-target-focus.service.js +83 -81
  207. package/dist/utilities/libraries/animator/animating-content/state-animation.d.ts +29 -26
  208. package/dist/utilities/libraries/animator/animating-content/state-animation.js +159 -165
  209. package/dist/utilities/libraries/animator/animating-content/state-animation.test.js +386 -375
  210. package/dist/utilities/libraries/animator/animator.spec.js +765 -656
  211. package/dist/utilities/libraries/binary-heap/binary-heap.d.ts +11 -11
  212. package/dist/utilities/libraries/binary-heap/binary-heap.js +79 -81
  213. package/dist/utilities/libraries/data-structures/binary-heap/binary-heap.d.ts +11 -11
  214. package/dist/utilities/libraries/data-structures/binary-heap/binary-heap.js +79 -81
  215. package/dist/utilities/libraries/data-structures/grid/grid.d.ts +35 -31
  216. package/dist/utilities/libraries/data-structures/grid/grid.js +128 -117
  217. package/dist/utilities/libraries/data-structures/grid/grid.spec.js +176 -138
  218. package/dist/utilities/libraries/data-structures/grid/grid.test.js +218 -141
  219. package/dist/utilities/libraries/data-structures/grid/position-to-grid-position-converter.d.ts +3 -3
  220. package/dist/utilities/libraries/data-structures/grid/position-to-grid-position-converter.js +15 -13
  221. package/dist/utilities/libraries/data-structures/queue/queue.d.ts +21 -21
  222. package/dist/utilities/libraries/data-structures/queue/queue.js +63 -66
  223. package/dist/utilities/libraries/data-structures/queue/queue.test.js +54 -55
  224. package/dist/utilities/libraries/grid-algorithms/closest-available-space/closest-available-space.helper.spec.js +122 -68
  225. package/dist/utilities/libraries/grid-algorithms/path-finder/path-finder.spec.js +140 -135
  226. package/dist/utilities/libraries/grid-algorithms/vector-field-path-finder/vector-field-path-finder.spec.js +293 -229
  227. package/dist/utilities/libraries/path-finder/path-finder.d.ts +7 -7
  228. package/dist/utilities/libraries/path-finder/path-finder.js +113 -109
  229. package/dist/utilities/libraries/path-finder/path-finder.spec.js +131 -106
  230. package/dist/utilities/services/keyboard/keyboard.d.ts +4 -4
  231. package/dist/utilities/services/keyboard/keyboard.js +42 -34
  232. package/dist/utilities/services/mouse/helpers/mouse-position.helper.d.ts +1 -1
  233. package/dist/utilities/services/mouse/helpers/mouse-position.helper.js +12 -12
  234. package/dist/utilities/services/mouse/helpers/mouse-position.helper.test.js +168 -73
  235. package/dist/utilities/services/mouse/mouse-target-focus.service.d.ts +15 -15
  236. package/dist/utilities/services/mouse/mouse-target-focus.service.js +79 -76
  237. package/dist/utilities/services/mouse/mouse.service.d.ts +9 -9
  238. package/dist/utilities/services/mouse/mouse.service.js +86 -72
  239. package/dist/utilities/services/mouse/mouser-target-focus.service.d.ts +11 -11
  240. package/dist/utilities/services/mouse/mouser-target-focus.service.js +83 -81
  241. package/package.json +8 -13
@@ -1,123 +1,127 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ Object.defineProperty(exports, '__esModule', { value: true });
3
2
  exports.PathFinder = void 0;
4
- const helpers_lib_1 = require("helpers-lib");
5
- const binary_heap_1 = require("../binary-heap/binary-heap");
3
+ const helpers_lib_1 = require('helpers-lib');
4
+ const binary_heap_1 = require('../binary-heap/binary-heap');
6
5
  const DIRECTIONS = [
7
- { x: -1, y: -1 },
8
- { x: -1, y: 0 },
9
- { x: -1, y: 1 },
10
- { x: 0, y: -1 },
11
- { x: 0, y: 1 },
12
- { x: 1, y: -1 },
13
- { x: 1, y: 0 },
14
- { x: 1, y: 1 }
6
+ { x: -1, y: -1 },
7
+ { x: -1, y: 0 },
8
+ { x: -1, y: 1 },
9
+ { x: 0, y: -1 },
10
+ { x: 0, y: 1 },
11
+ { x: 1, y: -1 },
12
+ { x: 1, y: 0 },
13
+ { x: 1, y: 1 }
15
14
  ];
16
15
  class Node {
17
- constructor(position, distanceFromStart, distanceToEnd, parent = undefined) {
18
- this.position = position;
19
- this.distanceFromStart = distanceFromStart;
20
- this.distanceToEnd = distanceToEnd;
21
- this.parent = parent;
22
- this.closed = false;
23
- }
24
- get pathLength() {
25
- return this.distanceFromStart + this.distanceToEnd;
26
- }
27
- isEqual(targetPosition) {
28
- return this.position.x === targetPosition.x && this.position.y === targetPosition.y;
29
- }
30
- createSolutionPath(directPathAvailable) {
31
- let path = [this.position];
32
- let current = this.parent;
33
- while (current !== undefined) {
34
- path.push(current.position);
35
- current = current.parent;
36
- }
37
- path.reverse();
38
- return { directPathAvailable, path };
39
- }
40
- getDistance(targetPosition) {
41
- return helpers_lib_1.Vector.getDistance(this.position, targetPosition);
16
+ constructor(position, distanceFromStart, distanceToEnd, parent = undefined) {
17
+ this.position = position;
18
+ this.distanceFromStart = distanceFromStart;
19
+ this.distanceToEnd = distanceToEnd;
20
+ this.parent = parent;
21
+ this.closed = false;
22
+ }
23
+ get pathLength() {
24
+ return this.distanceFromStart + this.distanceToEnd;
25
+ }
26
+ isEqual(targetPosition) {
27
+ return this.position.x === targetPosition.x && this.position.y === targetPosition.y;
28
+ }
29
+ createSolutionPath(directPathAvailable) {
30
+ const path = [this.position];
31
+ let current = this.parent;
32
+ while (current !== undefined) {
33
+ path.push(current.position);
34
+ current = current.parent;
42
35
  }
36
+ path.reverse();
37
+ return { directPathAvailable, path };
38
+ }
39
+ getDistance(targetPosition) {
40
+ return helpers_lib_1.Vector.getDistance(this.position, targetPosition);
41
+ }
43
42
  }
44
43
  class Grid {
45
- constructor(grid, startingPosition) {
46
- this.grid = grid;
47
- this.startingPosition = startingPosition;
48
- this.nodes = new Map();
49
- this.openMinBinaryHeap = new binary_heap_1.BinaryHeap('min');
50
- this.closedSet = [];
51
- this.width = grid[0].length;
52
- this.height = grid.length;
53
- let startingNode = new Node(this.startingPosition, 0, Number.MAX_SAFE_INTEGER);
54
- this.openMinBinaryHeap.add(startingNode.pathLength, startingNode);
55
- }
56
- get hasOpenNodes() {
57
- return this.openMinBinaryHeap.size > 0;
58
- }
59
- getNeighbors(node) {
60
- return DIRECTIONS.map(direction => ({ x: node.position.x + direction.x, y: node.position.y + direction.y }))
61
- .filter(neighborPosition => this.isPositionInsideGrid(neighborPosition) && this.isWalkable(neighborPosition))
62
- .map(neighborPosition => this.nodes.get(neighborPosition.x)?.get(neighborPosition.y) || this.createNewNode(neighborPosition));
63
- }
64
- popLowestPathCostNode() {
65
- let lowestPathNode = this.openMinBinaryHeap.pop();
66
- this.openMinBinaryHeap.delete(lowestPathNode);
67
- lowestPathNode.closed = true;
68
- this.closedSet.push(lowestPathNode);
69
- return lowestPathNode;
70
- }
71
- getBestClosedNode() {
72
- return this.closedSet.reduce((prev, current) => (prev.distanceToEnd < current.distanceToEnd ? prev : current));
73
- }
74
- changeNodeCost(node, distanceFromStart, targetPosition, newParent) {
75
- this.openMinBinaryHeap.delete(node);
76
- node.distanceFromStart = distanceFromStart;
77
- node.distanceToEnd = node.getDistance(targetPosition);
78
- node.parent = newParent;
79
- this.openMinBinaryHeap.add(node.pathLength, node);
80
- }
81
- createNewNode(position) {
82
- let node = new Node(position, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
83
- if (!this.nodes.get(position.x)) {
84
- this.nodes.set(position.x, new Map());
85
- }
86
- this.nodes.get(position.x)?.set(position.y, node);
87
- this.openMinBinaryHeap.add(node.pathLength, node);
88
- return node;
89
- }
90
- isWalkable(position) {
91
- return this.grid[position.y][position.x];
92
- }
93
- isPositionInsideGrid(position) {
94
- return position.x >= 0 && position.x < this.width && position.y >= 0 && position.y < this.height;
44
+ constructor(grid, startingPosition) {
45
+ this.grid = grid;
46
+ this.startingPosition = startingPosition;
47
+ this.nodes = new Map();
48
+ this.openMinBinaryHeap = new binary_heap_1.BinaryHeap('min');
49
+ this.closedSet = [];
50
+ this.width = grid[0].length;
51
+ this.height = grid.length;
52
+ const startingNode = new Node(this.startingPosition, 0, Number.MAX_SAFE_INTEGER);
53
+ this.openMinBinaryHeap.add(startingNode.pathLength, startingNode);
54
+ }
55
+ get hasOpenNodes() {
56
+ return this.openMinBinaryHeap.size > 0;
57
+ }
58
+ getNeighbors(node) {
59
+ return DIRECTIONS.map(direction => ({
60
+ x: node.position.x + direction.x,
61
+ y: node.position.y + direction.y
62
+ }))
63
+ .filter(neighborPosition => this.isPositionInsideGrid(neighborPosition) && this.isWalkable(neighborPosition))
64
+ .map(
65
+ neighborPosition => this.nodes.get(neighborPosition.x)?.get(neighborPosition.y) || this.createNewNode(neighborPosition)
66
+ );
67
+ }
68
+ popLowestPathCostNode() {
69
+ const lowestPathNode = this.openMinBinaryHeap.pop();
70
+ this.openMinBinaryHeap.delete(lowestPathNode);
71
+ lowestPathNode.closed = true;
72
+ this.closedSet.push(lowestPathNode);
73
+ return lowestPathNode;
74
+ }
75
+ getBestClosedNode() {
76
+ return this.closedSet.reduce((prev, current) => (prev.distanceToEnd < current.distanceToEnd ? prev : current));
77
+ }
78
+ changeNodeCost(node, distanceFromStart, targetPosition, newParent) {
79
+ this.openMinBinaryHeap.delete(node);
80
+ node.distanceFromStart = distanceFromStart;
81
+ node.distanceToEnd = node.getDistance(targetPosition);
82
+ node.parent = newParent;
83
+ this.openMinBinaryHeap.add(node.pathLength, node);
84
+ }
85
+ createNewNode(position) {
86
+ const node = new Node(position, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
87
+ if (!this.nodes.get(position.x)) {
88
+ this.nodes.set(position.x, new Map());
95
89
  }
90
+ this.nodes.get(position.x)?.set(position.y, node);
91
+ this.openMinBinaryHeap.add(node.pathLength, node);
92
+ return node;
93
+ }
94
+ isWalkable(position) {
95
+ return this.grid[position.y][position.x];
96
+ }
97
+ isPositionInsideGrid(position) {
98
+ return position.x >= 0 && position.x < this.width && position.y >= 0 && position.y < this.height;
99
+ }
96
100
  }
97
101
  class PathFinder {
98
- /**
99
- * Time Complexity: O(grid.height * grid.width)
100
- * Space Complexity: O(grid.height * grid.width)
101
- */
102
- static findPath(gridValues, startingPosition, targetPosition) {
103
- let grid = new Grid(gridValues, startingPosition);
104
- while (grid.hasOpenNodes) {
105
- let currentNode = grid.popLowestPathCostNode();
106
- if (currentNode.isEqual(targetPosition)) {
107
- return currentNode.createSolutionPath(true);
108
- }
109
- let neighbors = grid.getNeighbors(currentNode);
110
- for (let neighbor of neighbors) {
111
- if (!neighbor.closed) {
112
- let distanceFromStart = currentNode.distanceFromStart + currentNode.getDistance(neighbor.position);
113
- if (distanceFromStart < neighbor.distanceFromStart) {
114
- grid.changeNodeCost(neighbor, distanceFromStart, targetPosition, currentNode);
115
- }
116
- }
117
- }
102
+ /**
103
+ * Time Complexity: O(grid.height * grid.width)
104
+ * Space Complexity: O(grid.height * grid.width)
105
+ */
106
+ static findPath(gridValues, startingPosition, targetPosition) {
107
+ const grid = new Grid(gridValues, startingPosition);
108
+ while (grid.hasOpenNodes) {
109
+ const currentNode = grid.popLowestPathCostNode();
110
+ if (currentNode.isEqual(targetPosition)) {
111
+ return currentNode.createSolutionPath(true);
112
+ }
113
+ const neighbors = grid.getNeighbors(currentNode);
114
+ for (const neighbor of neighbors) {
115
+ if (!neighbor.closed) {
116
+ const distanceFromStart = currentNode.distanceFromStart + currentNode.getDistance(neighbor.position);
117
+ if (distanceFromStart < neighbor.distanceFromStart) {
118
+ grid.changeNodeCost(neighbor, distanceFromStart, targetPosition, currentNode);
119
+ }
118
120
  }
119
- return grid.getBestClosedNode().createSolutionPath(false);
121
+ }
120
122
  }
123
+ return grid.getBestClosedNode().createSolutionPath(false);
124
+ }
121
125
  }
122
126
  exports.PathFinder = PathFinder;
123
- //# sourceMappingURL=path-finder.js.map
127
+ //# sourceMappingURL=path-finder.js.map
@@ -1,116 +1,141 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_finder_1 = require("./path-finder");
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ const path_finder_1 = require('./path-finder');
4
3
  describe('PATH_FINDER', () => {
5
- test('basic 1', () => {
6
- let result = path_finder_1.PathFinder.findPath([[true]], { x: 0, y: 0 }, { x: 0, y: 0 });
7
- expect(result).toEqual({ directPathAvailable: true, path: [{ x: 0, y: 0 }] });
4
+ test('basic 1', () => {
5
+ const result = path_finder_1.PathFinder.findPath([[true]], { x: 0, y: 0 }, { x: 0, y: 0 });
6
+ expect(result).toEqual({
7
+ directPathAvailable: true,
8
+ path: [{ x: 0, y: 0 }]
8
9
  });
9
- test('basic 2', () => {
10
- let result = path_finder_1.PathFinder.findPath([[false]], { x: 0, y: 0 }, { x: 0, y: 0 });
11
- expect(result).toEqual({ directPathAvailable: true, path: [{ x: 0, y: 0 }] });
10
+ });
11
+ test('basic 2', () => {
12
+ const result = path_finder_1.PathFinder.findPath([[false]], { x: 0, y: 0 }, { x: 0, y: 0 });
13
+ expect(result).toEqual({
14
+ directPathAvailable: true,
15
+ path: [{ x: 0, y: 0 }]
12
16
  });
13
- test('should give the shortest path 1', () => {
14
- let result = path_finder_1.PathFinder.findPath([
15
- [true, true, true, true],
16
- [true, false, false, true],
17
- [true, false, false, true],
18
- [true, false, false, true]
19
- ], { x: 0, y: 0 }, { x: 3, y: 3 });
20
- expect(result).toEqual({
21
- directPathAvailable: true,
22
- path: [
23
- { x: 0, y: 0 },
24
- { x: 1, y: 0 },
25
- { x: 2, y: 0 },
26
- { x: 3, y: 1 },
27
- { x: 3, y: 2 },
28
- { x: 3, y: 3 }
29
- ]
30
- });
17
+ });
18
+ test('should give the shortest path 1', () => {
19
+ const result = path_finder_1.PathFinder.findPath(
20
+ [
21
+ [true, true, true, true],
22
+ [true, false, false, true],
23
+ [true, false, false, true],
24
+ [true, false, false, true]
25
+ ],
26
+ { x: 0, y: 0 },
27
+ { x: 3, y: 3 }
28
+ );
29
+ expect(result).toEqual({
30
+ directPathAvailable: true,
31
+ path: [
32
+ { x: 0, y: 0 },
33
+ { x: 1, y: 0 },
34
+ { x: 2, y: 0 },
35
+ { x: 3, y: 1 },
36
+ { x: 3, y: 2 },
37
+ { x: 3, y: 3 }
38
+ ]
31
39
  });
32
- test('should give the shortest path 2', () => {
33
- let result = path_finder_1.PathFinder.findPath([
34
- [true, true, true, false],
35
- [true, false, false, false],
36
- [true, true, false, true],
37
- [true, false, true, true]
38
- ], { x: 0, y: 0 }, { x: 3, y: 3 });
39
- expect(result).toEqual({
40
- directPathAvailable: true,
41
- path: [
42
- { x: 0, y: 0 },
43
- { x: 0, y: 1 },
44
- { x: 1, y: 2 },
45
- { x: 2, y: 3 },
46
- { x: 3, y: 3 }
47
- ]
48
- });
40
+ });
41
+ test('should give the shortest path 2', () => {
42
+ const result = path_finder_1.PathFinder.findPath(
43
+ [
44
+ [true, true, true, false],
45
+ [true, false, false, false],
46
+ [true, true, false, true],
47
+ [true, false, true, true]
48
+ ],
49
+ { x: 0, y: 0 },
50
+ { x: 3, y: 3 }
51
+ );
52
+ expect(result).toEqual({
53
+ directPathAvailable: true,
54
+ path: [
55
+ { x: 0, y: 0 },
56
+ { x: 0, y: 1 },
57
+ { x: 1, y: 2 },
58
+ { x: 2, y: 3 },
59
+ { x: 3, y: 3 }
60
+ ]
49
61
  });
50
- test('should give the shortest path 3', () => {
51
- let result = path_finder_1.PathFinder.findPath([
52
- [true, false, false, true, false],
53
- [true, false, true, false, true],
54
- [true, false, true, false, true],
55
- [false, true, false, false, true]
56
- ], { x: 0, y: 0 }, { x: 4, y: 3 });
57
- expect(result).toEqual({
58
- directPathAvailable: true,
59
- path: [
60
- { x: 0, y: 0 },
61
- { x: 0, y: 1 },
62
- { x: 0, y: 2 },
63
- { x: 1, y: 3 },
64
- { x: 2, y: 2 },
65
- { x: 2, y: 1 },
66
- { x: 3, y: 0 },
67
- { x: 4, y: 1 },
68
- { x: 4, y: 2 },
69
- { x: 4, y: 3 }
70
- ]
71
- });
62
+ });
63
+ test('should give the shortest path 3', () => {
64
+ const result = path_finder_1.PathFinder.findPath(
65
+ [
66
+ [true, false, false, true, false],
67
+ [true, false, true, false, true],
68
+ [true, false, true, false, true],
69
+ [false, true, false, false, true]
70
+ ],
71
+ { x: 0, y: 0 },
72
+ { x: 4, y: 3 }
73
+ );
74
+ expect(result).toEqual({
75
+ directPathAvailable: true,
76
+ path: [
77
+ { x: 0, y: 0 },
78
+ { x: 0, y: 1 },
79
+ { x: 0, y: 2 },
80
+ { x: 1, y: 3 },
81
+ { x: 2, y: 2 },
82
+ { x: 2, y: 1 },
83
+ { x: 3, y: 0 },
84
+ { x: 4, y: 1 },
85
+ { x: 4, y: 2 },
86
+ { x: 4, y: 3 }
87
+ ]
72
88
  });
73
- test('should give the shortest path backwards 3', () => {
74
- let result = path_finder_1.PathFinder.findPath([
75
- [true, false, false, true, false],
76
- [true, false, true, false, true],
77
- [true, false, true, false, true],
78
- [false, true, false, false, true]
79
- ], { x: 4, y: 3 }, { x: 0, y: 0 });
80
- expect(result).toEqual({
81
- directPathAvailable: true,
82
- path: [
83
- { x: 4, y: 3 },
84
- { x: 4, y: 2 },
85
- { x: 4, y: 1 },
86
- { x: 3, y: 0 },
87
- { x: 2, y: 1 },
88
- { x: 2, y: 2 },
89
- { x: 1, y: 3 },
90
- { x: 0, y: 2 },
91
- { x: 0, y: 1 },
92
- { x: 0, y: 0 }
93
- ]
94
- });
89
+ });
90
+ test('should give the shortest path backwards 3', () => {
91
+ const result = path_finder_1.PathFinder.findPath(
92
+ [
93
+ [true, false, false, true, false],
94
+ [true, false, true, false, true],
95
+ [true, false, true, false, true],
96
+ [false, true, false, false, true]
97
+ ],
98
+ { x: 4, y: 3 },
99
+ { x: 0, y: 0 }
100
+ );
101
+ expect(result).toEqual({
102
+ directPathAvailable: true,
103
+ path: [
104
+ { x: 4, y: 3 },
105
+ { x: 4, y: 2 },
106
+ { x: 4, y: 1 },
107
+ { x: 3, y: 0 },
108
+ { x: 2, y: 1 },
109
+ { x: 2, y: 2 },
110
+ { x: 1, y: 3 },
111
+ { x: 0, y: 2 },
112
+ { x: 0, y: 1 },
113
+ { x: 0, y: 0 }
114
+ ]
95
115
  });
96
- test('should give the shortest path to closest position', () => {
97
- let result = path_finder_1.PathFinder.findPath([
98
- [true, true, true, false],
99
- [true, false, false, false],
100
- [true, false, false, false],
101
- [true, true, false, true]
102
- ], { x: 0, y: 0 }, { x: 3, y: 3 });
103
- expect(result).toEqual({
104
- directPathAvailable: false,
105
- path: [
106
- { x: 0, y: 0 },
107
- { x: 0, y: 1 },
108
- { x: 0, y: 2 },
109
- { x: 1, y: 3 }
110
- ]
111
- });
116
+ });
117
+ test('should give the shortest path to closest position', () => {
118
+ const result = path_finder_1.PathFinder.findPath(
119
+ [
120
+ [true, true, true, false],
121
+ [true, false, false, false],
122
+ [true, false, false, false],
123
+ [true, true, false, true]
124
+ ],
125
+ { x: 0, y: 0 },
126
+ { x: 3, y: 3 }
127
+ );
128
+ expect(result).toEqual({
129
+ directPathAvailable: false,
130
+ path: [
131
+ { x: 0, y: 0 },
132
+ { x: 0, y: 1 },
133
+ { x: 0, y: 2 },
134
+ { x: 1, y: 3 }
135
+ ]
112
136
  });
113
- /*
137
+ });
138
+ /*
114
139
  test('stress test', () => {
115
140
  let size = 1600;
116
141
  let centerPos = { x: Math.floor(size / 2), y: Math.floor(size / 2) };
@@ -130,4 +155,4 @@ describe('PATH_FINDER', () => {
130
155
  console.log(end.getTime() - start.getTime());
131
156
  });*/
132
157
  });
133
- //# sourceMappingURL=path-finder.spec.js.map
158
+ //# sourceMappingURL=path-finder.spec.js.map
@@ -1,7 +1,7 @@
1
1
  import { Action } from 'actions-lib';
2
2
  export declare class KeyboardService {
3
- readonly keyPressed: Action<string>;
4
- private listOfPressedKeys;
5
- constructor();
6
- isKeyDown(key: string): boolean;
3
+ readonly keyPressed: Action<string>;
4
+ private listOfPressedKeys;
5
+ constructor();
6
+ isKeyDown(key: string): boolean;
7
7
  }
@@ -1,39 +1,47 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1
+ var __decorate =
2
+ (this && this.__decorate) ||
3
+ ((decorators, target, key, desc) => {
4
+ var c = arguments.length,
5
+ r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
6
+ d;
7
+ if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function')
8
+ r = Reflect.decorate(decorators, target, key, desc);
9
+ else
10
+ for (var i = decorators.length - 1; i >= 0; i--)
11
+ if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
12
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
13
+ });
14
+ var __metadata =
15
+ (this && this.__metadata) ||
16
+ ((k, v) => {
17
+ if (typeof Reflect === 'object' && typeof Reflect.metadata === 'function') return Reflect.metadata(k, v);
18
+ });
19
+ Object.defineProperty(exports, '__esModule', { value: true });
12
20
  exports.KeyboardService = void 0;
13
- const actions_lib_1 = require("actions-lib");
14
- const service_1 = require("../../../game-entities/service/service");
21
+ const actions_lib_1 = require('actions-lib');
22
+ const service_1 = require('../../../game-entities/service/service');
15
23
  let KeyboardService = class KeyboardService {
16
- constructor() {
17
- this.keyPressed = new actions_lib_1.Action();
18
- this.listOfPressedKeys = new Set();
19
- window.addEventListener('keydown', event => {
20
- this.listOfPressedKeys.add(event.key);
21
- !event.repeat && this.keyPressed.trigger(event.key);
22
- });
23
- window.addEventListener('keyup', event => {
24
- this.listOfPressedKeys.delete(event.key);
25
- });
26
- window.addEventListener('blur', () => {
27
- this.listOfPressedKeys.clear();
28
- });
29
- }
30
- isKeyDown(key) {
31
- return this.listOfPressedKeys.has(key);
32
- }
24
+ constructor() {
25
+ this.keyPressed = new actions_lib_1.Action();
26
+ this.listOfPressedKeys = new Set();
27
+ window.addEventListener('keydown', event => {
28
+ this.listOfPressedKeys.add(event.key);
29
+ !event.repeat && this.keyPressed.trigger(event.key);
30
+ });
31
+ window.addEventListener('keyup', event => {
32
+ this.listOfPressedKeys.delete(event.key);
33
+ });
34
+ window.addEventListener('blur', () => {
35
+ this.listOfPressedKeys.clear();
36
+ });
37
+ }
38
+ isKeyDown(key) {
39
+ return this.listOfPressedKeys.has(key);
40
+ }
33
41
  };
34
42
  exports.KeyboardService = KeyboardService;
35
- exports.KeyboardService = KeyboardService = __decorate([
36
- (0, service_1.ServiceDecorator)(),
37
- __metadata("design:paramtypes", [])
38
- ], KeyboardService);
39
- //# sourceMappingURL=keyboard.js.map
43
+ exports.KeyboardService = KeyboardService = __decorate(
44
+ [(0, service_1.ServiceDecorator)(), __metadata('design:paramtypes', [])],
45
+ KeyboardService
46
+ );
47
+ //# sourceMappingURL=keyboard.js.map
@@ -1,4 +1,4 @@
1
1
  import { Vector } from 'helpers-lib';
2
2
  export declare class MousePositionHelper {
3
- static includeScaleInScreenPosition(screenPosition: Vector, gameInstanceScale: number, screenSizeCenter: Vector): Vector;
3
+ static includeScaleInScreenPosition(screenPosition: Vector, gameInstanceScale: number, screenSizeCenter: Vector): Vector;
4
4
  }
@@ -1,17 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ Object.defineProperty(exports, '__esModule', { value: true });
3
2
  exports.MousePositionHelper = void 0;
4
- const helpers_lib_1 = require("helpers-lib");
3
+ const helpers_lib_1 = require('helpers-lib');
5
4
  class MousePositionHelper {
6
- static includeScaleInScreenPosition(screenPosition, gameInstanceScale, screenSizeCenter) {
7
- if (gameInstanceScale !== 1) {
8
- let centerToScaledScreenPosition = helpers_lib_1.Vector.fromTo(screenSizeCenter, screenPosition).multiply(1 / gameInstanceScale);
9
- return screenSizeCenter.add(centerToScaledScreenPosition);
10
- }
11
- else {
12
- return screenPosition;
13
- }
5
+ static includeScaleInScreenPosition(screenPosition, gameInstanceScale, screenSizeCenter) {
6
+ if (gameInstanceScale !== 1) {
7
+ const centerToScaledScreenPosition = helpers_lib_1.Vector.fromTo(screenSizeCenter, screenPosition).multiply(
8
+ 1 / gameInstanceScale
9
+ );
10
+ return screenSizeCenter.add(centerToScaledScreenPosition);
11
+ } else {
12
+ return screenPosition;
14
13
  }
14
+ }
15
15
  }
16
16
  exports.MousePositionHelper = MousePositionHelper;
17
- //# sourceMappingURL=mouse-position.helper.js.map
17
+ //# sourceMappingURL=mouse-position.helper.js.map