Skip to content

Commit

Permalink
Merge branch 'master' into release-config
Browse files Browse the repository at this point in the history
  • Loading branch information
TheApplePieGod committed Jan 9, 2024
2 parents f325287 + f775d5f commit f3f02e5
Show file tree
Hide file tree
Showing 28 changed files with 506 additions and 259 deletions.
2 changes: 1 addition & 1 deletion client/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<html lang="en" style="overscroll-behavior: none; overflow: hidden">

<head>
<meta charset="UTF-8">
Expand Down
6 changes: 3 additions & 3 deletions client/src/client-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ const ConfigBooleanElement: React.FC<{ configKey: string }> = ({ configKey }) =>
type={'checkbox'}
checked={value}
onChange={(e) => {
context.setState({
...context.state,
context.setState((prevState) => ({
...prevState,
config: { ...context.state.config, [configKey]: e.target.checked }
})
}))
localStorage.setItem('config' + configKey, JSON.stringify(e.target.checked))
// hopefully after the setState is done
setTimeout(() => publishEvent(EventType.RENDER, {}), 10)
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/confirm-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const ConfirmDialog: React.FC<PropsWithChildren<Props>> = (props) => {
const context = useAppContext()

React.useEffect(() => {
context.setState({ ...context.state, disableHotkeys: props.open })
context.setState((prevState) => ({ ...prevState, disableHotkeys: props.open }))
}, [props.open])

if (!props.open) return <></>
Expand Down
24 changes: 12 additions & 12 deletions client/src/components/controls-bar/controls-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ export const ControlsBar: React.FC = () => {
const currentUPSBuffer = React.useRef<number[]>([])

const currentMatch = appState.activeGame?.currentMatch
const isPlayable = appState.activeGame && appState.activeGame.playable
const isPlayable = appState.activeGame && appState.activeGame.playable && currentMatch
const hasNextMatch =
currentMatch && appState.activeGame!.matches.indexOf(currentMatch!) + 1 < appState.activeGame!.matches.length

const changePaused = (paused: boolean) => {
if (!currentMatch) return
setAppState({
...appState,
setAppState((prevState) => ({
...prevState,
paused: paused,
updatesPerSecond: appState.updatesPerSecond == 0 && !paused ? 1 : appState.updatesPerSecond
})
}))
}

const multiplyUpdatesPerSecond = (multiplier: number) => {
Expand Down Expand Up @@ -78,19 +78,19 @@ export const ControlsBar: React.FC = () => {
}

game.currentMatch = game.matches[prevMatchIndex + 1]
setAppState({
...appState,
setAppState((prevState) => ({
...prevState,
activeGame: game,
activeMatch: game.currentMatch
})
}))
}

const closeGame = () => {
setAppState({
...appState,
setAppState((prevState) => ({
...prevState,
activeGame: undefined,
activeMatch: undefined
})
}))
if (appState.tournament) setPage(PageType.TOURNAMENT)
}

Expand Down Expand Up @@ -175,8 +175,8 @@ export const ControlsBar: React.FC = () => {

if (!isPlayable) return null

const atStart = currentMatch!.currentTurn.turnNumber == 0
const atEnd = currentMatch!.currentTurn.turnNumber == currentMatch!.maxTurn
const atStart = currentMatch.currentTurn.turnNumber == 0
const atEnd = currentMatch.currentTurn.turnNumber == currentMatch.maxTurn

return (
<div className="flex absolute bottom-0 rounded-t-md z-10 pointer-events-none">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export const TournamentGameElement: React.FC<Props> = ({ lines, game }) => {
return
}
const loadedGame = Game.loadFullGameRaw(buffer)
appContext.setState({
...appContext.state,
appContext.setState((prevState) => ({
...prevState,
activeGame: loadedGame,
activeMatch: loadedGame.currentMatch,
queue: appContext.state.queue.concat([loadedGame])
})
}))
game.viewed = true
setPage(PageType.GAME)
setLoadingGame(false)
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/input-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const InputDialog: React.FC<PropsWithChildren<Props>> = (props) => {
const context = useAppContext()

React.useEffect(() => {
context.setState({ ...context.state, disableHotkeys: props.open })
context.setState((prevState) => ({ ...prevState, disableHotkeys: props.open }))
if (props.open) {
setValue(props.defaultValue ?? '')
}
Expand Down
12 changes: 9 additions & 3 deletions client/src/components/sidebar/map-editor/MapGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function verifyMapGuarantees(turn: Turn) {
const loc = turn.map.staticMap.spawnLocations[i]
for (let x = loc.x - 1; x <= loc.x + 1; x++) {
for (let y = loc.y - 1; y <= loc.y + 1; y++) {
if (x == loc.x && y == loc.y) continue
if (x < 0 || x >= turn.map.width || y < 0 || y >= turn.map.height) continue
const mapIdx = turn.map.locationToIndex(x, y)
if (
Expand All @@ -73,8 +72,8 @@ function verifyMapGuarantees(turn: Turn) {
}
}
}
if (totalSpawnableLocations < 18) {
return `Map has ${totalSpawnableLocations} spawnable locations. Must have at least 9 for each team`
if (totalSpawnableLocations < 9 * 3 * 2) {
return `Map has ${totalSpawnableLocations} spawnable locations. Must have 9 * 3 for each team`
}

const floodMask = new Int8Array(turn.map.width * turn.map.height)
Expand All @@ -92,6 +91,13 @@ function verifyMapGuarantees(turn: Turn) {
if (x < 0 || x >= turn.map.width || y < 0 || y >= turn.map.height) continue
const newIdx = turn.map.locationToIndex(x, y)
if (!turn.map.staticMap.divider[newIdx] && !floodMask[newIdx]) {
// Check if we can reach an enemy spawn location
for (let i = 0; i < turn.map.staticMap.spawnLocations.length; i++) {
const loc = turn.map.staticMap.spawnLocations[i]
if (loc.x == x && loc.y == y && i % 2 != 0)
return `Maps cannot have spawn zones that are initially reachable by both teams`
}

floodMask[newIdx] = 1
floodQueue.push(newIdx)
totalFlooded++
Expand Down
16 changes: 8 additions & 8 deletions client/src/components/sidebar/map-editor/map-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,23 @@ export const MapEditorPage: React.FC<Props> = (props) => {
// multiple times
mapParams.imported = undefined

context.setState({
...context.state,
activeGame: editGame.current,
activeMatch: editGame.current.currentMatch
})
context.setState((prevState) => ({
...prevState,
activeGame: editGame.current ?? undefined,
activeMatch: editGame.current?.currentMatch
}))

const turn = editGame.current.currentMatch!.currentTurn
const brushes = turn.map.getEditorBrushes().concat(turn.bodies.getEditorBrushes(turn.map.staticMap))
brushes[0].open = true
setBrushes(brushes)
setCleared(turn.bodies.isEmpty() && turn.map.isEmpty())
} else {
context.setState({
...context.state,
context.setState((prevState) => ({
...prevState,
activeGame: undefined,
activeMatch: undefined
})
}))
}
}, [mapParams, props.open])

Expand Down
24 changes: 16 additions & 8 deletions client/src/components/sidebar/queue/queue-game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ export const QueuedGame: React.FC<Props> = (props) => {
const setMatch = (match: Match) => {
match.jumpToTurn(0)
props.game.currentMatch = match
context.setState({
...context.state,
context.setState((prevState) => ({
...prevState,
activeGame: match.game,
activeMatch: match
})
}))
}

const close = () => {
context.setState({
...context.state,
context.setState((prevState) => ({
...prevState,
queue: context.state.queue.filter((v) => v !== props.game),
activeGame: context.state.activeGame === props.game ? undefined : context.state.activeGame,
activeMatch: context.state.activeGame === props.game ? undefined : context.state.activeMatch
})
}))
}

const getWinText = (winType: schema.WinType) => {
Expand Down Expand Up @@ -74,8 +74,16 @@ export const QueuedGame: React.FC<Props> = (props) => {
{!isTournamentMode && (
<span className="text-xxs leading-tight">
<span className="mx-1">-</span>
<span className={`font-bold text-team${match.winner.id - 1}`}>{match.winner.name}</span>
<span>{` wins ${getWinText(match.winType)}after ${match.maxTurn} rounds`}</span>
{match.winner !== null && match.winType !== null ? (
<>
<span className={`font-bold text-team${match.winner.id - 1}`}>
{match.winner.name}
</span>
<span>{` wins ${getWinText(match.winType)}after ${match.maxTurn} rounds`}</span>
</>
) : (
<span>Winner not known</span>
)}
</span>
)}
</p>
Expand Down
6 changes: 3 additions & 3 deletions client/src/components/sidebar/queue/queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ export const QueuePage: React.FC<Props> = (props) => {
const selectedMatch = game.matches[0]
game.currentMatch = selectedMatch

context.setState({
...context.state,
context.setState((prevState) => ({
...prevState,
queue: queue.concat([game]),
activeGame: game,
activeMatch: selectedMatch
})
}))
}
reader.readAsArrayBuffer(file)
}
Expand Down
39 changes: 24 additions & 15 deletions client/src/components/sidebar/runner/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { ConsoleLine } from './runner'
import { useForceUpdate } from '../../../util/react-util'
import WebSocketListener from './websocket'
import { useAppContext } from '../../../app-context'
import Game from '../../../playback/Game'
import Match from '../../../playback/Match'

export type JavaInstall = {
display: string
Expand Down Expand Up @@ -115,17 +117,24 @@ export function useScaffold(): Scaffold {
forceUpdate()
})

setWebSocketListener(
new WebSocketListener((game) => {
game.currentMatch = game.matches[0]
appContext.setState({
...appContext.state,
queue: appContext.state.queue.concat([game]),
activeGame: game,
activeMatch: game.currentMatch
})
})
)
const onGameCreated = (game: Game) => {
appContext.setState((prevState) => ({
...prevState,
queue: appContext.state.queue.concat([game]),
activeGame: game,
activeMatch: game.currentMatch
}))
}

const onMatchCreated = (match: Match) => {
appContext.setState((prevState) => ({
...prevState,
activeGame: match.game,
activeMatch: match
}))
}

setWebSocketListener(new WebSocketListener(onGameCreated, onMatchCreated, () => {}))
}, [])

useEffect(() => {
Expand Down Expand Up @@ -214,16 +223,16 @@ async function findDefaultScaffoldPath(nativeAPI: NativeAPI): Promise<string | u
const fromWin = await path.dirname(await path.dirname(appPath))
// scaffold/client/resources/app.asar
const from3 = await path.dirname(await path.dirname(await path.dirname(appPath)))
// scaffold/Battlecode Client.app/Contents/Resources/app.asar
// scaffold/client/Battlecode Client.app/Contents/Resources/app.asar
const fromMac = await path.dirname(
await path.dirname(await path.dirname(await path.dirname(await path.dirname(appPath))))
)

if (await fs.exists(from3)) {
if (await fs.exists(await path.join(from3, 'gradlew'))) {
return from3
} else if (await fs.exists(fromWin)) {
} else if (await fs.exists(await path.join(fromWin, 'gradlew'))) {
return fromWin
} else if (await fs.exists(fromMac)) {
} else if (await fs.exists(await path.join(fromMac, 'gradlew'))) {
return fromMac
}

Expand Down
Loading

0 comments on commit f3f02e5

Please sign in to comment.