From 402b4cfaf47eabd80bec357445f7d5d3c8e81c2b Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Sat, 25 Nov 2023 10:55:26 -0600 Subject: [PATCH] add soccer parsing --- README.md | 3 ++- packages/lib/index.js | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dab8f34..2c455ed 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,5 @@ - football - baseball - wrestling -- auto racing \ No newline at end of file +- auto racing +- soccer \ No newline at end of file diff --git a/packages/lib/index.js b/packages/lib/index.js index 9d5d92d..d7db8f3 100644 --- a/packages/lib/index.js +++ b/packages/lib/index.js @@ -50,7 +50,8 @@ class Console { break; case 0x16: this.sport = 'soccer'; - throw new Error('Soccer is not implemented'); + this.parseSoccer(); + break; case 0x60: this.sport = 'wrestling'; this.parseWrestling(); @@ -333,13 +334,13 @@ class Console { parseAutoRacing() { if (!this.sportInitialized) { + this.state.positions = []; this.sportInitialized = true; } const seqNum = this.latestPacket.buffer.at(10); if (seqNum === 0x11) { this.state.lap = this.getInt(this.latestPacket.buffer.at(19)) * 100 + this.getInt(this.latestPacket.buffer.at(20)); - this.state.positions = []; for (let i = 0; i < 10; i += 1) { const positionByte = this.latestPacket.buffer.at(21 + i); if (positionByte !== 0xaa) { @@ -349,6 +350,20 @@ class Console { } } + parseSoccer() { + 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.cornerKicks = this.getInt(this.latestPacket.buffer.at(21)); + this.state.guest.cornerKicks = this.getInt(this.latestPacket.buffer.at(22)); + } + } + /** * * @param {number} packedNumber