Skip to content

Commit 3b7e825

Browse files
Fix console link to correct match & increase console window
1 parent 90545dc commit 3b7e825

3 files changed

Lines changed: 33 additions & 18 deletions

File tree

client/src/components/sidebar/runner/runner.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ const MapSelector: React.FC<MapSelectorProps> = ({ maps, availableMaps, onSelect
378378
)
379379
}
380380

381-
export type ConsoleLine = { content: string; type: 'output' | 'error' | 'bold' }
381+
export type ConsoleLine = { content: string; type: 'output' | 'error' | 'bold'; matchIdx: number }
382382

383383
type Props = {
384384
lines: RingBuffer<ConsoleLine>
@@ -401,19 +401,23 @@ export const Console: React.FC<Props> = ({ lines }) => {
401401
}
402402
}
403403

404-
const focusRobot = (round: number, id: number) => {
404+
const focusRobot = (match: number, round: number, id: number) => {
405405
setPopout(false)
406-
GameRunner.jumpToRound(round)
407-
GameRenderer.setSelectedRobot(id)
408-
409-
// If turn playback is enabled, focus the robot's exact turn as well
410-
if (GameRunner.match?.playbackPerTurn) {
411-
GameRunner.jumpToRobotTurn(id)
412-
}
406+
GameRunner.setMatch(GameRunner.game?.matches[match], round)
407+
408+
// Update selection after a delay so it doesn't get overwritten
409+
setTimeout(() => {
410+
// If turn playback is enabled, focus the robot's exact turn as well
411+
GameRenderer.setSelectedRobot(id)
412+
if (GameRunner.match?.playbackPerTurn) {
413+
GameRunner.jumpToRobotTurn(id)
414+
}
415+
}, 5)
413416
}
414417

415418
const ConsoleRow = (props: { index: number; style: any }) => {
416-
const content = lines.get(props.index)!.content
419+
const row = lines.get(props.index)!
420+
const content = row.content
417421

418422
// Check if the printout is from a bot. If so, add a special click element
419423
// that selects the bot
@@ -429,7 +433,7 @@ export const Console: React.FC<Props> = ({ lines }) => {
429433
<div className="flex items-center gap-1 sele" style={props.style}>
430434
<span
431435
className="text-blueLight decoration-blueLight text-xs whitespace-nowrap underline cursor-pointer"
432-
onClick={() => focusRobot(round, id)}
436+
onClick={() => focusRobot(row.matchIdx, round, id)}
433437
>
434438
{`[Team ${team}, ID #${id}, Round ${round}]`}
435439
</span>

client/src/components/sidebar/runner/scaffold.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,23 @@ export const useScaffold = (): Scaffold => {
5353
const [error, setError] = useState('')
5454
const matchPID = useRef<string | undefined>(undefined)
5555
const forceUpdate = useForceUpdate()
56-
const consoleLines = useRef<RingBuffer<ConsoleLine>>(new RingBuffer(10000))
56+
const consoleLines = useRef<RingBuffer<ConsoleLine>>(new RingBuffer(50000))
5757

5858
const [webSocketListener, setWebSocketListener] = useState<WebSocketListener | undefined>()
5959

6060
const log = (line: ConsoleLine) => {
61+
// Set match index to be the same as the previous log value
62+
if (consoleLines.current.length() > 0) {
63+
line.matchIdx = consoleLines.current.get(consoleLines.current.length() - 1)!.matchIdx
64+
}
65+
66+
// If we encounter the end-of-match message, increment the match index
67+
if (line.content.startsWith('[server]') && line.content.includes('Finished')) {
68+
line.matchIdx++
69+
}
70+
6171
consoleLines.current.push(line)
72+
6273
forceUpdate()
6374
}
6475

@@ -107,7 +118,7 @@ export const useScaffold = (): Scaffold => {
107118
)
108119
matchPID.current = newPID
109120
} catch (e: any) {
110-
consoleLines.current.push({ content: e, type: 'error' })
121+
consoleLines.current.push({ content: e, type: 'error', matchIdx: 0 })
111122
}
112123
forceUpdate()
113124
}
@@ -176,15 +187,15 @@ export const useScaffold = (): Scaffold => {
176187

177188
nativeAPI.child_process.onStdout(({ pid, data }) => {
178189
if (pid !== matchPID.current) return
179-
log({ content: data, type: 'output' })
190+
log({ content: data, type: 'output', matchIdx: 0 })
180191
})
181192
nativeAPI.child_process.onStderr(({ pid, data }) => {
182193
if (pid !== matchPID.current) return
183-
log({ content: data, type: 'error' })
194+
log({ content: data, type: 'error', matchIdx: 0 })
184195
})
185196
nativeAPI.child_process.onExit(({ pid, code, signal }) => {
186197
if (pid !== matchPID.current) return
187-
log({ content: `Exited with code ${code} | ${JSON.stringify(signal)}`, type: 'bold' })
198+
log({ content: `Exited with code ${code} | ${JSON.stringify(signal)}`, type: 'bold', matchIdx: 0 })
188199
matchPID.current = undefined
189200
forceUpdate()
190201
})

client/src/playback/GameRunner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ class GameRunnerClass {
102102
})
103103
}
104104

105-
setMatch(match: Match | undefined): void {
105+
setMatch(match: Match | undefined, round: number = 1): void {
106106
this._trigger(this._matchListeners)
107107
if (match) {
108108
match.game.currentMatch = match
109109
this.setGame(match.game)
110-
match._jumpToStart()
110+
match._jumpToRound(round)
111111
GameRenderer.render()
112112
}
113113
this.setPaused(true)

0 commit comments

Comments
 (0)