Init Main project
This commit is contained in:
commit
9e581ae67f
220 changed files with 253987 additions and 0 deletions
356
src/client/screens/missionConfig/charts.ts
Normal file
356
src/client/screens/missionConfig/charts.ts
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
// Canvas chart renderers for ascent profile, telemetry channels, and orbital geometry
|
||||
// I started rendering by making charts first, they're cool
|
||||
import { generateTrajectory } from "../../../shared/ephemeris.js";
|
||||
import type {
|
||||
ContractOffer,
|
||||
FlightParams,
|
||||
MissionTemplate,
|
||||
SimResult,
|
||||
TrajectoryResult,
|
||||
} from "../../../shared/types.js";
|
||||
import { getColorMode } from "../../theme.js";
|
||||
import { clear, fmtDuration, fmtNum, h } from "../../ui.js";
|
||||
|
||||
export function drawAscentChart(
|
||||
ascentCanvas: HTMLCanvasElement,
|
||||
sim: SimResult,
|
||||
): void {
|
||||
const ctx = ascentCanvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
const light = getColorMode() === "light";
|
||||
const W = ascentCanvas.width;
|
||||
const H = ascentCanvas.height;
|
||||
ctx.fillStyle = light ? "#f8fafc" : "#0b0e14";
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
ctx.strokeStyle = light ? "rgba(15, 23, 42, 0.12)" : "rgba(42, 52, 73, 0.55)";
|
||||
ctx.lineWidth = 1;
|
||||
for (let i = 1; i < 5; i++) {
|
||||
const y = (H / 5) * i;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(48, y);
|
||||
ctx.lineTo(W - 14, y);
|
||||
ctx.stroke();
|
||||
}
|
||||
const pts = sim.telemetry;
|
||||
if (!pts.length) return;
|
||||
const maxDr = Math.max(250, ...pts.map((p) => p.downrange / 1000));
|
||||
const maxAlt = Math.max(220, ...pts.map((p) => p.altitude / 1000));
|
||||
const padL = 48;
|
||||
const padR = 16;
|
||||
const padT = 18;
|
||||
const padB = 26;
|
||||
const pw = W - padL - padR;
|
||||
const ph = H - padT - padB;
|
||||
const toX = (drKm: number) => padL + (drKm / maxDr) * pw;
|
||||
const toY = (altKm: number) => padT + ph - (altKm / maxAlt) * ph;
|
||||
const qPeak = pts.reduce(
|
||||
(best, p) => (p.dynamicPressure > best.dynamicPressure ? p : best),
|
||||
pts[0],
|
||||
);
|
||||
const qx = toX(qPeak.downrange / 1000);
|
||||
const qy = toY(qPeak.altitude / 1000);
|
||||
ctx.strokeStyle = sim.success ? (light ? "#0284c7" : "#60a5fa") : "#ef4444";
|
||||
ctx.lineWidth = 2.4;
|
||||
ctx.beginPath();
|
||||
pts.forEach((p, idx) => {
|
||||
const x = toX(p.downrange / 1000);
|
||||
const y = toY(p.altitude / 1000);
|
||||
if (idx === 0) ctx.moveTo(x, y);
|
||||
else ctx.lineTo(x, y);
|
||||
});
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = "#f59e0b";
|
||||
ctx.beginPath();
|
||||
ctx.arc(qx, qy, 4.5, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.font = "11px monospace";
|
||||
ctx.fillText(
|
||||
`Max-Q ${(qPeak.dynamicPressure / 1000).toFixed(1)} kPa`,
|
||||
Math.min(W - 140, qx + 8),
|
||||
Math.max(16, qy - 6),
|
||||
);
|
||||
ctx.fillStyle = light ? "#475569" : "#94a3b8";
|
||||
ctx.fillText("0 km", 6, padT + ph);
|
||||
ctx.fillText(`${Math.round(maxAlt)} km`, 4, padT + 10);
|
||||
ctx.fillText(`Downrange ${Math.round(maxDr)} km`, W - 150, H - 6);
|
||||
ctx.fillStyle = sim.success ? (light ? "#059669" : "#34d399") : "#ef4444";
|
||||
ctx.fillText(
|
||||
sim.success
|
||||
? `ORBIT INSERTION ${Math.round(sim.periapsis / 1000)}×${Math.round(sim.apoapsis / 1000)} km`
|
||||
: sim.failureDetail.slice(0, 56),
|
||||
padL + 8,
|
||||
20,
|
||||
);
|
||||
}
|
||||
|
||||
export function drawMultiTelemetryChart(
|
||||
telemetryDiagCanvas: HTMLCanvasElement,
|
||||
rootCauseBoxEl: HTMLElement,
|
||||
sim: SimResult,
|
||||
): void {
|
||||
const ctx = telemetryDiagCanvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
const light = getColorMode() === "light";
|
||||
const W = telemetryDiagCanvas.width;
|
||||
const H = telemetryDiagCanvas.height;
|
||||
ctx.fillStyle = light ? "#f8fafc" : "#0b0e14";
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
ctx.strokeStyle = light ? "rgba(15, 23, 42, 0.12)" : "rgba(42, 52, 73, 0.55)";
|
||||
ctx.lineWidth = 1;
|
||||
for (let i = 1; i < 4; i++) {
|
||||
const y = (H / 4) * i;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(42, y);
|
||||
ctx.lineTo(W - 16, y);
|
||||
ctx.stroke();
|
||||
}
|
||||
const pts = sim.telemetry;
|
||||
if (!pts.length) return;
|
||||
const maxT = Math.max(10, pts[pts.length - 1].t);
|
||||
const maxQ = Math.max(10000, ...pts.map((p) => p.dynamicPressure));
|
||||
const maxG = Math.max(4, ...pts.map((p) => p.gLoad));
|
||||
const maxCpu = Math.max(120, ...pts.map((p) => p.cpuLoadPct ?? 0));
|
||||
const maxRad = Math.max(2, ...pts.map((p) => p.radFluxMsvHr ?? 0));
|
||||
const padL = 42;
|
||||
const padT = 26;
|
||||
const padB = 22;
|
||||
const pw = W - padL - 16;
|
||||
const ph = H - padT - padB;
|
||||
const toX = (t: number) => padL + (t / maxT) * pw;
|
||||
const plotSeries = (
|
||||
color: string,
|
||||
getter: (p: (typeof pts)[number]) => number,
|
||||
) => {
|
||||
ctx.strokeStyle = color;
|
||||
ctx.lineWidth = 2;
|
||||
ctx.beginPath();
|
||||
pts.forEach((p, idx) => {
|
||||
const x = toX(p.t);
|
||||
const y = padT + ph - Math.min(1, Math.max(0, getter(p))) * ph;
|
||||
if (idx === 0) ctx.moveTo(x, y);
|
||||
else ctx.lineTo(x, y);
|
||||
});
|
||||
ctx.stroke();
|
||||
};
|
||||
const cpu100Y = padT + ph - (100 / maxCpu) * ph;
|
||||
ctx.save();
|
||||
ctx.setLineDash([4, 4]);
|
||||
ctx.strokeStyle = "rgba(245, 158, 11, 0.6)";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(padL, cpu100Y);
|
||||
ctx.lineTo(W - 16, cpu100Y);
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
plotSeries("#38bdf8", (p) => p.dynamicPressure / maxQ);
|
||||
plotSeries("#34d399", (p) => p.gLoad / maxG);
|
||||
plotSeries("#f59e0b", (p) => (p.cpuLoadPct ?? 0) / maxCpu);
|
||||
plotSeries("#f472b6", (p) => (p.radFluxMsvHr ?? 0) / maxRad);
|
||||
ctx.font = "11px monospace";
|
||||
ctx.fillStyle = "#38bdf8";
|
||||
ctx.fillText(`Q max ${(maxQ / 1000).toFixed(1)}kPa`, 46, 16);
|
||||
ctx.fillStyle = "#34d399";
|
||||
ctx.fillText(`G max ${maxG.toFixed(1)}G`, 178, 16);
|
||||
ctx.fillStyle = "#f59e0b";
|
||||
ctx.fillText(`CPU peak ${Math.round(sim.peakCpuLoadPct ?? 0)}%`, 284, 16);
|
||||
ctx.fillStyle = "#f472b6";
|
||||
ctx.fillText(
|
||||
`Rad peak ${maxRad.toFixed(1)} mSv/h (${sim.totalSeuCount ?? 0} SEU)`,
|
||||
420,
|
||||
16,
|
||||
);
|
||||
ctx.fillStyle = light ? "#475569" : "#94a3b8";
|
||||
ctx.fillText(`T+0s`, padL, H - 6);
|
||||
ctx.fillText(`T+${Math.round(maxT)}s`, W - 64, H - 6);
|
||||
const compFault =
|
||||
sim.failureReason === "computer_damaged" ||
|
||||
sim.failureReason === "computer_overload" ||
|
||||
sim.failureReason === "radiation_seu_lockup" ||
|
||||
pts.some((p) => p.computerStatus === "failed");
|
||||
clear(rootCauseBoxEl);
|
||||
rootCauseBoxEl.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread", style: { marginBottom: "6px" } },
|
||||
h("h3", {}, "Tier-2 Avionics & Propulsion Root-Cause Analyzer"),
|
||||
h(
|
||||
"span",
|
||||
{ class: `badge ${sim.success ? "ok" : "err"}` },
|
||||
sim.success ? "NOMINAL ASCENT" : (sim.failureReason ?? "FAULT"),
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Flight Computer Peak Load / SEUs"),
|
||||
h(
|
||||
"span",
|
||||
{
|
||||
class: `v ${(sim.peakCpuLoadPct ?? 0) > 125 ? "red" : (sim.peakCpuLoadPct ?? 0) > 95 ? "amber" : "green"}`,
|
||||
},
|
||||
`${Math.round(sim.peakCpuLoadPct ?? 0)}% • ${sim.totalSeuCount ?? 0} SEUs (${compFault ? "HW/CTRL FAULT" : "NOMINAL"})`,
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Peak Heat Flux / Dynamic Pressure"),
|
||||
h(
|
||||
"span",
|
||||
{ class: "v" },
|
||||
`${sim.peakHeatFluxWcm2.toFixed(1)} W/cm² • ${(sim.maxQ / 1000).toFixed(1)} kPa (Stage ${sim.maxQStage})`,
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Burnout State (Alt / Vel / Downrange)"),
|
||||
h(
|
||||
"span",
|
||||
{ class: "v" },
|
||||
`${(sim.burnoutAltitude / 1000).toFixed(1)} km • ${fmtNum(sim.burnoutVelocity)} m/s • ${(sim.burnoutDownrange / 1000).toFixed(1)} km`,
|
||||
),
|
||||
),
|
||||
...(sim.success
|
||||
? []
|
||||
: [
|
||||
h(
|
||||
"p",
|
||||
{
|
||||
class: "red mono",
|
||||
style: { fontSize: "11px", marginTop: "6px" },
|
||||
},
|
||||
`Diagnostic Verdict: ${sim.failureDetail}`,
|
||||
),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
export interface OrbitChartOptions {
|
||||
orbitCanvas: HTMLCanvasElement;
|
||||
gmatStatsBoxEl: HTMLElement;
|
||||
contract: ContractOffer | MissionTemplate | null;
|
||||
fp: FlightParams;
|
||||
gmatLoading: boolean;
|
||||
trajInput?: TrajectoryResult | null;
|
||||
}
|
||||
|
||||
export function drawOrbitChart(opts: OrbitChartOptions): void {
|
||||
const { orbitCanvas, gmatStatsBoxEl, contract, fp, gmatLoading, trajInput } =
|
||||
opts;
|
||||
const ctx = orbitCanvas.getContext("2d");
|
||||
if (!ctx) return;
|
||||
const light = getColorMode() === "light";
|
||||
const W = orbitCanvas.width;
|
||||
const H = orbitCanvas.height;
|
||||
ctx.fillStyle = light ? "#f8fafc" : "#0b0e14";
|
||||
ctx.fillRect(0, 0, W, H);
|
||||
const traj =
|
||||
trajInput ??
|
||||
generateTrajectory(contract?.target ?? "leo", undefined, 220, {
|
||||
altKm: fp.targetApoapsisKm,
|
||||
incDeg: fp.targetInclinationDeg,
|
||||
});
|
||||
const maxR = Math.max(1, ...traj.points.map((p) => Math.hypot(p.x, p.z)));
|
||||
const scale = (Math.min(W, H) * 0.4) / maxR;
|
||||
const cx = W * 0.5;
|
||||
const cy = H * 0.5;
|
||||
ctx.fillStyle =
|
||||
contract?.target === "mars"
|
||||
? "#d96b43"
|
||||
: contract?.target === "solar"
|
||||
? "#ffd166"
|
||||
: "#3498db";
|
||||
ctx.beginPath();
|
||||
ctx.arc(cx, cy, Math.max(8, Math.min(22, 6371 * scale)), 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.lineWidth = 2.4;
|
||||
for (let i = 1; i < traj.points.length; i++) {
|
||||
const p0 = traj.points[i - 1];
|
||||
const p1 = traj.points[i];
|
||||
const x0 = cx + p0.x * scale;
|
||||
const y0 = cy + p0.z * scale;
|
||||
const x1 = cx + p1.x * scale;
|
||||
const y1 = cy + p1.z * scale;
|
||||
if (p1.inShadow) {
|
||||
ctx.strokeStyle = "#a855f7";
|
||||
} else if ((p1.radBeltFlux ?? 0) > 1.0) {
|
||||
ctx.strokeStyle = "#f59e0b";
|
||||
} else {
|
||||
ctx.strokeStyle = light ? "#0284c7" : "#60a5fa";
|
||||
}
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x0, y0);
|
||||
ctx.lineTo(x1, y1);
|
||||
ctx.stroke();
|
||||
}
|
||||
const eclipseCount = traj.points.filter((p) => p.inShadow).length;
|
||||
const eclipsePct = Math.round(
|
||||
(eclipseCount / Math.max(1, traj.points.length)) * 100,
|
||||
);
|
||||
const peakFlux = Math.max(0, ...traj.points.map((p) => p.radBeltFlux ?? 0));
|
||||
const maxDrift = Math.max(
|
||||
0,
|
||||
...traj.points.map((p) => p.perturbationDriftKm ?? 0),
|
||||
);
|
||||
const samplePt = traj.points[Math.floor(traj.points.length * 0.25)];
|
||||
ctx.fillStyle = light ? "#475569" : "#94a3b8";
|
||||
ctx.font = "11px monospace";
|
||||
ctx.fillText(
|
||||
`[${traj.source.toUpperCase()}] Target ${(contract?.target ?? "leo").toUpperCase()} • Inc ${fp.targetInclinationDeg.toFixed(1)}° • Period ${fmtDuration(traj.period)}`,
|
||||
14,
|
||||
18,
|
||||
);
|
||||
ctx.fillStyle = "#a855f7";
|
||||
ctx.fillText(`Eclipse Shadow: ${eclipsePct}%`, 14, H - 10);
|
||||
ctx.fillStyle = "#f59e0b";
|
||||
ctx.fillText(`Peak Van Allen Flux: ${peakFlux.toFixed(2)}`, 190, H - 10);
|
||||
ctx.fillStyle = "#34d399";
|
||||
ctx.fillText(`Perturbation Drift: ${maxDrift.toFixed(1)} km`, 420, H - 10);
|
||||
clear(gmatStatsBoxEl);
|
||||
gmatStatsBoxEl.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread", style: { marginBottom: "4px" } },
|
||||
h("h3", {}, "Tier-3 GMAT Orbital Propagation & Environment"),
|
||||
h(
|
||||
"span",
|
||||
{ class: `badge ${traj.source === "gmat" ? "ok" : "info"}` },
|
||||
gmatLoading
|
||||
? "QUERYING GMAT..."
|
||||
: traj.source === "gmat"
|
||||
? "GMAT RK89"
|
||||
: "ANALYTIC + J2",
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Osculating SMA / Ecc"),
|
||||
h(
|
||||
"span",
|
||||
{ class: "v" },
|
||||
`${fmtNum(samplePt?.smaKm ?? 6371 + fp.targetApoapsisKm)} km • e ${(samplePt?.ecc ?? 0.002).toFixed(4)}`,
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Eclipse Shadow / Peak Rad Flux"),
|
||||
h(
|
||||
"span",
|
||||
{ class: "v amber" },
|
||||
`${eclipsePct}% shadow • ${peakFlux.toFixed(2)} rel flux`,
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "J2 / Drag Perturbation Drift"),
|
||||
h(
|
||||
"span",
|
||||
{ class: "v" },
|
||||
`${maxDrift.toFixed(2)} km per propagation window`,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
544
src/client/screens/missionConfig/prelaunch.ts
Normal file
544
src/client/screens/missionConfig/prelaunch.ts
Normal file
|
|
@ -0,0 +1,544 @@
|
|||
// Prelaunch QA, diagnostic tabs, weather hazards, and launch window cards
|
||||
import { api } from "../../api.js";
|
||||
import { navigate } from "../../router.js";
|
||||
import { state } from "../../state.js";
|
||||
import { computeLaunchWindow } from "../../../shared/ephemeris.js";
|
||||
import {
|
||||
buildRocket,
|
||||
computeDesignReliability,
|
||||
getDifficultyProfile,
|
||||
getUnlockedDiagnosticTier,
|
||||
} from "../../../shared/physics.js";
|
||||
import type {
|
||||
AgencyState,
|
||||
ContractOffer,
|
||||
DesignReliabilityReport,
|
||||
FlightParams,
|
||||
MissionTemplate,
|
||||
RocketDesign,
|
||||
SimResult,
|
||||
TrajectoryResult,
|
||||
} from "../../../shared/types.js";
|
||||
import type { GlossaryKey } from "../../glossary.js";
|
||||
import {
|
||||
clear,
|
||||
fmtDuration,
|
||||
fmtMoney,
|
||||
fmtNum,
|
||||
h,
|
||||
term,
|
||||
toast,
|
||||
} from "../../ui.js";
|
||||
import {
|
||||
drawAscentChart,
|
||||
drawMultiTelemetryChart,
|
||||
drawOrbitChart,
|
||||
} from "./charts.js";
|
||||
|
||||
export interface MissionConfigContext {
|
||||
agency: AgencyState;
|
||||
contract: ContractOffer | MissionTemplate | null;
|
||||
workingDesign: RocketDesign;
|
||||
profile: ReturnType<typeof getDifficultyProfile>;
|
||||
fp: FlightParams;
|
||||
ascentCanvas: HTMLCanvasElement;
|
||||
telemetryDiagCanvas: HTMLCanvasElement;
|
||||
orbitCanvas: HTMLCanvasElement;
|
||||
diagTabsEl: HTMLElement;
|
||||
diagPanelEl: HTMLElement;
|
||||
rootCauseBoxEl: HTMLElement;
|
||||
gmatStatsBoxEl: HTMLElement;
|
||||
simSummaryEl: HTMLElement;
|
||||
windowBoxEl: HTMLElement;
|
||||
hazardsBoxEl: HTMLElement;
|
||||
prelaunchBoxEl: HTMLElement;
|
||||
diagTab: "ascent" | "telemetry" | "gmat";
|
||||
latestSimResult: SimResult | null;
|
||||
cachedGmatTraj: TrajectoryResult | null;
|
||||
gmatLoading: boolean;
|
||||
onRecomputePreview: () => void;
|
||||
}
|
||||
|
||||
export function renderPrelaunchBox(
|
||||
ctx: MissionConfigContext,
|
||||
sim?: SimResult,
|
||||
): void {
|
||||
const { agency, workingDesign, profile, prelaunchBoxEl, onRecomputePreview } =
|
||||
ctx;
|
||||
const curAgency = state.agency ?? agency!;
|
||||
let rel: DesignReliabilityReport | null = null;
|
||||
let sfFee = 450_000;
|
||||
let insPrem = 0;
|
||||
try {
|
||||
const asm = buildRocket(workingDesign, state.parts, state.materials);
|
||||
rel = computeDesignReliability(workingDesign, asm, curAgency);
|
||||
sfFee = Math.max(450_000, Math.round(asm.totalCost * 0.04));
|
||||
insPrem =
|
||||
profile.id === "explorer" || profile.id === "sandbox"
|
||||
? 0
|
||||
: Math.round(asm.totalCost * 0.08);
|
||||
} catch {
|
||||
rel = null;
|
||||
}
|
||||
clear(prelaunchBoxEl);
|
||||
prelaunchBoxEl.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread", style: { marginBottom: "4px" } },
|
||||
h(
|
||||
"span",
|
||||
{ class: "mono", style: { fontSize: "11px", fontWeight: "700" } },
|
||||
"PRE-LAUNCH QA & COVERAGE",
|
||||
),
|
||||
h(
|
||||
"span",
|
||||
{
|
||||
class: `badge ${rel && rel.reliabilityPct >= 90 ? "ok" : rel && rel.reliabilityPct >= 80 ? "info" : "warn"}`,
|
||||
},
|
||||
rel ? `${rel.reliabilityPct.toFixed(1)}% REL` : "N/A",
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Orbit Corridor"),
|
||||
h(
|
||||
"span",
|
||||
{ class: "v info" },
|
||||
`±${profile.orbitTolPct}% Ap / ±${profile.incTolDeg}° Inc`,
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Static Fire QA"),
|
||||
h(
|
||||
"span",
|
||||
{ class: `v ${rel?.staticFired ? "green" : "amber"}` },
|
||||
rel?.staticFired
|
||||
? "VERIFIED (-8% Defect)"
|
||||
: `UNVERIFIED (${fmtMoney(profile.id === "sandbox" ? 0 : sfFee)})`,
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Launch Insurance"),
|
||||
h(
|
||||
"span",
|
||||
{
|
||||
class: `v ${curAgency.launchInsured || profile.id === "explorer" || profile.id === "sandbox" ? "green" : ""}`,
|
||||
},
|
||||
profile.id === "sandbox"
|
||||
? "INCLUDED (Sandbox)"
|
||||
: profile.id === "explorer"
|
||||
? "INCLUDED (Explorer)"
|
||||
: curAgency.launchInsured
|
||||
? `ACTIVE (+${fmtMoney(insPrem)})`
|
||||
: `OFF (${fmtMoney(insPrem)})`,
|
||||
),
|
||||
),
|
||||
...(sim
|
||||
? [
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Predicted Insertion"),
|
||||
h(
|
||||
"span",
|
||||
{
|
||||
class: `v ${sim.orbitGrade === "nominal" ? "green" : sim.orbitGrade === "partial" ? "amber" : "red"}`,
|
||||
},
|
||||
(sim.orbitGrade ?? "failed").toUpperCase(),
|
||||
),
|
||||
),
|
||||
]
|
||||
: []),
|
||||
h(
|
||||
"div",
|
||||
{ class: "row", style: { marginTop: "8px", gap: "6px" } },
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: `btn xs ${rel?.staticFired ? "ghost" : "primary"} grow`,
|
||||
disabled: !agency?.rocketDesign || !!rel?.staticFired,
|
||||
onClick: async () => {
|
||||
try {
|
||||
const res = await api.post<{ fee: number; agency: AgencyState }>(
|
||||
"/api/agency/static-fire",
|
||||
{
|
||||
design: workingDesign,
|
||||
},
|
||||
);
|
||||
state.agency = res.agency;
|
||||
toast(`Static fire completed (-${fmtMoney(res.fee)}).`, "ok");
|
||||
onRecomputePreview();
|
||||
} catch (err) {
|
||||
toast((err as Error).message, "err");
|
||||
}
|
||||
},
|
||||
},
|
||||
rel?.staticFired
|
||||
? "Static Fire OK"
|
||||
: `Static Fire (${fmtMoney(profile.id === "sandbox" ? 0 : sfFee)})`,
|
||||
),
|
||||
profile.id !== "explorer" && profile.id !== "sandbox"
|
||||
? h(
|
||||
"button",
|
||||
{
|
||||
class: `btn xs ${curAgency.launchInsured ? "warn" : "ghost"} grow`,
|
||||
onClick: async () => {
|
||||
try {
|
||||
const res = await api.post<{
|
||||
launchInsured: boolean;
|
||||
agency: AgencyState;
|
||||
}>("/api/agency/insurance", {
|
||||
enabled: !curAgency.launchInsured,
|
||||
});
|
||||
state.agency = res.agency;
|
||||
toast(
|
||||
res.launchInsured
|
||||
? "Launch insurance enabled (8%)."
|
||||
: "Launch insurance disabled.",
|
||||
"info",
|
||||
);
|
||||
renderPrelaunchBox(ctx, sim);
|
||||
} catch (err) {
|
||||
toast((err as Error).message, "err");
|
||||
}
|
||||
},
|
||||
},
|
||||
curAgency.launchInsured ? "Insurance: ON" : "Insure (8%)",
|
||||
)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
export function renderDiagPanel(ctx: MissionConfigContext): void {
|
||||
const {
|
||||
agency,
|
||||
contract,
|
||||
fp,
|
||||
ascentCanvas,
|
||||
telemetryDiagCanvas,
|
||||
orbitCanvas,
|
||||
diagTabsEl,
|
||||
diagPanelEl,
|
||||
rootCauseBoxEl,
|
||||
gmatStatsBoxEl,
|
||||
} = ctx;
|
||||
const diagTier = getUnlockedDiagnosticTier(
|
||||
agency?.unlockedTechs,
|
||||
agency?.difficulty,
|
||||
);
|
||||
clear(diagTabsEl);
|
||||
const tabs: Array<{
|
||||
id: MissionConfigContext["diagTab"];
|
||||
label: string;
|
||||
reqTier: number;
|
||||
}> = [
|
||||
{ id: "ascent", label: "Ascent Profile (Tier 1)", reqTier: 1 },
|
||||
{
|
||||
id: "telemetry",
|
||||
label: `Telemetry & Root-Cause (Tier 2${diagTier < 2 ? " LOCKED" : ""})`,
|
||||
reqTier: 2,
|
||||
},
|
||||
{
|
||||
id: "gmat",
|
||||
label: `GMAT Orbit & Perturbations (Tier 3${diagTier < 3 ? " LOCKED" : ""})`,
|
||||
reqTier: 3,
|
||||
},
|
||||
];
|
||||
for (const tb of tabs) {
|
||||
diagTabsEl.appendChild(
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: `btn xs ${ctx.diagTab === tb.id ? "selected" : "ghost"}`,
|
||||
onClick: () => {
|
||||
ctx.diagTab = tb.id;
|
||||
if (
|
||||
tb.id === "gmat" &&
|
||||
diagTier >= 3 &&
|
||||
!ctx.cachedGmatTraj &&
|
||||
!ctx.gmatLoading
|
||||
) {
|
||||
ctx.gmatLoading = true;
|
||||
void api
|
||||
.post<TrajectoryResult>("/api/trajectory", {
|
||||
target: contract?.target ?? "leo",
|
||||
altKm: fp.targetApoapsisKm,
|
||||
incDeg: fp.targetInclinationDeg,
|
||||
})
|
||||
.then((tr) => {
|
||||
ctx.cachedGmatTraj = tr;
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
ctx.gmatLoading = false;
|
||||
renderDiagPanel(ctx);
|
||||
});
|
||||
}
|
||||
renderDiagPanel(ctx);
|
||||
},
|
||||
},
|
||||
tb.label,
|
||||
),
|
||||
);
|
||||
}
|
||||
clear(diagPanelEl);
|
||||
if (ctx.diagTab === "ascent") {
|
||||
diagPanelEl.append(
|
||||
h("h3", { class: "dim" }, "Ascent Guidance & Max-Q Envelope Preview"),
|
||||
ascentCanvas,
|
||||
h("h3", { class: "dim" }, "Orbital Injection Geometry Preview"),
|
||||
orbitCanvas,
|
||||
);
|
||||
if (ctx.latestSimResult) drawAscentChart(ascentCanvas, ctx.latestSimResult);
|
||||
drawOrbitChart({
|
||||
orbitCanvas,
|
||||
gmatStatsBoxEl,
|
||||
contract,
|
||||
fp,
|
||||
gmatLoading: ctx.gmatLoading,
|
||||
trajInput: ctx.cachedGmatTraj,
|
||||
});
|
||||
} else if (ctx.diagTab === "telemetry") {
|
||||
if (diagTier < 2) {
|
||||
diagPanelEl.appendChild(
|
||||
h(
|
||||
"div",
|
||||
{
|
||||
class: "panel",
|
||||
style: { padding: "20px", borderColor: "var(--amber)" },
|
||||
},
|
||||
h("h3", {}, "Tier-2 Pre-Flight & Telemetry Suite Locked"),
|
||||
h(
|
||||
"p",
|
||||
{ class: "dim", style: { marginTop: "6px", lineHeight: "1.5" } },
|
||||
'Unlock "Avionics & Flight Telemetry Suite" ($4.5M) in the Dashboard R&D Tech Lab to inspect multi-channel Q / G-load / CPU load / radiation curves and failure root-cause analysis.',
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "btn sm primary",
|
||||
style: { marginTop: "10px" },
|
||||
onClick: () => navigate("dashboard"),
|
||||
},
|
||||
"Go to Dashboard Tech Lab",
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
diagPanelEl.append(telemetryDiagCanvas, rootCauseBoxEl);
|
||||
if (ctx.latestSimResult)
|
||||
drawMultiTelemetryChart(
|
||||
telemetryDiagCanvas,
|
||||
rootCauseBoxEl,
|
||||
ctx.latestSimResult,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (diagTier < 3) {
|
||||
diagPanelEl.appendChild(
|
||||
h(
|
||||
"div",
|
||||
{
|
||||
class: "panel",
|
||||
style: { padding: "20px", borderColor: "var(--amber)" },
|
||||
},
|
||||
h("h3", {}, "Tier-3 GMAT Orbital Diagnostics Locked"),
|
||||
h(
|
||||
"p",
|
||||
{ class: "dim", style: { marginTop: "6px", lineHeight: "1.5" } },
|
||||
'Unlock "GMAT Orbital Diagnostics Suite" ($12.0M) in the Dashboard R&D Tech Lab for GMAT RungeKutta89 perturbation drift, Van Allen radiation flux mapping, and orbital eclipse prediction.',
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "btn sm primary",
|
||||
style: { marginTop: "10px" },
|
||||
onClick: () => navigate("dashboard"),
|
||||
},
|
||||
"Go to Dashboard Tech Lab",
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
diagPanelEl.append(orbitCanvas, gmatStatsBoxEl);
|
||||
drawOrbitChart({
|
||||
orbitCanvas,
|
||||
gmatStatsBoxEl,
|
||||
contract,
|
||||
fp,
|
||||
gmatLoading: ctx.gmatLoading,
|
||||
trajInput: ctx.cachedGmatTraj,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function renderForecastBoxes(
|
||||
ctx: MissionConfigContext,
|
||||
sim: SimResult,
|
||||
): void {
|
||||
const { contract, simSummaryEl, windowBoxEl, hazardsBoxEl } = ctx;
|
||||
clear(simSummaryEl);
|
||||
const items: Array<{
|
||||
k: string;
|
||||
tip?: GlossaryKey;
|
||||
v: string;
|
||||
cls?: string;
|
||||
}> = [
|
||||
{
|
||||
k: "Predicted Outcome",
|
||||
v: sim.success
|
||||
? sim.orbitGrade === "partial"
|
||||
? "PARTIAL ORBIT"
|
||||
: "ORBIT OK"
|
||||
: (sim.failureReason ?? "FAILED"),
|
||||
cls: sim.success
|
||||
? sim.orbitGrade === "partial"
|
||||
? "warn"
|
||||
: "good"
|
||||
: "bad",
|
||||
},
|
||||
{
|
||||
k: "Burnout Ap × Pe",
|
||||
tip: "apoapsis",
|
||||
v: `${fmtNum(sim.apoapsis / 1000)} × ${fmtNum(sim.periapsis / 1000)} km`,
|
||||
},
|
||||
{
|
||||
k: "Peak Max-Q / G",
|
||||
tip: "max_q",
|
||||
v: `${(sim.maxQ / 1000).toFixed(1)} kPa / ${sim.peakGLoad.toFixed(1)} G`,
|
||||
},
|
||||
{
|
||||
k: "Peak CPU / Reserve Δv",
|
||||
tip: "cpu_load",
|
||||
v: `${Math.round(sim.peakCpuLoadPct ?? 0)}% CPU / ${fmtNum(sim.dvRemaining)} m/s`,
|
||||
cls:
|
||||
(sim.peakCpuLoadPct ?? 0) > 125
|
||||
? "bad"
|
||||
: sim.dvRemaining > 150
|
||||
? "good"
|
||||
: "warn",
|
||||
},
|
||||
];
|
||||
for (const it of items) {
|
||||
simSummaryEl.appendChild(
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-box" },
|
||||
h("div", { class: "k" }, it.tip ? term(it.k, it.tip) : it.k),
|
||||
h("div", { class: `v ${it.cls ?? ""}` }, it.v),
|
||||
),
|
||||
);
|
||||
}
|
||||
const activeHazards = state.world?.activeHazards ?? [];
|
||||
const upcomingHazards = state.world?.upcomingHazards ?? [];
|
||||
clear(hazardsBoxEl);
|
||||
hazardsBoxEl.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread", style: { marginBottom: "4px" } },
|
||||
h(
|
||||
"span",
|
||||
{ class: "mono", style: { fontSize: "11px", fontWeight: "700" } },
|
||||
term("PRE-LAUNCH HAZARD FORECAST", "space_weather"),
|
||||
),
|
||||
h(
|
||||
"span",
|
||||
{ class: `badge ${activeHazards.length ? "warn" : "ok"}` },
|
||||
activeHazards.length ? `${activeHazards.length} ACTIVE` : "CLEAR",
|
||||
),
|
||||
),
|
||||
...(activeHazards.length
|
||||
? activeHazards.map((hz) =>
|
||||
h(
|
||||
"div",
|
||||
{ class: "rule-item waived", style: { marginTop: "4px" } },
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread" },
|
||||
h("strong", { class: "amber" }, hz.title),
|
||||
h(
|
||||
"span",
|
||||
{ class: "badge warn" },
|
||||
`${hz.altMinKm}–${hz.altMaxKm} km`,
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "dim", style: { fontSize: "10px" } },
|
||||
hz.countermeasureHint,
|
||||
),
|
||||
),
|
||||
)
|
||||
: [
|
||||
h(
|
||||
"div",
|
||||
{ class: "dim mono", style: { fontSize: "10px" } },
|
||||
"No severe atmospheric or radiation anomalies active.",
|
||||
),
|
||||
]),
|
||||
...(upcomingHazards.length
|
||||
? [
|
||||
h(
|
||||
"div",
|
||||
{
|
||||
class: "faint mono",
|
||||
style: { fontSize: "10px", marginTop: "4px" },
|
||||
},
|
||||
`Next: ${upcomingHazards.map((u) => u.title).join(", ")}`,
|
||||
),
|
||||
]
|
||||
: []),
|
||||
);
|
||||
const win = computeLaunchWindow(
|
||||
contract?.target ?? "leo",
|
||||
state.world?.simTime ?? 0,
|
||||
contract?.launchWindowPeriodSec ?? 7200,
|
||||
);
|
||||
clear(windowBoxEl);
|
||||
windowBoxEl.append(
|
||||
h(
|
||||
"div",
|
||||
{ class: "spread" },
|
||||
h(
|
||||
"span",
|
||||
{ class: "mono", style: { fontSize: "11px", fontWeight: "700" } },
|
||||
"SYNODIC LAUNCH WINDOW",
|
||||
),
|
||||
h(
|
||||
"span",
|
||||
{
|
||||
class: `badge ${win.quality === "OPTIMAL" ? "ok" : win.quality === "FAIR" ? "info" : "warn"}`,
|
||||
},
|
||||
win.quality,
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Phase Penalty"),
|
||||
h(
|
||||
"span",
|
||||
{ class: `v ${win.penaltyDv > 0 ? "amber" : "green"}` },
|
||||
`+${win.penaltyDv} m/s`,
|
||||
),
|
||||
),
|
||||
h(
|
||||
"div",
|
||||
{ class: "stat-row" },
|
||||
h("span", { class: "k" }, "Next Optimal Peak"),
|
||||
h(
|
||||
"span",
|
||||
{ class: "v" },
|
||||
win.optimalInSec === 0 ? "OPEN NOW" : fmtDuration(win.optimalInSec),
|
||||
),
|
||||
),
|
||||
);
|
||||
renderPrelaunchBox(ctx, sim);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue