-
-
Notifications
You must be signed in to change notification settings - Fork 831
/
Collisions.ts
46 lines (39 loc) · 1.34 KB
/
Collisions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { CollisionMode } from "../../../../Enums/Modes/CollisionMode";
import { CollisionsAbsorb } from "./CollisionsAbsorb";
import { CollisionsOverlap } from "./CollisionsOverlap";
import type { ICollisions } from "../../../Interfaces/Particles/Collisions/ICollisions";
import type { IOptionLoader } from "../../../Interfaces/IOptionLoader";
import { ParticlesBounce } from "../Bounce/ParticlesBounce";
import type { RecursivePartial } from "../../../../Types/RecursivePartial";
/**
* @category Options
* [[include:Collisions.md]]
*/
export class Collisions implements ICollisions, IOptionLoader<ICollisions> {
absorb;
bounce;
enable;
mode: CollisionMode | keyof typeof CollisionMode;
overlap;
constructor() {
this.absorb = new CollisionsAbsorb();
this.bounce = new ParticlesBounce();
this.enable = false;
this.mode = CollisionMode.bounce;
this.overlap = new CollisionsOverlap();
}
load(data?: RecursivePartial<ICollisions>): void {
if (!data) {
return;
}
this.absorb.load(data.absorb);
this.bounce.load(data.bounce);
if (data.enable !== undefined) {
this.enable = data.enable;
}
if (data.mode !== undefined) {
this.mode = data.mode;
}
this.overlap.load(data.overlap);
}
}