Galaxy vault: black hole scene with flow/lock interaction

Stars per orbit, snapshot moons when locked, toggle on singularity.
This commit is contained in:
Tessera Agent
2026-11-09 10:48:30 +00:00
parent 50fe4ffffa
commit fa708f545d
5 changed files with 365 additions and 57 deletions

View File

@@ -0,0 +1,267 @@
import { useEffect, useMemo, useRef, useState } from "react";
import type { Orbit, Snapshot } from "../../api";
import { easeOutCubic, useGalaxyTime } from "../../hooks/useGalaxyMotion";
const MAX_STARS = 20;
const MAX_MOONS = 6;
type StarLayout = {
orbit: Orbit;
rx: number;
ry: number;
speed: number;
phase: number;
size: number;
};
function statusColor(status: string): string {
if (status === "failed") return "#f87171";
if (status === "running" || status === "rehearsed") return "#f0c468";
if (status === "completed") return "#4ade9a";
return "#94a3d4";
}
function groupSnaps(snaps: Snapshot[]): Map<string, Snapshot[]> {
const m = new Map<string, Snapshot[]>();
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 (
<div className="w-full h-full flex items-center justify-center pb-24 pointer-events-auto">
<svg
viewBox="-250 -250 500 500"
className="w-full max-w-[min(100vmin,520px)] h-auto max-h-[70dvh]"
role="application"
aria-label="Galaxy vault viewport"
>
<defs>
<radialGradient id="bhCore" cx="50%" cy="50%" r="50%">
<stop offset="0%" stopColor="#000" />
<stop offset="45%" stopColor="#0a0614" />
<stop offset="100%" stopColor="transparent" />
</radialGradient>
<radialGradient id="bhDisk" cx="50%" cy="50%" r="50%">
<stop offset="0%" stopColor="#a78bfa" stopOpacity="0.7" />
<stop offset="40%" stopColor="#f0c468" stopOpacity="0.35" />
<stop offset="100%" stopColor="transparent" />
</radialGradient>
<filter id="glow">
<feGaussianBlur stdDeviation="2" result="b" />
<feMerge>
<feMergeNode in="b" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</defs>
{/* faint orbital guides */}
{stars.map((s, i) => (
<ellipse
key={`path-${s.orbit.id}`}
cx="0"
cy="0"
rx={s.rx}
ry={s.ry}
fill="none"
stroke="#2d3a6b"
strokeOpacity={flowing ? 0.12 : 0.22}
strokeWidth="0.6"
strokeDasharray="3 6"
transform={`rotate(${(i * 17) % 40 - 20})`}
/>
))}
<BlackHoleCore t={t} flowing={flowing} onToggle={onToggleFlow} />
{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 (
<g key={s.orbit.id} filter="url(#glow)">
<circle
cx={x}
cy={y}
r={s.size + 8}
fill="transparent"
className="cursor-pointer"
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectOrbit(s.orbit.id);
}}
/>
<circle
cx={x}
cy={y}
r={s.size}
fill={color}
fillOpacity={0.85}
stroke="#eef1ff"
strokeOpacity={0.35}
strokeWidth="0.6"
className={!flowing ? "cursor-pointer" : "pointer-events-none"}
onClick={(e) => {
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 (
<g key={moon.id}>
<circle
cx={mx}
cy={my}
r={sel ? 5 : 3.5}
fill={sel ? "#a78bfa" : "#1e2647"}
stroke={sel ? "#c9d2f5" : color}
strokeWidth="0.8"
className="cursor-pointer"
onClick={(e) => {
e.stopPropagation();
onSelectSnapshot(moon.id);
}}
/>
</g>
);
})}
{!flowing && (
<text
x={x}
y={y - s.size - 6}
textAnchor="middle"
fill="#94a3d4"
fontSize="7"
className="font-mono pointer-events-none"
>
{s.orbit.name.length > 14
? `${s.orbit.name.slice(0, 12)}…`
: s.orbit.name}
</text>
)}
</g>
);
})}
</svg>
</div>
);
}
function BlackHoleCore({
t,
flowing,
onToggle,
}: {
t: number;
flowing: boolean;
onToggle: () => void;
}) {
const diskRot = flowing ? t * 28 : 0;
return (
<g className="cursor-pointer" onClick={onToggle}>
<title>{flowing ? "Click to lock vault for targeting" : "Click to resume galaxy flow"}</title>
<circle cx="0" cy="0" r="72" fill="url(#bhCore)" />
<ellipse
cx="0"
cy="0"
rx="52"
ry="14"
fill="none"
stroke="url(#bhDisk)"
strokeWidth="10"
opacity="0.55"
transform={`rotate(${diskRot})`}
/>
<ellipse
cx="0"
cy="0"
rx="38"
ry="9"
fill="url(#bhDisk)"
opacity="0.4"
transform={`rotate(${-diskRot * 1.3 + 20})`}
/>
<circle cx="0" cy="0" r="18" fill="#000" stroke="#a78bfa" strokeOpacity="0.5" strokeWidth="1" />
<circle cx="0" cy="0" r="48" fill="none" stroke="#a78bfa" strokeOpacity={flowing ? 0.15 : 0.35} strokeWidth="0.8" strokeDasharray="4 8">
{!flowing && null}
</circle>
<text y="4" textAnchor="middle" fill="#6b7ab8" fontSize="8" className="font-mono pointer-events-none">
VAULT
</text>
</g>
);
}

View File

@@ -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 (
<div className="absolute inset-0 overflow-hidden">
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_center,rgba(30,38,71,0.45)_0%,rgba(4,5,12,0.95)_65%)]" />
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_center,rgba(30,38,71,0.35)_0%,rgba(4,5,12,0.98)_70%)]" />
<Starfield />
<motion.div
className="absolute top-1/4 left-1/2 -translate-x-1/2 w-[80vmin] h-[40vmin] rounded-full bg-wormhole-violet/5 blur-3xl"
animate={{ opacity: [0.3, 0.55, 0.3], scale: [1, 1.05, 1] }}
transition={{ duration: 8, repeat: Infinity }}
className="absolute top-1/3 left-1/2 -translate-x-1/2 w-[90vmin] h-[50vmin] rounded-full bg-wormhole-violet/8 blur-3xl"
animate={{
opacity: capturing ? [0.5, 0.9, 0.5] : [0.25, 0.45, 0.25],
scale: capturing ? [1, 1.08, 1] : [1, 1.03, 1],
}}
transition={{ duration: capturing ? 2 : 8, repeat: Infinity }}
/>
<div className="relative z-10 h-full w-full pb-28">
<VaultRing
<motion.p
className="absolute top-20 left-1/2 -translate-x-1/2 z-20 text-[10px] font-mono tracking-widest uppercase pointer-events-none"
initial={false}
animate={{ color: flowing ? "#4ade9a" : "#f0c468" }}
>
{flowing ? "◉ vault flowing — click singularity to lock" : "◉ vault locked — select stars & moons"}
</motion.p>
<div className="relative z-10 h-full w-full">
<BlackholeGalaxy
orbits={orbits}
snapshots={snapshots}
onSelect={onSelect}
onCapture={onCapture}
capturing={capturing}
flowing={flowing}
onToggleFlow={onToggleFlow}
onSelectSnapshot={onSelect}
onSelectOrbit={onSelectOrbit}
selectedSnapshotId={selectedSnapshotId}
/>
</div>
</div>