feat(minigames): color-code versus emplacements and shrink the duel board
Give each emplacement type its own color (Command Post amber, Ammo Depot rose, Radar Site sky, FOB violet) so it is obvious what is placed where: the picker chips carry a matching swatch, placement cells and the in-battle "your fire bases" board use the type color, and struck enemy cells use the struck type's color. The shot view now carries the struck assetId so the enemy sector can be colored too. Cap the board at a compact width (max-w-sm) instead of stretching to fill the panel, so the 10x10 grid no longer dominates the screen.
This commit is contained in:
parent
005ff0e5df
commit
065018cf3c
3 changed files with 72 additions and 27 deletions
|
|
@ -25,6 +25,40 @@ import { cn } from "@/lib/utils";
|
|||
const BOARD = 10;
|
||||
const CORRECTION_STEP = 50;
|
||||
|
||||
/** Distinct color per emplacement type, for both the picker chips and grid cells. */
|
||||
const FOB_STYLES: Record<string, { cell: string; swatch: string; ring: string }> = {
|
||||
"command-post": {
|
||||
cell: "border-amber-500/70 bg-amber-500/30 text-amber-50",
|
||||
swatch: "bg-amber-400",
|
||||
ring: "border-amber-500/60",
|
||||
},
|
||||
"ammo-depot": {
|
||||
cell: "border-rose-500/70 bg-rose-500/30 text-rose-50",
|
||||
swatch: "bg-rose-400",
|
||||
ring: "border-rose-500/60",
|
||||
},
|
||||
"radar-site": {
|
||||
cell: "border-sky-500/70 bg-sky-500/30 text-sky-50",
|
||||
swatch: "bg-sky-400",
|
||||
ring: "border-sky-500/60",
|
||||
},
|
||||
fob: {
|
||||
cell: "border-violet-500/70 bg-violet-500/30 text-violet-50",
|
||||
swatch: "bg-violet-400",
|
||||
ring: "border-violet-500/60",
|
||||
},
|
||||
};
|
||||
|
||||
function fobStyle(id: string) {
|
||||
return (
|
||||
FOB_STYLES[id] ?? {
|
||||
cell: "border-emerald-500/70 bg-emerald-600/40 text-emerald-50",
|
||||
swatch: "bg-emerald-400",
|
||||
ring: "border-emerald-500/60",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function key(point: GridPoint): string {
|
||||
return `${point.x},${point.y}`;
|
||||
}
|
||||
|
|
@ -91,13 +125,13 @@ function PlacementPhase({
|
|||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const occupied = useMemo(() => {
|
||||
const map = new Map<string, { assetId: string; isNew: boolean }>();
|
||||
const map = new Map<string, string>();
|
||||
for (const definition of FOB_FLEET) {
|
||||
const placement = placements[definition.id];
|
||||
if (!placement) continue;
|
||||
const cells = cellsForPlacement(placement.origin, placement.orientation, definition.size, BOARD);
|
||||
if (!cells) continue;
|
||||
for (const cell of cells) map.set(key(cell), { assetId: definition.id, isNew: false });
|
||||
for (const cell of cells) map.set(key(cell), definition.id);
|
||||
}
|
||||
return map;
|
||||
}, [placements]);
|
||||
|
|
@ -204,23 +238,29 @@ function PlacementPhase({
|
|||
<div className="flex flex-wrap gap-2">
|
||||
{FOB_FLEET.map((definition) => {
|
||||
const placed = Boolean(placements[definition.id]);
|
||||
const style = fobStyle(definition.id);
|
||||
const selected = selectedId === definition.id;
|
||||
return (
|
||||
<button
|
||||
key={definition.id}
|
||||
type="button"
|
||||
onClick={() => setSelectedId(definition.id)}
|
||||
className={cn(
|
||||
"rounded-md border px-3 py-1.5 text-left text-xs transition-colors",
|
||||
selectedId === definition.id
|
||||
? "border-primary bg-accent"
|
||||
: "border-border hover:border-primary/50",
|
||||
"flex items-center gap-2 rounded-md border px-3 py-1.5 text-left text-xs transition-colors",
|
||||
selected ? cn("bg-accent", style.ring) : "border-border hover:border-primary/50",
|
||||
)}
|
||||
aria-pressed={selectedId === definition.id}
|
||||
aria-pressed={selected}
|
||||
>
|
||||
<span className="block font-medium">{definition.label}</span>
|
||||
<span className="block text-muted-foreground">
|
||||
{definition.size} cell{definition.size === 1 ? "" : "s"} ·{" "}
|
||||
{placed ? "placed" : "unplaced"}
|
||||
<span
|
||||
className={cn("size-3 shrink-0 rounded-sm", style.swatch)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<span className="flex flex-col">
|
||||
<span className="font-medium">{definition.label}</span>
|
||||
<span className="text-muted-foreground">
|
||||
{definition.size} cell{definition.size === 1 ? "" : "s"} ·{" "}
|
||||
{placed ? "placed" : "unplaced"}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
|
|
@ -235,10 +275,10 @@ function PlacementPhase({
|
|||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="overflow-auto rounded-lg border border-border bg-background p-3">
|
||||
<div className="mx-auto w-full max-w-sm overflow-auto rounded-lg border border-border bg-background p-3">
|
||||
<div
|
||||
className="grid gap-1"
|
||||
style={{ gridTemplateColumns: `repeat(${BOARD + 1}, minmax(1.5rem, 1fr))` }}
|
||||
style={{ gridTemplateColumns: `repeat(${BOARD + 1}, minmax(0, 1fr))` }}
|
||||
>
|
||||
<div />
|
||||
{Array.from({ length: BOARD }, (_, x) => (
|
||||
|
|
@ -255,6 +295,7 @@ function PlacementPhase({
|
|||
y={y}
|
||||
occupied={occupied}
|
||||
preview={new Set(previewCells.map(key))}
|
||||
previewClass={fobStyle(selectedId).cell}
|
||||
disabled={false}
|
||||
onPlace={placeAt}
|
||||
/>
|
||||
|
|
@ -275,12 +316,14 @@ function PlacementRow({
|
|||
y,
|
||||
occupied,
|
||||
preview,
|
||||
previewClass,
|
||||
disabled,
|
||||
onPlace,
|
||||
}: {
|
||||
y: number;
|
||||
occupied: Map<string, { assetId: string; isNew: boolean }>;
|
||||
occupied: Map<string, string>;
|
||||
preview: Set<string>;
|
||||
previewClass: string;
|
||||
disabled: boolean;
|
||||
onPlace: (x: number, y: number) => void;
|
||||
}) {
|
||||
|
|
@ -290,7 +333,7 @@ function PlacementRow({
|
|||
{y + 1}
|
||||
</div>
|
||||
{Array.from({ length: BOARD }, (_, x) => {
|
||||
const cell = occupied.get(`${x},${y}`);
|
||||
const assetId = occupied.get(`${x},${y}`);
|
||||
const isPreview = preview.has(`${x},${y}`);
|
||||
return (
|
||||
<button
|
||||
|
|
@ -301,14 +344,12 @@ function PlacementRow({
|
|||
onClick={() => onPlace(x, y)}
|
||||
className={cn(
|
||||
"flex aspect-square items-center justify-center rounded-sm border text-[10px] font-semibold transition-colors",
|
||||
cell
|
||||
? "border-emerald-500/70 bg-emerald-600/50 text-emerald-50"
|
||||
: "border-border bg-card hover:border-primary/60",
|
||||
isPreview && !cell && "border-sky-400/70 bg-sky-500/20",
|
||||
assetId ? fobStyle(assetId).cell : "border-border bg-card hover:border-primary/60",
|
||||
isPreview && !assetId && cn(previewClass, "opacity-60"),
|
||||
disabled && "cursor-not-allowed opacity-60",
|
||||
)}
|
||||
>
|
||||
{cell ? "▣" : ""}
|
||||
{assetId ? "▣" : ""}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
|
|
@ -434,8 +475,8 @@ function BattlePhase({
|
|||
key={`${x}-${y}`}
|
||||
label={`grid ${cellLabel(x, y)}`}
|
||||
className={cn(
|
||||
fob && "border-emerald-500/70 bg-emerald-600/40 text-emerald-50",
|
||||
destroyed && "border-red-500/70 bg-red-600/50 text-red-50",
|
||||
fob && !destroyed && fobStyle(fob.id).cell,
|
||||
fob && destroyed && "border-red-500/70 bg-red-600/50 text-red-50",
|
||||
)}
|
||||
>
|
||||
{fob ? "▣" : ""}
|
||||
|
|
@ -474,9 +515,11 @@ function BattlePhase({
|
|||
key={`${x}-${y}`}
|
||||
label={`grid ${cellLabel(x, y)}`}
|
||||
className={cn(
|
||||
(shot?.outcome === "hit" || shot?.outcome === "destroyed") &&
|
||||
"border-amber-500/70 bg-amber-500/20 text-amber-200",
|
||||
shot?.outcome === "hit" && shot.assetId && fobStyle(shot.assetId).cell,
|
||||
shot?.outcome === "destroyed" && "border-red-500/70 bg-red-600/40 text-red-50",
|
||||
shot?.outcome === "hit" &&
|
||||
!shot.assetId &&
|
||||
"border-amber-500/70 bg-amber-500/20 text-amber-200",
|
||||
pending && "border-sky-400 ring-2 ring-sky-400/60",
|
||||
)}
|
||||
interactive={Boolean(yourTurn && firstShot)}
|
||||
|
|
@ -548,7 +591,7 @@ function BoardPanel({
|
|||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Card>
|
||||
<Card className="mx-auto w-full max-w-sm">
|
||||
<CardHeader className="border-b p-3">
|
||||
<CardTitle className="text-sm">{title}</CardTitle>
|
||||
<p className="text-xs text-muted-foreground">{subtitle}</p>
|
||||
|
|
@ -556,7 +599,7 @@ function BoardPanel({
|
|||
<CardContent className="p-3">
|
||||
<div
|
||||
className="grid gap-1"
|
||||
style={{ gridTemplateColumns: `repeat(${BOARD + 1}, minmax(1.4rem, 1fr))` }}
|
||||
style={{ gridTemplateColumns: `repeat(${BOARD + 1}, minmax(0, 1fr))` }}
|
||||
>
|
||||
<div />
|
||||
{Array.from({ length: BOARD }, (_, x) => (
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ export interface VersusFobView {
|
|||
export interface VersusShotView {
|
||||
readonly grid: GridPoint;
|
||||
readonly outcome: ShotOutcome;
|
||||
/** Emplacement type struck (known to the shooter), or null on a miss. */
|
||||
readonly assetId: string | null;
|
||||
}
|
||||
|
||||
export interface VersusYouView {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export function projectFob(fob: VersusFob): VersusFobView {
|
|||
}
|
||||
|
||||
function projectShots(shots: readonly VersusShot[]): VersusShotView[] {
|
||||
return shots.map((shot) => ({ grid: shot.grid, outcome: shot.outcome }));
|
||||
return shots.map((shot) => ({ grid: shot.grid, outcome: shot.outcome, assetId: shot.assetId }));
|
||||
}
|
||||
|
||||
/** Build the safe, per-viewer view of a match. */
|
||||
|
|
|
|||
Loading…
Reference in a new issue