Skip to content

Commit 3623b70

Browse files
committed
cat removal fix
1 parent d24649b commit 3623b70

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

client/src/playback/Brushes.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,23 +546,27 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
546546
if (!body) return null
547547

548548
const team = body.team
549+
const pos = body.pos
549550
this.bodies.removeBody(body.id)
550551
const waypoints = this.map.catWaypoints.get(body.id)
551552
this.map.catWaypoints.delete(body.id)
552553

553-
return { team, waypoints }
554+
return { team, waypoints, pos }
554555
}
555-
556556
if (isCat) {
557557
// shouldnt matter which team we add to since cats are neutral
558558
const id = add(x, y, this.bodies.game.teams[0])
559559
if (id) return () => this.bodies.removeBody(id)
560560
return null
561561
} else {
562-
const { team, waypoints } = remove(x, y)!
562+
const removed = remove(x, y)
563+
if (!removed) return null
564+
565+
const { team, waypoints, pos } = removed
563566
if (!team) return null
567+
564568
return () => {
565-
add(x, y, team)
569+
add(pos.x, pos.y, team)
566570
if (waypoints) {
567571
this.map.catWaypoints.set(this.bodies.getBodyAtLocation(x, y)!.id, waypoints)
568572
}
@@ -573,14 +577,21 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
573577
// Override default symmetric apply behavior because cats occupy a 2x2 footprint
574578
public apply(x: number, y: number, fields: Record<string, MapEditorBrushField>, robotOne: boolean): UndoFunction {
575579
const undoFunctions: UndoFunction[] = []
580+
581+
const body = this.bodies.getBodyAtLocation(x, y)
582+
const anchor = body?.pos
583+
576584
const undo0 = this.symmetricApply(x, y, fields, robotOne)
577585

578586
// Return early if brush could not be applied
579587
if (!undo0) return () => {}
580588

581589
undoFunctions.push(undo0)
582590

583-
const symmetryPoint = this.map.applySymmetryCat({ x: x, y: y })
591+
const symmetryPoint = !anchor
592+
? this.map.applySymmetryCat({ x: x, y: y })
593+
: this.map.applySymmetryCat(anchor)
594+
584595
if (symmetryPoint.x != x || symmetryPoint.y != y) {
585596
const undo1 = this.symmetricApply(symmetryPoint.x, symmetryPoint.y, fields, !robotOne)
586597

0 commit comments

Comments
 (0)