1
0
Fork 0
polaris-task-force/src/components/frontend/minigames/dev/BomperatorDevControls.tsx
Z8MB1E 3c774279aa feat(minigames): superuser developer console dock across all ten games
Adds a shared fixed-position debugging dock (Controls/State/Log tabs) gated
to dynamic superusers, mounted per minigame. Multiplayer games gain synced
server-authoritative admin commands with [dev-admin] audit logging: poker
(force fold, force street, per-viewer reveal-all, clock control, stack
adjust, force expire), blackjack (bankroll adjust, next-card injection,
dealer override, force expire), bomperator (pure applyAdminCommand: crates,
pickups, eliminate, freeze, sudden death, timer, end round; mirrored over
the arena REST path), and CFF Versus (reveal fleets, force shot outcome,
skip turn). Solo games get client-side tuning via persisted dev settings:
flappy physics sliders plus pause and invincibility, EOD layout reveal and
seeded boards, radio transcript view and timer freeze, aim trainer seed and
difficulty overrides plus hitbox overlay, OPORD answer reveal and study
window, call-for-fire target reveal, seeded grids, and free corrections.

Includes 26 new integration specs (command purity, gating, audit lines) and
a poker e2e smoke for the dock. Plan: Minigame Developer Console.
2026-10-20 12:48:27 -04:00

250 lines
8 KiB
TypeScript

"use client";
import { useState } from "react";
import type {
BomperatorAdminCommand,
BomperatorView,
} from "@/app/(frontend)/minigames/bomperator/actions";
import {
bomperatorAdminCommand,
forceExpireBomperatorMatch,
} from "@/app/(frontend)/minigames/bomperator/actions";
import type { PowerUpKind } from "@/lib/minigames/bomperator/types";
import { TICKS_PER_SECOND } from "@/lib/minigames/bomperator/constants";
import { Combobox } from "@/components/ui/combobox";
import { Input } from "@/components/ui/input";
import { pushDevLog } from "./devLog";
import { DevButton, DevSection } from "./primitives";
/**
* Ordnance Disposal controls for the shared minigame dev dock. Every command
* rides `bomperatorAdminCommand`, which works over both transports (arena REST
* proxy or in-process registry); cheats land on the board through the normal
* snapshot fan-out, so every client sees them by next tick.
*/
const PICKUP_OPTIONS: readonly { value: PowerUpKind; label: string }[] = [
{ value: "bomb", label: "Bomb (+1 charge)" },
{ value: "range", label: "Range (+1 reach)" },
{ value: "speed", label: "Speed (+1 cell/s)" },
{ value: "kick", label: "Kick (shove charges)" },
];
interface BomperatorDevControlsProps {
readonly matchId: string;
readonly match: BomperatorView;
}
export function BomperatorDevControls({ matchId, match }: BomperatorDevControlsProps) {
const [seat, setSeat] = useState<string>("");
const [pickup, setPickup] = useState<PowerUpKind>("bomb");
const [timerSeconds, setTimerSeconds] = useState<string>("30");
const [winnerSeat, setWinnerSeat] = useState<string>("");
const [error, setError] = useState<string | null>(null);
const send = async (cmd: BomperatorAdminCommand) => {
pushDevLog("action", `bomperator: ${cmd.kind} sent`);
try {
const result = await bomperatorAdminCommand(matchId, cmd);
if (!result.success) {
const message = result.error ?? "The admin command failed.";
setError(message);
pushDevLog("error", `bomperator: ${cmd.kind} failed (${message})`);
} else {
setError(null);
pushDevLog("action", `bomperator: ${cmd.kind} applied`);
}
} catch (caught) {
const message = caught instanceof Error ? caught.message : "The admin command failed.";
setError(message);
pushDevLog("error", `bomperator: ${cmd.kind} threw (${message})`);
}
};
const seatOptions = match.players.map((player) => ({
value: String(player.seat),
label: `${player.name}${player.alive ? "" : " (down)"} · seat ${player.seat}`,
}));
const aliveSeatOptions = match.players
.filter((player) => player.alive)
.map((player) => ({ value: String(player.seat), label: player.name }));
return (
<>
{error && <p className="text-sm text-destructive">{error}</p>}
<DevSection title="Board">
<DevButton
type="button"
variant="outline"
size="sm"
className="w-fit"
confirm
onClick={() => void send({ kind: "destroyCrates" })}
>
Destroy all crates
</DevButton>
<DevButton
type="button"
variant="outline"
size="sm"
className="w-fit"
confirm
disabled={match.suddenDeath}
onClick={() => void send({ kind: "suddenDeathNow" })}
>
Sudden death now
</DevButton>
</DevSection>
<DevSection title="Grant pickup to seat">
<div className="flex items-center gap-2">
<Combobox
className="h-8 flex-1 text-xs"
value={seat}
onValueChange={setSeat}
placeholder="Seat"
searchPlaceholder="Search technicians..."
options={seatOptions}
/>
<Combobox
className="h-8 w-32 text-xs"
value={pickup}
onValueChange={(next) => setPickup(next as PowerUpKind)}
options={PICKUP_OPTIONS.map((option) => ({
value: option.value,
label: option.label,
}))}
/>
</div>
<DevButton
type="button"
variant="outline"
size="sm"
className="w-fit"
disabled={seat === ""}
onClick={() => {
if (seat === "") return;
void send({ kind: "grantPickup", seat: Number(seat), pickup });
}}
>
Grant pickup
</DevButton>
</DevSection>
<DevSection title="Eliminate technician">
<div className="flex items-center gap-2">
<Combobox
className="h-8 flex-1 text-xs"
value={seat}
onValueChange={setSeat}
placeholder="Seat"
searchPlaceholder="Search technicians..."
options={aliveSeatOptions}
/>
<DevButton
type="button"
variant="destructive"
size="sm"
confirm
disabled={seat === ""}
onClick={() => {
if (seat === "") return;
void send({ kind: "eliminate", seat: Number(seat) });
}}
>
Eliminate
</DevButton>
</div>
</DevSection>
<DevSection title="Match control">
<div className="flex items-center gap-2">
<DevButton
type="button"
variant={match.frozen ? "default" : "outline"}
size="sm"
onClick={() => void send({ kind: "freeze", frozen: !match.frozen })}
>
{match.frozen ? "Unfreeze ticks" : "Freeze ticks"}
</DevButton>
{match.frozen && (
<span className="text-xs font-medium text-amber-400">Simulation frozen</span>
)}
</div>
<div className="flex items-center gap-2">
<Input
type="number"
min={0}
step={1}
placeholder="Seconds"
value={timerSeconds}
onChange={(event) => setTimerSeconds(event.target.value)}
className="h-8 w-24 text-xs"
/>
<DevButton
type="button"
variant="outline"
size="sm"
disabled={!Number.isFinite(Number(timerSeconds)) || Number(timerSeconds) < 0}
onClick={() =>
void send({
kind: "setRoundTimer",
ticks: Math.round(Number(timerSeconds) * TICKS_PER_SECOND),
})
}
>
Set round timer
</DevButton>
</div>
<div className="flex items-center gap-2">
<Combobox
className="h-8 flex-1 text-xs"
value={winnerSeat}
onValueChange={setWinnerSeat}
placeholder="Round winner (empty = draw)"
searchPlaceholder="Search technicians..."
options={[{ value: "-1", label: "Draw (no winner)" }, ...aliveSeatOptions]}
/>
<DevButton
type="button"
variant="outline"
size="sm"
confirm
onClick={() =>
void send({
kind: "endRound",
winnerSeat: winnerSeat === "" || winnerSeat === "-1" ? null : Number(winnerSeat),
})
}
>
Force end round
</DevButton>
</div>
</DevSection>
<DevSection title="Match">
<DevButton
type="button"
variant="destructive"
size="sm"
className="w-fit"
confirm
confirmLabel="Click again to expire match"
onClick={async () => {
pushDevLog("action", "bomperator: force-expire-match sent");
const result = await forceExpireBomperatorMatch(matchId);
pushDevLog(
result.success ? "action" : "error",
result.success
? "bomperator: force-expire-match applied"
: `bomperator: force-expire-match failed (${result.error ?? "unknown"})`,
);
}}
>
Force expire match
</DevButton>
</DevSection>
</>
);
}