Skip to content

Commit 90c12a3

Browse files
committed
Merge branch 'schema' of https://github.com/battlecode/battlecode26 into schema
2 parents c6635d5 + 85a3feb commit 90c12a3

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

client/src/playback/Actions.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
118118
const fontY =
119119
coords.y - (2 + 4 * random2) * interpolationFactor + 8 * interpolationFactor * interpolationFactor - 0.5
120120
ctx.fillText('nom', fontX, fontY)
121-
src.imgPath = 'robots/cat/cat_feed.png' // is reset in `finish`.
121+
src.imgPath = `robots/cat/cat_feed_${src.direction}.png`// is reset in `finish`.
122122
ctx.restore()
123123
}
124124

@@ -344,6 +344,12 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
344344
}
345345
ctx.stroke()
346346
ctx.globalAlpha = 1
347+
body.imgPath = `robots/cat/cat_scratch_${body.direction}.png`
348+
}
349+
350+
finish(round: Round): void {
351+
const body = round.bodies.getById(this.robotId)
352+
body.imgPath = 'robots/cat/cat.png'
347353
}
348354
},
349355
[schema.Action.CatPounce]: class CatPounceAction extends Action<schema.CatPounce> {

client/src/playback/Brushes.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,15 @@ export class WallsBrush extends SymmetricMapEditorBrush<StaticMap> {
317317
const cheeseMine = this.map.cheeseMines.findIndex((l) => squareIntersects(l, pos, 2))
318318
const dirt = this.map.initialDirt[idx]
319319

320+
for (const waypoints of this.map.catWaypoints.values()) {
321+
for (const waypoint of waypoints) {
322+
if (waypoint.x === pos.x && waypoint.y === pos.y) return true
323+
for (let nei of this.map.getNeighbors(waypoint.x, waypoint.y)) {
324+
if (nei.x === pos.x && nei.y === pos.y) return true
325+
}
326+
}
327+
}
328+
320329
if (cheeseMine !== -1 || dirt) return true
321330

322331
this.map.walls[idx] = 1
@@ -551,23 +560,27 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
551560
if (!body) return null
552561

553562
const team = body.team
563+
const pos = body.pos
554564
this.bodies.removeBody(body.id)
555565
const waypoints = this.map.catWaypoints.get(body.id)
556566
this.map.catWaypoints.delete(body.id)
557567

558-
return { team, waypoints }
568+
return { team, waypoints, pos }
559569
}
560-
561570
if (isCat) {
562571
// shouldnt matter which team we add to since cats are neutral
563572
const id = add(x, y, this.bodies.game.teams[0])
564573
if (id) return () => this.bodies.removeBody(id)
565574
return null
566575
} else {
567-
const { team, waypoints } = remove(x, y)!
576+
const removed = remove(x, y)
577+
if (!removed) return null
578+
579+
const { team, waypoints, pos } = removed
568580
if (!team) return null
581+
569582
return () => {
570-
add(x, y, team)
583+
add(pos.x, pos.y, team)
571584
if (waypoints) {
572585
this.map.catWaypoints.set(this.bodies.getBodyAtLocation(x, y)!.id, waypoints)
573586
}
@@ -578,6 +591,10 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
578591
// Override default symmetric apply behavior because cats occupy a 2x2 footprint
579592
public apply(x: number, y: number, fields: Record<string, MapEditorBrushField>, robotOne: boolean): UndoFunction {
580593
const undoFunctions: UndoFunction[] = []
594+
595+
const body = this.bodies.getBodyAtLocation(x, y)
596+
const anchor = body?.pos
597+
581598
const undo0 = this.symmetricApply(x, y, fields, robotOne)
582599

583600
// Return early if brush could not be applied
@@ -589,7 +606,7 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
589606
if (fields.catOrWaypointMode.value === 1) {
590607
symmetryPoint = this.map.applySymmetry({ x: x, y: y })
591608
} else {
592-
symmetryPoint = this.map.applySymmetryCat({ x: x, y: y })
609+
symmetryPoint = !anchor ? this.map.applySymmetryCat({ x: x, y: y }) : this.map.applySymmetryCat(anchor)
593610
}
594611
if (symmetryPoint.x != x || symmetryPoint.y != y) {
595612
const undo1 = this.symmetricApply(symmetryPoint.x, symmetryPoint.y, fields, !robotOne)

0 commit comments

Comments
 (0)