blob: 44c06fb03e02196b4eef901123b993862849d421 (
plain) (
blame)
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
74
75
|
import { notif_alert, notif_warn, notif_info, notif_success } from './notification';
export default class hoverControlModule {
#throttle = 0;
#throttleAcc = 0;
#rudder = 0;
#rudderAcc = 0;
#arm = 0;
#armAcc = 0;
constructor() {}
acc(accString) {
accString.match(/[A-Z][-,0-9]+/g).forEach((item, i) => {
switch (item.substring(0, 1)) {
case "T":
this.#throttleAcc = parseInt(item.substring(1, item.length));
break;
case "R":
this.#rudderAcc = parseInt(item.substring(1, item.length));
break;
case "A":
this.#armAcc = parseInt(item.substring(1, item.length)) == 1;
if (this.#armAcc) {
document.body.classList.add("armed");
} else {
document.body.classList.remove("armed");
}
break;
case "S":
break;
default:
console.log(`Unkown acc: ${item}`);
}
});
document.querySelector(".acc-string pre").innerHTML = `T: ${this.#throttleAcc}, R: ${this.#rudderAcc}`;
}
reset() {
this.setArm(0);
this.setThrottle(0);
this.setRudder(0);
}
setThrottle(throttle) {
if (!this.#armAcc) { return; }
if (throttle > 100) { throttle = 100; }
if (throttle < 0) { throttle = 0; }
this.#throttle = throttle;
}
getThrottle() {
return this.#throttle;
}
setRudder(rudder) {
if (!this.#armAcc) { return; }
if (rudder > 90) { rudder = 90; }
if (rudder < -90) { rudder = -90; }
this.#rudder = rudder;
}
getRudder() {
return this.#rudder;
}
setArm(arm) {
this.#arm = arm;
if (!this.#arm) {
this.#throttle = 0;
this.#rudder = 0;
}
}
getArm() {
return this.#arm;
}
}
|