"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(""); const [pickup, setPickup] = useState("bomb"); const [timerSeconds, setTimerSeconds] = useState("30"); const [winnerSeat, setWinnerSeat] = useState(""); const [error, setError] = useState(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 &&

{error}

} void send({ kind: "destroyCrates" })} > Destroy all crates void send({ kind: "suddenDeathNow" })} > Sudden death now
setPickup(next as PowerUpKind)} options={PICKUP_OPTIONS.map((option) => ({ value: option.value, label: option.label, }))} />
{ if (seat === "") return; void send({ kind: "grantPickup", seat: Number(seat), pickup }); }} > Grant pickup
{ if (seat === "") return; void send({ kind: "eliminate", seat: Number(seat) }); }} > Eliminate
void send({ kind: "freeze", frozen: !match.frozen })} > {match.frozen ? "Unfreeze ticks" : "Freeze ticks"} {match.frozen && ( Simulation frozen )}
setTimerSeconds(event.target.value)} className="h-8 w-24 text-xs" /> void send({ kind: "setRoundTimer", ticks: Math.round(Number(timerSeconds) * TICKS_PER_SECOND), }) } > Set round timer
void send({ kind: "endRound", winnerSeat: winnerSeat === "" || winnerSeat === "-1" ? null : Number(winnerSeat), }) } > Force end round
{ 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 ); }