Scale galaxy viewport: spread orbits, larger vault, lock solver

This commit is contained in:
Tessera Agent
2026-11-09 10:54:52 +00:00
parent fa708f545d
commit a920235feb
2 changed files with 229 additions and 114 deletions

View File

@@ -1,18 +1,19 @@
import { useEffect, useMemo, useRef, useState } from "react";
import type { Orbit, Snapshot } from "../../api";
import {
flowOrbitPhysics,
lockedSlot,
lerpPos,
moonPositions,
positionOnEllipse,
} from "../../lib/galaxyLayout";
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;
};
const STAR_R_FLOW = 5.5;
const STAR_R_LOCK = 11;
const HIT_R_LOCK = 18;
function statusColor(status: string): string {
if (status === "failed") return "#f87171";
@@ -64,53 +65,45 @@ export function BlackholeGalaxy({
}
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))));
const dt = (performance.now() - blendStart.current) / 800;
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 starOrbits = useMemo(
() => orbits.slice(0, MAX_STARS),
[orbits],
);
const snapsByOrbit = useMemo(() => groupSnaps(snapshots), [snapshots]);
return (
<div className="w-full h-full flex items-center justify-center pb-24 pointer-events-auto">
<div className="w-[92%] max-w-[960px] h-[min(80dvh,88vw)] mx-auto flex items-center justify-center pb-16 pointer-events-auto">
<svg
viewBox="-250 -250 500 500"
className="w-full max-w-[min(100vmin,520px)] h-auto max-h-[70dvh]"
viewBox="-280 -280 560 560"
className="w-full h-full"
preserveAspectRatio="xMidYMid meet"
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="55%" 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="0%" stopColor="#c4b5fd" stopOpacity="0.85" />
<stop offset="45%" stopColor="#f0c468" stopOpacity="0.45" />
<stop offset="100%" stopColor="transparent" />
</radialGradient>
<filter id="glow">
<feGaussianBlur stdDeviation="2" result="b" />
<feGaussianBlur stdDeviation="2.5" result="b" />
<feMerge>
<feMergeNode in="b" />
<feMergeNode in="SourceGraphic" />
@@ -118,99 +111,131 @@ export function BlackholeGalaxy({
</filter>
</defs>
{/* faint orbital guides */}
{stars.map((s, i) => (
{starOrbits.map((orbit, i) => {
const phys = flowOrbitPhysics(i, starOrbits.length);
return (
<ellipse
key={`path-${s.orbit.id}`}
key={`path-${orbit.id}`}
cx="0"
cy="0"
rx={s.rx}
ry={s.ry}
rx={phys.rx}
ry={phys.ry}
fill="none"
stroke="#2d3a6b"
strokeOpacity={flowing ? 0.12 : 0.22}
strokeWidth="0.6"
strokeDasharray="3 6"
transform={`rotate(${(i * 17) % 40 - 20})`}
stroke="#3d4f8c"
strokeOpacity={flowing ? 0.1 : 0.22}
strokeWidth="0.8"
strokeDasharray="4 8"
transform={`rotate(${phys.tiltDeg})`}
/>
))}
);
})}
<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);
{starOrbits.map((orbit, i) => {
const phys = flowOrbitPhysics(i, starOrbits.length);
const flowAngle = phys.phase + t * phys.speed;
const flowPos = positionOnEllipse(
flowAngle,
phys.rx,
phys.ry,
phys.tiltDeg,
);
const lockPos = lockedSlot(i, starOrbits.length);
const { x, y } = lerpPos(flowPos, lockPos, 1 - blend);
const moons = snapsByOrbit.get(orbit.name) ?? [];
const color = statusColor(orbit.last_status);
const starR = flowing ? STAR_R_FLOW : STAR_R_LOCK;
const interactive = !flowing || blend < 0.15;
const moonPts = moonPositions(
x,
y,
moons.length,
t,
flowing && blend > 0.5,
30,
);
return (
<g key={s.orbit.id} filter="url(#glow)">
<g key={orbit.id} filter="url(#glow)">
{!flowing && (
<circle
cx={x}
cy={y}
r={s.size + 8}
r={HIT_R_LOCK}
fill="transparent"
className="cursor-pointer"
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectOrbit(s.orbit.id);
onSelectOrbit(orbit.id);
}}
/>
)}
<circle
cx={x}
cy={y}
r={s.size}
r={starR}
fill={color}
fillOpacity={0.85}
fillOpacity={0.9}
stroke="#eef1ff"
strokeOpacity={0.35}
strokeWidth="0.6"
className={!flowing ? "cursor-pointer" : "pointer-events-none"}
strokeOpacity={0.4}
strokeWidth={flowing ? 0.5 : 1}
className={interactive ? "cursor-pointer" : "pointer-events-none"}
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectOrbit(s.orbit.id);
if (!flowing) onSelectOrbit(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;
{moons.map((moon, mi) => {
const mp = moonPts[mi];
const sel = moon.id === selectedSnapshotId;
const mr = flowing ? 2.8 : sel ? 7 : 5.5;
const hit = flowing ? mr : 10;
return (
<g key={moon.id}>
{!flowing && (
<circle
cx={mx}
cy={my}
r={sel ? 5 : 3.5}
fill={sel ? "#a78bfa" : "#1e2647"}
stroke={sel ? "#c9d2f5" : color}
strokeWidth="0.8"
cx={mp.x}
cy={mp.y}
r={hit}
fill="transparent"
className="cursor-pointer"
onClick={(e) => {
e.stopPropagation();
onSelectSnapshot(moon.id);
}}
/>
)}
<circle
cx={mp.x}
cy={mp.y}
r={mr}
fill={sel ? "#a78bfa" : "#12182f"}
stroke={sel ? "#e8ecff" : color}
strokeWidth={flowing ? 0.5 : 1}
className={!flowing ? "cursor-pointer" : "pointer-events-none"}
opacity={flowing ? 0.55 : 1}
onClick={(e) => {
e.stopPropagation();
if (!flowing) onSelectSnapshot(moon.id);
}}
/>
</g>
);
})}
{!flowing && (
<text
x={x}
y={y - s.size - 6}
y={y - starR - 10}
textAnchor="middle"
fill="#94a3d4"
fontSize="7"
fill="#c9d2f5"
fontSize="11"
className="font-mono pointer-events-none"
>
{s.orbit.name.length > 14
? `${s.orbit.name.slice(0, 12)}…`
: s.orbit.name}
{orbit.name.length > 16
? `${orbit.name.slice(0, 14)}…`
: orbit.name}
</text>
)}
</g>
@@ -230,36 +255,43 @@ function BlackHoleCore({
flowing: boolean;
onToggle: () => void;
}) {
const diskRot = flowing ? t * 28 : 0;
const diskRot = flowing ? t * 22 : 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)" />
<circle cx="0" cy="0" r="118" fill="url(#bhCore)" opacity="0.85" />
<ellipse
cx="0"
cy="0"
rx="52"
ry="14"
rx="98"
ry="26"
fill="none"
stroke="url(#bhDisk)"
strokeWidth="10"
opacity="0.55"
strokeWidth="14"
opacity="0.65"
transform={`rotate(${diskRot})`}
/>
<ellipse
cx="0"
cy="0"
rx="38"
ry="9"
rx="72"
ry="18"
fill="url(#bhDisk)"
opacity="0.4"
transform={`rotate(${-diskRot * 1.3 + 20})`}
opacity="0.5"
transform={`rotate(${-diskRot * 1.4 + 14})`}
/>
<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">
<circle cx="0" cy="0" r="32" fill="#000" stroke="#a78bfa" strokeOpacity="0.65" strokeWidth="1.5" />
<circle
cx="0"
cy="0"
r="108"
fill="none"
stroke="#a78bfa"
strokeOpacity={flowing ? 0.12 : 0.28}
strokeWidth="1"
strokeDasharray="6 10"
/>
<text y="6" textAnchor="middle" fill="#94a3d4" fontSize="14" className="font-mono pointer-events-none">
VAULT
</text>
</g>

View File

@@ -0,0 +1,83 @@
/** Flow + lock layouts in viewBox coordinates (±~240). */
export type OrbitPhysics = {
rx: number;
ry: number;
tiltDeg: number;
speed: number;
phase: number;
};
const GOLDEN = 2.399963229728653;
export function flowOrbitPhysics(index: number, total: number): OrbitPhysics {
const ring = index % 4;
return {
rx: 128 + ring * 26 + (index % 3) * 12,
ry: 88 + (index % 5) * 16 + ring * 12,
tiltDeg: -28 + (index * 19) % 56,
speed: 0.06 + (index % 7) * 0.011,
phase: (index / Math.max(total, 1)) * Math.PI * 2 + index * 0.17,
};
}
export function positionOnEllipse(
angle: number,
rx: number,
ry: number,
tiltDeg: number,
): { x: number; y: number } {
const ex = Math.cos(angle) * rx;
const ey = Math.sin(angle) * ry;
const rad = (tiltDeg * Math.PI) / 180;
return {
x: ex * Math.cos(rad) - ey * Math.sin(rad),
y: ex * Math.sin(rad) + ey * Math.cos(rad),
};
}
/** Even spread with minimum separation — polar slots + ring stagger. */
export function lockedSlot(index: number, total: number): { x: number; y: number } {
const n = Math.max(total, 1);
const angle = -Math.PI / 2 + index * GOLDEN;
const band = index % 3;
const radius = 138 + band * 48 + Math.floor(index / 3) * 6;
const squash = 0.92 + (index % 2) * 0.06;
return {
x: Math.cos(angle) * radius,
y: Math.sin(angle) * radius * squash,
};
}
export function moonPositions(
cx: number,
cy: number,
count: number,
time: number,
flowing: boolean,
baseSpread = 26,
): { x: number; y: number; angle: number }[] {
const out: { x: number; y: number; angle: number }[] = [];
for (let mi = 0; mi < count; mi++) {
const slice = (mi / Math.max(count, 1)) * Math.PI * 2;
const angle = flowing ? slice + time * (0.45 + mi * 0.05) : slice - Math.PI / 2;
const dist = flowing ? baseSpread * 0.55 : baseSpread + (mi % 2) * 4;
out.push({
angle,
x: cx + Math.cos(angle) * dist,
y: cy + Math.sin(angle) * dist * 0.85,
});
}
return out;
}
export function lerpPos(
a: { x: number; y: number },
b: { x: number; y: number },
t: number,
): { x: number; y: number } {
return {
x: a.x * t + b.x * (1 - t),
y: a.y * t + b.y * (1 - t),
};
}