1
0
Fork 0

fix(minigames): pick up placed emplacements on click instead of overwriting

Clicking a grid cell always placed the currently selected emplacement
there and silently deleted whatever it overlapped, so clicking an
earlier emplacement (after selection auto-advanced) clobbered it. Now
clicking a placed emplacement selects it so it can be moved, and placing
onto an occupied cell is refused with a message instead of deleting the
other emplacement. Adds the pick-up hint to the editor copy.
This commit is contained in:
Jason Fraley 2026-10-11 22:12:04 -04:00
parent 3ce9677fd0
commit d4bf0e9742

View file

@ -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({
</div>
<p className="text-xs text-muted-foreground">
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.
</p>
</CardContent>
</Card>