@gg-web-engine/rapier2d 0.0.56 → 0.0.57

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.
@@ -28,13 +28,13 @@ export declare class Rapier2dRigidBodyComponent implements IRigidBody2dComponent
28
28
  RigidBodyDesc,
29
29
  Omit<Omit<Body2DOptions, 'dynamic'>, 'mass'>
30
30
  ];
31
- get debugBodySettings(): DebugBody2DSettings;
31
+ readonly debugBodySettings: DebugBody2DSettings;
32
32
  constructor(world: Rapier2dWorldComponent, _colliderDescr: ColliderDesc[], shape: Shape2DDescriptor, _bodyDescr: RigidBodyDesc, _colliderOptions: Omit<Omit<Body2DOptions, 'dynamic'>, 'mass'>);
33
33
  protected collisionGroups: InteractionGroups;
34
- get interactWithCollisionGroups(): CollisionGroup[];
35
- set interactWithCollisionGroups(value: CollisionGroup[] | 'all');
36
- get ownCollisionGroups(): CollisionGroup[];
37
- set ownCollisionGroups(value: CollisionGroup[] | 'all');
34
+ get interactWithCollisionGroups(): ReadonlyArray<CollisionGroup>;
35
+ set interactWithCollisionGroups(value: ReadonlyArray<CollisionGroup> | 'all');
36
+ get ownCollisionGroups(): ReadonlyArray<CollisionGroup>;
37
+ set ownCollisionGroups(value: ReadonlyArray<CollisionGroup> | 'all');
38
38
  clone(): Rapier2dRigidBodyComponent;
39
39
  addToWorld(world: Gg2dWorld<VisualTypeDocRepo2D, Rapier2dPhysicsTypeDocRepo>): void;
40
40
  removeFromWorld(world: Gg2dWorld<VisualTypeDocRepo2D, Rapier2dPhysicsTypeDocRepo>): void;
@@ -1,4 +1,4 @@
1
- import { BitMask, Pnt2, } from '@gg-web-engine/core';
1
+ import { BitMask, DebugBody2DSettings, Pnt2, } from '@gg-web-engine/core';
2
2
  import { Vector2, } from '@dimforge/rapier2d-compat';
3
3
  export class Rapier2dRigidBodyComponent {
4
4
  get position() {
@@ -53,15 +53,6 @@ export class Rapier2dRigidBodyComponent {
53
53
  get factoryProps() {
54
54
  return [this._colliderDescr, this.shape, this._bodyDescr, this._colliderOptions];
55
55
  }
56
- get debugBodySettings() {
57
- var _a;
58
- if (this._bodyDescr.mass > 0) {
59
- return { shape: this.shape, type: 'RIGID_DYNAMIC', sleeping: !!((_a = this._nativeBody) === null || _a === void 0 ? void 0 : _a.isSleeping()) };
60
- }
61
- else {
62
- return { shape: this.shape, type: 'RIGID_STATIC' };
63
- }
64
- }
65
56
  constructor(world, _colliderDescr, shape, _bodyDescr, _colliderOptions) {
66
57
  this.world = world;
67
58
  this._colliderDescr = _colliderDescr;
@@ -72,7 +63,12 @@ export class Rapier2dRigidBodyComponent {
72
63
  this._nativeBody = null;
73
64
  this._nativeBodyColliders = null;
74
65
  this.name = '';
66
+ this.debugBodySettings = new DebugBody2DSettings(this._bodyDescr.mass > 0
67
+ ? { type: 'RIGID_DYNAMIC', sleeping: () => { var _a; return !!((_a = this._nativeBody) === null || _a === void 0 ? void 0 : _a.isSleeping()); } }
68
+ : { type: 'RIGID_STATIC' }, this.shape);
75
69
  this.collisionGroups = BitMask.full(32);
70
+ this.ownCollisionGroups = (_colliderOptions === null || _colliderOptions === void 0 ? void 0 : _colliderOptions.ownCollisionGroups) || [world.mainCollisionGroup];
71
+ this.interactWithCollisionGroups = (_colliderOptions === null || _colliderOptions === void 0 ? void 0 : _colliderOptions.interactWithCollisionGroups) || [world.mainCollisionGroup];
76
72
  }
77
73
  get interactWithCollisionGroups() {
78
74
  return BitMask.unpack(this.collisionGroups, 16);
@@ -13,7 +13,8 @@ export declare class Rapier2dTriggerComponent extends Rapier2dRigidBodyComponent
13
13
  get onEntityLeft(): Observable<Rapier2dRigidBodyComponent>;
14
14
  protected readonly onEnter$: Subject<Rapier2dRigidBodyComponent>;
15
15
  protected readonly onLeft$: Subject<Rapier2dRigidBodyComponent>;
16
- get debugBodySettings(): DebugBody2DSettings;
16
+ readonly debugBodySettings: DebugBody2DSettings;
17
+ protected intersectionsAmount: number;
17
18
  constructor(world: Rapier2dWorldComponent, _colliderDescr: ColliderDesc[], shape: Shape2DDescriptor, _bodyDescr: RigidBodyDesc);
18
19
  addToWorld(world: Gg2dWorld<VisualTypeDocRepo2D, Rapier2dPhysicsTypeDocRepo>): void;
19
20
  checkOverlaps(): void;
@@ -1,5 +1,6 @@
1
- import { Subject } from 'rxjs';
1
+ import { map, merge, Subject } from 'rxjs';
2
2
  import { Rapier2dRigidBodyComponent } from './rapier-2d-rigid-body.component';
3
+ import { DebugBody2DSettings, } from '@gg-web-engine/core';
3
4
  export class Rapier2dTriggerComponent extends Rapier2dRigidBodyComponent {
4
5
  get onEntityEntered() {
5
6
  return this.onEnter$.asObservable();
@@ -7,9 +8,6 @@ export class Rapier2dTriggerComponent extends Rapier2dRigidBodyComponent {
7
8
  get onEntityLeft() {
8
9
  return this.onLeft$.asObservable();
9
10
  }
10
- get debugBodySettings() {
11
- return { shape: this.shape, type: 'TRIGGER' };
12
- }
13
11
  constructor(world, _colliderDescr, shape, _bodyDescr) {
14
12
  super(world, _colliderDescr, shape, _bodyDescr, null);
15
13
  this.world = world;
@@ -18,11 +16,22 @@ export class Rapier2dTriggerComponent extends Rapier2dRigidBodyComponent {
18
16
  this._bodyDescr = _bodyDescr;
19
17
  this.onEnter$ = new Subject();
20
18
  this.onLeft$ = new Subject();
19
+ this.debugBodySettings = new DebugBody2DSettings({ type: 'TRIGGER', activated: () => this.intersectionsAmount > 0 }, this.shape);
20
+ this.intersectionsAmount = 0;
21
+ merge(this.onEnter$.pipe(map(() => true)), this.onLeft$.pipe(map(() => false))).subscribe(enter => {
22
+ if (enter) {
23
+ this.intersectionsAmount++;
24
+ }
25
+ else {
26
+ this.intersectionsAmount--;
27
+ }
28
+ });
21
29
  }
22
30
  addToWorld(world) {
23
31
  if (world.physicsWorld != this.world) {
24
32
  throw new Error('Rapier2D bodies cannot be shared between different worlds');
25
33
  }
34
+ this.intersectionsAmount = 0;
26
35
  this._nativeBody = this.world.nativeWorld.createRigidBody(this._bodyDescr);
27
36
  this._nativeBodyColliders = this._colliderDescr.map(c => this.world.nativeWorld.createCollider(c, this._nativeBody));
28
37
  this.world.handleIdEntityMap.set(this._nativeBody.handle, this);
@@ -45,6 +54,9 @@ export class Rapier2dTriggerComponent extends Rapier2dRigidBodyComponent {
45
54
  }
46
55
  clone() {
47
56
  const [colliderDescr, sd, bd] = super.factoryProps;
48
- return new Rapier2dTriggerComponent(this.world, colliderDescr, sd, bd);
57
+ const component = new Rapier2dTriggerComponent(this.world, colliderDescr, sd, bd);
58
+ component.ownCollisionGroups = this.ownCollisionGroups;
59
+ component.interactWithCollisionGroups = this.interactWithCollisionGroups;
60
+ return component;
49
61
  }
50
62
  }
@@ -14,6 +14,7 @@ export declare class Rapier2dWorldComponent implements IPhysicsWorld2dComponent<
14
14
  private _gravity;
15
15
  get gravity(): Point2;
16
16
  set gravity(value: Point2);
17
+ readonly mainCollisionGroup: CollisionGroup;
17
18
  protected _nativeWorld: World | null;
18
19
  get nativeWorld(): World;
19
20
  private _eventQueue;
@@ -47,6 +47,7 @@ export class Rapier2dWorldComponent {
47
47
  this.children = [];
48
48
  this.unitScale = 100; // TODO abstractize somehow, hardcoded now
49
49
  this._gravity = Pnt2.scalarMult({ x: 0, y: 9.82 }, this.unitScale);
50
+ this.mainCollisionGroup = 0;
50
51
  this._nativeWorld = null;
51
52
  this._eventQueue = null;
52
53
  this.handleIdEntityMap = new Map();
@@ -68,7 +69,7 @@ export class Rapier2dWorldComponent {
68
69
  (_a = this._nativeWorld) === null || _a === void 0 ? void 0 : _a.step(this.eventQueue);
69
70
  }
70
71
  registerCollisionGroup() {
71
- for (let i = 0; i < 16; i++) {
72
+ for (let i = 1; i < 16; i++) {
72
73
  if (!this.lockedCollisionGroups.includes(i)) {
73
74
  this.lockedCollisionGroups.push(i);
74
75
  return i;
@@ -7,7 +7,7 @@ export class Rapier2dFactory {
7
7
  this.world = world;
8
8
  }
9
9
  createRigidBody(descriptor, transform) {
10
- return new Rapier2dRigidBodyComponent(this.world, this.createColliderDescr(descriptor.shape), descriptor.shape, this.createRigidBodyDescr(descriptor.body, transform), Object.assign({ friction: 0.5, restitution: 0.1, ownCollisionGroups: 'all', interactWithCollisionGroups: 'all' }, descriptor.body));
10
+ return new Rapier2dRigidBodyComponent(this.world, this.createColliderDescr(descriptor.shape), descriptor.shape, this.createRigidBodyDescr(descriptor.body, transform), Object.assign({ friction: 0.5, restitution: 0.1, ownCollisionGroups: [this.world.mainCollisionGroup], interactWithCollisionGroups: [this.world.mainCollisionGroup] }, descriptor.body));
11
11
  }
12
12
  createTrigger(descriptor, transform) {
13
13
  const colliderDescr = this.createColliderDescr(descriptor);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gg-web-engine/rapier2d",
3
- "version": "0.0.56",
3
+ "version": "0.0.57",
4
4
  "description": "An attempt to create open source game engine for browser",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  "homepage": "https://github.com/AndyGura/gg-web-engine#readme",
29
29
  "devDependencies": {
30
30
  "@dimforge/rapier2d-compat": "0.0.0-50223ff-20240729",
31
- "@gg-web-engine/core": "0.0.56",
31
+ "@gg-web-engine/core": "0.0.57",
32
32
  "@types/jest": "^29.5.12",
33
33
  "jest": "^29.7.0",
34
34
  "jest-environment-jsdom": "^29.7.0",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@dimforge/rapier2d-compat": "0.0.0-50223ff-20240729",
42
- "@gg-web-engine/core": "0.0.56",
42
+ "@gg-web-engine/core": "0.0.57",
43
43
  "rxjs": "7.8.1"
44
44
  },
45
45
  "jest": {