diff --git a/src/components/frontend/minigames/call-for-fire-versus/VersusMatch.tsx b/src/components/frontend/minigames/call-for-fire-versus/VersusMatch.tsx index 9b13b61f..b0a2be93 100644 --- a/src/components/frontend/minigames/call-for-fire-versus/VersusMatch.tsx +++ b/src/components/frontend/minigames/call-for-fire-versus/VersusMatch.tsx @@ -144,32 +144,50 @@ function PlacementPhase({ const placeAt = useCallback( (x: number, y: number) => { + // Clicking a placed emplacement picks it up instead of overwriting it. + const existing = occupied.get(`${x},${y}`); + if (existing && existing !== selectedId) { + setSelectedId(existing); + setError(null); + return; + } + const definition = FOB_FLEET.find((f) => f.id === selectedId); if (!definition) return; const origin: GridPoint = { x, y }; const cells = cellsForFob(definition, origin, orientation, BOARD); - setError(cells ? null : `${definition.label} does not fit there.`); - setPlacements((current) => { - const next = { ...current }; - // Drop any other asset occupying these cells. - if (cells) { - for (const cell of cells) { - for (const otherId of Object.keys(next)) { - if (otherId === selectedId) continue; - const other = next[otherId]; - const otherDefinition = FOB_FLEET.find((f) => f.id === otherId)!; - const otherCells = cellsForFob(otherDefinition, other.origin, other.orientation, BOARD); - if (otherCells?.some((c) => c.x === cell.x && c.y === cell.y)) delete next[otherId]; - } - } - } - next[selectedId] = { assetId: selectedId, origin, orientation }; - return next; + if (!cells) { + setError(`${definition.label} does not fit there.`); + return; + } + + // Refuse overlaps rather than silently deleting another emplacement. + const conflict = FOB_FLEET.find((other) => { + if (other.id === selectedId) return false; + const otherPlacement = placements[other.id]; + if (!otherPlacement) return false; + const otherCells = cellsForFob( + other, + otherPlacement.origin, + otherPlacement.orientation, + BOARD, + ); + return Boolean(otherCells?.some((c) => cells.some((n) => n.x === c.x && n.y === c.y))); }); + if (conflict) { + setError(`That would overlap the ${conflict.label}.`); + return; + } + + setError(null); + setPlacements((current) => ({ + ...current, + [selectedId]: { assetId: selectedId, origin, orientation }, + })); const nextUnplaced = FOB_FLEET.find((f) => f.id !== selectedId && !placements[f.id]); if (nextUnplaced) setSelectedId(nextUnplaced.id); }, - [orientation, placements, selectedId], + [occupied, orientation, placements, selectedId], ); const allPlaced = FOB_FLEET.every((definition) => placements[definition.id]); @@ -301,8 +319,8 @@ function PlacementPhase({

- Select an emplacement, then click a cell to set its anchor. Toggle orientation for the - longer assets. + Select an emplacement, then click a cell to set its anchor. Click a placed emplacement to + pick it up and move it. Toggle orientation for the longer assets.