bard-legends-framework 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/physics/entity-types/physics-entity.d.ts +4 -1
- package/dist/physics/entity-types/physics-entity.js +6 -0
- package/dist/physics/entity-types/physics-entity.js.map +1 -1
- package/dist/physics/libs/p2js.helper.d.ts +4 -1
- package/dist/physics/libs/p2js.helper.js +20 -0
- package/dist/physics/libs/p2js.helper.js.map +1 -1
- package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics-internal.controller.d.ts +6 -4
- package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics-internal.controller.js +9 -6
- package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics-internal.controller.js.map +1 -1
- package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.d.ts +13 -8
- package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.js +22 -11
- package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.js.map +1 -1
- package/dist/physics/module//342/232/234/357/270/217gateways/dtos/requests.dto.d.ts +5 -0
- package/dist/physics/module//342/232/234/357/270/217gateways/physics.gateway.d.ts +2 -1
- package/dist/physics/module//342/232/234/357/270/217gateways/physics.gateway.js +4 -1
- package/dist/physics/module//342/232/234/357/270/217gateways/physics.gateway.js.map +1 -1
- package/dist/physics/module//360/237/223/220services/collision/collisions.service.d.ts +10 -0
- package/dist/physics/module//360/237/223/220services/collision/collisions.service.js +106 -0
- package/dist/physics/module//360/237/223/220services/collision/collisions.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/collision/hit-test.service.d.ts +13 -0
- package/dist/physics/module//360/237/223/220services/collision/hit-test.service.js +87 -0
- package/dist/physics/module//360/237/223/220services/collision/hit-test.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/creation/border.service.d.ts +5 -0
- package/dist/physics/module//360/237/223/220services/creation/border.service.js +42 -0
- package/dist/physics/module//360/237/223/220services/creation/border.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/creation/materials.service.d.ts +15 -0
- package/dist/physics/module//360/237/223/220services/creation/materials.service.js +120 -0
- package/dist/physics/module//360/237/223/220services/creation/materials.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/creation/physics-world.service.d.ts +21 -0
- package/dist/physics/module//360/237/223/220services/creation/physics-world.service.js +109 -0
- package/dist/physics/module//360/237/223/220services/creation/physics-world.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/creation/shape-creation.service.d.ts +9 -0
- package/dist/physics/module//360/237/223/220services/creation/shape-creation.service.js +97 -0
- package/dist/physics/module//360/237/223/220services/creation/shape-creation.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.d.ts +14 -0
- package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.js +102 -0
- package/dist/physics/module//360/237/223/220services/explosions/eliptic-explosion.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/explosions/explosion.service.d.ts +14 -0
- package/dist/physics/module//360/237/223/220services/explosions/explosion.service.js +87 -0
- package/dist/physics/module//360/237/223/220services/explosions/explosion.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.d.ts +9 -0
- package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.js +73 -0
- package/dist/physics/module//360/237/223/220services/explosions/helpers/ray-cast-hit-converter.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/path-finding/availability-grid.service.d.ts +12 -0
- package/dist/physics/module//360/237/223/220services/path-finding/availability-grid.service.js +63 -0
- package/dist/physics/module//360/237/223/220services/path-finding/availability-grid.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/path-finding/path-finder.service.d.ts +15 -0
- package/dist/physics/module//360/237/223/220services/path-finding/path-finder.service.js +92 -0
- package/dist/physics/module//360/237/223/220services/path-finding/path-finder.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/query/physics-query.service.d.ts +9 -0
- package/dist/physics/module//360/237/223/220services/query/physics-query.service.js +25 -0
- package/dist/physics/module//360/237/223/220services/query/physics-query.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/ray-casting/ray-casting.service.d.ts +9 -0
- package/dist/physics/module//360/237/223/220services/ray-casting/ray-casting.service.js +92 -0
- package/dist/physics/module//360/237/223/220services/ray-casting/ray-casting.service.js.map +1 -0
- package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.d.ts +22 -0
- package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js +135 -0
- package/dist/physics/module//360/237/223/220services/test-visuals/test-visuals.service.js.map +1 -0
- package/package.json +1 -1
- package/package.json.bak +1 -1
|
@@ -14,18 +14,21 @@ export declare abstract class PhysicsEntity extends Entity {
|
|
|
14
14
|
get area(): number;
|
|
15
15
|
get mass(): number;
|
|
16
16
|
get collisions(): ReadonlyArray<CollisionReport>;
|
|
17
|
+
readonly physicsWorldId: string;
|
|
17
18
|
readonly physicsBodyGroup: PhysicsBodyGroup;
|
|
18
19
|
readonly includeInPathfinding: boolean;
|
|
19
20
|
protected readonly p2Body: p2.Body;
|
|
20
21
|
protected readonly type: 'dynamic' | 'static';
|
|
21
22
|
protected physicsDestroy: () => void;
|
|
22
|
-
private readonly physicsWorldId;
|
|
23
23
|
private readonly physicsInternalGateway;
|
|
24
|
+
private physicsGroup;
|
|
25
|
+
private physicsMask;
|
|
24
26
|
private _area;
|
|
25
27
|
private _mass;
|
|
26
28
|
private _collisions;
|
|
27
29
|
constructor(physicsWorldId: string, physicsEntityDefinition: PhysicsEntityDefinition, type: 'dynamic' | 'static');
|
|
28
30
|
abstract convertToDTO(): PhysicsBodyDTO;
|
|
29
31
|
destroy(): void;
|
|
32
|
+
canCollideWith(target: PhysicsEntity): boolean;
|
|
30
33
|
protected setCollisionReports(collisionReports: CollisionReport[]): void;
|
|
31
34
|
}
|
|
@@ -6,6 +6,7 @@ const physics_internal_gateway_1 = require("../module/\u269C\uFE0Fgateways/physi
|
|
|
6
6
|
const p2js_helper_1 = require("../libs/p2js.helper");
|
|
7
7
|
const game_entities_1 = require("../../game-entities");
|
|
8
8
|
const update_cycle_1 = require("../../game-entities/update-cycle");
|
|
9
|
+
const physics_body_groups_1 = require("../libs/physics-body-groups");
|
|
9
10
|
class PhysicsEntity extends game_entities_1.Entity {
|
|
10
11
|
static { this.p2BodyIdToPhysicsBody = new Map(); }
|
|
11
12
|
static { this.physicsEntities = new Map(); }
|
|
@@ -57,6 +58,8 @@ class PhysicsEntity extends game_entities_1.Entity {
|
|
|
57
58
|
this.type = type;
|
|
58
59
|
this.physicsBodyGroup = physicsEntityDefinition.shapeDefinition.group;
|
|
59
60
|
this.includeInPathfinding = physicsEntityDefinition.includeOnPathfinding;
|
|
61
|
+
this.physicsGroup = physics_body_groups_1.PhysicsBodyGroups.getGroupConstant(this.physicsBodyGroup);
|
|
62
|
+
this.physicsMask = physics_body_groups_1.PhysicsBodyGroups.getMaskConstant(this.physicsBodyGroup);
|
|
60
63
|
this.p2Body = this.physicsInternalGateway.createBody(physicsEntityDefinition, material, materialDefinition, this.type);
|
|
61
64
|
this._area = this.p2Body.getArea();
|
|
62
65
|
this._mass = this.p2Body.mass;
|
|
@@ -79,6 +82,9 @@ class PhysicsEntity extends game_entities_1.Entity {
|
|
|
79
82
|
};
|
|
80
83
|
}
|
|
81
84
|
destroy() { }
|
|
85
|
+
canCollideWith(target) {
|
|
86
|
+
return p2js_helper_1.P2JSHelper.arePhysicsGroupsCollidable(this.physicsGroup, this.physicsMask, target.physicsGroup, target.physicsMask);
|
|
87
|
+
}
|
|
82
88
|
// Managed by CollisionsService
|
|
83
89
|
setCollisionReports(collisionReports) {
|
|
84
90
|
this._collisions = collisionReports;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physics-entity.js","sourceRoot":"","sources":["../../../src/physics/entity-types/physics-entity.ts"],"names":[],"mappings":";;;AAAA,6CAAqC;AAGrC,sG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AG,IAAI,CAAC;gBACtB,IAAI,CAAC,iBAAiB,EAAE,CAAC;gBACzB,IAAI,CAAC,aAAa,EAAE,CAAC;gBACrB,IAAI,CAAC,cAAc,EAAE,CAAC;gBACtB,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IAID,OAAO,KAAU,CAAC;IAElB,cAAc,CAAC,MAAqB;QAClC,OAAO,wBAAU,CAAC,0BAA0B,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAC7H,CAAC;IAED,+BAA+B;IACrB,mBAAmB,CAAC,gBAAmC;QAC/D,IAAI,CAAC,WAAW,GAAG,gBAAgB,CAAC;QACpC,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;;AAnIH,sCAoIC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
/// <reference types="p2" />
|
|
2
1
|
import { Rectangle, Vector } from 'helpers-lib';
|
|
2
|
+
import p2 from 'p2';
|
|
3
3
|
export declare class P2JSHelper {
|
|
4
4
|
static aabbToBoundingBox(aabb: p2.AABB): Rectangle;
|
|
5
5
|
static arrayToVector(array: [number, number]): Vector;
|
|
6
6
|
static vectorToArray(vector: Vector): [number, number];
|
|
7
7
|
static pushBody(body: p2.Body, hitPosition: Vector, hitDirection: Vector, severity: number): void;
|
|
8
|
+
static arePhysicsGroupsCollidable(groupA: number, maskA: number, groupB: number, maskB: number): boolean;
|
|
9
|
+
static canCollideWith(p2BodyA: p2.Body, p2BodyB: p2.Body): boolean;
|
|
10
|
+
static cloneP2Body(p2Body: p2.Body): p2.Body;
|
|
8
11
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.P2JSHelper = void 0;
|
|
4
7
|
const helpers_lib_1 = require("helpers-lib");
|
|
8
|
+
const p2_1 = __importDefault(require("p2"));
|
|
5
9
|
class P2JSHelper {
|
|
6
10
|
static aabbToBoundingBox(aabb) {
|
|
7
11
|
return helpers_lib_1.Rectangle.fromRect({
|
|
@@ -26,6 +30,22 @@ class P2JSHelper {
|
|
|
26
30
|
let relativePoint = [hitPosition.x - body.position[0], hitPosition.y - body.position[1]];
|
|
27
31
|
body.applyImpulse(this.vectorToArray(impulse), relativePoint);
|
|
28
32
|
}
|
|
33
|
+
static arePhysicsGroupsCollidable(groupA, maskA, groupB, maskB) {
|
|
34
|
+
// eslint-disable-next-line no-bitwise
|
|
35
|
+
return (groupA & maskB) !== 0 && (groupB & maskA) !== 0;
|
|
36
|
+
}
|
|
37
|
+
static canCollideWith(p2BodyA, p2BodyB) {
|
|
38
|
+
return p2BodyA.shapes.some(shapeA => p2BodyB.shapes.some(shapeB => P2JSHelper.arePhysicsGroupsCollidable(shapeA.collisionGroup, shapeA.collisionMask, shapeB.collisionGroup, shapeB.collisionMask)));
|
|
39
|
+
}
|
|
40
|
+
static cloneP2Body(p2Body) {
|
|
41
|
+
let clone = new p2_1.default.Body({
|
|
42
|
+
position: p2Body.position,
|
|
43
|
+
angle: p2Body.angle,
|
|
44
|
+
type: p2Body.type
|
|
45
|
+
});
|
|
46
|
+
clone.shapes = p2Body.shapes;
|
|
47
|
+
return clone;
|
|
48
|
+
}
|
|
29
49
|
}
|
|
30
50
|
exports.P2JSHelper = P2JSHelper;
|
|
31
51
|
//# sourceMappingURL=p2js.helper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"p2js.helper.js","sourceRoot":"","sources":["../../../src/physics/libs/p2js.helper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"p2js.helper.js","sourceRoot":"","sources":["../../../src/physics/libs/p2js.helper.ts"],"names":[],"mappings":";;;;;;AAAA,6CAAgD;AAChD,4CAAoB;AAEpB,MAAa,UAAU;IACrB,MAAM,CAAC,iBAAiB,CAAC,IAAa;QACpC,OAAO,uBAAS,CAAC,QAAQ,CAAC;YACxB,OAAO,EAAE;gBACP,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;gBACrB,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;aACtB;YACD,WAAW,EAAE;gBACX,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;gBACrB,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;aACtB;SACF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,KAAuB;QAC1C,OAAO,IAAI,oBAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,MAAc;QACjC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,IAAa,EAAE,WAAmB,EAAE,YAAoB,EAAE,QAAgB;QACxF,IAAI,OAAO,GAAG,YAAY,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,aAAa,GAAqB,CAAC,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QAC3G,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,CAAC,0BAA0B,CAAC,MAAc,EAAE,KAAa,EAAE,MAAc,EAAE,KAAa;QAC5F,sCAAsC;QACtC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,OAAgB,EAAE,OAAgB;QACtD,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAClC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAC3B,UAAU,CAAC,0BAA0B,CACnC,MAAM,CAAC,cAAc,EACrB,MAAM,CAAC,aAAa,EACpB,MAAM,CAAC,cAAc,EACrB,MAAM,CAAC,aAAa,CACrB,CACF,CACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,MAAe;QAChC,IAAI,KAAK,GAAG,IAAI,YAAE,CAAC,IAAI,CAAC;YACtB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;SAClB,CAAC,CAAC;QACH,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAvDD,gCAuDC"}
|
|
@@ -2,15 +2,17 @@
|
|
|
2
2
|
import { ActionListenerCallbackFunction, ActionSubscription } from 'actions-lib';
|
|
3
3
|
import { PhysicsEntityDefinition } from '../../../interfaces';
|
|
4
4
|
import { PhysicsBodyGroup } from '../../../libs/physics-body-groups';
|
|
5
|
-
import { MaterialsService } from '../../📐services/materials.service';
|
|
6
|
-
import { PhysicsWorldService } from '../../📐services/physics-world.service';
|
|
7
|
-
import { ShapeCreationService } from '../../📐services/shape-creation.service';
|
|
5
|
+
import { MaterialsService } from '../../📐services/creation/materials.service';
|
|
6
|
+
import { PhysicsWorldService } from '../../📐services/creation/physics-world.service';
|
|
7
|
+
import { ShapeCreationService } from '../../📐services/creation/shape-creation.service';
|
|
8
8
|
import { MaterialDefinition } from '../dtos/shared-interfaces.dto';
|
|
9
|
+
import { PhysicsQueryService } from '../../📐services/query/physics-query.service';
|
|
9
10
|
export declare class PhysicsInternalController {
|
|
10
11
|
private physicsWorldService;
|
|
11
12
|
private physicsMaterialsService;
|
|
12
13
|
private shapeCreationService;
|
|
13
|
-
|
|
14
|
+
private physicsQueryService;
|
|
15
|
+
constructor(physicsWorldService: PhysicsWorldService, physicsMaterialsService: MaterialsService, shapeCreationService: ShapeCreationService, physicsQueryService: PhysicsQueryService);
|
|
14
16
|
createBody(physicsEntityDefinition: PhysicsEntityDefinition, material: p2.Material, materialDefinition: MaterialDefinition, type: 'dynamic' | 'static'): p2.Body;
|
|
15
17
|
getMaterial(physicsWorldId: string, name: string): p2.Material;
|
|
16
18
|
getMaterialDefinition(physicsWorldId: string, name: string): MaterialDefinition;
|
|
@@ -10,16 +10,18 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PhysicsInternalController = void 0;
|
|
13
|
-
const materials_service_1 = require("../../\uD83D\uDCD0services/materials.service");
|
|
14
|
-
const physics_world_service_1 = require("../../\uD83D\uDCD0services/physics-world.service");
|
|
15
|
-
const shape_creation_service_1 = require("../../\uD83D\uDCD0services/shape-creation.service");
|
|
13
|
+
const materials_service_1 = require("../../\uD83D\uDCD0services/creation/materials.service");
|
|
14
|
+
const physics_world_service_1 = require("../../\uD83D\uDCD0services/creation/physics-world.service");
|
|
15
|
+
const shape_creation_service_1 = require("../../\uD83D\uDCD0services/creation/shape-creation.service");
|
|
16
16
|
const game_entities_1 = require("../../../../game-entities");
|
|
17
17
|
const physics_internal_gateway_1 = require("../physics-internal.gateway");
|
|
18
|
+
const physics_query_service_1 = require("../../\uD83D\uDCD0services/query/physics-query.service");
|
|
18
19
|
let PhysicsInternalController = class PhysicsInternalController {
|
|
19
|
-
constructor(physicsWorldService, physicsMaterialsService, shapeCreationService) {
|
|
20
|
+
constructor(physicsWorldService, physicsMaterialsService, shapeCreationService, physicsQueryService) {
|
|
20
21
|
this.physicsWorldService = physicsWorldService;
|
|
21
22
|
this.physicsMaterialsService = physicsMaterialsService;
|
|
22
23
|
this.shapeCreationService = shapeCreationService;
|
|
24
|
+
this.physicsQueryService = physicsQueryService;
|
|
23
25
|
}
|
|
24
26
|
createBody(physicsEntityDefinition, material, materialDefinition, type) {
|
|
25
27
|
return this.shapeCreationService.createBody(physicsEntityDefinition, material, materialDefinition, type);
|
|
@@ -37,7 +39,7 @@ let PhysicsInternalController = class PhysicsInternalController {
|
|
|
37
39
|
this.physicsWorldService.removeBody(physicsWorldId, p2Body);
|
|
38
40
|
}
|
|
39
41
|
subscribeToPhysicsStep(physicsWorldId, callback) {
|
|
40
|
-
return this.
|
|
42
|
+
return this.physicsQueryService.subscribeToPhysicsStep(physicsWorldId, callback);
|
|
41
43
|
}
|
|
42
44
|
};
|
|
43
45
|
exports.PhysicsInternalController = PhysicsInternalController;
|
|
@@ -45,6 +47,7 @@ exports.PhysicsInternalController = PhysicsInternalController = __decorate([
|
|
|
45
47
|
(0, game_entities_1.ControllerDecorator)({ controllerLink: physics_internal_gateway_1.PhysicsInternalControllerLink }),
|
|
46
48
|
__metadata("design:paramtypes", [physics_world_service_1.PhysicsWorldService,
|
|
47
49
|
materials_service_1.MaterialsService,
|
|
48
|
-
shape_creation_service_1.ShapeCreationService
|
|
50
|
+
shape_creation_service_1.ShapeCreationService,
|
|
51
|
+
physics_query_service_1.PhysicsQueryService])
|
|
49
52
|
], PhysicsInternalController);
|
|
50
53
|
//# sourceMappingURL=physics-internal.controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physics-internal.controller.js","sourceRoot":"","sources":["../../../../../src/physics/module/⚜️gateways/controllers/physics-internal.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,
|
|
1
|
+
{"version":3,"file":"physics-internal.controller.js","sourceRoot":"","sources":["../../../../../src/physics/module/⚜️gateways/controllers/physics-internal.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,6FAA+E;AAC/E,qGAAsF;AACtF,uGAAwF;AACxF,6DAAgE;AAChE,0EAA4E;AAE5E,kGAAmF;AAG5E,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IACpC,YACU,mBAAwC,EACxC,uBAAyC,EACzC,oBAA0C,EAC1C,mBAAwC;QAHxC,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,4BAAuB,GAAvB,uBAAuB,CAAkB;QACzC,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,wBAAmB,GAAnB,mBAAmB,CAAqB;IAC/C,CAAC;IAEJ,UAAU,CACR,uBAAgD,EAChD,QAAqB,EACrB,kBAAsC,EACtC,IAA0B;QAE1B,OAAO,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,uBAAuB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAC3G,CAAC;IAED,WAAW,CAAC,cAAsB,EAAE,IAAY;QAC9C,OAAO,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IACxE,CAAC;IAED,qBAAqB,CAAC,cAAsB,EAAE,IAAY;QACxD,OAAO,IAAI,CAAC,uBAAuB,CAAC,qBAAqB,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAClF,CAAC;IAED,OAAO,CACL,cAAsB,EACtB,IAAa,EACb,eAAwB,EACxB,gBAAkC,EAClC,oBAA6B;QAE7B,OAAO,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,EAAE,eAAe,EAAE,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;IACzH,CAAC;IAED,UAAU,CAAC,cAAsB,EAAE,MAAe;QAChD,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAC9D,CAAC;IAED,sBAAsB,CACpB,cAAsB,EACtB,QAAyE;QAEzE,OAAO,IAAI,CAAC,mBAAmB,CAAC,sBAAsB,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;IACnF,CAAC;CACF,CAAA;AA7CY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mCAAmB,EAAC,EAAE,cAAc,EAAE,wDAA6B,EAAE,CAAC;qCAGtC,2CAAmB;QACf,oCAAgB;QACnB,6CAAoB;QACrB,2CAAmB;GALvC,yBAAyB,CA6CrC"}
|
package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.d.ts
CHANGED
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { Rectangle, Vector } from 'helpers-lib';
|
|
2
|
-
import { PhysicsWorldService } from '../../📐services/physics-world.service';
|
|
3
|
-
import { CreatePhysicsWorldRequestDTO, PhysicsExplosionOptions } from '../dtos/requests.dto';
|
|
2
|
+
import { PhysicsWorldService } from '../../📐services/creation/physics-world.service';
|
|
3
|
+
import { CreatePhysicsWorldRequestDTO, HitTestOptions, PhysicsExplosionOptions } from '../dtos/requests.dto';
|
|
4
4
|
import { PhysicsBodyGroup } from '../../../libs/physics-body-groups';
|
|
5
5
|
import { PathFinderResult } from '../../../../utilities/libraries/grid-algorithms/path-finder/path-finder';
|
|
6
|
-
import { PathFinderService } from '../../📐services/path-finder.service';
|
|
7
|
-
import {
|
|
6
|
+
import { PathFinderService } from '../../📐services/path-finding/path-finder.service';
|
|
7
|
+
import { TestVisualsService } from '../../📐services/test-visuals/test-visuals.service';
|
|
8
8
|
import { ExplosionHit, MapSizeDTO } from '../dtos/responses.dto';
|
|
9
|
-
import { ExplosionService } from '../../📐services/explosion.service';
|
|
10
|
-
import { ElipticExplosionService } from '../../📐services/eliptic-explosion.service';
|
|
9
|
+
import { ExplosionService } from '../../📐services/explosions/explosion.service';
|
|
10
|
+
import { ElipticExplosionService } from '../../📐services/explosions/eliptic-explosion.service';
|
|
11
|
+
import { HitTestService } from '../../📐services/collision/hit-test.service';
|
|
12
|
+
import { PhysicsQueryService } from '../../📐services/query/physics-query.service';
|
|
11
13
|
export declare class PhysicsController {
|
|
12
14
|
private physicsWorldService;
|
|
13
15
|
private pathFinderService;
|
|
14
|
-
private
|
|
16
|
+
private testVisualsService;
|
|
15
17
|
private explosionService;
|
|
16
18
|
private elipticExplosionService;
|
|
17
|
-
|
|
19
|
+
private hitTestService;
|
|
20
|
+
private physicsQueryService;
|
|
21
|
+
constructor(physicsWorldService: PhysicsWorldService, pathFinderService: PathFinderService, testVisualsService: TestVisualsService, explosionService: ExplosionService, elipticExplosionService: ElipticExplosionService, hitTestService: HitTestService, physicsQueryService: PhysicsQueryService);
|
|
18
22
|
createPhysicsWorld(request: CreatePhysicsWorldRequestDTO): string;
|
|
19
23
|
getMapSize(physicsWorldId: string): MapSizeDTO;
|
|
24
|
+
hitTest(physicsEntityId: string, options?: HitTestOptions): boolean;
|
|
20
25
|
findPath(physicsWorldId: string, startingPosition: Vector, target: Vector | string, options?: {
|
|
21
26
|
includeDiagonals?: boolean;
|
|
22
27
|
collidableWithGroup?: PhysicsBodyGroup;
|
package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.js
CHANGED
|
@@ -11,25 +11,34 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PhysicsController = void 0;
|
|
13
13
|
const game_entities_1 = require("../../../../game-entities");
|
|
14
|
-
const physics_world_service_1 = require("../../\uD83D\uDCD0services/physics-world.service");
|
|
14
|
+
const physics_world_service_1 = require("../../\uD83D\uDCD0services/creation/physics-world.service");
|
|
15
15
|
const physics_gateway_1 = require("../physics.gateway");
|
|
16
|
-
const path_finder_service_1 = require("../../\uD83D\uDCD0services/path-finder.service");
|
|
17
|
-
const
|
|
18
|
-
const explosion_service_1 = require("../../\uD83D\uDCD0services/explosion.service");
|
|
19
|
-
const eliptic_explosion_service_1 = require("../../\uD83D\uDCD0services/eliptic-explosion.service");
|
|
16
|
+
const path_finder_service_1 = require("../../\uD83D\uDCD0services/path-finding/path-finder.service");
|
|
17
|
+
const test_visuals_service_1 = require("../../\uD83D\uDCD0services/test-visuals/test-visuals.service");
|
|
18
|
+
const explosion_service_1 = require("../../\uD83D\uDCD0services/explosions/explosion.service");
|
|
19
|
+
const eliptic_explosion_service_1 = require("../../\uD83D\uDCD0services/explosions/eliptic-explosion.service");
|
|
20
|
+
const hit_test_service_1 = require("../../\uD83D\uDCD0services/collision/hit-test.service");
|
|
21
|
+
const physics_query_service_1 = require("../../\uD83D\uDCD0services/query/physics-query.service");
|
|
22
|
+
const physics_entity_1 = require("../../../entity-types/physics-entity");
|
|
20
23
|
let PhysicsController = class PhysicsController {
|
|
21
|
-
constructor(physicsWorldService, pathFinderService,
|
|
24
|
+
constructor(physicsWorldService, pathFinderService, testVisualsService, explosionService, elipticExplosionService, hitTestService, physicsQueryService) {
|
|
22
25
|
this.physicsWorldService = physicsWorldService;
|
|
23
26
|
this.pathFinderService = pathFinderService;
|
|
24
|
-
this.
|
|
27
|
+
this.testVisualsService = testVisualsService;
|
|
25
28
|
this.explosionService = explosionService;
|
|
26
29
|
this.elipticExplosionService = elipticExplosionService;
|
|
30
|
+
this.hitTestService = hitTestService;
|
|
31
|
+
this.physicsQueryService = physicsQueryService;
|
|
27
32
|
}
|
|
28
33
|
createPhysicsWorld(request) {
|
|
29
34
|
return this.physicsWorldService.createPhysicsWorld(request);
|
|
30
35
|
}
|
|
31
36
|
getMapSize(physicsWorldId) {
|
|
32
|
-
return this.
|
|
37
|
+
return this.physicsQueryService.getMapSize(physicsWorldId);
|
|
38
|
+
}
|
|
39
|
+
hitTest(physicsEntityId, options) {
|
|
40
|
+
let physicsEntity = physics_entity_1.PhysicsEntity.getPhysicsInstanceOrFail(physicsEntityId);
|
|
41
|
+
return this.hitTestService.hitTest(physicsEntity['p2Body'], options);
|
|
33
42
|
}
|
|
34
43
|
findPath(physicsWorldId, startingPosition, target, options) {
|
|
35
44
|
return this.pathFinderService.findPathAStar(physicsWorldId, startingPosition, target, options);
|
|
@@ -44,7 +53,7 @@ let PhysicsController = class PhysicsController {
|
|
|
44
53
|
return this.elipticExplosionService.createElipticExplosion(physicsWorldId, explosionCenter, rotation, size, physicsBodyGroup, severity, options);
|
|
45
54
|
}
|
|
46
55
|
printPathfindingTestGrid(physicsWorldId, testLayerId, target, physicsBodyGroup, area, gridCellSize) {
|
|
47
|
-
this.
|
|
56
|
+
this.testVisualsService.printPathfindingTestGrid(physicsWorldId, testLayerId, target, physicsBodyGroup, area, gridCellSize);
|
|
48
57
|
}
|
|
49
58
|
};
|
|
50
59
|
exports.PhysicsController = PhysicsController;
|
|
@@ -52,8 +61,10 @@ exports.PhysicsController = PhysicsController = __decorate([
|
|
|
52
61
|
(0, game_entities_1.ControllerDecorator)({ controllerLink: physics_gateway_1.PhysicsControllerLink }),
|
|
53
62
|
__metadata("design:paramtypes", [physics_world_service_1.PhysicsWorldService,
|
|
54
63
|
path_finder_service_1.PathFinderService,
|
|
55
|
-
|
|
64
|
+
test_visuals_service_1.TestVisualsService,
|
|
56
65
|
explosion_service_1.ExplosionService,
|
|
57
|
-
eliptic_explosion_service_1.ElipticExplosionService
|
|
66
|
+
eliptic_explosion_service_1.ElipticExplosionService,
|
|
67
|
+
hit_test_service_1.HitTestService,
|
|
68
|
+
physics_query_service_1.PhysicsQueryService])
|
|
58
69
|
], PhysicsController);
|
|
59
70
|
//# sourceMappingURL=physics.controller.js.map
|
package/dist/physics/module//342/232/234/357/270/217gateways/controllers/physics.controller.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physics.controller.js","sourceRoot":"","sources":["../../../../../src/physics/module/⚜️gateways/controllers/physics.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6DAAgE;AAChE,
|
|
1
|
+
{"version":3,"file":"physics.controller.js","sourceRoot":"","sources":["../../../../../src/physics/module/⚜️gateways/controllers/physics.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6DAAgE;AAChE,qGAAsF;AAEtF,wDAA2D;AAG3D,qGAAsF;AACtF,uGAAwF;AAExF,+FAAiF;AACjF,+GAAgG;AAChG,4FAA6E;AAC7E,kGAAmF;AACnF,yEAAqE;AAG9D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAC5B,YACU,mBAAwC,EACxC,iBAAoC,EACpC,kBAAsC,EACtC,gBAAkC,EAClC,uBAAgD,EAChD,cAA8B,EAC9B,mBAAwC;QANxC,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,4BAAuB,GAAvB,uBAAuB,CAAyB;QAChD,mBAAc,GAAd,cAAc,CAAgB;QAC9B,wBAAmB,GAAnB,mBAAmB,CAAqB;IAC/C,CAAC;IAEJ,kBAAkB,CAAC,OAAqC;QACtD,OAAO,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED,UAAU,CAAC,cAAsB;QAC/B,OAAO,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,CAAC,eAAuB,EAAE,OAAwB;QACvD,IAAI,aAAa,GAAG,8BAAa,CAAC,wBAAwB,CAAC,eAAe,CAAC,CAAC;QAC5E,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC;IACvE,CAAC;IAED,QAAQ,CACN,cAAsB,EACtB,gBAAwB,EACxB,MAAuB,EACvB,OAAgF;QAEhF,OAAO,IAAI,CAAC,i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AAiB,CAmF7B"}
|
|
@@ -13,3 +13,8 @@ export interface PhysicsExplosionOptions {
|
|
|
13
13
|
readonly debugRayDuration?: number;
|
|
14
14
|
readonly hitOnlyClosest?: boolean;
|
|
15
15
|
}
|
|
16
|
+
export interface HitTestOptions {
|
|
17
|
+
readonly overridePosition?: Vector;
|
|
18
|
+
readonly overrideRotation?: number;
|
|
19
|
+
readonly testLayerId?: string;
|
|
20
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Rectangle, Vector } from 'helpers-lib';
|
|
2
2
|
import { ControllerLink } from '../../../game-entities';
|
|
3
|
-
import { CreatePhysicsWorldRequestDTO, PhysicsExplosionOptions } from './dtos/requests.dto';
|
|
3
|
+
import { CreatePhysicsWorldRequestDTO, HitTestOptions, PhysicsExplosionOptions } from './dtos/requests.dto';
|
|
4
4
|
import { PhysicsBodyGroup } from '../../libs/physics-body-groups';
|
|
5
5
|
import { PathFinderResult } from '../../../utilities/libraries/grid-algorithms/path-finder/path-finder';
|
|
6
6
|
import { ExplosionHit, MapSizeDTO } from './dtos/responses.dto';
|
|
@@ -8,6 +8,7 @@ export declare const PhysicsControllerLink: ControllerLink;
|
|
|
8
8
|
export declare class PhysicsGateway {
|
|
9
9
|
createPhysicsWorld(request: CreatePhysicsWorldRequestDTO): string;
|
|
10
10
|
getMapSize(physicsWorldId: string): MapSizeDTO;
|
|
11
|
+
hitTest(physicsEntityId: string, options?: HitTestOptions): boolean;
|
|
11
12
|
findPath(physicsWorldId: string, startingPosition: Vector, target: Vector | string, options?: {
|
|
12
13
|
includeDiagonals?: boolean;
|
|
13
14
|
collidableWithGroup?: PhysicsBodyGroup;
|
|
@@ -8,7 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.PhysicsGateway = exports.PhysicsControllerLink = void 0;
|
|
10
10
|
const game_entities_1 = require("../../../game-entities");
|
|
11
|
-
const path_finder_service_1 = require("../\uD83D\uDCD0services/path-finder.service");
|
|
11
|
+
const path_finder_service_1 = require("../\uD83D\uDCD0services/path-finding/path-finder.service");
|
|
12
12
|
exports.PhysicsControllerLink = new game_entities_1.ControllerLink();
|
|
13
13
|
let PhysicsGateway = class PhysicsGateway {
|
|
14
14
|
createPhysicsWorld(request) {
|
|
@@ -17,6 +17,9 @@ let PhysicsGateway = class PhysicsGateway {
|
|
|
17
17
|
getMapSize(physicsWorldId) {
|
|
18
18
|
return exports.PhysicsControllerLink.trigger('getMapSize', physicsWorldId);
|
|
19
19
|
}
|
|
20
|
+
hitTest(physicsEntityId, options) {
|
|
21
|
+
return exports.PhysicsControllerLink.trigger('hitTest', physicsEntityId, options);
|
|
22
|
+
}
|
|
20
23
|
findPath(physicsWorldId, startingPosition, target, options) {
|
|
21
24
|
return exports.PhysicsControllerLink.trigger('findPath', physicsWorldId, startingPosition, target, options);
|
|
22
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physics.gateway.js","sourceRoot":"","sources":["../../../../src/physics/module/⚜️gateways/physics.gateway.ts"],"names":[],"mappings":";;;;;;;;;AAEA,0DAA0E;AAI1E,
|
|
1
|
+
{"version":3,"file":"physics.gateway.js","sourceRoot":"","sources":["../../../../src/physics/module/⚜️gateways/physics.gateway.ts"],"names":[],"mappings":";;;;;;;;;AAEA,0DAA0E;AAI1E,kGAAwF;AAG3E,QAAA,qBAAqB,GAAG,IAAI,8BAAc,EAAE,CAAC;AAGnD,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,kBAAkB,CAAC,OAAqC;QACtD,OAAO,6BAAqB,CAAC,OAAO,CAAS,oBAAoB,EAAE,OAAO,CAAC,CAAC;IAC9E,CAAC;IAED,UAAU,CAAC,cAAsB;QAC/B,OAAO,6BAAqB,CAAC,OAAO,CAAa,YAAY,EAAE,cAAc,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,CAAC,eAAuB,EAAE,OAAwB;QACvD,OAA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AD1B,IAAA,gCAAgB,GAAE;GACN,cAAc,CA+F1B"}
|
|
@@ -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/collision/collisions.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6CAA6C;AAE7C,2DAAuE;AACvE,6DAA6D;AAC7D,yEAAqE;AAErE,2DAAuD;AAIhD,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,uBAAu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B,2BAA2B,EAAE,GAAW,EAAE;gBACxC,IAAI,CAAC,wBAAwB,EAAE,CAAC;oBAC9B,wBAAwB,GAAG,gBAAgB,CAAC,MAAM,CAAC,oBAAM,CAAC,QAAQ,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACpG,CAAC;gBACD,OAAO,wBAAwB,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,13 @@
|
|
|
1
|
+
import p2 from 'p2';
|
|
2
|
+
import { TestVisualsService } from '../test-visuals/test-visuals.service';
|
|
3
|
+
import { HitTestOptions } from '../../⚜️gateways';
|
|
4
|
+
export declare class HitTestService {
|
|
5
|
+
private testVisualsService;
|
|
6
|
+
private bodyClones;
|
|
7
|
+
constructor(testVisualsService: TestVisualsService);
|
|
8
|
+
step(): void;
|
|
9
|
+
hitTest(p2Body: p2.Body, options?: HitTestOptions): boolean;
|
|
10
|
+
private applyOverriddenValues;
|
|
11
|
+
private getAABB;
|
|
12
|
+
private getBodyClone;
|
|
13
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.HitTestService = void 0;
|
|
16
|
+
const helpers_lib_1 = require("helpers-lib");
|
|
17
|
+
const p2_1 = __importDefault(require("p2"));
|
|
18
|
+
const game_entities_1 = require("../../../../game-entities");
|
|
19
|
+
const test_visuals_service_1 = require("../test-visuals/test-visuals.service");
|
|
20
|
+
const p2js_helper_1 = require("../../../libs/p2js.helper");
|
|
21
|
+
const physics_entity_1 = require("../../../entity-types/physics-entity");
|
|
22
|
+
let HitTestService = class HitTestService {
|
|
23
|
+
constructor(testVisualsService) {
|
|
24
|
+
this.testVisualsService = testVisualsService;
|
|
25
|
+
this.bodyClones = new Map();
|
|
26
|
+
}
|
|
27
|
+
step() {
|
|
28
|
+
this.bodyClones.clear();
|
|
29
|
+
}
|
|
30
|
+
hitTest(p2Body, options) {
|
|
31
|
+
let p2World = p2Body.world;
|
|
32
|
+
let physicsEntity = physics_entity_1.PhysicsEntity.getFromP2BodyIdOrFail(p2Body.id);
|
|
33
|
+
let bodyClone = this.getBodyClone(p2Body);
|
|
34
|
+
this.applyOverriddenValues(bodyClone, options);
|
|
35
|
+
let overlappingBodyClones = p2World.broadphase
|
|
36
|
+
.aabbQuery(p2World, this.getAABB(bodyClone))
|
|
37
|
+
.map(targetBody => physics_entity_1.PhysicsEntity.getFromP2BodyIdOrFail(targetBody.id))
|
|
38
|
+
.filter(targetEntity => targetEntity.includeInPathfinding)
|
|
39
|
+
.filter(targetEntity => physicsEntity.canCollideWith(targetEntity))
|
|
40
|
+
.map(targetEntity => this.getBodyClone(targetEntity['p2Body']));
|
|
41
|
+
let hitFound = false;
|
|
42
|
+
if (overlappingBodyClones.length !== 0) {
|
|
43
|
+
let p2WorldClone = new p2_1.default.World();
|
|
44
|
+
p2WorldClone.addBody(bodyClone);
|
|
45
|
+
overlappingBodyClones.forEach(body => p2WorldClone.addBody(body));
|
|
46
|
+
p2WorldClone.step(1, 1, 1);
|
|
47
|
+
hitFound = p2WorldClone.narrowphase.contactEquations.some(contactEquation => contactEquation.bodyA === bodyClone || contactEquation.bodyB === bodyClone);
|
|
48
|
+
p2WorldClone.clear();
|
|
49
|
+
}
|
|
50
|
+
if (options?.testLayerId) {
|
|
51
|
+
let color = hitFound ? helpers_lib_1.ColorHelper.red : helpers_lib_1.ColorHelper.green;
|
|
52
|
+
this.testVisualsService.createPhysicsEntityShapeVisual(p2Body, options.testLayerId, {
|
|
53
|
+
overridePosition: options.overridePosition,
|
|
54
|
+
overrideRotation: options.overrideRotation,
|
|
55
|
+
color
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return hitFound;
|
|
59
|
+
}
|
|
60
|
+
applyOverriddenValues(p2Body, options) {
|
|
61
|
+
if (options?.overridePosition) {
|
|
62
|
+
p2Body.position = p2js_helper_1.P2JSHelper.vectorToArray(options.overridePosition);
|
|
63
|
+
}
|
|
64
|
+
if (options?.overrideRotation) {
|
|
65
|
+
p2Body.angle = options.overrideRotation;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
getAABB(p2Body) {
|
|
69
|
+
p2Body.aabbNeedsUpdate = true;
|
|
70
|
+
p2Body.updateAABB();
|
|
71
|
+
return p2Body.aabb;
|
|
72
|
+
}
|
|
73
|
+
getBodyClone(p2Body) {
|
|
74
|
+
let bodyClone = this.bodyClones.get(p2Body.id);
|
|
75
|
+
if (!bodyClone) {
|
|
76
|
+
bodyClone = p2js_helper_1.P2JSHelper.cloneP2Body(p2Body);
|
|
77
|
+
this.bodyClones.set(p2Body.id, bodyClone);
|
|
78
|
+
}
|
|
79
|
+
return bodyClone;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
exports.HitTestService = HitTestService;
|
|
83
|
+
exports.HitTestService = HitTestService = __decorate([
|
|
84
|
+
(0, game_entities_1.ServiceDecorator)(),
|
|
85
|
+
__metadata("design:paramtypes", [test_visuals_service_1.TestVisualsService])
|
|
86
|
+
], HitTestService);
|
|
87
|
+
//# sourceMappingURL=hit-test.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hit-test.service.js","sourceRoot":"","sources":["../../../../../src/physics/module/📐services/collision/hit-test.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAA0C;AAC1C,4CAAoB;AAEpB,6DAA6D;AAC7D,+EAA0E;AAC1E,2DAAuD;AAEvD,yEAAqE;AAG9D,IAAM,cAAc,GAApB,MAAM,cAAc;IAGzB,YAAoB,kBAAsC;QAAtC,uBAAkB,GAAlB,kBAAkB,CAAoB;QAFlD,eAAU,GAAG,IAAI,GAAG,EAAmB,CAAC;IAEa,CAAC;IAE9D,IAAI;QACF,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;IAED,OAAO,CAAC,MAAe,EAAE,OAAwB;QAC/C,IAAI,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC;QAC3B,IAAI,aAAa,GAAG,8BAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAEnE,IAAI,SAAS,GAAG,IAAI,CAAC,YAAY,C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