Skip to content

Commit 97092b0

Browse files
Merge branch 'master' into release-config
2 parents 1e12bf6 + e69e0cf commit 97092b0

39 files changed

+384
-186
lines changed

client/src/app-context.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export interface AppState {
99
activeGame: Game | undefined
1010
activeMatch: Match | undefined
1111
tournament: Tournament | undefined
12-
loadingRemoteContent: boolean
12+
tournamentMinRound: number // Minimum round to display
13+
loadingRemoteContent: string
1314
updatesPerSecond: number
1415
paused: boolean
1516
disableHotkeys: boolean
@@ -21,7 +22,8 @@ const DEFAULT_APP_STATE: AppState = {
2122
activeGame: undefined,
2223
activeMatch: undefined,
2324
tournament: undefined,
24-
loadingRemoteContent: false,
25+
tournamentMinRound: 1,
26+
loadingRemoteContent: '',
2527
updatesPerSecond: 1,
2628
paused: true,
2729
disableHotkeys: false,

client/src/client-config.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const DEFAULT_CONFIG = {
1414
showHealthBars: false,
1515
showMapXY: true,
1616
showFlagCarryIndicator: true,
17-
streamRunnerGames: false
17+
streamRunnerGames: false,
18+
validateMaps: false
1819
}
1920

2021
const configDescription: { [key: string]: string } = {
@@ -23,7 +24,8 @@ const configDescription: { [key: string]: string } = {
2324
showHealthBars: 'Show health bars below all robots',
2425
showMapXY: 'Show X,Y when hovering a tile',
2526
showFlagCarryIndicator: 'Show an obvious indicator over flag carriers',
26-
streamRunnerGames: 'Stream each round from the runner live as the game is being played'
27+
streamRunnerGames: 'Stream each round from the runner live as the game is being played',
28+
validateMaps: 'Validate maps before running a game'
2729
}
2830

2931
export function getDefaultConfig(): ClientConfig {

client/src/components/forms.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { PropsWithChildren } from 'react'
2+
import { useAppContext } from '../app-context'
23

34
interface SelectProps {
45
value?: string | number
@@ -40,11 +41,14 @@ interface NumInputProps {
4041
changeValue: (newValue: number) => void
4142
}
4243
export const NumInput: React.FC<NumInputProps> = (props) => {
44+
const context = useAppContext()
45+
46+
const [focused, setFocused] = React.useState(false)
4347
const [tempValue, setTempValue] = React.useState<string | undefined>()
4448

45-
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
49+
const handleInputChange = (val: string) => {
4650
// Direct change from arrows
47-
const value = parseInt(e.target.value)
51+
const value = parseInt(val)
4852
if (!isNaN(value) && value >= props.min && value <= props.max) {
4953
props.changeValue(value)
5054
}
@@ -53,16 +57,28 @@ export const NumInput: React.FC<NumInputProps> = (props) => {
5357
const handleInputBlur = () => {
5458
// Reset temp value after user loses focus
5559
setTempValue(undefined)
60+
setFocused(false)
5661
}
5762

63+
const handleClick = () => {
64+
setTempValue(undefined)
65+
handleInputChange(tempValue || '')
66+
}
67+
68+
React.useEffect(() => {
69+
context.setState((prevState) => ({ ...prevState, disableHotkeys: focused }))
70+
}, [focused])
71+
5872
return (
5973
<input
6074
className={'border border-black py-0.5 px-1 rounded-md w-12 ' + (props.className ?? '')}
6175
type="number"
6276
value={tempValue ?? props.value}
6377
onBlur={handleInputBlur}
64-
onInput={handleInputChange}
78+
onFocus={() => setFocused(true)}
79+
onInput={(e) => handleInputChange(e.currentTarget.value)}
6580
onChange={(e) => setTempValue(e.target.value)}
81+
onClick={handleClick}
6682
/>
6783
)
6884
}
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import React from 'react'
22
import { GameRenderer } from './game-renderer'
3-
import { useAppContext } from '../../app-context';
4-
import { TournamentRenderer } from './tournament-renderer/tournament-renderer';
3+
import { useAppContext } from '../../app-context'
4+
import { TournamentRenderer } from './tournament-renderer/tournament-renderer'
55

66
export const GameArea: React.FC = () => {
77
const appContext = useAppContext()
88

9-
if (!appContext.state.activeGame && appContext.state.tournament)
9+
if (appContext.state.loadingRemoteContent) {
10+
return (
11+
<div className="relative w-full h-screen flex items-center justify-center">
12+
<p className="text-white text-center">{`Loading remote ${appContext.state.loadingRemoteContent}...`}</p>
13+
</div>
14+
)
15+
}
16+
17+
if (!appContext.state.activeGame && appContext.state.tournament) {
1018
return <TournamentRenderer />
19+
}
1120

1221
return <GameRenderer />
1322
}

client/src/components/game/game-renderer.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ export const GameRenderer: React.FC = () => {
7373
updateCanvasDimensions(dynamicCanvas.current, { x: width, y: height })
7474
updateCanvasDimensions(overlayCanvas.current, { x: width, y: height })
7575
setSelectedSquare(undefined)
76+
setSelectedBodyID(undefined)
77+
setHoveredTile(undefined)
78+
setHoveredBodyID(undefined)
7679
publishEvent(EventType.INITIAL_RENDER, {})
7780
}, [appContext.state.activeMatch, backgroundCanvas.current, dynamicCanvas.current, overlayCanvas.current])
7881

@@ -135,11 +138,7 @@ export const GameRenderer: React.FC = () => {
135138
ref={wrapperRef}
136139
>
137140
{!activeMatch ? (
138-
appContext.state.loadingRemoteContent ? (
139-
<p className="text-white text-center">Loading remote game...</p>
140-
) : (
141-
<p className="text-white text-center">Select a game from the queue</p>
142-
)
141+
<p className="text-white text-center">Select a game from the queue</p>
143142
) : (
144143
<>
145144
<canvas

client/src/components/game/tournament-renderer/tournament-game.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export const TournamentGameElement: React.FC<Props> = ({ lines, game }) => {
3131
return
3232
}
3333
const loadedGame = Game.loadFullGameRaw(buffer)
34+
35+
// select the first match
36+
const selectedMatch = loadedGame.matches[0]
37+
loadedGame.currentMatch = selectedMatch
38+
3439
appContext.setState((prevState) => ({
3540
...prevState,
3641
activeGame: loadedGame,
@@ -47,7 +52,7 @@ export const TournamentGameElement: React.FC<Props> = ({ lines, game }) => {
4752
return (
4853
<Pressable
4954
className={
50-
'pt-4 px-2 pb-2 mx-2 my-4 rounded d-flex flex-col relative border-2 border-white min-w-[80px] max-w-[120px] ' +
55+
'pt-4 px-2 pb-2 mx-2 my-4 rounded d-flex flex-col relative border-2 border-white min-w-[80px] max-w-[140px] ' +
5156
(loadingGame ? 'opacity-50' : '') +
5257
' ' +
5358
(game.gameFile

0 commit comments

Comments
 (0)