bard-legends-framework 0.3.3 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/dist/game-entities/service/service.test.js +24 -8
  2. package/dist/game-entities/service/service.test.js.map +1 -1
  3. package/dist/physics/entity-types/immovable-physics-entity.d.ts +12 -0
  4. package/dist/physics/entity-types/immovable-physics-entity.js +28 -0
  5. package/dist/physics/entity-types/immovable-physics-entity.js.map +1 -0
  6. package/dist/physics/entity-types/movable-entity.d.ts +11 -0
  7. package/dist/physics/entity-types/movable-entity.js +26 -0
  8. package/dist/physics/entity-types/movable-entity.js.map +1 -0
  9. package/dist/physics/entity-types/movable-physics-entity.d.ts +20 -0
  10. package/dist/physics/entity-types/movable-physics-entity.js +96 -0
  11. package/dist/physics/entity-types/movable-physics-entity.js.map +1 -0
  12. package/dist/physics/entity-types/physics-entity.d.ts +31 -0
  13. package/dist/physics/entity-types/physics-entity.js +91 -0
  14. package/dist/physics/entity-types/physics-entity.js.map +1 -0
  15. package/dist/physics/index.d.ts +6 -9
  16. package/dist/physics/index.js +7 -14
  17. package/dist/physics/index.js.map +1 -1
  18. package/dist/physics/interfaces.d.ts +1 -35
  19. package/dist/physics/interfaces.js +1 -2
  20. package/dist/physics/interfaces.js.map +1 -1
  21. package/dist/physics/libs/p2js.helper.d.ts +8 -0
  22. package/dist/physics/libs/p2js.helper.js +31 -0
  23. package/dist/physics/libs/p2js.helper.js.map +1 -0
  24. package/dist/physics/libs/physics-body-groups.d.ts +15 -0
  25. package/dist/physics/libs/physics-body-groups.js +76 -0
  26. package/dist/physics/libs/physics-body-groups.js.map +1 -0
  27. package/dist/physics/libs/position-to-grid-position-converter.d.ts +6 -0
  28. package/dist/physics/libs/position-to-grid-position-converter.js +17 -0
  29. package/dist/physics/libs/position-to-grid-position-converter.js.map +1 -0
  30. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics-internal.controller.d.ts +23 -0
  31. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics-internal.controller.js +50 -0
  32. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics-internal.controller.js.map +1 -0
  33. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.d.ts +28 -0
  34. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.js +59 -0
  35. package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.js.map +1 -0
  36. package/dist/physics/module//342/232/234/357/270/217gateways/dtos/requests.dto.d.ts +15 -0
  37. package/dist/physics/module//342/232/234/357/270/217gateways/dtos/requests.dto.js +3 -0
  38. package/dist/physics/module//342/232/234/357/270/217gateways/dtos/requests.dto.js.map +1 -0
  39. package/dist/physics/module//342/232/234/357/270/217gateways/dtos/responses.dto.d.ts +30 -0
  40. package/dist/physics/module//342/232/234/357/270/217gateways/dtos/responses.dto.js +3 -0
  41. package/dist/physics/module//342/232/234/357/270/217gateways/dtos/responses.dto.js.map +1 -0
  42. package/dist/physics/module//342/232/234/357/270/217gateways/dtos/shared-interfaces.dto.d.ts +21 -0
  43. package/dist/physics/module//342/232/234/357/270/217gateways/dtos/shared-interfaces.dto.js +7 -0
  44. package/dist/physics/module//342/232/234/357/270/217gateways/dtos/shared-interfaces.dto.js.map +1 -0
  45. package/dist/physics/module//342/232/234/357/270/217gateways/index.d.ts +4 -0
  46. package/dist/physics/module//342/232/234/357/270/217gateways/index.js +26 -0
  47. package/dist/physics/module//342/232/234/357/270/217gateways/index.js.map +1 -0
  48. package/dist/physics/module//342/232/234/357/270/217gateways/physics-internal.gateway.d.ts +18 -0
  49. package/dist/physics/module//342/232/234/357/270/217gateways/physics-internal.gateway.js +36 -0
  50. package/dist/physics/module//342/232/234/357/270/217gateways/physics-internal.gateway.js.map +1 -0
  51. package/dist/physics/module//342/232/234/357/270/217gateways/physics.gateway.d.ts +19 -0
  52. package/dist/physics/module//342/232/234/357/270/217gateways/physics.gateway.js +40 -0
  53. package/dist/physics/module//342/232/234/357/270/217gateways/physics.gateway.js.map +1 -0
  54. package/dist/physics/module//360/237/223/220services/availability-grid.service.d.ts +12 -0
  55. package/dist/physics/module//360/237/223/220services/availability-grid.service.js +63 -0
  56. package/dist/physics/module//360/237/223/220services/availability-grid.service.js.map +1 -0
  57. package/dist/physics/module//360/237/223/220services/border.service.d.ts +5 -0
  58. package/dist/physics/module//360/237/223/220services/border.service.js +42 -0
  59. package/dist/physics/module//360/237/223/220services/border.service.js.map +1 -0
  60. package/dist/physics/module//360/237/223/220services/collisions.service.d.ts +10 -0
  61. package/dist/physics/module//360/237/223/220services/collisions.service.js +106 -0
  62. package/dist/physics/module//360/237/223/220services/collisions.service.js.map +1 -0
  63. package/dist/physics/module//360/237/223/220services/debug-visuals.service.d.ts +14 -0
  64. package/dist/physics/module//360/237/223/220services/debug-visuals.service.js +95 -0
  65. package/dist/physics/module//360/237/223/220services/debug-visuals.service.js.map +1 -0
  66. package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.d.ts +14 -0
  67. package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.js +99 -0
  68. package/dist/physics/module//360/237/223/220services/eliptic-explosion.service.js.map +1 -0
  69. package/dist/physics/module//360/237/223/220services/explosion.service.d.ts +14 -0
  70. package/dist/physics/module//360/237/223/220services/explosion.service.js +88 -0
  71. package/dist/physics/module//360/237/223/220services/explosion.service.js.map +1 -0
  72. package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.d.ts +5 -0
  73. package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.js +71 -0
  74. package/dist/physics/module//360/237/223/220services/helpers/ray-cast-hit-converter.js.map +1 -0
  75. package/dist/physics/module//360/237/223/220services/materials.service.d.ts +15 -0
  76. package/dist/physics/module//360/237/223/220services/materials.service.js +120 -0
  77. package/dist/physics/module//360/237/223/220services/materials.service.js.map +1 -0
  78. package/dist/physics/module//360/237/223/220services/path-finder.service.d.ts +15 -0
  79. package/dist/physics/module//360/237/223/220services/path-finder.service.js +92 -0
  80. package/dist/physics/module//360/237/223/220services/path-finder.service.js.map +1 -0
  81. package/dist/physics/module//360/237/223/220services/physics-world.service.d.ts +26 -0
  82. package/dist/physics/module//360/237/223/220services/physics-world.service.js +112 -0
  83. package/dist/physics/module//360/237/223/220services/physics-world.service.js.map +1 -0
  84. package/dist/physics/module//360/237/223/220services/ray-casting.service.d.ts +9 -0
  85. package/dist/physics/module//360/237/223/220services/ray-casting.service.js +92 -0
  86. package/dist/physics/module//360/237/223/220services/ray-casting.service.js.map +1 -0
  87. package/dist/physics/module//360/237/223/220services/shape-creation.service.d.ts +9 -0
  88. package/dist/physics/module//360/237/223/220services/shape-creation.service.js +95 -0
  89. package/dist/physics/module//360/237/223/220services/shape-creation.service.js.map +1 -0
  90. package/dist/physics/module//360/237/247/212entities/border.entity.d.ts +5 -0
  91. package/dist/physics/module//360/237/247/212entities/border.entity.js +25 -0
  92. package/dist/physics/module//360/237/247/212entities/border.entity.js.map +1 -0
  93. package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.d.ts +12 -0
  94. package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.js +40 -0
  95. package/dist/physics/module//360/237/247/212entities/data-structures/availability-grid-cache.js.map +1 -0
  96. package/dist/physics/module//360/237/247/212entities/physics-world.entity.d.ts +30 -0
  97. package/dist/physics/module//360/237/247/212entities/physics-world.entity.js +45 -0
  98. package/dist/physics/module//360/237/247/212entities/physics-world.entity.js.map +1 -0
  99. package/dist/pixi/display-object/objects/graphics.d.ts +1 -0
  100. package/dist/pixi/display-object/objects/graphics.js +7 -0
  101. package/dist/pixi/display-object/objects/graphics.js.map +1 -1
  102. package/dist/pixi/game.d.ts +4 -0
  103. package/dist/pixi/game.js +12 -0
  104. package/dist/pixi/game.js.map +1 -1
  105. package/dist/pixi/helpers/screen-position-to-stage.helper.d.ts +4 -0
  106. package/dist/pixi/helpers/screen-position-to-stage.helper.js +17 -0
  107. package/dist/pixi/helpers/screen-position-to-stage.helper.js.map +1 -0
  108. package/dist/pixi/helpers/screen-position-to-stage.helper.test.d.ts +1 -0
  109. package/dist/pixi/helpers/screen-position-to-stage.helper.test.js +83 -0
  110. package/dist/pixi/helpers/screen-position-to-stage.helper.test.js.map +1 -0
  111. package/dist/pixi/index.d.ts +3 -0
  112. package/dist/pixi/index.js +7 -1
  113. package/dist/pixi/index.js.map +1 -1
  114. package/dist/pixi/services/keyboard/keyboard.d.ts +7 -0
  115. package/dist/pixi/services/keyboard/keyboard.js +39 -0
  116. package/dist/pixi/services/keyboard/keyboard.js.map +1 -0
  117. package/dist/pixi/services/mouse/mouse-target-focus.service.d.ts +20 -0
  118. package/dist/pixi/services/mouse/mouse-target-focus.service.js +85 -0
  119. package/dist/pixi/services/mouse/mouse-target-focus.service.js.map +1 -0
  120. package/dist/pixi/services/mouse/mouse.service.d.ts +10 -0
  121. package/dist/pixi/services/mouse/mouse.service.js +68 -0
  122. package/dist/pixi/services/mouse/mouse.service.js.map +1 -0
  123. package/dist/utilities/index.d.ts +4 -4
  124. package/dist/utilities/index.js +7 -7
  125. package/dist/utilities/index.js.map +1 -1
  126. package/dist/utilities/libraries/grid-algorithms/closest-available-space/closest-available-space.helper.js +3 -2
  127. package/dist/utilities/libraries/grid-algorithms/closest-available-space/closest-available-space.helper.js.map +1 -1
  128. package/package.json +2 -2
  129. package/package.json.bak +2 -2
@@ -0,0 +1,63 @@
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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AvailabilityGridService = void 0;
10
+ const helpers_lib_1 = require("helpers-lib");
11
+ const game_entities_1 = require("../../../game-entities");
12
+ const p2js_helper_1 = require("../../libs/p2js.helper");
13
+ const position_to_grid_position_converter_1 = require("../../libs/position-to-grid-position-converter");
14
+ const physics_body_groups_1 = require("../../libs/physics-body-groups");
15
+ const grid_1 = require("../../../utilities/libraries/data-structures/grid/grid");
16
+ const physics_entity_1 = require("../../entity-types/physics-entity");
17
+ const path_finder_service_1 = require("./path-finder.service");
18
+ const utilities_1 = require("../../../utilities");
19
+ let AvailabilityGridService = class AvailabilityGridService {
20
+ onBodyAdded(physicsWorld, body, physicsBodyGroup) {
21
+ body.aabbNeedsUpdate = true;
22
+ body.updateAABB();
23
+ let boundingBox = p2js_helper_1.P2JSHelper.aabbToBoundingBox(body.aabb);
24
+ physicsWorld.availabilityGridCache.getCollidableGrids(physicsBodyGroup).forEach(item => {
25
+ let gridSpaceBoundingBox = position_to_grid_position_converter_1.PositionToGridPositionConverter.areaToGridArea(boundingBox, item.cellSize);
26
+ item.grid.safeSetArea(gridSpaceBoundingBox, false);
27
+ });
28
+ }
29
+ findClosestAvailableSpace(physicsWorld, body, physicsBodyGroup, gridCellSize = path_finder_service_1.DEFAULT_GRID_CELL_SIZE) {
30
+ body.aabbNeedsUpdate = true;
31
+ body.updateAABB();
32
+ let changeVector = utilities_1.ClosestAvailableSpaceHelper.findByConvertingGridSpace(this.getAvilabilityGrid(physicsWorld, gridCellSize, physicsBodyGroup), p2js_helper_1.P2JSHelper.aabbToBoundingBox(body.aabb), gridCellSize);
33
+ return changeVector;
34
+ }
35
+ getAvilabilityGrid(physicsWorld, cellSize, physicsBodyGroup = physics_body_groups_1.PhysicsBodyGroup.none) {
36
+ let grid = physicsWorld.availabilityGridCache.get(cellSize, physicsBodyGroup);
37
+ if (!grid) {
38
+ grid = this.createGrid(physicsWorld, cellSize, physicsBodyGroup);
39
+ physicsWorld.availabilityGridCache.set(cellSize, physicsBodyGroup, grid);
40
+ }
41
+ return grid;
42
+ }
43
+ createGrid(physicsWorld, cellSize, physicsBodyGroup) {
44
+ let grid = grid_1.Grid.createNew(new helpers_lib_1.Vector(Math.floor(physicsWorld.mapSize.x / cellSize), Math.floor(physicsWorld.mapSize.y / cellSize)), true);
45
+ physicsWorld.p2World.bodies.forEach(p2Body => {
46
+ let physicsEntity = physics_entity_1.PhysicsEntity.getFromP2BodyIdOrFail(p2Body.id);
47
+ if (physicsEntity.includeInPathfinding && physics_body_groups_1.PhysicsBodyGroups.canCollide(physicsEntity.physicsBodyGroup, physicsBodyGroup)) {
48
+ let gridSpaceBoundingBox = this.getGridSpaceBoundingBox(p2Body, cellSize);
49
+ grid?.safeSetArea(gridSpaceBoundingBox, false);
50
+ }
51
+ });
52
+ return grid;
53
+ }
54
+ getGridSpaceBoundingBox(p2Body, cellSize) {
55
+ let boundingBox = p2js_helper_1.P2JSHelper.aabbToBoundingBox(p2Body.aabb);
56
+ return position_to_grid_position_converter_1.PositionToGridPositionConverter.areaToGridArea(boundingBox, cellSize);
57
+ }
58
+ };
59
+ exports.AvailabilityGridService = AvailabilityGridService;
60
+ exports.AvailabilityGridService = AvailabilityGridService = __decorate([
61
+ (0, game_entities_1.ServiceDecorator)()
62
+ ], AvailabilityGridService);
63
+ //# sourceMappingURL=availability-grid.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"availability-grid.service.js","sourceRoot":"","sources":["../../../../src/physics/module/📐services/availability-grid.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6CAAgD;AAEhD,0DAA0D;AAC1D,wDAAoD;AACpD,wGAAiG;AACjG,wEAAqF;AAErF,iFAA8E;AAC9E,sEAAkE;AAClE,+DAA+D;AAC/D,kDAAiE;AAG1D,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAClC,WAAW,CAAC,YAAgC,EAAE,IAAa,EAAE,gBAAkC;QAC7F,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC5B,I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AAC;IAEO,UAAU,CAAC,YAAgC,EAAE,QAAgB,EAAE,gBAAkC;QACvG,IAAI,IAAI,GAAG,WAAI,CAAC,SAAS,CACvB,IAAI,oBAAM,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,QAAQ,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EACxG,IAAI,CACL,CAAC;QAEF,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAC3C,IAAI,aAAa,GAAG,8BAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACnE,IAAI,aAAa,CAAC,oBAAoB,IAAI,uCAAiB,CAAC,UAAU,CAAC,aAAa,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,EAAE,CAAC;gBACzH,IAAI,oBAAoB,GAAG,IAAI,CAAC,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;gBAC1E,IAAI,EAAE,WAAW,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;YACjD,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,uBAAuB,CAAC,MAAe,EAAE,QAAgB;QAC/D,IAAI,WAAW,GAAG,wBAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5D,OAAO,qEAA+B,CAAC,cAAc,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC/E,CAAC;CACF,CAAA;AAhEY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,gCAAgB,GAAE;GACN,uBAAuB,CAgEnC"}
@@ -0,0 +1,5 @@
1
+ import { Vector } from 'helpers-lib';
2
+ export declare class BorderService {
3
+ createBorders(physicsWorldId: string, mapSize: Vector): void;
4
+ private createBorder;
5
+ }
@@ -0,0 +1,42 @@
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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.BorderService = void 0;
10
+ const helpers_lib_1 = require("helpers-lib");
11
+ const __gateways_1 = require("../\u269C\uFE0Fgateways");
12
+ const game_entities_1 = require("../../../game-entities");
13
+ const border_entity_1 = require("../\uD83E\uDDCAentities/border.entity");
14
+ const physics_body_groups_1 = require("../../libs/physics-body-groups");
15
+ const interfaces_1 = require("../../interfaces");
16
+ let BorderService = class BorderService {
17
+ createBorders(physicsWorldId, mapSize) {
18
+ this.createBorder(physicsWorldId, new helpers_lib_1.Vector(mapSize.x / 2, -50), new helpers_lib_1.Vector(mapSize.x + 200, 100)); // Top border
19
+ this.createBorder(physicsWorldId, new helpers_lib_1.Vector(mapSize.x / 2, mapSize.y + 50), new helpers_lib_1.Vector(mapSize.x + 200, 100)); // Bottom border
20
+ this.createBorder(physicsWorldId, new helpers_lib_1.Vector(-50, mapSize.y / 2), new helpers_lib_1.Vector(100, mapSize.y + 200)); // Left border
21
+ this.createBorder(physicsWorldId, new helpers_lib_1.Vector(mapSize.x + 50, mapSize.y / 2), new helpers_lib_1.Vector(100, mapSize.y + 200)); // Right border
22
+ }
23
+ createBorder(physicsWorldId, position, size) {
24
+ return new border_entity_1.BorderEntity(physicsWorldId, {
25
+ shapeDefinition: {
26
+ materialName: __gateways_1.BORDER_MATERIAL_NAME,
27
+ group: physics_body_groups_1.PhysicsBodyGroup.border,
28
+ shapeType: interfaces_1.PhysicsShapeType.rectangle,
29
+ shapeData: { size }
30
+ },
31
+ position,
32
+ rotation: 0,
33
+ addInEmptySpace: false,
34
+ includeOnPathfinding: true
35
+ }).attach(physicsWorldId);
36
+ }
37
+ };
38
+ exports.BorderService = BorderService;
39
+ exports.BorderService = BorderService = __decorate([
40
+ (0, game_entities_1.ServiceDecorator)()
41
+ ], BorderService);
42
+ //# sourceMappingURL=border.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"border.service.js","sourceRoot":"","sources":["../../../../src/physics/module/📐services/border.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6CAAqC;AAErC,wDAAqD;AACrD,0DAA0D;AAC1D,yEAA2D;AAC3D,wEAAkE;AAClE,iDAAoD;AAG7C,IAAM,aAAa,GAAnB,MAAM,aAAa;IACxB,aAAa,CAAC,cAAsB,EAAE,OAAe;QACnD,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,IAAI,oBAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,oBAAM,CAAC,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa;QAClH,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,IAAI,oBAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,oBAAM,CAAC,OAAO,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,gBAAgB;QAChI,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,IAAI,oBAAM,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,oBAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc;QACnH,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,IAAI,oBAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,oBAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe;IACjI,CAAC;IAEO,YAAY,CAAC,cAAsB,EAAE,QAAgB,EAAE,IAAY;QACzE,OAAO,IAAI,4BAAY,CAAC,cAAc,EAAE;YACtC,eAAe,EAAE;gBACf,YAAY,EAAE,iCAAoB;gBAClC,KAAK,EAAE,sCAAgB,CAAC,MAAM;gBAC9B,SAAS,EAAE,6BAAgB,CAAC,SAAS;gBACrC,SAAS,EAAE,EAAE,IAAI,EAAE;aACpB;YACD,QAAQ;YACR,QAAQ,EAAE,CAAC;YACX,eAAe,EAAE,KAAK;YACtB,oBAAoB,EAAE,IAAI;SAC3B,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAC5B,CAAC;CACF,CAAA;AAtBY,sCAAa;wBAAb,aAAa;IADzB,IAAA,gCAAgB,GAAE;GACN,aAAa,CAsBzB"}
@@ -0,0 +1,10 @@
1
+ import { PhysicsWorldEntity } from '../🧊entities/physics-world.entity';
2
+ export declare class CollisionsService {
3
+ registerPhysicsWorld(physicsWorld: PhysicsWorldEntity): void;
4
+ step(physicsWorld: PhysicsWorldEntity, time: number, delta: number): void;
5
+ private handleSpeedLimit;
6
+ private registerContactEquation;
7
+ private getCollisionDetails;
8
+ private getCollisionDetail;
9
+ private getNormals;
10
+ }
@@ -0,0 +1,106 @@
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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.CollisionsService = void 0;
10
+ const helpers_lib_1 = require("helpers-lib");
11
+ const __gateways_1 = require("../\u269C\uFE0Fgateways");
12
+ const game_entities_1 = require("../../../game-entities");
13
+ const physics_entity_1 = require("../../entity-types/physics-entity");
14
+ const p2js_helper_1 = require("../../libs/p2js.helper");
15
+ let CollisionsService = class CollisionsService {
16
+ registerPhysicsWorld(physicsWorld) {
17
+ physicsWorld.p2World.on('beginContact', (event) => {
18
+ event.contactEquations.forEach(contactEquation => {
19
+ this.registerContactEquation(physicsWorld, contactEquation);
20
+ });
21
+ });
22
+ }
23
+ step(physicsWorld, time, delta) {
24
+ physics_entity_1.PhysicsEntity.getPhysicsEntities().forEach(entity => {
25
+ entity['_collisions'] = [];
26
+ });
27
+ physicsWorld.p2World.narrowphase.contactEquations.forEach(contactEquation => {
28
+ this.registerContactEquation(physicsWorld, contactEquation);
29
+ });
30
+ physicsWorld.bodiesInContactWith.forEach((item, bodyId) => {
31
+ this.handleSpeedLimit(item.p2Body);
32
+ item.entity['setCollisionReports'](physicsWorld.collisionReports.get(bodyId) || []);
33
+ });
34
+ physicsWorld.bodiesInContactWith.clear();
35
+ physicsWorld.collisionReports.clear();
36
+ }
37
+ handleSpeedLimit(body) {
38
+ let velocity = p2js_helper_1.P2JSHelper.arrayToVector(body.velocity);
39
+ if (velocity.length > __gateways_1.SPEED_LIMIT) {
40
+ velocity = velocity.normalize(__gateways_1.SPEED_LIMIT);
41
+ body.velocity = p2js_helper_1.P2JSHelper.vectorToArray(velocity);
42
+ }
43
+ body.angularVelocity = Math.min(Math.max(body.angularVelocity, -__gateways_1.ROTATIONAL_SPEED_LIMIT), __gateways_1.ROTATIONAL_SPEED_LIMIT);
44
+ }
45
+ registerContactEquation(physicsWorld, contactEquation) {
46
+ let entityA = physics_entity_1.PhysicsEntity.getFromP2BodyId(contactEquation.bodyA.id);
47
+ let entityB = physics_entity_1.PhysicsEntity.getFromP2BodyId(contactEquation.bodyB.id);
48
+ if (entityA && entityB) {
49
+ physicsWorld.bodiesInContactWith.set(contactEquation.bodyA.id, { p2Body: contactEquation.bodyA, entity: entityA });
50
+ physicsWorld.bodiesInContactWith.set(contactEquation.bodyB.id, { p2Body: contactEquation.bodyB, entity: entityB });
51
+ let bodyACollisions = physicsWorld.collisionReports.get(contactEquation.bodyA.id) || [];
52
+ let bodyBCollisions = physicsWorld.collisionReports.get(contactEquation.bodyB.id) || [];
53
+ let { collisionDetailsA, collisionDetailsB } = this.getCollisionDetails(entityA, entityB, contactEquation);
54
+ bodyACollisions.push({
55
+ self: collisionDetailsA,
56
+ target: collisionDetailsB
57
+ });
58
+ bodyBCollisions.push({
59
+ self: collisionDetailsB,
60
+ target: collisionDetailsA
61
+ });
62
+ physicsWorld.collisionReports.set(contactEquation.bodyA.id, bodyACollisions);
63
+ physicsWorld.collisionReports.set(contactEquation.bodyB.id, bodyBCollisions);
64
+ }
65
+ else {
66
+ console.warn('ContactEquationOrganiser: Entity not found for contact equation', contactEquation);
67
+ }
68
+ }
69
+ getCollisionDetails(entityA, entityB, contactEquation) {
70
+ let dtoA = entityA.convertToDTO();
71
+ let dtoB = entityB.convertToDTO();
72
+ let contactPointA = p2js_helper_1.P2JSHelper.arrayToVector(contactEquation.contactPointA);
73
+ let contactPointB = p2js_helper_1.P2JSHelper.arrayToVector(contactEquation.contactPointB);
74
+ let { normalA, normalB } = this.getNormals(contactEquation);
75
+ return {
76
+ collisionDetailsA: this.getCollisionDetail(dtoA, contactEquation.bodyA.mass, contactPointA, normalA, entityA.area),
77
+ collisionDetailsB: this.getCollisionDetail(dtoB, contactEquation.bodyB.mass, contactPointB, normalB, entityB.area)
78
+ };
79
+ }
80
+ getCollisionDetail(physicsBodyDTOSelf, massSelf, contactPointSelf, normalSelf, areaSelf) {
81
+ let positionRelativeToObject;
82
+ return {
83
+ body: physicsBodyDTOSelf,
84
+ getPositionReletiveToObject: () => {
85
+ if (!positionRelativeToObject) {
86
+ positionRelativeToObject = contactPointSelf.rotate(helpers_lib_1.Radian.toVector(-physicsBodyDTOSelf.rotation));
87
+ }
88
+ return positionRelativeToObject;
89
+ },
90
+ position: contactPointSelf,
91
+ mass: massSelf,
92
+ area: areaSelf,
93
+ normal: normalSelf
94
+ };
95
+ }
96
+ getNormals(contactEquation) {
97
+ let contactEquationNormalA = p2js_helper_1.P2JSHelper.arrayToVector(contactEquation.normalA);
98
+ let contactEquationNormalB = contactEquationNormalA.multiply(-1);
99
+ return { normalA: contactEquationNormalA, normalB: contactEquationNormalB };
100
+ }
101
+ };
102
+ exports.CollisionsService = CollisionsService;
103
+ exports.CollisionsService = CollisionsService = __decorate([
104
+ (0, game_entities_1.ServiceDecorator)()
105
+ ], CollisionsService);
106
+ //# sourceMappingURL=collisions.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collisions.service.js","sourceRoot":"","sources":["../../../../src/physics/module/📐services/collisions.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6CAA6C;AAE7C,wDAAoE;AACpE,0DAA0D;AAC1D,sEAAkE;AAElE,wDAAoD;AAI7C,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,oBAAoB,CAAC,YAAgC;QACnD,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC,cAAc,EAAE,CAAC,KAA2B,EAAE,EAAE;YACtE,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE;gBAC/C,IAAI,CAAC,uBAAuB,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;YAC9D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC,YAAgC,EAAE,IAAY,EAAE,KAAa;QAChE,8BAAa,CAAC,kBAAkB,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YAClD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wB,CAAC;YAClC,CAAC;YACD,QAAQ,EAAE,gBAAgB;YAC1B,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,UAAU;SACnB,CAAC;IACJ,CAAC;IAEO,UAAU,CAAC,eAAmC;QACpD,IAAI,sBAAsB,GAAG,wBAAU,CAAC,aAAa,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC/E,IAAI,sBAAsB,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC;IAC9E,CAAC;CACF,CAAA;AAhHY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,gCAAgB,GAAE;GACN,iBAAiB,CAgH7B"}
@@ -0,0 +1,14 @@
1
+ import { Rectangle, Vector } from 'helpers-lib';
2
+ import { AvailabilityGridService } from './availability-grid.service';
3
+ import { PhysicsWorldEntity } from '../🧊entities/physics-world.entity';
4
+ import { PhysicsBodyGroup } from '../../libs/physics-body-groups';
5
+ import { PathFinderService } from './path-finder.service';
6
+ import { RayCast } from '../⚜️gateways';
7
+ export declare class DebugVisualsService {
8
+ private availabilityGridService;
9
+ private pathFinderService;
10
+ constructor(availabilityGridService: AvailabilityGridService, pathFinderService: PathFinderService);
11
+ printPathfindingTestGrid(physicsWorldId: string, testLayerId: string, target: Vector | string, physicsBodyGroup: PhysicsBodyGroup, area: Rectangle, gridCellSize: number): void;
12
+ createExplosionDebugVisual(physicsWorld: PhysicsWorldEntity, testLayerId: string, rayCasts: RayCast[], explosionCenter: Vector, radius: number, duration?: number): void;
13
+ createElipticExplosionDebugVisual(physicsWorld: PhysicsWorldEntity, testLayerId: string, rayCasts: RayCast[], explosionCenter: Vector, rotation: number, size: Vector, duration?: number): void;
14
+ }
@@ -0,0 +1,95 @@
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;
6
+ 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 });
12
+ exports.DebugVisualsService = void 0;
13
+ const helpers_lib_1 = require("helpers-lib");
14
+ const game_entities_1 = require("../../../game-entities");
15
+ const availability_grid_service_1 = require("./availability-grid.service");
16
+ const physics_world_entity_1 = require("../\uD83E\uDDCAentities/physics-world.entity");
17
+ const path_finder_service_1 = require("./path-finder.service");
18
+ const position_to_grid_position_converter_1 = require("../../libs/position-to-grid-position-converter");
19
+ const pixi_1 = require("../../../pixi");
20
+ const utilities_1 = require("../../../utilities");
21
+ let DebugVisualsService = class DebugVisualsService {
22
+ constructor(availabilityGridService, pathFinderService) {
23
+ this.availabilityGridService = availabilityGridService;
24
+ this.pathFinderService = pathFinderService;
25
+ }
26
+ printPathfindingTestGrid(physicsWorldId, testLayerId, target, physicsBodyGroup, area, gridCellSize) {
27
+ let physicsWorld = physics_world_entity_1.PhysicsWorldEntity.getInstanceByIdOrFail(physicsWorldId);
28
+ let availabilityGrid = this.availabilityGridService.getAvilabilityGrid(physicsWorld, gridCellSize, physicsBodyGroup);
29
+ availabilityGrid
30
+ .map((value, position) => ({
31
+ position: position_to_grid_position_converter_1.PositionToGridPositionConverter.gridPositionToPosition(position, gridCellSize),
32
+ availability: value
33
+ }))
34
+ .forEach(value => {
35
+ if (value.position.isInsideRectangle(area)) {
36
+ let direction = this.pathFinderService.findPathDirection(physicsWorldId, value.position, target, physicsBodyGroup);
37
+ let graphics;
38
+ if (direction === undefined) {
39
+ graphics = pixi_1.Graphics.createRectangle(new helpers_lib_1.Vector(8, 8), 2, helpers_lib_1.ColorHelper.red)
40
+ .parent(testLayerId)
41
+ .setPosition(value.position)
42
+ .attach(physicsWorldId);
43
+ }
44
+ else {
45
+ graphics = pixi_1.Graphics.createArrow(25, value.availability ? helpers_lib_1.ColorHelper.green : helpers_lib_1.ColorHelper.red)
46
+ .parent(testLayerId)
47
+ .setPosition(value.position)
48
+ .setRotation(direction)
49
+ .attach(physicsWorldId);
50
+ }
51
+ let animator = new utilities_1.Animator(graphics, 'alpha', { duration: 1000, animation: new utilities_1.AnimationEaseIn() });
52
+ animator.animate({ alpha: 0 }).then(() => {
53
+ graphics.destroy();
54
+ });
55
+ }
56
+ });
57
+ }
58
+ createExplosionDebugVisual(physicsWorld, testLayerId, rayCasts, explosionCenter, radius, duration = 300) {
59
+ let lineContainer = pixi_1.Container.create().parent(testLayerId).setAlpha(0.5).attach(physicsWorld);
60
+ pixi_1.Graphics.createCircle(radius, helpers_lib_1.ColorHelper.blue)
61
+ .parent(lineContainer)
62
+ .setPosition(explosionCenter)
63
+ .setAlpha(0.5)
64
+ .attach(physicsWorld);
65
+ rayCasts.forEach(ray => {
66
+ let color = ray.hits.length > 0 ? helpers_lib_1.ColorHelper.red : helpers_lib_1.ColorHelper.white;
67
+ pixi_1.Graphics.createVector(explosionCenter, ray.line.to, color).parent(lineContainer).attach(physicsWorld);
68
+ });
69
+ new utilities_1.Animator(lineContainer, 'alpha', { duration, animation: new utilities_1.AnimationEaseIn() }).animate({ alpha: 0 }).then(() => {
70
+ lineContainer.destroy();
71
+ });
72
+ }
73
+ createElipticExplosionDebugVisual(physicsWorld, testLayerId, rayCasts, explosionCenter, rotation, size, duration = 300) {
74
+ let lineContainer = pixi_1.Container.create().parent(testLayerId).setAlpha(0.5).attach(physicsWorld);
75
+ pixi_1.Graphics.createElipse(size, helpers_lib_1.ColorHelper.blue)
76
+ .parent(lineContainer)
77
+ .setPosition(explosionCenter)
78
+ .setRotation(rotation)
79
+ .setAlpha(0.5)
80
+ .attach(physicsWorld);
81
+ rayCasts.forEach(ray => {
82
+ let color = ray.hits.length > 0 ? helpers_lib_1.ColorHelper.red : helpers_lib_1.ColorHelper.white;
83
+ pixi_1.Graphics.createVector(ray.line.from, ray.line.to, color).parent(lineContainer).attach(physicsWorld);
84
+ });
85
+ new utilities_1.Animator(lineContainer, 'alpha', { duration, animation: new utilities_1.AnimationEaseIn() }).animate({ alpha: 0 }).then(() => {
86
+ lineContainer.destroy();
87
+ });
88
+ }
89
+ };
90
+ exports.DebugVisualsService = DebugVisualsService;
91
+ exports.DebugVisualsService = DebugVisualsService = __decorate([
92
+ (0, game_entities_1.ServiceDecorator)(),
93
+ __metadata("design:paramtypes", [availability_grid_service_1.AvailabilityGridService, path_finder_service_1.PathFinderService])
94
+ ], DebugVisualsService);
95
+ //# sourceMappingURL=debug-visuals.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-visuals.service.js","sourceRoot":"","sources":["../../../../src/physics/module/📐services/debug-visuals.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAmE;AAEnE,0DAA0D;AAC1D,2EAAsE;AACtE,uFAAwE;AAExE,+DAA0D;AAC1D,wGAAiG;AAEjG,wCAAoD;AACpD,kDAA+D;AAGxD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,YAAoB,uBAAgD,EAAU,iBAAoC;QAA9F,4BAAuB,GAAvB,uBAAuB,CAAyB;QAAU,sBAAiB,GAAjB,iBAAiB,CAAmB;IAAG,CAAC;IAEtH,wBAAwB,CACtB,cAAsB,EACtB,WAAmB,EACnB,MAAuB,EACvB,gBAAkC,EAClC,IAAe,EACf,YAAoB;QAEpB,IAAI,YAAY,GAAG,yCAAkB,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;QAE5E,IAAI,gBAAgB,GAAG,IAAI,CAA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AAI,CAAC,GAAG,EAAE;YACnH,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAhGY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,gCAAgB,GAAE;qCAE4B,mDAAuB,EAA6B,uCAAiB;GADvG,mBAAmB,CAgG/B"}
@@ -0,0 +1,14 @@
1
+ import { Vector } from 'helpers-lib';
2
+ import { PhysicsBodyGroup } from '../../libs/physics-body-groups';
3
+ import { ExplosionHit, PhysicsExplosionOptions } from '../⚜️gateways';
4
+ import { RayCastingService } from './ray-casting.service';
5
+ import { DebugVisualsService } from './debug-visuals.service';
6
+ export declare class ElipticExplosionService {
7
+ private rayCastingService;
8
+ private debugVisualsService;
9
+ constructor(rayCastingService: RayCastingService, debugVisualsService: DebugVisualsService);
10
+ createElipticExplosion(physicsWorldId: string, explosionCenter: Vector, rotation: number, size: Vector, physicsBodyGroup: PhysicsBodyGroup, severity: number, options?: PhysicsExplosionOptions): ExplosionHit[];
11
+ private createRays;
12
+ private getWidthOfLine;
13
+ private applyForcesToBodies;
14
+ }
@@ -0,0 +1,99 @@
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;
6
+ 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 });
12
+ exports.ElipticExplosionService = void 0;
13
+ const helpers_lib_1 = require("helpers-lib");
14
+ const game_entities_1 = require("../../../game-entities");
15
+ const ray_casting_service_1 = require("./ray-casting.service");
16
+ const debug_visuals_service_1 = require("./debug-visuals.service");
17
+ const physics_world_entity_1 = require("../\uD83E\uDDCAentities/physics-world.entity");
18
+ const ray_cast_hit_converter_1 = require("./helpers/ray-cast-hit-converter");
19
+ const p2js_helper_1 = require("../../libs/p2js.helper");
20
+ const MIN_GAP_BETWEEN_LINES = 15;
21
+ let ElipticExplosionService = class ElipticExplosionService {
22
+ constructor(rayCastingService, debugVisualsService) {
23
+ this.rayCastingService = rayCastingService;
24
+ this.debugVisualsService = debugVisualsService;
25
+ }
26
+ createElipticExplosion(physicsWorldId, explosionCenter, rotation, size, physicsBodyGroup, severity, options) {
27
+ let physicsWorld = physics_world_entity_1.PhysicsWorldEntity.getInstanceByIdOrFail(physicsWorldId);
28
+ let rayCasts = this.createRays(explosionCenter, rotation, size, physicsBodyGroup, options?.hitOnlyClosest === true, physicsWorld);
29
+ let explosionHits = ray_cast_hit_converter_1.RayCastHitConverter.toExplosionHits(rayCasts, false);
30
+ this.applyForcesToBodies(explosionHits, severity);
31
+ if (options?.testLayerId) {
32
+ this.debugVisualsService.createElipticExplosionDebugVisual(physicsWorld, options.testLayerId, rayCasts, explosionCenter, rotation, size, options.debugRayDuration);
33
+ }
34
+ return explosionHits;
35
+ }
36
+ createRays(explosionCenter, rotation, size, physicsBodyGroup, hitOnlyClosest, physicsWorld) {
37
+ let lines = [];
38
+ let centerDirection = helpers_lib_1.Radian.toVector(rotation);
39
+ let lineDirection = helpers_lib_1.Radian.toVector(rotation + helpers_lib_1.Radian.get90);
40
+ let horizontalVector = lineDirection.normalize(size.x);
41
+ lines.push(new helpers_lib_1.Line(explosionCenter, explosionCenter.add(horizontalVector)));
42
+ lines.push(new helpers_lib_1.Line(explosionCenter, explosionCenter.add(horizontalVector.multiply(-1))));
43
+ let verticalVector = centerDirection.normalize(size.y);
44
+ lines.push(new helpers_lib_1.Line(explosionCenter, explosionCenter.add(verticalVector)));
45
+ lines.push(new helpers_lib_1.Line(explosionCenter, explosionCenter.add(verticalVector.multiply(-1))));
46
+ let lineCount = Math.round(size.y / MIN_GAP_BETWEEN_LINES);
47
+ let gap = (size.y / (lineCount * 2 + 1)) * 2;
48
+ let gapVector = centerDirection.normalize(gap);
49
+ let width = size.x;
50
+ let heightSquared = Math.pow(size.y, 2);
51
+ helpers_lib_1.ArrayHelper.createIntegerArray(lineCount).forEach(index => {
52
+ let distanceFromCenter = gap * (index + 1);
53
+ let distanceFromCenterVector = gapVector.multiply(index + 1);
54
+ let vector = lineDirection.normalize(this.getWidthOfLine(width, heightSquared, distanceFromCenter));
55
+ let center1 = explosionCenter.add(distanceFromCenterVector);
56
+ lines.push(new helpers_lib_1.Line(center1, center1.add(vector)));
57
+ lines.push(new helpers_lib_1.Line(center1, center1.add(vector.multiply(-1))));
58
+ let center2 = explosionCenter.add(distanceFromCenterVector.multiply(-1));
59
+ lines.push(new helpers_lib_1.Line(center2, center2.add(vector)));
60
+ lines.push(new helpers_lib_1.Line(center2, center2.add(vector.multiply(-1))));
61
+ });
62
+ return lines.map(line => {
63
+ if (hitOnlyClosest) {
64
+ let hit = this.rayCastingService.castClosest(physicsWorld, line, physicsBodyGroup);
65
+ return { line, hits: hit ? [hit] : [] };
66
+ }
67
+ else {
68
+ let hits = this.rayCastingService.castAllFirstContacts(physicsWorld, line, physicsBodyGroup);
69
+ return { line, hits };
70
+ }
71
+ });
72
+ }
73
+ getWidthOfLine(width, heightSquared, distanceFromCenter) {
74
+ return Math.sqrt(1 - Math.pow(distanceFromCenter, 2) / heightSquared) * width;
75
+ }
76
+ applyForcesToBodies(explosionHits, severity) {
77
+ explosionHits.forEach(explosionHit => {
78
+ explosionHit.raycastResults.forEach(rayCastResult => {
79
+ let hitDirection;
80
+ let force;
81
+ if (rayCastResult.isExternal()) {
82
+ hitDirection = rayCastResult.line.fromTo;
83
+ force = severity * 2;
84
+ }
85
+ else {
86
+ hitDirection = rayCastResult.line.fromTo.multiply(-1);
87
+ force = severity * (1 - rayCastResult.fraction) * 8;
88
+ }
89
+ p2js_helper_1.P2JSHelper.pushBody(rayCastResult.body, rayCastResult.hitPosition(), hitDirection, force);
90
+ });
91
+ });
92
+ }
93
+ };
94
+ exports.ElipticExplosionService = ElipticExplosionService;
95
+ exports.ElipticExplosionService = ElipticExplosionService = __decorate([
96
+ (0, game_entities_1.ServiceDecorator)(),
97
+ __metadata("design:paramtypes", [ray_casting_service_1.RayCastingService, debug_visuals_service_1.DebugVisualsService])
98
+ ], ElipticExplosionService);
99
+ //# sourceMappingURL=eliptic-explosion.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eliptic-explosion.service.js","sourceRoot":"","sources":["../../../../src/physics/module/📐services/eliptic-explosion.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAgE;AAEhE,0DAA0D;AAG1D,+DAA0D;AAC1D,mEAA8D;AAC9D,uFAAwE;AACxE,6EAAuE;AACvE,wDAAoD;AAEpD,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAG1B,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAClC,YAAoB,iBAAoC,EAAU,mBAAwC;QAAtF,sBAAiB,GAAjB,iBAAiB,CAAmB;QAAU,wBAAmB,GAAnB,mBAAmB,CAAqB;IAAG,CAAC;IAE9G,sBAAsB,CACpB,cAAsB,EACtB,eAAuB,EACvB,QAAgB,EAChB,IAAY,EACZ,gBAAkC,EAClC,QAAgB,EAChB,OAAiC;QAEjC,IAAI,YAAY,GAAG,yCAAkB,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;QAC5E,IAAI,QAAQ,GAAc,IAAI,CAAC,UAAU,CACvC,eAAe,EACf,QAAQ,EACR,IAAI,EACJ,gBAAgB,EAChB,OAAO,EAAE,cAAc,KAAK,IAAI,EAChC,YAAY,CACb,CAAC;QAEF,IAAI,aAAa,GAAG,4CAAmB,CAAC,eAAe,CAAC,QAAQ,EAAE,KA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AY,CAAC,cAAc,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;gBAClD,IAAI,YAAoB,CAAC;gBACzB,IAAI,KAAa,CAAC;gBAClB,IAAI,aAAa,CAAC,UAAU,EAAE,EAAE,CAAC;oBAC/B,YAAY,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC;oBACzC,KAAK,GAAG,QAAQ,GAAG,CAAC,CAAC;gBACvB,CAAC;qBAAM,CAAC;oBACN,YAAY,GAAG,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;oBACtD,KAAK,GAAG,QAAQ,GAAG,CAAC,CAAC,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBACtD,CAAC;gBAED,wBAAU,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,aAAa,CAAC,WAAW,EAAE,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;YAC5F,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAjHY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,gCAAgB,GAAE;qCAEsB,uCAAiB,EAA+B,2CAAmB;GAD/F,uBAAuB,CAiHnC"}
@@ -0,0 +1,14 @@
1
+ import { Vector } from 'helpers-lib';
2
+ import { ExplosionHit, PhysicsExplosionOptions } from '../⚜️gateways';
3
+ import { PhysicsBodyGroup } from '../../libs/physics-body-groups';
4
+ import { DebugVisualsService } from './debug-visuals.service';
5
+ import { RayCastingService } from './ray-casting.service';
6
+ export declare class ExplosionService {
7
+ private rayCastingService;
8
+ private debugVisualsService;
9
+ constructor(rayCastingService: RayCastingService, debugVisualsService: DebugVisualsService);
10
+ createExplosion(physicsWorldId: string, explosionCenter: Vector, radius: number, physicsBodyGroup: PhysicsBodyGroup, severity: number, options?: PhysicsExplosionOptions): ExplosionHit[];
11
+ private createRays;
12
+ private applyForcesToBodies;
13
+ private getTotalCountOfRays;
14
+ }
@@ -0,0 +1,88 @@
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;
6
+ 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 });
12
+ exports.ExplosionService = void 0;
13
+ const helpers_lib_1 = require("helpers-lib");
14
+ const game_entities_1 = require("../../../game-entities");
15
+ const physics_world_entity_1 = require("../\uD83E\uDDCAentities/physics-world.entity");
16
+ const p2js_helper_1 = require("../../libs/p2js.helper");
17
+ const ray_cast_hit_converter_1 = require("./helpers/ray-cast-hit-converter");
18
+ const debug_visuals_service_1 = require("./debug-visuals.service");
19
+ const ray_casting_service_1 = require("./ray-casting.service");
20
+ let ExplosionService = class ExplosionService {
21
+ constructor(rayCastingService, debugVisualsService) {
22
+ this.rayCastingService = rayCastingService;
23
+ this.debugVisualsService = debugVisualsService;
24
+ }
25
+ createExplosion(physicsWorldId, explosionCenter, radius, physicsBodyGroup, severity, options) {
26
+ let physicsWorld = physics_world_entity_1.PhysicsWorldEntity.getInstanceByIdOrFail(physicsWorldId);
27
+ let totalCountOfRays = this.getTotalCountOfRays(radius);
28
+ let rayCasts = this.createRays(explosionCenter, radius, physicsBodyGroup, totalCountOfRays, options?.hitOnlyClosest === true, physicsWorld);
29
+ let explosionHits = ray_cast_hit_converter_1.RayCastHitConverter.toExplosionHits(rayCasts);
30
+ this.applyForcesToBodies(explosionCenter, radius, severity, totalCountOfRays, explosionHits);
31
+ if (options?.testLayerId) {
32
+ this.debugVisualsService.createExplosionDebugVisual(physicsWorld, options.testLayerId, rayCasts, explosionCenter, radius, options.debugRayDuration);
33
+ }
34
+ return explosionHits;
35
+ }
36
+ createRays(explosionCenter, radius, physicsBodyGroup, totalCountOfRays, hitOnlyClosest, physicsWorld) {
37
+ let radianPerLine = helpers_lib_1.Radian.get360 / totalCountOfRays;
38
+ let directionVector = new helpers_lib_1.Vector(0, -radius);
39
+ let rotationVector = helpers_lib_1.Radian.toVector(radianPerLine);
40
+ return helpers_lib_1.ArrayHelper.createEmptyArray(totalCountOfRays)
41
+ .map(() => {
42
+ let to = explosionCenter.add(directionVector);
43
+ directionVector = directionVector.rotate(rotationVector);
44
+ return new helpers_lib_1.Line(explosionCenter, to);
45
+ })
46
+ .map(line => {
47
+ if (hitOnlyClosest) {
48
+ let hit = this.rayCastingService.castClosest(physicsWorld, line, physicsBodyGroup);
49
+ return { line, hits: hit ? [hit] : [] };
50
+ }
51
+ else {
52
+ let hits = this.rayCastingService.castAllFirstContacts(physicsWorld, line, physicsBodyGroup);
53
+ return { line, hits };
54
+ }
55
+ });
56
+ }
57
+ applyForcesToBodies(explosionCenter, radius, severity, totalCountOfRays, explosionHits) {
58
+ explosionHits.forEach(explosionHit => {
59
+ if (explosionHit.isExternal) {
60
+ explosionHit.raycastResults.forEach(rayCastResult => {
61
+ let force = severity * (1 - rayCastResult.fraction);
62
+ p2js_helper_1.P2JSHelper.pushBody(rayCastResult.body, rayCastResult.hitPosition(), rayCastResult.line.fromTo, force);
63
+ });
64
+ }
65
+ else {
66
+ let p2Body = explosionHit.body['p2Body'];
67
+ let vectorToCenter = helpers_lib_1.Vector.fromTo(explosionCenter, p2js_helper_1.P2JSHelper.arrayToVector(p2Body.position));
68
+ let fractionToCenter = vectorToCenter.length / radius;
69
+ let force = (severity * totalCountOfRays * fractionToCenter) / 2;
70
+ p2js_helper_1.P2JSHelper.pushBody(p2Body, explosionHit.getHitPosition(), vectorToCenter, force);
71
+ }
72
+ });
73
+ }
74
+ getTotalCountOfRays(radius) {
75
+ if (radius > 100) {
76
+ return Math.floor(radius * 0.3);
77
+ }
78
+ else {
79
+ return Math.floor(radius * 0.26 + 4);
80
+ }
81
+ }
82
+ };
83
+ exports.ExplosionService = ExplosionService;
84
+ exports.ExplosionService = ExplosionService = __decorate([
85
+ (0, game_entities_1.ServiceDecorator)(),
86
+ __metadata("design:paramtypes", [ray_casting_service_1.RayCastingService, debug_visuals_service_1.DebugVisualsService])
87
+ ], ExplosionService);
88
+ //# sourceMappingURL=explosion.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"explosion.service.js","sourceRoot":"","sources":["../../../../src/physics/module/📐services/explosion.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6CAAgE;AAGhE,0DAA0D;AAE1D,uFAAwE;AACxE,wDAAoD;AACpD,6EAAuE;AACvE,mEAA8D;AAC9D,+DAA0D;AAGnD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YAAoB,iBAAoC,EAAU,mBAAwC;QAAtF,sBAAiB,GAAjB,iBAAiB,CAAmB;QAAU,wBAAmB,GAAnB,mBAAmB,CAAqB;IAAG,CAAC;IAE9G,eAAe,CACb,cAAsB,EACtB,eAAuB,EACvB,MAAc,EACd,gBAAkC,EAClC,QAAgB,EAChB,OAAiC;QAEjC,IAAI,YAAY,GAAG,yCAAkB,CAAC,qBAAqB,CAAC,cAAc,CAAC,CAAC;QAC5E,IAAI,gBAAgB,GAAG,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC;QAExD,IAAI,QAAQ,GAAG,IAAI,CAAC,UAAU,CAC5B,eAAe,EACf,MAAM,EACN,gBAAgB,EAChB,gBAAgB,EAChB,OAAO,EAAE,cAAc,KAAK,IAAI,EAChC,YAAY,CACb,CAAC;QACF,IAAI,aAAa,GAAG,4CAAmB,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;Q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;IACL,CAAC;IAEO,mBAAmB,CAAC,MAAc;QACxC,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;CACF,CAAA;AAlGY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,gCAAgB,GAAE;qCAEsB,uCAAiB,EAA+B,2CAAmB;GAD/F,gBAAgB,CAkG5B"}
@@ -0,0 +1,5 @@
1
+ import { ExplosionHit, RayCast } from '../../⚜️gateways';
2
+ export declare class RayCastHitConverter {
3
+ static toExplosionHits(rayCasts: RayCast[], allRaysStartingFromSamePosition?: boolean): ExplosionHit[];
4
+ private static convertRayResultGroupToExplosionHit;
5
+ }