-
Notifications
You must be signed in to change notification settings - Fork 12
/
VehicleDoorCollection.ts
73 lines (65 loc) · 2.1 KB
/
VehicleDoorCollection.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Vehicle } from './Vehicle';
import { VehicleDoorIndex } from '../enums';
import { VehicleDoor } from './VehicleDoor';
export class VehicleDoorCollection {
private _owner: Vehicle;
private readonly _vehicleDoors: Map<VehicleDoorIndex, VehicleDoor> = new Map<
VehicleDoorIndex,
VehicleDoor
>();
constructor(owner: Vehicle) {
this._owner = owner;
}
public getDoors(index: VehicleDoorIndex): VehicleDoor | undefined {
if (!this._vehicleDoors.has(index)) {
this._vehicleDoors.set(index, new VehicleDoor(this._owner, index));
}
return this._vehicleDoors.get(index);
}
public getAllDoors(): (VehicleDoor | null | undefined)[] {
return Object.keys(VehicleDoorIndex)
.filter(key => !isNaN(Number(key)))
.map(key => {
const index = Number(key);
if (this.hasDoor(index)) {
return this.getDoors(index);
}
return null;
})
.filter(d => d);
}
public openAllDoors(loose?: boolean, instantly?: boolean): void {
this.getAllDoors().forEach(door => {
door?.open(loose, instantly);
});
}
public closeAllDoors(instantly?: boolean): void {
this.getAllDoors().forEach(door => {
door?.close(instantly);
});
}
public breakAllDoors(stayInTheWorld?: boolean): void {
this.getAllDoors().forEach(door => {
door?.break(stayInTheWorld);
});
}
public hasDoor(index: VehicleDoorIndex): boolean {
if (this._owner.Bones === undefined) return false;
switch (index) {
case VehicleDoorIndex.FrontLeftDoor:
return this._owner.Bones.hasBone('door_dside_f');
case VehicleDoorIndex.FrontRightDoor:
return this._owner.Bones.hasBone('door_pside_f');
case VehicleDoorIndex.BackLeftDoor:
return this._owner.Bones.hasBone('door_dside_r');
case VehicleDoorIndex.BackRightDoor:
return this._owner.Bones.hasBone('door_pside_r');
case VehicleDoorIndex.Hood:
return this._owner.Bones.hasBone('bonnet');
case VehicleDoorIndex.Trunk:
return this._owner.Bones.hasBone('boot');
default:
return false;
}
}
}