add hockey parsing

This commit is contained in:
2023-11-25 11:35:27 -06:00
parent 402b4cfaf4
commit 59422675dc
2 changed files with 55 additions and 2 deletions
+53 -1
View File
@@ -58,7 +58,8 @@ class Console {
break;
case 0x40:
this.sport = 'hockey';
throw new Error('Hockey is not implemented');
this.parseHockey();
break;
case 0x85:
this.sport = 'auto_racing';
this.parseAutoRacing();
@@ -364,6 +365,57 @@ class Console {
}
}
parseHockey() {
if (!this.sportInitialized) {
this.sportInitialized = true;
}
const seqNum = this.latestPacket.buffer.at(10);
if (seqNum === 0x11) {
this.state.home.shotsOnGoal = this.getInt(this.latestPacket.buffer.at(16));
this.state.guest.shotsOnGoal = this.getInt(this.latestPacket.buffer.at(17));
this.state.home.saves = this.getInt(this.latestPacket.buffer.at(21));
this.state.guest.saves = this.getInt(this.latestPacket.buffer.at(22));
}
if (seqNum === 0x22) {
this.state.home.penalties = [];
this.state.guest.penalties = [];
for (let i = 0; i < 2; i += 1) {
const startIndex = 11 + i * 3;
if (this.latestPacket.buffer.at(startIndex) !== 0xaa) {
const penaltyClock = {
minutes: this.latestPacket.buffer.subarray(startIndex, startIndex + 1).toString('hex'),
seconds: this.latestPacket.buffer.subarray(startIndex + 1, startIndex + 2).toString('hex'),
};
penaltyClock.display = `${penaltyClock.minutes}:${penaltyClock.seconds}`;
this.state.home.penalties.push({
clock: penaltyClock,
playerNum: this.getInt(this.latestPacket.buffer.at(startIndex + 2)),
});
}
}
for (let i = 0; i < 2; i += 1) {
const startIndex = 17 + i * 3;
if (this.latestPacket.buffer.at(startIndex) !== 0xaa) {
const penaltyClock = {
minutes: this.latestPacket.buffer.subarray(startIndex, startIndex + 1).toString('hex'),
seconds: this.latestPacket.buffer.subarray(startIndex + 1, startIndex + 2).toString('hex'),
};
penaltyClock.display = `${penaltyClock.minutes}:${penaltyClock.seconds}`;
this.state.guest.penalties.push({
clock: penaltyClock,
playerNum: this.getInt(this.latestPacket.buffer.at(startIndex + 2)),
});
}
}
}
}
/**
*
* @param {number} packedNumber