11import { Referee_Stage , Referee_Command } from '@/proto/ssl_gc_referee_message_pb'
22import { Team } from '@/proto/ssl_gc_common_pb'
3- import { type GameEvent } from '@/proto/ssl_gc_game_event_pb'
3+ import {
4+ type GameEvent ,
5+ type GameEvent_BotCrashDrawn ,
6+ type GameEvent_BotCrashUnique ,
7+ } from '@/proto/ssl_gc_game_event_pb'
48
59const stageToText = new Map < Referee_Stage , string > ( [
610 [ Referee_Stage . NORMAL_FIRST_HALF_PRE , 'Match to be started' ] ,
@@ -100,14 +104,31 @@ const seconds = (v: number): string => {
100104 return Number ( Math . ceil ( v * 10 ) / 10 ) . toFixed ( 1 ) + 's'
101105}
102106
107+ function appendCrashDetails (
108+ event : GameEvent_BotCrashDrawn | GameEvent_BotCrashUnique ,
109+ text : string ,
110+ ) {
111+ const crashSpeed = event . crashSpeed
112+ const crashAngle = event . crashAngle
113+ const speedDiff = event . speedDiff
114+ if ( crashSpeed > 0 ) {
115+ text += ` with ${ velocity ( crashSpeed ) } `
116+ }
117+ if ( crashAngle > 0 ) {
118+ text += ` @ ${ radToDeg ( crashAngle ) } `
119+ }
120+ if ( speedDiff > 0 ) {
121+ text += ` (Δ ${ velocity ( speedDiff ) } )`
122+ }
123+ return text
124+ }
125+
103126export const mapGameEventToText = ( gameEvent : GameEvent ) : string => {
104127 if ( ! gameEvent . event ) {
105128 return 'unknown game event'
106129 }
107130
108131 switch ( gameEvent . event . case ) {
109- case 'prepared' :
110- return `Prepared after ${ seconds ( gameEvent . event . value . timeTaken ) } `
111132 case 'noProgressInGame' :
112133 return `No progress for ${ seconds ( gameEvent . event . value . time ) } `
113134 case 'placementFailed' : {
@@ -152,20 +173,12 @@ export const mapGameEventToText = (gameEvent: GameEvent): string => {
152173 return `${ teamAndBot ( gameEvent . event . value ) } might have scored a goal`
153174 case 'goal' :
154175 return `${ teamAndBot ( gameEvent . event . value ) } has scored a goal`
155- case 'indirectGoal' :
156- return `${ teamAndBot ( gameEvent . event . value ) } performed an illegal indirect goal`
157- case 'chippedGoal' :
158- return `${ teamAndBot ( gameEvent . event . value ) } chipped on goal`
159176 case 'invalidGoal' : {
160177 const event = gameEvent . event . value
161178 return `Scored goal by ${ teamAndBot ( event ) } is invalid: ${ event . message } `
162179 }
163180 case 'aimlessKick' :
164181 return `${ teamAndBot ( gameEvent . event . value ) } kicked aimlessly`
165- case 'kickTimeout' : {
166- const event = gameEvent . event . value
167- return `${ teamAndBot ( event ) } has not kicked within ${ seconds ( event . time ) } `
168- }
169182 case 'keeperHeldBall' : {
170183 const event = gameEvent . event . value
171184 return `${ teamAndBot ( event ) } 's keeper held the ball for ${ seconds ( event . duration ) } `
@@ -174,22 +187,6 @@ export const mapGameEventToText = (gameEvent: GameEvent): string => {
174187 return `${ teamAndBot ( gameEvent . event . value ) } touched ball twice`
175188 case 'attackerTouchedBallInDefenseArea' :
176189 return `${ teamAndBot ( gameEvent . event . value ) } touched ball in opponent defense area`
177- case 'attackerTouchedOpponentInDefenseArea' : {
178- const event = gameEvent . event . value
179- const byTeam = event . byTeam
180- const otherTeam = oppositeTeam ( byTeam )
181- const violator = event . byBot
182- const victim = event . victim
183- return `${ formatTeam ( byTeam ) } ${ violator } touched ${ formatTeam ( otherTeam ) } ${ victim } in defense area`
184- }
185- case 'attackerTouchedOpponentInDefenseAreaSkipped' : {
186- const event = gameEvent . event . value
187- const byTeam = event . byTeam
188- const otherTeam = oppositeTeam ( byTeam )
189- const violator = event . byBot
190- const victim = event . victim
191- return `${ formatTeam ( byTeam ) } ${ violator } touched ${ formatTeam ( otherTeam ) } ${ victim } in defense area`
192- }
193190 case 'botDribbledBallTooFar' :
194191 return `${ teamAndBot ( gameEvent . event . value ) } dribbled ball too far`
195192 case 'botKickedBallTooFast' : {
@@ -204,62 +201,17 @@ export const mapGameEventToText = (gameEvent: GameEvent): string => {
204201 return `${ teamAndBot ( gameEvent . event . value ) } interfered placement`
205202 case 'botCrashDrawn' : {
206203 const event = gameEvent . event . value
207- const crashSpeed = event . crashSpeed
208- const crashAngle = event . crashAngle
209- const speedDiff = event . speedDiff
210- let text = `Bot Blue ${ event . botBlue } and Yellow ${ event . botYellow } crashed`
211- if ( crashSpeed > 0 ) {
212- text += ` with ${ velocity ( crashSpeed ) } `
213- }
214- if ( crashAngle > 0 ) {
215- text += ` @ ${ radToDeg ( crashAngle ) } `
216- }
217- if ( speedDiff > 0 ) {
218- text += ` (Δ ${ velocity ( speedDiff ) } )`
219- }
220- return text
204+ const text = `Bot Blue ${ event . botBlue } and Yellow ${ event . botYellow } crashed`
205+ return appendCrashDetails ( event , text )
221206 }
222207 case 'botCrashUnique' : {
223208 const event = gameEvent . event . value
224209 const byTeam = event . byTeam
225210 const otherTeam = oppositeTeam ( byTeam )
226211 const violator = event . violator
227212 const victim = event . victim
228- const crashSpeed = event . crashSpeed
229- const crashAngle = event . crashAngle
230- const speedDiff = event . speedDiff
231- let text = `${ formatTeam ( byTeam ) } ${ violator } crashed into ${ formatTeam ( otherTeam ) } ${ victim } `
232- if ( crashSpeed > 0 ) {
233- text += ` with ${ velocity ( crashSpeed ) } `
234- }
235- if ( crashAngle > 0 ) {
236- text += ` @ ${ radToDeg ( crashAngle ) } `
237- }
238- if ( speedDiff > 0 ) {
239- text += ` (Δ ${ velocity ( speedDiff ) } )`
240- }
241- return text
242- }
243- case 'botCrashUniqueSkipped' : {
244- const event = gameEvent . event . value
245- const byTeam = event . byTeam
246- const otherTeam = oppositeTeam ( byTeam )
247- const violator = event . violator
248- const victim = event . victim
249- const crashSpeed = event . crashSpeed
250- const crashAngle = event . crashAngle
251- const speedDiff = event . speedDiff
252- let text = `Skipped: ${ formatTeam ( byTeam ) } ${ violator } crashed into ${ formatTeam ( otherTeam ) } ${ victim } `
253- if ( crashSpeed > 0 ) {
254- text += ` with ${ velocity ( crashSpeed ) } `
255- }
256- if ( crashAngle > 0 ) {
257- text += ` @ ${ radToDeg ( crashAngle ) } `
258- }
259- if ( speedDiff > 0 ) {
260- text += ` (Δ ${ velocity ( speedDiff ) } )`
261- }
262- return text
213+ const text = `${ formatTeam ( byTeam ) } ${ violator } crashed into ${ formatTeam ( otherTeam ) } ${ victim } `
214+ return appendCrashDetails ( event , text )
263215 }
264216 case 'botPushedBot' : {
265217 const event = gameEvent . event . value
@@ -274,19 +226,6 @@ export const mapGameEventToText = (gameEvent: GameEvent): string => {
274226 }
275227 return text
276228 }
277- case 'botPushedBotSkipped' : {
278- const event = gameEvent . event . value
279- const byTeam = event . byTeam
280- const otherTeam = oppositeTeam ( byTeam )
281- const violator = event . violator
282- const victim = event . victim
283- const dist = event . pushedDistance
284- let text = `Skipped: ${ formatTeam ( byTeam ) } ${ violator } pushed ${ formatTeam ( otherTeam ) } ${ victim } `
285- if ( dist > 0 ) {
286- text += ` over ${ distance ( dist ) } `
287- }
288- return text
289- }
290229 case 'botHeldBallDeliberately' : {
291230 const event = gameEvent . event . value
292231 return `${ teamAndBot ( event ) } held ball deliberately for ${ event . duration } `
@@ -303,18 +242,12 @@ export const mapGameEventToText = (gameEvent: GameEvent): string => {
303242 const event = gameEvent . event . value
304243 return `${ teamAndBot ( event ) } too close to kick point (${ distance ( event . distance ) } )`
305244 }
306- case 'defenderInDefenseAreaPartially' : {
307- const event = gameEvent . event . value
308- return `${ teamAndBot ( event ) } touched ball while partially inside own defense area (${ distance ( event . distance ) } )`
309- }
310245 case 'defenderInDefenseArea' : {
311246 const event = gameEvent . event . value
312247 return `${ teamAndBot ( event ) } touched ball while fully inside own defense area (${ distance ( event . distance ) } )`
313248 }
314249 case 'multipleCards' :
315250 return `${ teamAndBot ( gameEvent . event . value ) } collected multiple cards`
316- case 'multiplePlacementFailures' :
317- return `${ teamAndBot ( gameEvent . event . value ) } failed ball placement repeatedly`
318251 case 'multipleFouls' : {
319252 const event = gameEvent . event . value
320253 return (
0 commit comments