@@ -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
@@ -476,11 +485,13 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
476485 public symmetricApply ( x : number , y : number , fields : Record < string , MapEditorBrushField > , robotOne : boolean ) {
477486 const isCat : boolean = fields . isCat . value
478487 const selectedBodyID = GameRenderer . getSelectedRobot ( )
488+ let lastSelectedCatLoc : Vector | null = null
479489
480490 if ( selectedBodyID !== null && selectedBodyID !== undefined ) {
481491 const body = this . bodies . bodies . get ( selectedBodyID )
482492 if ( body && body . robotType === schema . RobotType . CAT ) {
483493 this . lastSelectedCat = selectedBodyID
494+ lastSelectedCatLoc = this . bodies . getById ( this . lastSelectedCat ) ?. pos
484495 }
485496 }
486497
@@ -491,6 +502,7 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
491502 if ( ! robotOne ) {
492503 const symmetricPoint = this . map . applySymmetryCat ( this . bodies . getById ( this . lastSelectedCat ) ! . pos )
493504 currentCat = this . bodies . getBodyAtLocation ( symmetricPoint . x , symmetricPoint . y ) ! . id
505+ lastSelectedCatLoc = this . map . applySymmetry ( lastSelectedCatLoc ! )
494506 }
495507
496508 // if undoing a waypoint addition
@@ -518,6 +530,9 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
518530 return null
519531 }
520532
533+ if ( ! this . map . catWaypoints . has ( currentCat ) ) {
534+ this . map . catWaypoints . set ( currentCat , [ lastSelectedCatLoc ! ] )
535+ }
521536 this . map . catWaypoints . get ( currentCat ) ?. push ( { x, y } )
522537
523538 return ( ) => {
@@ -535,7 +550,6 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
535550
536551 const id = this . bodies . getNextID ( )
537552 this . bodies . spawnBodyFromValues ( id , schema . RobotType . CAT , team , pos , 0 , robotOne ? 0 : 1 )
538- this . map . catWaypoints . set ( id , [ { x : x , y : y } ] ) // add initial waypoint at spawn location
539553
540554 return id
541555 }
@@ -546,23 +560,27 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
546560 if ( ! body ) return null
547561
548562 const team = body . team
563+ const pos = body . pos
549564 this . bodies . removeBody ( body . id )
550565 const waypoints = this . map . catWaypoints . get ( body . id )
551566 this . map . catWaypoints . delete ( body . id )
552567
553- return { team, waypoints }
568+ return { team, waypoints, pos }
554569 }
555-
556570 if ( isCat ) {
557571 // shouldnt matter which team we add to since cats are neutral
558572 const id = add ( x , y , this . bodies . game . teams [ 0 ] )
559573 if ( id ) return ( ) => this . bodies . removeBody ( id )
560574 return null
561575 } else {
562- const { team, waypoints } = remove ( x , y ) !
576+ const removed = remove ( x , y )
577+ if ( ! removed ) return null
578+
579+ const { team, waypoints, pos } = removed
563580 if ( ! team ) return null
581+
564582 return ( ) => {
565- add ( x , y , team )
583+ add ( pos . x , pos . y , team )
566584 if ( waypoints ) {
567585 this . map . catWaypoints . set ( this . bodies . getBodyAtLocation ( x , y ) ! . id , waypoints )
568586 }
@@ -573,14 +591,23 @@ export class CatBrush extends SymmetricMapEditorBrush<StaticMap> {
573591 // Override default symmetric apply behavior because cats occupy a 2x2 footprint
574592 public apply ( x : number , y : number , fields : Record < string , MapEditorBrushField > , robotOne : boolean ) : UndoFunction {
575593 const undoFunctions : UndoFunction [ ] = [ ]
594+
595+ const body = this . bodies . getBodyAtLocation ( x , y )
596+ const anchor = body ?. pos
597+
576598 const undo0 = this . symmetricApply ( x , y , fields , robotOne )
577599
578600 // Return early if brush could not be applied
579601 if ( ! undo0 ) return ( ) => { }
580602
581603 undoFunctions . push ( undo0 )
582604
583- const symmetryPoint = this . map . applySymmetryCat ( { x : x , y : y } )
605+ let symmetryPoint : { x : number ; y : number }
606+ if ( fields . catOrWaypointMode . value === 1 ) {
607+ symmetryPoint = this . map . applySymmetry ( { x : x , y : y } )
608+ } else {
609+ symmetryPoint = ! anchor ? this . map . applySymmetryCat ( { x : x , y : y } ) : this . map . applySymmetryCat ( anchor )
610+ }
584611 if ( symmetryPoint . x != x || symmetryPoint . y != y ) {
585612 const undo1 = this . symmetricApply ( symmetryPoint . x , symmetryPoint . y , fields , ! robotOne )
586613
0 commit comments