Skip to content

Commit 384d5e2

Browse files
Merge branch 'master' into public-release
2 parents dd126f1 + f51e595 commit 384d5e2

File tree

12 files changed

+37
-833
lines changed

12 files changed

+37
-833
lines changed

client/package-lock.json

Lines changed: 0 additions & 565 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,9 @@
129129
"homepage": "https://github.com/battlecode/battlecode25#readme",
130130
"dependencies": {
131131
"@headlessui/react": "^2.2.0",
132-
"@types/d3": "^7.4.2",
133132
"assert": "^2.0.0",
134133
"battlecode-schema": "file:../schema",
135134
"child_process": "^1.0.2",
136-
"d3": "^7.8.5",
137135
"electron-fetch": "^1.9.1",
138136
"electron-is-dev": "^2.0.0",
139137
"fs": "^0.0.1-security",

client/src/components/sidebar/game/d3-histogram.tsx

Lines changed: 0 additions & 80 deletions
This file was deleted.

client/src/components/sidebar/game/d3-line-chart.tsx

Lines changed: 0 additions & 166 deletions
This file was deleted.

client/src/components/sidebar/game/quick-line-chart.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { useEffect, useRef } from 'react'
22
import { Colors, currentColors } from '../../../colors'
33
import { drawAxes, getAxes, setCanvasResolution } from '../../../util/graph-util'
4+
import { useGame } from '../../../playback/GameRunner'
45

56
export interface LineChartDataPoint {
67
round: number
7-
brown: number
8-
white: number
8+
team0: number
9+
team1: number
910
}
1011

1112
interface LineChartProps {
@@ -29,6 +30,7 @@ export const QuickLineChart: React.FC<LineChartProps> = ({
2930
resolution = window.devicePixelRatio ?? 1
3031
}) => {
3132
const canvasRef = useRef<HTMLCanvasElement | null>(null)
33+
const game = useGame()
3234

3335
useEffect(() => {
3436
if (!canvasRef.current) return
@@ -38,22 +40,22 @@ export const QuickLineChart: React.FC<LineChartProps> = ({
3840

3941
setCanvasResolution(canvas, width, height, resolution)
4042

41-
const max = Math.max(...data.map((d) => Math.max(d.brown, d.white)))
43+
const max = Math.max(...data.map((d) => Math.max(d.team0, d.team1)))
4244
const { xScale, yScale, innerWidth, innerHeight } = getAxes(width, height, margin, { x: data.length, y: max })
4345

4446
context.clearRect(0, 0, width, height)
4547

4648
if (data.length > 0) {
47-
context.strokeStyle = currentColors[Colors.TEAM_ONE]
49+
context.strokeStyle = game?.teams[0].color ?? 'black'
4850
context.beginPath()
49-
context.moveTo(xScale(data[0].round), yScale(data[0].white))
50-
for (let i = 1; i < data.length; i++) context.lineTo(xScale(data[i].round), yScale(data[i].white))
51+
context.moveTo(xScale(data[0].round), yScale(data[0].team0))
52+
for (let i = 1; i < data.length; i++) context.lineTo(xScale(data[i].round), yScale(data[i].team0))
5153
context.stroke()
5254

53-
context.strokeStyle = currentColors[Colors.TEAM_TWO]
55+
context.strokeStyle = game?.teams[1].color ?? 'black'
5456
context.beginPath()
55-
context.moveTo(xScale(data[0].round), yScale(data[0].brown))
56-
for (let i = 1; i < data.length; i++) context.lineTo(xScale(data[i].round), yScale(data[i].brown))
57+
context.moveTo(xScale(data[0].round), yScale(data[0].team1))
58+
for (let i = 1; i < data.length; i++) context.lineTo(xScale(data[i].round), yScale(data[i].team1))
5759
context.stroke()
5860
}
5961

client/src/components/sidebar/game/resource-graph.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react'
2-
import { D3LineChart, LineChartDataPoint } from './d3-line-chart'
32
import assert from 'assert'
43
import { useRound } from '../../../playback/GameRunner'
54
import Round from '../../../playback/Round'
6-
import { QuickLineChart } from './quick-line-chart'
5+
import { LineChartDataPoint, QuickLineChart } from './quick-line-chart'
76

87
interface Props {
98
active: boolean
@@ -26,8 +25,8 @@ function getChartData(round: Round, property: string): LineChartDataPoint[] {
2625
return values[0].slice(0, round.roundNumber).map((value, index) => {
2726
return {
2827
round: index + 1,
29-
white: value as number,
30-
brown: values[1][index] as number
28+
team0: value as number,
29+
team1: values[1][index] as number
3130
}
3231
})
3332
}

client/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const CLIENT_VERSION = '1.3.1'
1+
export const CLIENT_VERSION = '1.3.2'
22
export const SPEC_VERSION = '1'
33
export const BATTLECODE_YEAR: number = 2025
44
export const MAP_SIZE_RANGE = {

client/src/playback/Game.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ export default class Game {
9696
this.id = nextID++
9797
}
9898

99+
get complete() {
100+
return this.winner !== null
101+
}
102+
99103
/*
100104
* Adds a new game event to the game.
101105
*/

client/src/playback/Match.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,16 @@ export default class Match {
292292
*/
293293
public _jumpToRound(roundNumber: number): void {
294294
if (!this.game.playable) return
295+
if (this.snapshots.length === 0) return
295296

296297
this._roundSimulation()
297298

298-
roundNumber = Math.max(1, Math.min(roundNumber, this.maxRound))
299+
// Determine the maximum round we are allowed to jump to. If the game is
300+
// incomplete (still being updated with rounds), prevent jumping to the last
301+
// round to prevent issues (TODO: investigate why, but this seems to fix it)
302+
const maxRound = this.maxRound - (this.game.complete ? 0 : 1)
303+
304+
roundNumber = Math.max(1, Math.min(roundNumber, maxRound))
299305
if (roundNumber == this.currentRound.roundNumber) return
300306

301307
// Select the closest snapshot round, or mutate the current round if we can

client/src/util/graph-util.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Axis } from 'd3'
2-
31
export function getAxes(
42
width: number,
53
height: number,

0 commit comments

Comments
 (0)