From fa708f545d2db6046b8e60b1d6f4084b1ced0966 Mon Sep 17 00:00:00 2001 From: Tessera Agent Date: Mon, 9 Nov 2026 10:48:30 +0000 Subject: [PATCH] Galaxy vault: black hole scene with flow/lock interaction Stars per orbit, snapshot moons when locked, toggle on singularity. --- docs/UI.md | 39 ++- web/src/App.tsx | 35 +-- web/src/components/scene/BlackholeGalaxy.tsx | 267 +++++++++++++++++++ web/src/components/scene/VaultScene.tsx | 47 +++- web/src/hooks/useGalaxyMotion.ts | 34 +++ 5 files changed, 365 insertions(+), 57 deletions(-) create mode 100644 web/src/components/scene/BlackholeGalaxy.tsx create mode 100644 web/src/hooks/useGalaxyMotion.ts diff --git a/docs/UI.md b/docs/UI.md index 364e41e..8ab3759 100644 --- a/docs/UI.md +++ b/docs/UI.md @@ -1,39 +1,32 @@ -# Tessera canvas — Space Engine mode +# Tessera canvas — galaxy vault (Space Engine mode) -Diegetic **cockpit HUD** over a persistent **vault viewport**. No admin tabs — systems open as translucent console overlays. +Diegetic **cockpit HUD** over a persistent **galaxy viewport**. The vault is a **black hole** at center; each **orbit** is a **star** on an elliptical path; **snapshots** are **moons** around that star (when locked). -## Viewport (always on) +## Viewport modes -- Starfield + nebula wash, orbital snapshot ring (SVG) -- Corner brackets, scanlines, vignette -- Telemetry strip: link status, tile count, stored mass -- Left rail: last four snapshot targets (mono labels) -- Center action: **CAPTURE NOW** +| Mode | Behavior | +|------|----------| +| **Flowing** (default) | Stars orbit the singularity; accretion disk spins; moons hidden; targets not clickable | +| **Locked** | Click **black hole** once — bodies ease into spaced slots and **stop**; star opens orbit console; moon opens snapshot tile | -## HUD rail (glyph console) +Click the **black hole** again to resume flow. HUD line under telemetry: green “flowing” / amber “locked”. -| Glyph | System | Overlay | -|-------|--------|---------| -| ◎ | Viewport | Dismiss overlays — pure scene | -| ⟳ | Orbits | Right console — schedules, rehearse, create | -| ◉ | Wormhole | Outpost pairing uplink | -| ◇ | Decay | Retention presets in use | -| ↩ | Restore | Bottom console — reconstitute + 12s grace | +## HUD rail -**Esc** closes an open console. +Unchanged — ◎ ⟳ ◉ ◇ ↩ consoles; **Esc** dismisses. -## Overlays (not pages) +## Data -- **Snapshot tile** — slides from left when a ring tile is selected on viewport -- **Orbit / Wormhole / Decay / Reconstitute** — HUD panels with console chrome +- Stars: `GET /api/v1/orbits` (status → star color) +- Moons: `GET /api/v1/snapshots` grouped by `orbit_name`, max 6 per star -## API +## Demo -Unchanged — see prior polish notes; TanStack Query on `/api/v1/*` and `/health`. +`TESSERA_DATA_DIR=... tessera seed-demo --force` for 12+ stars. ## Build ```bash cd web && npm run build -cargo build --release -p tessera-hub # embeds dist +cargo build --release -p tessera-hub ``` diff --git a/web/src/App.tsx b/web/src/App.tsx index 9d268b0..0f47f31 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -29,6 +29,7 @@ export default function App() { const [mode, setMode] = useState("scene"); const [selectedSnap, setSelectedSnap] = useState(null); const [pairing, setPairing] = useState<{ code: string; expires_at: string } | null>(null); + const [galaxyFlowing, setGalaxyFlowing] = useState(true); const qc = useQueryClient(); const health = useQuery({ @@ -81,27 +82,19 @@ export default function App() { return (
- {/* Scene always visible */} - {}} capturing={capturing} /> - } - > - {(data) => ( - { - if (!(orbits.data?.length ?? 0)) setMode("orbits"); - else capture.mutate(); - }} - onSelect={(id) => { - setSelectedSnap(id); - }} - /> - )} - + setGalaxyFlowing((f) => !f)} + capturing={capturing || capture.isPending} + selectedSnapshotId={selectedSnap} + onSelect={(id) => setSelectedSnap(id)} + onSelectOrbit={() => { + setGalaxyFlowing(false); + setMode("orbits"); + }} + /> { + const m = new Map(); + for (const s of snaps) { + const list = m.get(s.orbit_name) ?? []; + list.push(s); + m.set(s.orbit_name, list); + } + for (const [k, v] of m) { + v.sort((a, b) => b.taken_at.localeCompare(a.taken_at)); + m.set(k, v.slice(0, MAX_MOONS)); + } + return m; +} + +export function BlackholeGalaxy({ + orbits, + snapshots, + flowing, + onToggleFlow, + onSelectSnapshot, + onSelectOrbit, + selectedSnapshotId, +}: { + orbits: Orbit[]; + snapshots: Snapshot[]; + flowing: boolean; + onToggleFlow: () => void; + onSelectSnapshot: (id: string) => void; + onSelectOrbit: (id: string) => void; + selectedSnapshotId?: string | null; +}) { + const t = useGalaxyTime(!flowing); + const [blend, setBlend] = useState(1); + const blendStart = useRef(0); + const wasFlowing = useRef(flowing); + + useEffect(() => { + if (wasFlowing.current !== flowing) { + blendStart.current = performance.now(); + wasFlowing.current = flowing; + } + let raf = 0; + const tick = () => { + const dt = (performance.now() - blendStart.current) / 600; + setBlend(flowing ? Math.min(1, dt) : Math.max(0, 1 - easeOutCubic(Math.min(1, dt)))); + if (dt < 1) raf = requestAnimationFrame(tick); + }; + raf = requestAnimationFrame(tick); + return () => cancelAnimationFrame(raf); + }, [flowing]); + + const stars = useMemo((): StarLayout[] => { + const list = orbits.slice(0, MAX_STARS); + return list.map((orbit, i) => { + const n = Math.max(list.length, 1); + const tier = i % 3; + return { + orbit, + rx: 92 + tier * 22 + (i % 4) * 6, + ry: 56 + tier * 14 + (i % 3) * 8, + speed: 0.08 + (i % 7) * 0.012, + phase: (i / n) * Math.PI * 2, + size: 5 + (orbit.name.length % 3), + }; + }); + }, [orbits]); + + const snapsByOrbit = useMemo(() => groupSnaps(snapshots), [snapshots]); + + return ( +
+ + + + + + + + + + + + + + + + + + + + + + {/* faint orbital guides */} + {stars.map((s, i) => ( + + ))} + + + + {stars.map((s, i) => { + const n = stars.length; + const slotAngle = (i / n) * Math.PI * 2 - Math.PI / 2; + const flowAngle = s.phase + t * s.speed; + const angle = flowAngle * blend + slotAngle * (1 - blend); + const x = Math.cos(angle) * s.rx; + const y = Math.sin(angle) * s.ry; + const moons = snapsByOrbit.get(s.orbit.name) ?? []; + const color = statusColor(s.orbit.last_status); + + return ( + + { + e.stopPropagation(); + if (!flowing) onSelectOrbit(s.orbit.id); + }} + /> + { + e.stopPropagation(); + if (!flowing) onSelectOrbit(s.orbit.id); + }} + /> + {!flowing && + moons.map((moon, mi) => { + const mAngle = (mi / Math.max(moons.length, 1)) * Math.PI * 2 + 0.3; + const mx = x + Math.cos(mAngle) * 14; + const my = y + Math.sin(mAngle) * 10; + const sel = moon.id === selectedSnapshotId; + return ( + + { + e.stopPropagation(); + onSelectSnapshot(moon.id); + }} + /> + + ); + })} + {!flowing && ( + + {s.orbit.name.length > 14 + ? `${s.orbit.name.slice(0, 12)}…` + : s.orbit.name} + + )} + + ); + })} + +
+ ); +} + +function BlackHoleCore({ + t, + flowing, + onToggle, +}: { + t: number; + flowing: boolean; + onToggle: () => void; +}) { + const diskRot = flowing ? t * 28 : 0; + return ( + + {flowing ? "Click to lock vault for targeting" : "Click to resume galaxy flow"} + + + + + + {!flowing && null} + + + VAULT + + + ); +} diff --git a/web/src/components/scene/VaultScene.tsx b/web/src/components/scene/VaultScene.tsx index ef05f1e..6891d04 100644 --- a/web/src/components/scene/VaultScene.tsx +++ b/web/src/components/scene/VaultScene.tsx @@ -1,34 +1,55 @@ import { motion } from "motion/react"; -import type { Snapshot } from "../../api"; -import { VaultRing } from "../vault/VaultRing"; +import type { Orbit, Snapshot } from "../../api"; import { Starfield } from "./Starfield"; +import { BlackholeGalaxy } from "./BlackholeGalaxy"; export function VaultScene({ + orbits, snapshots, + flowing, + onToggleFlow, onSelect, - onCapture, + onSelectOrbit, + selectedSnapshotId, capturing, }: { + orbits: Orbit[]; snapshots: Snapshot[]; + flowing: boolean; + onToggleFlow: () => void; onSelect: (id: string) => void; - onCapture?: () => void; + onSelectOrbit: (id: string) => void; + selectedSnapshotId?: string | null; capturing?: boolean; }) { return (
-
+
-
- + {flowing ? "◉ vault flowing — click singularity to lock" : "◉ vault locked — select stars & moons"} + +
+
diff --git a/web/src/hooks/useGalaxyMotion.ts b/web/src/hooks/useGalaxyMotion.ts new file mode 100644 index 0000000..80ccc57 --- /dev/null +++ b/web/src/hooks/useGalaxyMotion.ts @@ -0,0 +1,34 @@ +import { useEffect, useRef, useState } from "react"; + +/** Seconds since mount, frozen while paused. */ +export function useGalaxyTime(paused: boolean): number { + const [t, setT] = useState(0); + const start = useRef(performance.now()); + const frozen = useRef(0); + const wasPaused = useRef(paused); + + useEffect(() => { + if (paused) { + frozen.current = (performance.now() - start.current) / 1000; + wasPaused.current = true; + return; + } + if (wasPaused.current) { + start.current = performance.now() - frozen.current * 1000; + wasPaused.current = false; + } + let raf = 0; + const tick = () => { + setT((performance.now() - start.current) / 1000); + raf = requestAnimationFrame(tick); + }; + raf = requestAnimationFrame(tick); + return () => cancelAnimationFrame(raf); + }, [paused]); + + return paused ? frozen.current : t; +} + +export function easeOutCubic(x: number): number { + return 1 - Math.pow(1 - x, 3); +}