Scale galaxy viewport: spread orbits, larger vault, lock solver
This commit is contained in:
@@ -1,18 +1,19 @@
|
|||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import type { Orbit, Snapshot } from "../../api";
|
import type { Orbit, Snapshot } from "../../api";
|
||||||
|
import {
|
||||||
|
flowOrbitPhysics,
|
||||||
|
lockedSlot,
|
||||||
|
lerpPos,
|
||||||
|
moonPositions,
|
||||||
|
positionOnEllipse,
|
||||||
|
} from "../../lib/galaxyLayout";
|
||||||
import { easeOutCubic, useGalaxyTime } from "../../hooks/useGalaxyMotion";
|
import { easeOutCubic, useGalaxyTime } from "../../hooks/useGalaxyMotion";
|
||||||
|
|
||||||
const MAX_STARS = 20;
|
const MAX_STARS = 20;
|
||||||
const MAX_MOONS = 6;
|
const MAX_MOONS = 6;
|
||||||
|
const STAR_R_FLOW = 5.5;
|
||||||
type StarLayout = {
|
const STAR_R_LOCK = 11;
|
||||||
orbit: Orbit;
|
const HIT_R_LOCK = 18;
|
||||||
rx: number;
|
|
||||||
ry: number;
|
|
||||||
speed: number;
|
|
||||||
phase: number;
|
|
||||||
size: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
function statusColor(status: string): string {
|
function statusColor(status: string): string {
|
||||||
if (status === "failed") return "#f87171";
|
if (status === "failed") return "#f87171";
|
||||||
@@ -64,53 +65,45 @@ export function BlackholeGalaxy({
|
|||||||
}
|
}
|
||||||
let raf = 0;
|
let raf = 0;
|
||||||
const tick = () => {
|
const tick = () => {
|
||||||
const dt = (performance.now() - blendStart.current) / 600;
|
const dt = (performance.now() - blendStart.current) / 800;
|
||||||
setBlend(flowing ? Math.min(1, dt) : Math.max(0, 1 - easeOutCubic(Math.min(1, dt))));
|
setBlend(
|
||||||
|
flowing ? Math.min(1, dt) : Math.max(0, 1 - easeOutCubic(Math.min(1, dt))),
|
||||||
|
);
|
||||||
if (dt < 1) raf = requestAnimationFrame(tick);
|
if (dt < 1) raf = requestAnimationFrame(tick);
|
||||||
};
|
};
|
||||||
raf = requestAnimationFrame(tick);
|
raf = requestAnimationFrame(tick);
|
||||||
return () => cancelAnimationFrame(raf);
|
return () => cancelAnimationFrame(raf);
|
||||||
}, [flowing]);
|
}, [flowing]);
|
||||||
|
|
||||||
const stars = useMemo((): StarLayout[] => {
|
const starOrbits = useMemo(
|
||||||
const list = orbits.slice(0, MAX_STARS);
|
() => orbits.slice(0, MAX_STARS),
|
||||||
return list.map((orbit, i) => {
|
[orbits],
|
||||||
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]);
|
const snapsByOrbit = useMemo(() => groupSnaps(snapshots), [snapshots]);
|
||||||
|
|
||||||
return (
|
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
|
<svg
|
||||||
viewBox="-250 -250 500 500"
|
viewBox="-280 -280 560 560"
|
||||||
className="w-full max-w-[min(100vmin,520px)] h-auto max-h-[70dvh]"
|
className="w-full h-full"
|
||||||
|
preserveAspectRatio="xMidYMid meet"
|
||||||
role="application"
|
role="application"
|
||||||
aria-label="Galaxy vault viewport"
|
aria-label="Galaxy vault viewport"
|
||||||
>
|
>
|
||||||
<defs>
|
<defs>
|
||||||
<radialGradient id="bhCore" cx="50%" cy="50%" r="50%">
|
<radialGradient id="bhCore" cx="50%" cy="50%" r="50%">
|
||||||
<stop offset="0%" stopColor="#000" />
|
<stop offset="0%" stopColor="#000" />
|
||||||
<stop offset="45%" stopColor="#0a0614" />
|
<stop offset="55%" stopColor="#0a0614" />
|
||||||
<stop offset="100%" stopColor="transparent" />
|
<stop offset="100%" stopColor="transparent" />
|
||||||
</radialGradient>
|
</radialGradient>
|
||||||
<radialGradient id="bhDisk" cx="50%" cy="50%" r="50%">
|
<radialGradient id="bhDisk" cx="50%" cy="50%" r="50%">
|
||||||
<stop offset="0%" stopColor="#a78bfa" stopOpacity="0.7" />
|
<stop offset="0%" stopColor="#c4b5fd" stopOpacity="0.85" />
|
||||||
<stop offset="40%" stopColor="#f0c468" stopOpacity="0.35" />
|
<stop offset="45%" stopColor="#f0c468" stopOpacity="0.45" />
|
||||||
<stop offset="100%" stopColor="transparent" />
|
<stop offset="100%" stopColor="transparent" />
|
||||||
</radialGradient>
|
</radialGradient>
|
||||||
<filter id="glow">
|
<filter id="glow">
|
||||||
<feGaussianBlur stdDeviation="2" result="b" />
|
<feGaussianBlur stdDeviation="2.5" result="b" />
|
||||||
<feMerge>
|
<feMerge>
|
||||||
<feMergeNode in="b" />
|
<feMergeNode in="b" />
|
||||||
<feMergeNode in="SourceGraphic" />
|
<feMergeNode in="SourceGraphic" />
|
||||||
@@ -118,99 +111,131 @@ export function BlackholeGalaxy({
|
|||||||
</filter>
|
</filter>
|
||||||
</defs>
|
</defs>
|
||||||
|
|
||||||
{/* faint orbital guides */}
|
{starOrbits.map((orbit, i) => {
|
||||||
{stars.map((s, i) => (
|
const phys = flowOrbitPhysics(i, starOrbits.length);
|
||||||
<ellipse
|
return (
|
||||||
key={`path-${s.orbit.id}`}
|
<ellipse
|
||||||
cx="0"
|
key={`path-${orbit.id}`}
|
||||||
cy="0"
|
cx="0"
|
||||||
rx={s.rx}
|
cy="0"
|
||||||
ry={s.ry}
|
rx={phys.rx}
|
||||||
fill="none"
|
ry={phys.ry}
|
||||||
stroke="#2d3a6b"
|
fill="none"
|
||||||
strokeOpacity={flowing ? 0.12 : 0.22}
|
stroke="#3d4f8c"
|
||||||
strokeWidth="0.6"
|
strokeOpacity={flowing ? 0.1 : 0.22}
|
||||||
strokeDasharray="3 6"
|
strokeWidth="0.8"
|
||||||
transform={`rotate(${(i * 17) % 40 - 20})`}
|
strokeDasharray="4 8"
|
||||||
/>
|
transform={`rotate(${phys.tiltDeg})`}
|
||||||
))}
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
<BlackHoleCore t={t} flowing={flowing} onToggle={onToggleFlow} />
|
<BlackHoleCore t={t} flowing={flowing} onToggle={onToggleFlow} />
|
||||||
|
|
||||||
{stars.map((s, i) => {
|
{starOrbits.map((orbit, i) => {
|
||||||
const n = stars.length;
|
const phys = flowOrbitPhysics(i, starOrbits.length);
|
||||||
const slotAngle = (i / n) * Math.PI * 2 - Math.PI / 2;
|
const flowAngle = phys.phase + t * phys.speed;
|
||||||
const flowAngle = s.phase + t * s.speed;
|
const flowPos = positionOnEllipse(
|
||||||
const angle = flowAngle * blend + slotAngle * (1 - blend);
|
flowAngle,
|
||||||
const x = Math.cos(angle) * s.rx;
|
phys.rx,
|
||||||
const y = Math.sin(angle) * s.ry;
|
phys.ry,
|
||||||
const moons = snapsByOrbit.get(s.orbit.name) ?? [];
|
phys.tiltDeg,
|
||||||
const color = statusColor(s.orbit.last_status);
|
);
|
||||||
|
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 (
|
return (
|
||||||
<g key={s.orbit.id} filter="url(#glow)">
|
<g key={orbit.id} filter="url(#glow)">
|
||||||
|
{!flowing && (
|
||||||
|
<circle
|
||||||
|
cx={x}
|
||||||
|
cy={y}
|
||||||
|
r={HIT_R_LOCK}
|
||||||
|
fill="transparent"
|
||||||
|
className="cursor-pointer"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
onSelectOrbit(orbit.id);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<circle
|
<circle
|
||||||
cx={x}
|
cx={x}
|
||||||
cy={y}
|
cy={y}
|
||||||
r={s.size + 8}
|
r={starR}
|
||||||
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}
|
fill={color}
|
||||||
fillOpacity={0.85}
|
fillOpacity={0.9}
|
||||||
stroke="#eef1ff"
|
stroke="#eef1ff"
|
||||||
strokeOpacity={0.35}
|
strokeOpacity={0.4}
|
||||||
strokeWidth="0.6"
|
strokeWidth={flowing ? 0.5 : 1}
|
||||||
className={!flowing ? "cursor-pointer" : "pointer-events-none"}
|
className={interactive ? "cursor-pointer" : "pointer-events-none"}
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (!flowing) onSelectOrbit(s.orbit.id);
|
if (!flowing) onSelectOrbit(orbit.id);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{!flowing &&
|
{moons.map((moon, mi) => {
|
||||||
moons.map((moon, mi) => {
|
const mp = moonPts[mi];
|
||||||
const mAngle = (mi / Math.max(moons.length, 1)) * Math.PI * 2 + 0.3;
|
const sel = moon.id === selectedSnapshotId;
|
||||||
const mx = x + Math.cos(mAngle) * 14;
|
const mr = flowing ? 2.8 : sel ? 7 : 5.5;
|
||||||
const my = y + Math.sin(mAngle) * 10;
|
const hit = flowing ? mr : 10;
|
||||||
const sel = moon.id === selectedSnapshotId;
|
return (
|
||||||
return (
|
<g key={moon.id}>
|
||||||
<g key={moon.id}>
|
{!flowing && (
|
||||||
<circle
|
<circle
|
||||||
cx={mx}
|
cx={mp.x}
|
||||||
cy={my}
|
cy={mp.y}
|
||||||
r={sel ? 5 : 3.5}
|
r={hit}
|
||||||
fill={sel ? "#a78bfa" : "#1e2647"}
|
fill="transparent"
|
||||||
stroke={sel ? "#c9d2f5" : color}
|
|
||||||
strokeWidth="0.8"
|
|
||||||
className="cursor-pointer"
|
className="cursor-pointer"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
onSelectSnapshot(moon.id);
|
onSelectSnapshot(moon.id);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</g>
|
)}
|
||||||
);
|
<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 && (
|
{!flowing && (
|
||||||
<text
|
<text
|
||||||
x={x}
|
x={x}
|
||||||
y={y - s.size - 6}
|
y={y - starR - 10}
|
||||||
textAnchor="middle"
|
textAnchor="middle"
|
||||||
fill="#94a3d4"
|
fill="#c9d2f5"
|
||||||
fontSize="7"
|
fontSize="11"
|
||||||
className="font-mono pointer-events-none"
|
className="font-mono pointer-events-none"
|
||||||
>
|
>
|
||||||
{s.orbit.name.length > 14
|
{orbit.name.length > 16
|
||||||
? `${s.orbit.name.slice(0, 12)}…`
|
? `${orbit.name.slice(0, 14)}…`
|
||||||
: s.orbit.name}
|
: orbit.name}
|
||||||
</text>
|
</text>
|
||||||
)}
|
)}
|
||||||
</g>
|
</g>
|
||||||
@@ -230,36 +255,43 @@ function BlackHoleCore({
|
|||||||
flowing: boolean;
|
flowing: boolean;
|
||||||
onToggle: () => void;
|
onToggle: () => void;
|
||||||
}) {
|
}) {
|
||||||
const diskRot = flowing ? t * 28 : 0;
|
const diskRot = flowing ? t * 22 : 0;
|
||||||
return (
|
return (
|
||||||
<g className="cursor-pointer" onClick={onToggle}>
|
<g className="cursor-pointer" onClick={onToggle}>
|
||||||
<title>{flowing ? "Click to lock vault for targeting" : "Click to resume galaxy flow"}</title>
|
<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
|
<ellipse
|
||||||
cx="0"
|
cx="0"
|
||||||
cy="0"
|
cy="0"
|
||||||
rx="52"
|
rx="98"
|
||||||
ry="14"
|
ry="26"
|
||||||
fill="none"
|
fill="none"
|
||||||
stroke="url(#bhDisk)"
|
stroke="url(#bhDisk)"
|
||||||
strokeWidth="10"
|
strokeWidth="14"
|
||||||
opacity="0.55"
|
opacity="0.65"
|
||||||
transform={`rotate(${diskRot})`}
|
transform={`rotate(${diskRot})`}
|
||||||
/>
|
/>
|
||||||
<ellipse
|
<ellipse
|
||||||
cx="0"
|
cx="0"
|
||||||
cy="0"
|
cy="0"
|
||||||
rx="38"
|
rx="72"
|
||||||
ry="9"
|
ry="18"
|
||||||
fill="url(#bhDisk)"
|
fill="url(#bhDisk)"
|
||||||
opacity="0.4"
|
opacity="0.5"
|
||||||
transform={`rotate(${-diskRot * 1.3 + 20})`}
|
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="32" fill="#000" stroke="#a78bfa" strokeOpacity="0.65" strokeWidth="1.5" />
|
||||||
<circle cx="0" cy="0" r="48" fill="none" stroke="#a78bfa" strokeOpacity={flowing ? 0.15 : 0.35} strokeWidth="0.8" strokeDasharray="4 8">
|
<circle
|
||||||
{!flowing && null}
|
cx="0"
|
||||||
</circle>
|
cy="0"
|
||||||
<text y="4" textAnchor="middle" fill="#6b7ab8" fontSize="8" className="font-mono pointer-events-none">
|
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
|
VAULT
|
||||||
</text>
|
</text>
|
||||||
</g>
|
</g>
|
||||||
|
|||||||
83
web/src/lib/galaxyLayout.ts
Normal file
83
web/src/lib/galaxyLayout.ts
Normal 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),
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user