From a1a2dbdcac2580f5e2c062f470bc7bc2772712eb Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Sun, 11 Oct 2026 22:18:20 -0400 Subject: [PATCH] feat(minigames): highlight the selected emplacement and add rotation controls Ring the selected emplacement's grid cells and document the controls in the editor help text. Rotate a placed emplacement in place by double-clicking it or by pressing the Horizontal/Vertical toggle (the toggle also sets the orientation for a new placement, and is disabled for the fixed 2x2 Command Post). Fix: moving an emplacement after rotating it kept the default orientation instead of the rotated one, so the rotation was lost on the next click. placeAt now preserves the emplacement's stored orientation when moving it. --- .../call-for-fire-versus/VersusMatch.tsx | 100 ++++++++++++++++-- 1 file changed, 89 insertions(+), 11 deletions(-) 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 b0a2be93..3e989c14 100644 --- a/src/components/frontend/minigames/call-for-fire-versus/VersusMatch.tsx +++ b/src/components/frontend/minigames/call-for-fire-versus/VersusMatch.tsx @@ -144,10 +144,11 @@ function PlacementPhase({ const placeAt = useCallback( (x: number, y: number) => { - // Clicking a placed emplacement picks it up instead of overwriting it. + // Clicking a placed emplacement picks it up; its own cells stay inert so a + // double-click can rotate it without also nudging its anchor. const existing = occupied.get(`${x},${y}`); - if (existing && existing !== selectedId) { - setSelectedId(existing); + if (existing) { + if (existing !== selectedId) setSelectedId(existing); setError(null); return; } @@ -155,7 +156,10 @@ function PlacementPhase({ const definition = FOB_FLEET.find((f) => f.id === selectedId); if (!definition) return; const origin: GridPoint = { x, y }; - const cells = cellsForFob(definition, origin, orientation, BOARD); + // Keep an already-placed emplacement's orientation when moving it; only + // fall back to the toggle default for a brand-new placement. + const placeOrientation = placements[selectedId]?.orientation ?? orientation; + const cells = cellsForFob(definition, origin, placeOrientation, BOARD); if (!cells) { setError(`${definition.label} does not fit there.`); return; @@ -182,7 +186,7 @@ function PlacementPhase({ setError(null); setPlacements((current) => ({ ...current, - [selectedId]: { assetId: selectedId, origin, orientation }, + [selectedId]: { assetId: selectedId, origin, orientation: placeOrientation }, })); const nextUnplaced = FOB_FLEET.find((f) => f.id !== selectedId && !placements[f.id]); if (nextUnplaced) setSelectedId(nextUnplaced.id); @@ -190,6 +194,44 @@ function PlacementPhase({ [occupied, orientation, placements, selectedId], ); + /** Double-click a placed line emplacement to flip its orientation in place. */ + const rotateAsset = useCallback( + (assetId: string) => { + const definition = FOB_FLEET.find((f) => f.id === assetId); + const placement = placements[assetId]; + if (!definition || !placement || definition.shape === "square") return; + const nextOrientation: FobOrientation = placement.orientation === "h" ? "v" : "h"; + const cells = cellsForFob(definition, placement.origin, nextOrientation, BOARD); + if (!cells) { + setError(`${definition.label} does not fit rotated there.`); + return; + } + const conflict = FOB_FLEET.find((other) => { + if (other.id === assetId) 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(`Cannot rotate: it would overlap the ${conflict.label}.`); + return; + } + setError(null); + setSelectedId(assetId); + setPlacements((current) => ({ + ...current, + [assetId]: { ...placement, orientation: nextOrientation }, + })); + }, + [placements], + ); + const allPlaced = FOB_FLEET.every((definition) => placements[definition.id]); const confirm = useCallback(async () => { @@ -206,6 +248,18 @@ function PlacementPhase({ else setError(result.error ?? "Could not confirm your emplacements."); }, [allPlaced, match.matchId, onMatch, placements]); + const selectedIsSquare = selectedDefinition.shape === "square"; + const effectiveOrientation = selectedPlacement ? selectedPlacement.orientation : orientation; + + const toggleOrientation = useCallback(() => { + if (selectedIsSquare) return; + if (selectedPlacement) { + rotateAsset(selectedId); + return; + } + setOrientation((value) => (value === "h" ? "v" : "h")); + }, [rotateAsset, selectedId, selectedIsSquare, selectedPlacement]); + return ( @@ -281,12 +335,15 @@ function PlacementPhase({ ); })} @@ -311,17 +368,28 @@ function PlacementPhase({ occupied={occupied} preview={new Set(previewCells.map(key))} previewClass={fobStyle(selectedId).cell} + selectedId={selectedId} disabled={false} onPlace={placeAt} + onRotate={rotateAsset} /> ))} -

- 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. -

+
+

How to emplace

+
    +
  • Select an emplacement above, then click a cell to anchor it there.
  • +
  • Click a placed emplacement to pick it up, then click a new cell to move it.
  • +
  • + Double-click a placed emplacement, or press the Horizontal/Vertical toggle, to rotate + it in place. The Command Post is a fixed 2x2 block and does not rotate. +
  • +
  • The toggle also sets the orientation used for your next placement.
  • +
  • Emplacements cannot overlap, and your opponent never sees your layout.
  • +
+
); @@ -332,15 +400,19 @@ function PlacementRow({ occupied, preview, previewClass, + selectedId, disabled, onPlace, + onRotate, }: { y: number; occupied: Map; preview: Set; previewClass: string; + selectedId: string; disabled: boolean; onPlace: (x: number, y: number) => void; + onRotate: (assetId: string) => void; }) { return ( <> @@ -350,17 +422,23 @@ function PlacementRow({ {Array.from({ length: BOARD }, (_, x) => { const assetId = occupied.get(`${x},${y}`); const isPreview = preview.has(`${x},${y}`); + const selected = assetId !== undefined && assetId === selectedId; return (