diff --git a/README.md b/README.md index 2c455ed..22968c1 100644 --- a/README.md +++ b/README.md @@ -7,4 +7,5 @@ - baseball - wrestling - auto racing -- soccer \ No newline at end of file +- soccer +- hockey \ No newline at end of file diff --git a/packages/lib/index.js b/packages/lib/index.js index d7db8f3..ce1cb3a 100644 --- a/packages/lib/index.js +++ b/packages/lib/index.js @@ -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