51 lines
No EOL
1.4 KiB
TypeScript
51 lines
No EOL
1.4 KiB
TypeScript
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// Author: Sascha Nitsch https://contentnation.net/@grumpydevelop
|
|
|
|
class RobotCmd {
|
|
powerLeft: number = 0;
|
|
powerRight: number = 0;
|
|
radarMin: number = -1;
|
|
radarMax: number = -1;
|
|
gunTarget: number = -1;
|
|
fire?: boolean;
|
|
|
|
toObject() {
|
|
const o: Object = {};
|
|
if (this.powerLeft !== -9999) {
|
|
o['powerLeft'] = this.powerLeft;
|
|
}
|
|
if (this.powerRight !== -9999) {
|
|
o['powerRight'] = this.powerRight;
|
|
}
|
|
o['radarMin'] = this.radarMin;
|
|
o['radarMax'] = this.radarMax;
|
|
if (this.gunTarget !== -1) {
|
|
o['gunTarget'] = this.gunTarget;
|
|
}
|
|
if (this.fire === true) {
|
|
o['fire'] = true;
|
|
}
|
|
return o;
|
|
}
|
|
|
|
mergeObject(o: Object) {
|
|
if (o['powerLeft'] !== undefined) {
|
|
this.powerLeft = o['powerLeft'];
|
|
}
|
|
if (o['powerRight'] !== undefined) {
|
|
this.powerRight = o['powerRight'];
|
|
}
|
|
if (o['radarMin'] !== undefined) {
|
|
this.radarMin = o['radarMin'];
|
|
}
|
|
if (o['radarMax'] !== undefined) {
|
|
this.radarMax = o['radarMax'];
|
|
}
|
|
if (o['gunTarget'] !== undefined) {
|
|
this.gunTarget = o['gunTarget'];
|
|
}
|
|
this.fire = o['fire'] === true;
|
|
}
|
|
}
|
|
|
|
export { RobotCmd } |