Game UI: diegetic HUD over persistent vault scene

Space Engine-style viewport with cockpit frame, glyph rail,
console overlays for orbits/wormhole/decay/reconstitute.
This commit is contained in:
Tessera Agent
2026-11-09 10:36:21 +00:00
parent 1a67876f19
commit d358c73291
8 changed files with 481 additions and 128 deletions

View File

@@ -1,6 +1,5 @@
import { useState } from "react";
import { useEffect, useMemo, useState } from "react";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { AnimatePresence } from "motion/react";
import {
abortReconstitute,
fetchHealth,
@@ -12,24 +11,22 @@ import {
} from "./api";
import { vaultStatusFromOrbits } from "./lib/format";
import { DecayView } from "./components/decay/DecayView";
import { AppHeader, NavBar, type Tab } from "./components/layout/NavBar";
import { OrbitsView } from "./components/orbits/OrbitsView";
import { WormholeView } from "./components/outposts/WormholeView";
import { ReconstituteWizard } from "./components/reconstitute/ReconstituteWizard";
import { Starfield } from "./components/scene/Starfield";
import { VaultScene } from "./components/scene/VaultScene";
import { SnapshotSheet } from "./components/vault/SnapshotSheet";
import { VaultRing } from "./components/vault/VaultRing";
import {
CockpitFrame,
SnapshotsMiniList,
TelemetryStrip,
} from "./components/hud/DiegeticHUD";
import { HUDPanel, SceneAction } from "./components/hud/HUDPanel";
import { HUDRail, type HUDMode } from "./components/hud/HUDRail";
import { EmptyState } from "./components/ui/EmptyState";
import { QueryGate } from "./components/ui/QueryGate";
import { Sheet } from "./components/ui/Sheet";
import { StatusDot } from "./components/ui/StatusDot";
import { Button } from "./components/ui/Button";
type Overlay = "none" | "snapshot" | "reconstitute";
export default function App() {
const [tab, setTab] = useState<Tab>("vault");
const [overlay, setOverlay] = useState<Overlay>("none");
const [mode, setMode] = useState<HUDMode>("scene");
const [selectedSnap, setSelectedSnap] = useState<string | null>(null);
const [pairing, setPairing] = useState<{ code: string; expires_at: string } | null>(null);
const qc = useQueryClient();
@@ -40,13 +37,11 @@ export default function App() {
refetchInterval: 30_000,
retry: 1,
});
const snaps = useQuery({
queryKey: ["snapshots"],
queryFn: fetchSnapshots,
refetchInterval: 8_000,
});
const orbits = useQuery({
queryKey: ["orbits"],
queryFn: fetchOrbits,
@@ -55,122 +50,160 @@ export default function App() {
const vaultStatus = vaultStatusFromOrbits(orbits.data ?? []);
const hubOnline = health.isSuccess;
const totalBytes = useMemo(
() => (snaps.data ?? []).reduce((a, s) => a + s.size_bytes, 0),
[snaps.data],
);
const capturing =
orbits.data?.some((o) => o.last_status === "running") ?? false;
const capture = useMutation({
mutationFn: async () => {
const list = orbits.data ?? [];
const target = list[0];
const target = orbits.data?.[0];
if (!target) throw new Error("no-orbit");
await runOrbit(target.id);
},
onSuccess: () => {
qc.invalidateQueries({ queryKey: ["snapshots", "orbits"] });
},
onSuccess: () => qc.invalidateQueries({ queryKey: ["snapshots", "orbits"] }),
});
const selectedSnapshot = snaps.data?.find((s) => s.id === selectedSnap);
return (
<div className="h-[100dvh] flex flex-col bg-space-950 text-star-100 overflow-hidden relative">
<Starfield />
<AppHeader
statusDot={<StatusDot status={hubOnline ? vaultStatus : "grey"} size="lg" />}
subtitle={hubOnline ? "Orbital backup vault" : "Hub unreachable"}
/>
useEffect(() => {
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape" && mode !== "scene") setMode("scene");
};
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [mode]);
<main className="flex-1 min-h-0 relative z-[1]">
{tab === "vault" && (
<QueryGate
query={snaps}
empty={
<EmptyState
title="Quiet vault"
body="No snapshots on the ring yet. Add an orbit or capture now."
action={{
label: "Go to orbits",
onClick: () => setTab("orbits"),
}}
/>
}
>
{(data) => (
<VaultRing
snapshots={data}
capturing={capture.isPending || orbits.data?.some((o) => o.last_status === "running")}
onCapture={() => {
if (!(orbits.data?.length ?? 0)) setTab("orbits");
else capture.mutate();
}}
onSelect={(id) => {
setSelectedSnap(id);
setOverlay("snapshot");
}}
/>
)}
</QueryGate>
)}
{tab === "orbits" && (
<QueryGate
query={orbits}
empty={<OrbitsView orbits={[]} />}
>
{(data) => <OrbitsView orbits={data} />}
</QueryGate>
)}
{tab === "outposts" && (
<WormholeView
pairing={pairing}
onPaired={(p) => setPairing(p)}
const snapshotPanel = selectedSnapshot && mode === "scene";
return (
<div className="h-[100dvh] w-full overflow-hidden bg-space-950 text-star-100 relative">
{/* Scene always visible */}
<QueryGate
query={snaps}
empty={
<VaultScene snapshots={[]} onSelect={() => {}} capturing={capturing} />
}
>
{(data) => (
<VaultScene
snapshots={data}
capturing={capturing || capture.isPending}
onCapture={() => {
if (!(orbits.data?.length ?? 0)) setMode("orbits");
else capture.mutate();
}}
onSelect={(id) => {
setSelectedSnap(id);
}}
/>
)}
{tab === "decay" && (
<DecayView appliedPresets={(orbits.data ?? []).map((o) => o.decay_preset ?? "week-of-dailies")} />
)}
</QueryGate>
{tab === "vault" && (
<div className="absolute bottom-20 inset-x-0 flex justify-center px-4 pointer-events-none">
<Button
variant="ghost"
className="pointer-events-auto text-xs shadow-lg backdrop-blur-md"
onClick={() => setOverlay("reconstitute")}
>
Reconstitute…
</Button>
</div>
)}
</main>
<CockpitFrame>
<TelemetryStrip
status={vaultStatus}
online={hubOnline}
snapCount={snaps.data?.length ?? 0}
totalBytes={totalBytes}
/>
<SnapshotsMiniList
snapshots={snaps.data ?? []}
selected={selectedSnap}
onSelect={(id) => setSelectedSnap(id)}
/>
</CockpitFrame>
<NavBar active={tab} onChange={setTab} />
<div className="absolute bottom-24 left-1/2 -translate-x-1/2 z-30 flex gap-3 pointer-events-none">
<SceneAction
label={capture.isPending ? "ORBIT ACTIVE…" : "CAPTURE NOW"}
disabled={capture.isPending}
onClick={() => {
if (!(orbits.data?.length ?? 0)) setMode("orbits");
else capture.mutate();
}}
/>
</div>
<AnimatePresence>
{overlay === "snapshot" && selectedSnapshot && (
<Sheet
open
title="Snapshot tile"
onClose={() => setOverlay("none")}
>
<SnapshotSheet
snap={selectedSnapshot}
onReconstitute={() => setOverlay("reconstitute")}
/>
</Sheet>
<HUDRail active={mode} onSelect={setMode} capturing={capturing} />
<HUDPanel
open={!!snapshotPanel}
title="Snapshot tile"
subtitle="Point-in-time mass on the ring"
side="left"
onClose={() => setSelectedSnap(null)}
>
{selectedSnapshot && (
<SnapshotSheet
snap={selectedSnapshot}
onReconstitute={() => setMode("reconstitute")}
/>
)}
{overlay === "reconstitute" && (
<Sheet open title="Reconstitute" onClose={() => setOverlay("none")}>
<ReconstituteWizard
snapshots={snaps.data ?? []}
selected={selectedSnap}
onStart={startReconstitute}
onPoll={pollReconstitute}
onAbort={abortReconstitute}
/>
</Sheet>
</HUDPanel>
<HUDPanel
open={mode === "orbits"}
title="Orbit console"
subtitle="Schedule circles — not a spreadsheet"
onClose={() => setMode("scene")}
>
<QueryGate query={orbits} empty={<OrbitsView orbits={[]} />}>
{(data) => <OrbitsView orbits={data} />}
</QueryGate>
</HUDPanel>
<HUDPanel
open={mode === "wormhole"}
title="Wormhole uplink"
subtitle="Pair an outpost once"
onClose={() => setMode("scene")}
>
<WormholeView pairing={pairing} onPaired={setPairing} />
</HUDPanel>
<HUDPanel
open={mode === "decay"}
title="Decay field"
subtitle="What fades, on purpose"
onClose={() => setMode("scene")}
>
<DecayView
appliedPresets={(orbits.data ?? []).map(
(o) => o.decay_preset ?? "week-of-dailies",
)}
/>
</HUDPanel>
<HUDPanel
open={mode === "reconstitute"}
title="Reconstitute"
subtitle="12s grace — abort restores nothing"
side="bottom"
onClose={() => setMode("scene")}
>
{(snaps.data?.length ?? 0) === 0 ? (
<EmptyState
title="No tiles to restore"
body="Capture an orbit first, then return here."
/>
) : (
<ReconstituteWizard
snapshots={snaps.data ?? []}
selected={selectedSnap}
onStart={startReconstitute}
onPoll={pollReconstitute}
onAbort={abortReconstitute}
/>
)}
</AnimatePresence>
</HUDPanel>
{capture.isError && (
<p className="absolute top-14 inset-x-0 text-center text-xs text-orbit-amber pointer-events-none">
Add an orbit first, then capture.
<p className="absolute top-24 inset-x-0 text-center text-[10px] font-mono text-orbit-amber z-30">
NO ORBIT — OPEN ⟳ CONSOLE
</p>
)}
</div>