astraeus 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +192 -0
- package/README.md +205 -34
- package/package.json +5 -4
- package/src/api/AstraeusScene.d.ts +24 -6
- package/src/api/AstraeusScene.js +46 -19
- package/src/api/AstraeusScene.node.js +46 -19
- package/src/api/assembleScene.d.ts +36 -0
- package/src/api/assembleScene.js +175 -0
- package/src/api/bodySetChecks.d.ts +10 -0
- package/src/api/bodySetChecks.js +117 -0
- package/src/api/bodySetInput.d.ts +81 -0
- package/src/api/bodySetInput.js +1 -0
- package/src/api/containingBlock.d.ts +6 -0
- package/src/api/containingBlock.js +16 -0
- package/src/api/data.d.ts +17 -5
- package/src/api/data.js +28 -10
- package/src/api/definitionOf.d.ts +16 -0
- package/src/api/definitionOf.js +20 -0
- package/src/api/errors.d.ts +61 -1
- package/src/api/frozenCopy.d.ts +6 -0
- package/src/api/frozenCopy.js +26 -0
- package/src/api/group.d.ts +8 -2
- package/src/api/group.js +24 -5
- package/src/api/index.d.ts +19 -7
- package/src/api/index.js +2 -2
- package/src/api/index.node.js +2 -2
- package/src/api/listeners.d.ts +5 -0
- package/src/api/listeners.js +25 -0
- package/src/api/look.d.ts +47 -0
- package/src/api/look.js +1 -0
- package/src/api/lookInput.d.ts +3 -0
- package/src/api/lookInput.js +41 -0
- package/src/api/moonPanelInput.d.ts +60 -0
- package/src/api/moonPanelInput.js +1 -0
- package/src/api/mount.d.ts +10 -16
- package/src/api/mount.js +27 -11
- package/src/api/mount.node.js +27 -11
- package/src/api/pathProvenance.d.ts +15 -6
- package/src/api/pathProvenance.js +23 -11
- package/src/api/pickerInput.d.ts +25 -0
- package/src/api/pickerInput.js +1 -0
- package/src/api/planBodies.d.ts +72 -0
- package/src/api/planBodies.js +300 -0
- package/src/api/planBodySets.d.ts +68 -0
- package/src/api/planBodySets.js +234 -0
- package/src/api/planCamera.d.ts +83 -0
- package/src/api/planCamera.js +184 -0
- package/src/api/planGroups.d.ts +36 -0
- package/src/api/planGroups.js +103 -0
- package/src/api/planMoonPanel.d.ts +19 -0
- package/src/api/planMoonPanel.js +104 -0
- package/src/api/planPaths.d.ts +40 -0
- package/src/api/planPaths.js +212 -0
- package/src/api/planPicker.d.ts +12 -0
- package/src/api/planPicker.js +40 -0
- package/src/api/planPlaces.d.ts +16 -0
- package/src/api/planPlaces.js +99 -0
- package/src/api/planStory.d.ts +26 -0
- package/src/api/planStory.js +66 -0
- package/src/api/planTimeline.d.ts +27 -0
- package/src/api/planTimeline.js +68 -0
- package/src/api/planViews.d.ts +25 -0
- package/src/api/planViews.js +35 -0
- package/src/api/prepared.js +4 -1
- package/src/api/renamedInputs.d.ts +15 -0
- package/src/api/renamedInputs.js +39 -0
- package/src/api/scene.d.ts +176 -65
- package/src/api/scene.js +257 -725
- package/src/api/sceneFreeze.d.ts +4 -0
- package/src/api/sceneFreeze.js +10 -0
- package/src/api/sceneReads.d.ts +171 -0
- package/src/api/sceneReads.js +6 -0
- package/src/api/sphereOfInfluence.d.ts +20 -0
- package/src/api/sphereOfInfluence.js +48 -0
- package/src/api/story.d.ts +49 -19
- package/src/api/story.js +54 -22
- package/src/api/sunOrbit.js +9 -11
- package/src/api/time.d.ts +2 -1
- package/src/api/time.js +2 -1
- package/src/api/viewerCamera.d.ts +22 -0
- package/src/api/viewerCamera.js +84 -0
- package/src/api/viewerClock.d.ts +30 -0
- package/src/api/viewerClock.js +85 -0
- package/src/api/viewerFirstDraw.d.ts +14 -0
- package/src/api/viewerFirstDraw.js +26 -0
- package/src/api/viewerHandle.d.ts +79 -0
- package/src/api/viewerHandle.js +31 -0
- package/src/api/viewerLink.d.ts +91 -13
- package/src/api/viewerLink.js +111 -64
- package/src/api/viewerLooks.d.ts +19 -0
- package/src/api/viewerLooks.js +37 -0
- package/src/api/viewerPicker.d.ts +22 -0
- package/src/api/viewerPicker.js +49 -0
- package/src/api/viewerSelection.d.ts +25 -0
- package/src/api/viewerSelection.js +31 -0
- package/src/api/viewerViews.d.ts +10 -0
- package/src/api/viewerViews.js +18 -0
- package/src/api/viewerZones.d.ts +20 -0
- package/src/api/viewerZones.js +47 -0
- package/src/api/views.d.ts +41 -0
- package/src/api/views.js +82 -0
- package/src/app/App.d.ts +5 -3
- package/src/app/App.js +211 -75
- package/src/app/App.node.js +211 -75
- package/src/app/AstraeusScene.d.ts +19 -2
- package/src/app/AstraeusScene.js +4 -4
- package/src/app/BodyView.d.ts +4 -1
- package/src/app/BodyView.js +2 -2
- package/src/app/CameraController.d.ts +12 -0
- package/src/app/CameraController.js +3 -1
- package/src/app/DeveloperSettings.d.ts +1 -4
- package/src/app/DeveloperSettings.js +6 -10
- package/src/app/FeatureMarkers.d.ts +4 -3
- package/src/app/FeatureMarkers.js +8 -13
- package/src/app/FrameRateSection.js +2 -1
- package/src/app/OrbitSetView.js +1 -1
- package/src/app/SettingControls.d.ts +11 -3
- package/src/app/SettingControls.js +10 -2
- package/src/app/SkyView.d.ts +3 -10
- package/src/app/SkyView.js +6 -28
- package/src/app/StoryMarkers.d.ts +4 -1
- package/src/app/StoryMarkers.js +3 -2
- package/src/app/TrackedBodyView.d.ts +1 -1
- package/src/app/TrackedBodyView.js +20 -11
- package/src/app/address.d.ts +16 -0
- package/src/app/address.js +31 -0
- package/src/app/bodyDraw.d.ts +10 -7
- package/src/app/bodyDraw.js +12 -32
- package/src/app/bodyMetrics.js +2 -2
- package/src/app/bodySet.d.ts +4 -20
- package/src/app/bodySet.js +5 -16
- package/src/app/debugReadout.js +1 -1
- package/src/app/displaySwitches.d.ts +4 -0
- package/src/app/displaySwitches.js +6 -0
- package/src/app/experienceDefinition.d.ts +14 -23
- package/src/app/listSwitch.d.ts +8 -14
- package/src/app/listSwitch.js +3 -10
- package/src/app/liveLook.d.ts +39 -0
- package/src/app/liveLook.js +66 -0
- package/src/app/look.d.ts +36 -0
- package/src/app/look.js +61 -0
- package/src/app/mission.d.ts +16 -3
- package/src/app/mission.js +16 -1
- package/src/app/openClock.d.ts +3 -2
- package/src/app/openClock.js +3 -3
- package/src/app/sceneCamera.d.ts +2 -0
- package/src/app/sceneCamera.js +23 -0
- package/src/app/sceneFrame.d.ts +6 -4
- package/src/app/sceneFrame.js +55 -14
- package/src/app/sceneHooks.js +3 -2
- package/src/app/style.css +114 -139
- package/src/app/trackedMetrics.d.ts +10 -3
- package/src/app/trackedMetrics.js +22 -11
- package/src/app/viewHiding.d.ts +13 -0
- package/src/app/viewHiding.js +37 -0
- package/src/app/viewLink.d.ts +10 -32
- package/src/app/viewLink.js +10 -49
- package/src/app/viewerPort.d.ts +56 -0
- package/src/app/views.d.ts +32 -0
- package/src/app/views.js +2 -0
- package/src/assets/bodies/galileanMoons.js +1 -2
- package/src/assets/bodies/io.js +2 -2
- package/src/assets/bodies/listedMoons.d.ts +1 -1
- package/src/assets/bodies/listedMoons.js +2 -3
- package/src/assets/bodies/planetSystemMaps.js +2 -3
- package/src/assets/bodies/venus.js +2 -6
- package/src/assets/catalogue.js +1 -2
- package/src/assets/licence.d.ts +3 -3
- package/src/assets/licence.js +3 -3
- package/src/assets/pictures.d.ts +15 -12
- package/src/assets/pictures.js +24 -20
- package/src/assets/sky.d.ts +6 -5
- package/src/assets/sky.js +6 -9
- package/src/assets/visual.d.ts +4 -0
- package/src/core/bodies/index.d.ts +0 -4
- package/src/core/bodies/index.js +1 -6
- package/src/core/bodies/jupiterData.d.ts +0 -1
- package/src/core/bodies/jupiterData.js +2 -5
- package/src/core/bodies/moonSystem.d.ts +1 -1
- package/src/core/bodies/moonSystem.js +102 -55
- package/src/core/bodies/outerPlanetRingData.js +2 -2
- package/src/core/bodies/planetTrajectory.js +1 -1
- package/src/core/bodySetFamilies.d.ts +20 -0
- package/src/core/bodySetFamilies.js +14 -0
- package/src/core/chebyshevEphemeris.js +1 -1
- package/src/core/elementsBody.d.ts +8 -4
- package/src/core/elementsBody.js +32 -11
- package/src/core/elementsGroup.d.ts +27 -0
- package/src/core/elementsGroup.js +85 -0
- package/src/core/events.d.ts +2 -0
- package/src/core/events.js +2 -0
- package/src/core/illumination.js +1 -1
- package/src/core/listedOrbitGroup.d.ts +2 -0
- package/src/core/listedOrbitGroup.js +11 -7
- package/src/core/moonListText.d.ts +6 -0
- package/src/core/moonListText.js +19 -0
- package/src/core/moonTrajectory.js +1 -1
- package/src/core/pacing.d.ts +38 -3
- package/src/core/pacing.js +55 -4
- package/src/core/planetModels.js +2 -2
- package/src/core/planetSeries.d.ts +8 -0
- package/src/core/planetSeries.js +16 -2
- package/src/core/pointGroup.js +1 -1
- package/src/core/provenance.d.ts +2 -1
- package/src/core/provenance.js +2 -2
- package/src/core/referenceCenters.js +5 -5
- package/src/core/sampledTrajectory.js +1 -1
- package/src/core/scalePolicy.d.ts +1 -0
- package/src/core/startView.d.ts +19 -0
- package/src/core/startView.js +28 -0
- package/src/core/state.d.ts +6 -2
- package/src/core/state.js +3 -3
- package/src/core/storyPanels.d.ts +63 -0
- package/src/core/storyPanels.js +111 -0
- package/src/core/sunCentredSources.d.ts +4 -0
- package/src/core/sunCentredSources.js +9 -2
- package/src/core/timeInput.d.ts +4 -0
- package/src/core/timeInput.js +4 -0
- package/src/shell/AstraeusShell.d.ts +17 -3
- package/src/shell/AstraeusShell.js +60 -13
- package/src/shell/AstraeusShell.node.js +60 -13
- package/src/shell/Collapsible.d.ts +4 -3
- package/src/shell/Collapsible.js +5 -5
- package/src/shell/ControlsDrawer.d.ts +1 -1
- package/src/shell/ControlsDrawer.js +3 -1
- package/src/shell/DisplaySwitches.d.ts +18 -1
- package/src/shell/DisplaySwitches.js +20 -6
- package/src/shell/InfoPanel.d.ts +3 -1
- package/src/shell/InfoPanel.js +5 -4
- package/src/shell/MoonFamilyPanel.js +1 -1
- package/src/shell/ObjectControls.d.ts +3 -1
- package/src/shell/ObjectControls.js +2 -2
- package/src/shell/Sources.d.ts +5 -3
- package/src/shell/Sources.js +5 -5
- package/src/shell/StoryPanelView.d.ts +4 -3
- package/src/shell/StoryPanelView.js +8 -6
- package/src/shell/SwitchControl.d.ts +5 -11
- package/src/shell/SwitchControl.js +2 -20
- package/src/shell/TimelineBar.css +84 -66
- package/src/shell/TimelineBar.d.ts +5 -2
- package/src/shell/TimelineBar.js +37 -11
- package/src/shell/TimelineBar.node.js +37 -11
- package/src/shell/TopBar.css +22 -22
- package/src/shell/TopBar.d.ts +9 -3
- package/src/shell/TopBar.js +5 -5
- package/src/shell/TopBar.node.js +5 -5
- package/src/shell/bootLoader.d.ts +4 -10
- package/src/shell/bootLoader.js +6 -52
- package/src/shell/embedded.css +18 -18
- package/src/shell/experience.d.ts +1 -1
- package/src/shell/moonFamilies.d.ts +2 -6
- package/src/shell/moonFamilies.js +2 -18
- package/src/shell/phone.css +58 -58
- package/src/shell/storyPanels.d.ts +2 -53
- package/src/shell/storyPanels.js +1 -106
- package/src/shell/style.css +153 -134
- package/src/shell/timelineModel.d.ts +13 -0
- package/src/shell/timelineModel.js +25 -0
- package/src/shell/useDrawers.d.ts +3 -2
- package/src/shell/useDrawers.js +4 -3
- package/src/shell/viewCamera.d.ts +4 -0
- package/src/shell/viewCamera.js +13 -0
- package/src/shell/viewerKeys.d.ts +8 -0
- package/src/shell/viewerKeys.js +16 -0
- package/src/synthetic/syntheticDefinition.js +20 -24
- package/src/synthetic/syntheticJourneyScene.js +14 -4
- package/src/synthetic/syntheticProbeDefinition.js +2 -1
- package/src/synthetic/syntheticViewsDefinition.d.ts +3 -0
- package/src/synthetic/syntheticViewsDefinition.js +38 -0
- package/data/moons/jupiter.json +0 -3333
- package/data/moons/neptune.json +0 -555
- package/data/moons/pluto.json +0 -205
- package/data/moons/saturn.json +0 -8267
- package/data/moons/uranus.json +0 -887
- package/src/app/addressNavigation.d.ts +0 -17
- package/src/app/addressNavigation.js +0 -16
- package/src/assets/bodies/jupiterMoonCatalogue.d.ts +0 -3
- package/src/assets/bodies/jupiterMoonCatalogue.js +0 -4
- package/src/assets/bodies/outerPlanetCatalogues.d.ts +0 -7
- package/src/assets/bodies/outerPlanetCatalogues.js +0 -8
- package/src/assets/bodies/swiftTuttle.d.ts +0 -12
- package/src/assets/bodies/swiftTuttle.js +0 -13
- package/src/assets/moonCatalogue.d.ts +0 -49
- package/src/assets/moonCatalogue.js +0 -80
- package/src/core/bodies/outerPlanetData.d.ts +0 -4
- package/src/core/bodies/outerPlanetData.js +0 -13
- package/src/core/bodies/swiftTuttle.d.ts +0 -46
- package/src/core/bodies/swiftTuttle.js +0 -106
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { createProvenance } from "../core/provenance.js";
|
|
2
|
+
import { SampledTrajectory } from "../core/sampledTrajectory.js";
|
|
3
|
+
import { createState } from "../core/state.js";
|
|
4
|
+
import { createOrbTwoBodyAdapter } from "../core/twoBodyAdapter.js";
|
|
5
|
+
import { createStateResolver } from "../core/stateResolver.js";
|
|
6
|
+
import { createOrbAstronomyAdapter } from "../core/astronomyAdapter.js";
|
|
7
|
+
import { planetSeriesLoaded } from "../core/planetSeries.js";
|
|
8
|
+
import { catalogue as builtInCatalogue } from "../assets/catalogue.js";
|
|
9
|
+
import { lineBodies } from "../app/mission.js";
|
|
10
|
+
import { planLineStretches, planPathProvenance } from "./pathProvenance.js";
|
|
11
|
+
import { influenceStretches, sphereOfInfluenceKm } from "./sphereOfInfluence.js";
|
|
12
|
+
import { SceneError } from "./errors.js";
|
|
13
|
+
import { rejectRenamed } from "./renamedInputs.js";
|
|
14
|
+
import { toUtcMs } from "./time.js";
|
|
15
|
+
import { frozenList } from "./sceneReads.js";
|
|
16
|
+
const DEFAULT_COLOR = "#ffd27a";
|
|
17
|
+
const PROVIDER_PATH_SAMPLES = 128;
|
|
18
|
+
/** Samples along a path when its farthest distance is read for the default zoom-out. */
|
|
19
|
+
const PATH_COVER_SAMPLES = 400;
|
|
20
|
+
/** The paths in the order added, as the public list states them. */
|
|
21
|
+
export function pathReads(tracked) {
|
|
22
|
+
return frozenList([...tracked].map(({ body, center, description, knownLimitations }) => ({ id: body.id, label: body.label, center, provenance: body.provenance, ...(description === undefined ? {} : { description }), knownLimitations: Object.freeze([...(knownLimitations ?? [])]) }))); // addTrajectory always sets a provenance
|
|
23
|
+
}
|
|
24
|
+
/** Validates and stores one path about `center`. */
|
|
25
|
+
export function buildTracked(input, center, labelReaches) {
|
|
26
|
+
const id = input.id;
|
|
27
|
+
rejectRenamed("TrajectoryInput", input, `addTrajectory("${id}")`);
|
|
28
|
+
if (!builtInCatalogue.has(center))
|
|
29
|
+
throw new SceneError("unknown-body", `addTrajectory("${id}"): centre "${center}" is not a catalogued body`);
|
|
30
|
+
const provenance = input.provenance ?? createProvenance({ sourceType: "illustrative", sources: ["Supplied by the caller"], accuracy: "As supplied; the engine makes no claim.", notes: "Positions were passed to addTrajectory." });
|
|
31
|
+
const common = { id, label: input.label ?? id, color: input.color ?? DEFAULT_COLOR, anchorTimesUtcMs: [], provenance };
|
|
32
|
+
const readouts = readoutsOf(id, input.readouts);
|
|
33
|
+
if (input.labelReachEarthRadii !== undefined) {
|
|
34
|
+
checkLabelReach(input.labelReachEarthRadii, new SceneError("bad-trajectory", `addTrajectory("${id}"): labelReachEarthRadii ${String(input.labelReachEarthRadii)} must be a positive finite number`));
|
|
35
|
+
labelReaches.set(id, input.labelReachEarthRadii);
|
|
36
|
+
}
|
|
37
|
+
if (input.plane !== undefined && input.plane !== "EQJ" && input.plane !== "ecliptic-j2000")
|
|
38
|
+
throw new SceneError("bad-trajectory", `addTrajectory("${id}"): plane "${String(input.plane)}" must be "EQJ" or "ecliptic-j2000"`);
|
|
39
|
+
const toEqj = input.plane === "ecliptic-j2000" ? createOrbTwoBodyAdapter().eclipticJ2000ToEqjMatrix() : null;
|
|
40
|
+
const body = "samples" in input ? sampledBody(common, input, center, toEqj) : providerBody(common, input, toEqj);
|
|
41
|
+
const span = { startUtcMs: body.trajectory.bounds.startUtcMs, endUtcMs: body.trajectory.bounds.endUtcMs };
|
|
42
|
+
const provenanceSpans = input.provenanceSpans === undefined ? undefined : planPathProvenance(id, input.provenanceSpans, span);
|
|
43
|
+
checkLineFixedToType(id, input.lineFixedTo);
|
|
44
|
+
const auto = input.lineFixedTo === "auto";
|
|
45
|
+
const lineFixedTo = typeof input.lineFixedTo === "object" ? planLineStretches(id, input.lineFixedTo, span) : auto ? undefined : input.lineFixedTo;
|
|
46
|
+
return { center, ...(auto ? { auto: true } : {}), body: withAnchors(lineFixedTo === undefined ? body : { ...body, lineFixedTo }, input.anchors), readouts, ...(provenanceSpans === undefined ? {} : { provenanceSpans }), ...(input.description === undefined ? {} : { description: input.description }), ...(input.knownLimitations === undefined ? {} : { knownLimitations: input.knownLimitations }) };
|
|
47
|
+
}
|
|
48
|
+
/** Rotates a vector by a row-major 3x3 matrix; a missing matrix leaves it as it is. Input that is not three numbers passes through for the State checks to refuse. */
|
|
49
|
+
function rotated(matrix, v) {
|
|
50
|
+
if (matrix === null || v === undefined || v.length !== 3)
|
|
51
|
+
return v;
|
|
52
|
+
return [0, 1, 2].map((row) => matrix[3 * row] * v[0] + matrix[3 * row + 1] * v[1] + matrix[3 * row + 2] * v[2]);
|
|
53
|
+
}
|
|
54
|
+
function sampledBody(common, input, center, toEqj) {
|
|
55
|
+
const samples = input.samples.map((sample, index) => {
|
|
56
|
+
const velocityKmS = rotated(toEqj, sample.velocityKmS);
|
|
57
|
+
return { positionKm: rotated(toEqj, sample.positionKm), ...(velocityKmS === undefined ? {} : { velocityKmS }), timeUtcMs: toUtcMs(sample.time, `addTrajectory("${common.id}") sample ${index} time`) };
|
|
58
|
+
});
|
|
59
|
+
try {
|
|
60
|
+
const trajectory = new SampledTrajectory({ body: common.id, center, samples });
|
|
61
|
+
return { ...common, trajectory, pathTimesUtcMs: samples.map((sample) => sample.timeUtcMs) };
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (error instanceof SceneError)
|
|
65
|
+
throw error;
|
|
66
|
+
throw new SceneError("bad-trajectory", `addTrajectory("${common.id}"): ${error instanceof Error ? error.message : String(error)}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** `lineFixedTo` is a body id, `"auto"` or a list; anything else is `bad-trajectory` (the list's own faults are named by `planLineStretches`). */
|
|
70
|
+
function checkLineFixedToType(id, value) {
|
|
71
|
+
if (value !== undefined && typeof value !== "string" && typeof value !== "object")
|
|
72
|
+
throw new SceneError("bad-trajectory", `addTrajectory("${id}"): lineFixedTo ${String(value)} must be a body id, "auto" or a list of stretches`);
|
|
73
|
+
}
|
|
74
|
+
function providerBody(common, input, toEqj) {
|
|
75
|
+
if (typeof input.provider?.stateAt !== "function")
|
|
76
|
+
throw new SceneError("bad-trajectory", `addTrajectory("${common.id}"): provider needs a stateAt(time) function`);
|
|
77
|
+
const bounds = { startUtcMs: toUtcMs(input.bounds?.start, `addTrajectory("${common.id}") bounds.start`), endUtcMs: toUtcMs(input.bounds?.end, `addTrajectory("${common.id}") bounds.end`) };
|
|
78
|
+
if (bounds.endUtcMs <= bounds.startUtcMs)
|
|
79
|
+
throw new SceneError("bad-trajectory", `addTrajectory("${common.id}"): bounds must end after they start`);
|
|
80
|
+
const trajectory = { body: common.id, bounds, stateAt: (timeUtcMs, center) => rotatedState(toEqj, input.provider.stateAt(timeUtcMs, center)) };
|
|
81
|
+
// Whole milliseconds, because the state resolver refuses a fractional time (the line is placed against another body at these times).
|
|
82
|
+
const step = (bounds.endUtcMs - bounds.startUtcMs) / (PROVIDER_PATH_SAMPLES - 1);
|
|
83
|
+
return { ...common, trajectory, pathTimesUtcMs: Array.from({ length: PROVIDER_PATH_SAMPLES }, (_, index) => Math.round(bounds.startUtcMs + index * step)) };
|
|
84
|
+
}
|
|
85
|
+
/** A provider's State with its position and velocity rotated into EQJ; unchanged for EQJ input. */
|
|
86
|
+
function rotatedState(matrix, state) {
|
|
87
|
+
if (matrix === null)
|
|
88
|
+
return state;
|
|
89
|
+
return createState({ body: state.body, center: state.center, timeUtcMs: state.timeUtcMs, positionKm: rotated(matrix, state.positionKm), ...(state.velocityKmS === undefined ? {} : { velocityKmS: rotated(matrix, state.velocityKmS) }), orientation: state.orientation });
|
|
90
|
+
}
|
|
91
|
+
/** Throws `error` unless `reach` is a positive finite number. */
|
|
92
|
+
export function checkLabelReach(reach, error) {
|
|
93
|
+
if (!(typeof reach === "number" && Number.isFinite(reach) && reach > 0))
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
const READOUT_KINDS = ["range", "speed", "distance", "altitude"];
|
|
97
|
+
/** The body a readout names, if any. */
|
|
98
|
+
function readoutBody(spec) {
|
|
99
|
+
return spec.kind === "range" ? spec.marker : spec.kind === "distance" ? spec.to : spec.kind === "altitude" ? spec.above : undefined;
|
|
100
|
+
}
|
|
101
|
+
/** Checks each readout's kind and the catalogued body it names; whether the scene holds that body is checked when the definition is built. */
|
|
102
|
+
export function readoutsOf(id, readouts = [], call = "addTrajectory") {
|
|
103
|
+
if (!Array.isArray(readouts))
|
|
104
|
+
throw new SceneError("bad-readout", `${call}("${id}"): readouts must be a list`);
|
|
105
|
+
for (const spec of readouts) {
|
|
106
|
+
if (!READOUT_KINDS.includes(spec?.kind))
|
|
107
|
+
throw new SceneError("bad-readout", `${call}("${id}"): readout kind "${String(spec?.kind)}" is not one of ${READOUT_KINDS.join(", ")}`);
|
|
108
|
+
const named = readoutBody(spec);
|
|
109
|
+
if (spec.kind !== "range" && spec.kind !== "speed" && named === undefined)
|
|
110
|
+
throw new SceneError("bad-readout", `${call}("${id}"): readout ${spec.kind} needs ${spec.kind === "distance" ? "`to`" : "`above`"}, the body to measure against`);
|
|
111
|
+
if (named !== undefined && !builtInCatalogue.has(named))
|
|
112
|
+
throw new SceneError("bad-readout", `${call}("${id}"): readout ${spec.kind} names "${named}", which is not a catalogued body`);
|
|
113
|
+
}
|
|
114
|
+
return readouts;
|
|
115
|
+
}
|
|
116
|
+
/** The body with its anchors: sorted by time, each labelled with its id. Every anchor needs a distinct id and a moment inside the path. */
|
|
117
|
+
function withAnchors(body, anchors = []) {
|
|
118
|
+
if (!Array.isArray(anchors))
|
|
119
|
+
throw new SceneError("bad-anchor", `addTrajectory("${body.id}"): anchors must be a list`);
|
|
120
|
+
const { startUtcMs, endUtcMs } = body.trajectory.bounds;
|
|
121
|
+
const seen = new Set();
|
|
122
|
+
const placed = anchors.map((anchor) => {
|
|
123
|
+
if (typeof anchor?.id !== "string" || anchor.id === "")
|
|
124
|
+
throw new SceneError("bad-anchor", `addTrajectory("${body.id}"): every anchor needs a non-empty id`);
|
|
125
|
+
if (seen.has(anchor.id))
|
|
126
|
+
throw new SceneError("bad-anchor", `addTrajectory("${body.id}"): anchor "${anchor.id}" appears twice`);
|
|
127
|
+
seen.add(anchor.id);
|
|
128
|
+
const timeUtcMs = anchorTime(body.id, anchor);
|
|
129
|
+
if (timeUtcMs < startUtcMs || timeUtcMs > endUtcMs)
|
|
130
|
+
throw new SceneError("bad-anchor", `addTrajectory("${body.id}"): anchor "${anchor.id}" is outside the path (${new Date(startUtcMs).toISOString()} to ${new Date(endUtcMs).toISOString()})`);
|
|
131
|
+
return { id: anchor.id, timeUtcMs };
|
|
132
|
+
}).sort((a, b) => a.timeUtcMs - b.timeUtcMs);
|
|
133
|
+
return placed.length === 0 ? body : { ...body, anchorTimesUtcMs: placed.map((anchor) => anchor.timeUtcMs), anchorLabels: placed.map((anchor) => anchor.id) };
|
|
134
|
+
}
|
|
135
|
+
function anchorTime(path, anchor) {
|
|
136
|
+
try {
|
|
137
|
+
return toUtcMs(anchor.time);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
throw new SceneError("bad-anchor", `addTrajectory("${path}"): anchor "${anchor.id}" has a time "${String(anchor.time)}" that is not a valid moment`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* The distance the default zoom-out must cover for the scene's paths about the scene centre (I-114): a path reaching past the planets must fit whole whichever point of it the camera looks at,
|
|
145
|
+
* so twice its farthest distance from the centre (no two points of a path are farther apart than that). Sampled over each path's span; undefined when no path is about the centre.
|
|
146
|
+
*/
|
|
147
|
+
export function pathCover(tracked, sunCentred, centre) {
|
|
148
|
+
if (!sunCentred)
|
|
149
|
+
return undefined;
|
|
150
|
+
const about = [...tracked].filter((entry) => entry.center === centre);
|
|
151
|
+
if (about.length === 0)
|
|
152
|
+
return undefined;
|
|
153
|
+
return () => 2 * Math.max(...about.map(({ body }) => {
|
|
154
|
+
const { startUtcMs, endUtcMs } = body.trajectory.bounds;
|
|
155
|
+
let farthest = 0;
|
|
156
|
+
for (let k = 0; k < PATH_COVER_SAMPLES; k += 1)
|
|
157
|
+
farthest = Math.max(farthest, Math.hypot(...body.trajectory.stateAt(Math.round(startUtcMs + ((endUtcMs - startUtcMs) * k) / (PATH_COVER_SAMPLES - 1)), centre).positionKm));
|
|
158
|
+
return farthest;
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
/** The stretches of a `lineFixedTo: "auto"` path: the innermost scene body whose sphere of influence holds each sample (`sphereOfInfluence.ts`). Reads body states, so the planet series must be loaded. */
|
|
162
|
+
function autoStretches(catalogue, entry, ids) {
|
|
163
|
+
const resolver = createStateResolver(catalogue.definitions(), catalogue.sources(), createOrbAstronomyAdapter());
|
|
164
|
+
const norm = (v) => Math.hypot(v[0], v[1], v[2]);
|
|
165
|
+
const candidates = [];
|
|
166
|
+
for (const id of ids) {
|
|
167
|
+
const { parentId, gmKm3S2 } = catalogue.get(id).definition;
|
|
168
|
+
if (parentId === undefined) {
|
|
169
|
+
candidates.push({ id, radiusKm: () => Infinity, probeDistanceKm: () => 0 });
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
const parentGm = catalogue.get(parentId).definition.gmKm3S2;
|
|
173
|
+
if (!(gmKm3S2 > 0 && parentGm > 0))
|
|
174
|
+
continue; // no published GM: this body cannot hold a probe
|
|
175
|
+
candidates.push({
|
|
176
|
+
id,
|
|
177
|
+
radiusKm: (t) => sphereOfInfluenceKm(gmKm3S2, parentGm, norm(resolver.stateOf(id, t, parentId).positionKm)),
|
|
178
|
+
probeDistanceKm: (t) => {
|
|
179
|
+
const probe = entry.body.trajectory.stateAt(t, entry.center).positionKm;
|
|
180
|
+
const body = resolver.stateOf(id, t, entry.center).positionKm;
|
|
181
|
+
return norm([probe[0] - body[0], probe[1] - body[1], probe[2] - body[2]]);
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return influenceStretches(entry.body.pathTimesUtcMs, candidates);
|
|
186
|
+
}
|
|
187
|
+
/** The `"auto"` paths' one resolution into `tracked`: `now` runs it (through the caller's guarded read) when the planet series are in; else `later` is true and `settle` runs it in `prepare`. */
|
|
188
|
+
export function autoPaths(catalogue, entries, tracked, ids) {
|
|
189
|
+
const pending = entries.some((entry) => entry.auto === true);
|
|
190
|
+
const later = pending && !planetSeriesLoaded();
|
|
191
|
+
const resolve = () => entries.forEach((entry, index) => { if (entry.auto === true)
|
|
192
|
+
tracked[index] = { ...entry.body, lineFixedTo: autoStretches(catalogue, entry, ids) }; });
|
|
193
|
+
return { later, now: (guard) => { if (pending && !later)
|
|
194
|
+
guard(resolve); }, settle: (guard) => { if (later)
|
|
195
|
+
guard(resolve); } };
|
|
196
|
+
}
|
|
197
|
+
/** A readout, or the body the line is fixed to, names a body the scene must hold. */
|
|
198
|
+
export function checkReadouts(entry, ids) {
|
|
199
|
+
for (const { index, body } of lineBodies(entry.body.lineFixedTo)) {
|
|
200
|
+
if (!ids.includes(body))
|
|
201
|
+
throw new SceneError("bad-trajectory", `addTrajectory("${entry.body.id}"): lineFixedTo${index === null ? "" : `[${index}]`} names "${body}", which has not been added to the scene`);
|
|
202
|
+
}
|
|
203
|
+
checkNamedReadouts(entry.body.id, entry.readouts, ids, "addTrajectory");
|
|
204
|
+
}
|
|
205
|
+
/** The readouts of a path or a body name only bodies the scene holds. */
|
|
206
|
+
export function checkNamedReadouts(id, readouts, ids, call) {
|
|
207
|
+
for (const spec of readouts) {
|
|
208
|
+
const named = readoutBody(spec);
|
|
209
|
+
if (named !== undefined && !ids.includes(named))
|
|
210
|
+
throw new SceneError("bad-readout", `${call}("${id}"): readout ${spec.kind} names "${named}", which has not been added to the scene`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PickerInput } from "./pickerInput.js";
|
|
2
|
+
/** What a `Scene` has planned for its picker. */
|
|
3
|
+
export declare class PickerPlan {
|
|
4
|
+
#private;
|
|
5
|
+
set(input: PickerInput): void;
|
|
6
|
+
/** The picker as set (frozen); undefined when none was set. */
|
|
7
|
+
get input(): PickerInput | undefined;
|
|
8
|
+
/** The definition's entry; absent when none was set. */
|
|
9
|
+
entry(): {
|
|
10
|
+
readonly picker: PickerInput;
|
|
11
|
+
} | Record<string, never>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { SceneError } from "./errors.js";
|
|
2
|
+
const bad = (message) => new SceneError("bad-picker", `setPicker: ${message}`);
|
|
3
|
+
const isText = (value) => typeof value === "string" && value !== "";
|
|
4
|
+
/** Checks the picker's id, label, options and starting value; throws `bad-picker`. */
|
|
5
|
+
function checkInput(input) {
|
|
6
|
+
if (typeof input !== "object" || input === null)
|
|
7
|
+
throw bad("give an { id, label, options, value } object");
|
|
8
|
+
if (!isText(input.id))
|
|
9
|
+
throw bad("the picker needs a non-empty id");
|
|
10
|
+
if (!isText(input.label))
|
|
11
|
+
throw bad("the picker needs a label");
|
|
12
|
+
if (!Array.isArray(input.options))
|
|
13
|
+
throw bad("options must be a list");
|
|
14
|
+
const values = new Set();
|
|
15
|
+
for (const option of input.options) {
|
|
16
|
+
if (!isText(option?.value))
|
|
17
|
+
throw bad("every option needs a non-empty value");
|
|
18
|
+
if (!isText(option.label))
|
|
19
|
+
throw bad(`option "${option.value}" needs a label`);
|
|
20
|
+
if (values.has(option.value))
|
|
21
|
+
throw bad(`option "${option.value}" appears twice`);
|
|
22
|
+
values.add(option.value);
|
|
23
|
+
}
|
|
24
|
+
if (!values.has(input.value))
|
|
25
|
+
throw bad(`value "${String(input.value)}" is not one of the options`);
|
|
26
|
+
}
|
|
27
|
+
/** What a `Scene` has planned for its picker. */
|
|
28
|
+
export class PickerPlan {
|
|
29
|
+
#input;
|
|
30
|
+
set(input) {
|
|
31
|
+
checkInput(input);
|
|
32
|
+
this.#input = Object.freeze({ id: input.id, label: input.label, value: input.value, options: Object.freeze(input.options.map((option) => Object.freeze({ value: option.value, label: option.label }))) });
|
|
33
|
+
}
|
|
34
|
+
/** The picker as set (frozen); undefined when none was set. */
|
|
35
|
+
get input() { return this.#input; }
|
|
36
|
+
/** The definition's entry; absent when none was set. */
|
|
37
|
+
entry() {
|
|
38
|
+
return this.#input === undefined ? {} : { picker: this.#input };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BodyId } from "../core/body.js";
|
|
2
|
+
import type { ExperienceDefinition } from "../app/experienceDefinition.js";
|
|
3
|
+
import type { BodyRef } from "./bodies.js";
|
|
4
|
+
import type { PlacesInput } from "./moonPanelInput.js";
|
|
5
|
+
import { type ScenePlacesRead } from "./sceneReads.js";
|
|
6
|
+
type BodyFeatureSet = NonNullable<ExperienceDefinition["experience"]["bodyFeatures"]>[number];
|
|
7
|
+
/** What a `Scene` has planned for its tagged surface places, by body. */
|
|
8
|
+
export declare class PlacesPlan {
|
|
9
|
+
readonly sets: Map<string, PlacesInput>;
|
|
10
|
+
add(body: BodyRef | BodyId, input: PlacesInput): void;
|
|
11
|
+
/** The places in the order added. */
|
|
12
|
+
reads(): readonly ScenePlacesRead[];
|
|
13
|
+
/** The shell's sets, once the finished scene says which bodies it holds (`labels` maps them to their labels). */
|
|
14
|
+
featureSets(labels: ReadonlyMap<string, string>): readonly BodyFeatureSet[];
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createProvenance } from "../core/provenance.js";
|
|
2
|
+
import { SceneError } from "./errors.js";
|
|
3
|
+
import { frozenCopy } from "./frozenCopy.js";
|
|
4
|
+
import { idOf } from "./bodySetChecks.js";
|
|
5
|
+
import { frozenList } from "./sceneReads.js";
|
|
6
|
+
const HEX = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;
|
|
7
|
+
const bad = (body, message) => new SceneError("bad-places", `addPlaces("${String(body)}"): ${message}`);
|
|
8
|
+
const isText = (value) => typeof value === "string" && value !== "";
|
|
9
|
+
const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
10
|
+
/** Checks the categories; returns nothing, throws `bad-places`. */
|
|
11
|
+
function checkCategories(body, categories) {
|
|
12
|
+
if (!Array.isArray(categories))
|
|
13
|
+
throw bad(body, "categories must be a list");
|
|
14
|
+
const keys = new Set();
|
|
15
|
+
for (const category of categories) {
|
|
16
|
+
if (!isText(category?.key))
|
|
17
|
+
throw bad(body, "every category needs a non-empty key");
|
|
18
|
+
if (keys.has(category.key))
|
|
19
|
+
throw bad(body, `category "${category.key}" appears twice`);
|
|
20
|
+
keys.add(category.key);
|
|
21
|
+
if (!isText(category.label))
|
|
22
|
+
throw bad(body, `category "${category.key}" needs a label`);
|
|
23
|
+
if (typeof category.color !== "string" || !HEX.test(category.color))
|
|
24
|
+
throw bad(body, `category "${category.key}": color "${String(category.color)}" is not a hex colour such as "#9de3a8"`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Checks one place: its words, its position and its details. */
|
|
28
|
+
function checkPlace(body, place) {
|
|
29
|
+
for (const field of ["name", "kind", "category", "description"])
|
|
30
|
+
if (!isText(place[field]))
|
|
31
|
+
throw bad(body, `place "${place.id}": ${field} must be a non-empty text`);
|
|
32
|
+
if (!isNumber(place.latitudeDeg) || place.latitudeDeg < -90 || place.latitudeDeg > 90)
|
|
33
|
+
throw bad(body, `place "${place.id}": latitudeDeg must be a number from -90 to 90`);
|
|
34
|
+
if (!isNumber(place.longitudeDeg))
|
|
35
|
+
throw bad(body, `place "${place.id}": longitudeDeg must be a finite number`);
|
|
36
|
+
const details = place.details;
|
|
37
|
+
if (details !== undefined && !(Array.isArray(details) && details.every((fact) => isText(fact?.label) && isText(fact.value))))
|
|
38
|
+
throw bad(body, `place "${place.id}": details must be a list of { label, value } with both texts non-empty`);
|
|
39
|
+
}
|
|
40
|
+
/** Checks the categories, places, provenance and limits of one body's places. */
|
|
41
|
+
function checkInput(body, input) {
|
|
42
|
+
if (typeof input !== "object" || input === null)
|
|
43
|
+
throw bad(body, "give a { categories, places, provenance } object");
|
|
44
|
+
checkCategories(body, input.categories);
|
|
45
|
+
if (!Array.isArray(input.places) || input.places.length === 0)
|
|
46
|
+
throw bad(body, "give at least one place");
|
|
47
|
+
const ids = new Set();
|
|
48
|
+
for (const place of input.places) {
|
|
49
|
+
if (!isText(place?.id))
|
|
50
|
+
throw bad(body, "every place needs a non-empty id");
|
|
51
|
+
if (ids.has(place.id))
|
|
52
|
+
throw bad(body, `place "${place.id}" appears twice`);
|
|
53
|
+
ids.add(place.id);
|
|
54
|
+
checkPlace(body, place);
|
|
55
|
+
}
|
|
56
|
+
if (typeof input.provenance !== "object" || input.provenance === null)
|
|
57
|
+
throw bad(body, "the places need a provenance");
|
|
58
|
+
try {
|
|
59
|
+
createProvenance(input.provenance);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
throw bad(body, `provenance: ${error instanceof Error ? error.message : String(error)}`);
|
|
63
|
+
}
|
|
64
|
+
if (input.knownLimitations !== undefined && !(Array.isArray(input.knownLimitations) && input.knownLimitations.every(isText)))
|
|
65
|
+
throw bad(body, "knownLimitations must be a list of non-empty texts");
|
|
66
|
+
}
|
|
67
|
+
/** What a `Scene` has planned for its tagged surface places, by body. */
|
|
68
|
+
export class PlacesPlan {
|
|
69
|
+
sets = new Map();
|
|
70
|
+
add(body, input) {
|
|
71
|
+
const id = idOf(body);
|
|
72
|
+
if (!isText(id))
|
|
73
|
+
throw bad(id, "name the body: a body or its id");
|
|
74
|
+
if (this.sets.has(id))
|
|
75
|
+
throw new SceneError("duplicate-id", `addPlaces("${id}"): that body already has places; give them all in one call`);
|
|
76
|
+
checkInput(id, input);
|
|
77
|
+
this.sets.set(id, frozenCopy(input));
|
|
78
|
+
}
|
|
79
|
+
/** The places in the order added. */
|
|
80
|
+
reads() {
|
|
81
|
+
return frozenList([...this.sets].map(([body, input]) => ({ body, count: input.places.length })));
|
|
82
|
+
}
|
|
83
|
+
/** The shell's sets, once the finished scene says which bodies it holds (`labels` maps them to their labels). */
|
|
84
|
+
featureSets(labels) {
|
|
85
|
+
return [...this.sets].map(([body, input]) => {
|
|
86
|
+
const label = labels.get(body);
|
|
87
|
+
if (label === undefined)
|
|
88
|
+
throw bad(body, "the body has not been added to the scene");
|
|
89
|
+
return {
|
|
90
|
+
bodyId: body,
|
|
91
|
+
bodyLabel: label,
|
|
92
|
+
categories: input.categories.map(({ key, label: categoryLabel, color }) => ({ key, label: categoryLabel, color })),
|
|
93
|
+
features: input.places.map((place) => ({ id: place.id, name: place.name, featureType: place.kind, category: place.category, latitude: place.latitudeDeg, longitude: place.longitudeDeg, description: place.description, details: (place.details ?? []).map(({ label: factLabel, value }) => ({ label: factLabel, value })) })),
|
|
94
|
+
provenance: createProvenance(input.provenance),
|
|
95
|
+
...(input.knownLimitations === undefined ? {} : { knownLimitations: [...input.knownLimitations] }),
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TimelineEvent } from "../core/events.js";
|
|
2
|
+
import type { TimeBounds } from "../core/trajectory.js";
|
|
3
|
+
import { type StoryPanelSet } from "../core/storyPanels.js";
|
|
4
|
+
import type { ExperienceConfig } from "../shell/experience.js";
|
|
5
|
+
import { type AddEventsOptions, type EventInput, type StoryPanelInput, type StoryPanelPlaybackInput } from "./story.js";
|
|
6
|
+
import type { Tracked } from "./planPaths.js";
|
|
7
|
+
import { type SceneEventRead, type ScenePanelRead } from "./sceneReads.js";
|
|
8
|
+
/** What a `Scene` has planned for its story layer: events, where their times come from, and story panels. */
|
|
9
|
+
export declare class StoryPlan {
|
|
10
|
+
#private;
|
|
11
|
+
events: readonly TimelineEvent[];
|
|
12
|
+
addEvents(events: readonly EventInput[], options: AddEventsOptions): void;
|
|
13
|
+
/** Appends a batch; one that fails its checks adds nothing. */
|
|
14
|
+
addPanels(panels: readonly StoryPanelInput[]): void;
|
|
15
|
+
setPanelPlayback(playback: StoryPanelPlaybackInput): void;
|
|
16
|
+
/** The events name only objects the scene holds. */
|
|
17
|
+
checkObjects(ids: ReadonlySet<string>): void;
|
|
18
|
+
/** The story panels, resolved against this scene's events, the anchors of its paths, its objects and timeline span. */
|
|
19
|
+
panels(window: TimeBounds, tracked: Iterable<Tracked>, objectIds: readonly string[]): StoryPanelSet | undefined;
|
|
20
|
+
/** The events sorted by time, each with its own provenance, else the batch's. */
|
|
21
|
+
eventReads(): readonly SceneEventRead[];
|
|
22
|
+
/** The story panels as the public list states them (resolved as `panels` resolves them); empty when none were added. */
|
|
23
|
+
panelReads(window: TimeBounds, tracked: Iterable<Tracked>, objectIds: readonly string[]): readonly ScenePanelRead[];
|
|
24
|
+
/** The event provenance entries of the experience: the batch's, and each event's own. */
|
|
25
|
+
provenanceEntries(): Pick<ExperienceConfig, "eventProvenance" | "eventProvenanceById">;
|
|
26
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { DEFAULT_PANEL_PLAYBACK } from "../core/storyPanels.js";
|
|
2
|
+
import { checkEventObjects, eventProvenanceOf, eventsOf, panelBatchOf, panelPlaybackOf, panelsOf } from "./story.js";
|
|
3
|
+
import { frozenList } from "./sceneReads.js";
|
|
4
|
+
/** What a `Scene` has planned for its story layer: events, where their times come from, and story panels. */
|
|
5
|
+
export class StoryPlan {
|
|
6
|
+
events = [];
|
|
7
|
+
#eventProvenance;
|
|
8
|
+
#eventOwnProvenance = new Map();
|
|
9
|
+
#panels;
|
|
10
|
+
#playback = DEFAULT_PANEL_PLAYBACK;
|
|
11
|
+
addEvents(events, options) {
|
|
12
|
+
const merged = eventsOf(events, this.events);
|
|
13
|
+
const own = events.flatMap((event) => event.provenance === undefined ? [] : [[event.id, eventProvenanceOf(event.provenance, event.id)]]);
|
|
14
|
+
const batch = options.provenance === undefined ? undefined : eventProvenanceOf(options.provenance);
|
|
15
|
+
this.events = merged;
|
|
16
|
+
for (const [id, provenance] of own)
|
|
17
|
+
this.#eventOwnProvenance.set(id, provenance);
|
|
18
|
+
if (batch !== undefined)
|
|
19
|
+
this.#eventProvenance = batch;
|
|
20
|
+
}
|
|
21
|
+
/** Appends a batch; one that fails its checks adds nothing. */
|
|
22
|
+
addPanels(panels) {
|
|
23
|
+
const known = this.#panels ?? [];
|
|
24
|
+
this.#panels = [...known, ...panelBatchOf(panels, known)];
|
|
25
|
+
}
|
|
26
|
+
setPanelPlayback(playback) {
|
|
27
|
+
this.#playback = panelPlaybackOf(playback);
|
|
28
|
+
}
|
|
29
|
+
/** The events name only objects the scene holds. */
|
|
30
|
+
checkObjects(ids) {
|
|
31
|
+
checkEventObjects(this.events, ids);
|
|
32
|
+
}
|
|
33
|
+
/** The story panels, resolved against this scene's events, the anchors of its paths, its objects and timeline span. */
|
|
34
|
+
panels(window, tracked, objectIds) {
|
|
35
|
+
if (this.#panels === undefined)
|
|
36
|
+
return undefined;
|
|
37
|
+
const anchors = new Map();
|
|
38
|
+
for (const { body } of tracked)
|
|
39
|
+
body.anchorLabels?.forEach((label, index) => { if (!anchors.has(label))
|
|
40
|
+
anchors.set(label, body.anchorTimesUtcMs[index]); });
|
|
41
|
+
return panelsOf(this.#panels, this.#playback, { events: this.events, anchors, objectIds, window });
|
|
42
|
+
}
|
|
43
|
+
/** The events sorted by time, each with its own provenance, else the batch's. */
|
|
44
|
+
eventReads() {
|
|
45
|
+
return frozenList(this.events.map(({ id, label, timeUtcMs, type, object, withinMs }) => {
|
|
46
|
+
const provenance = this.#eventOwnProvenance.get(id) ?? this.#eventProvenance;
|
|
47
|
+
return { id, label, timeUtcMs, ...(type === undefined ? {} : { type }), ...(object === undefined ? {} : { object }), ...(withinMs === undefined ? {} : { withinSeconds: withinMs / 1000 }), ...(provenance === undefined ? {} : { provenance }) };
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
/** The story panels as the public list states them (resolved as `panels` resolves them); empty when none were added. */
|
|
51
|
+
panelReads(window, tracked, objectIds) {
|
|
52
|
+
const set = this.panels(window, tracked, objectIds);
|
|
53
|
+
return frozenList((set?.panels ?? []).map(({ id, timeUtcMs, title, body, details, provenance, objectId }) => ({
|
|
54
|
+
id, timeUtcMs, title, provenance,
|
|
55
|
+
body: Object.freeze([...body]), details: Object.freeze([...details]),
|
|
56
|
+
...(objectId === undefined ? {} : { object: objectId }),
|
|
57
|
+
})));
|
|
58
|
+
}
|
|
59
|
+
/** The event provenance entries of the experience: the batch's, and each event's own. */
|
|
60
|
+
provenanceEntries() {
|
|
61
|
+
return {
|
|
62
|
+
...(this.#eventProvenance === undefined ? {} : { eventProvenance: this.#eventProvenance }),
|
|
63
|
+
...(this.#eventOwnProvenance.size === 0 ? {} : { eventProvenanceById: Object.fromEntries(this.#eventOwnProvenance) }),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TimelineEvent } from "../core/events.js";
|
|
2
|
+
import type { TimeBounds } from "../core/trajectory.js";
|
|
3
|
+
import type { ExperienceDefinition } from "../app/experienceDefinition.js";
|
|
4
|
+
import { type TimeInput } from "./time.js";
|
|
5
|
+
import type { SceneTimelineRead } from "./sceneReads.js";
|
|
6
|
+
import { type TimelineInput, type TimelineSetting } from "./story.js";
|
|
7
|
+
/** What a `Scene` has planned for its timeline: the opening time, the timeline setting, and from them the span, clock, rates and pacing. */
|
|
8
|
+
export declare class TimelinePlan {
|
|
9
|
+
#private;
|
|
10
|
+
/** The timeline the caller set, if any. */
|
|
11
|
+
setting: TimelineSetting | undefined;
|
|
12
|
+
setTime(time: TimeInput): void;
|
|
13
|
+
setTimeline(timeline: TimelineInput): void;
|
|
14
|
+
/** The speeds offered: the caller's, else 1 minute, 1 hour and 1 day per second. */
|
|
15
|
+
rates(): readonly number[];
|
|
16
|
+
/** The timeline span and the moment the clock opens at; a moment outside a span the caller set is a `bad-timeline`. */
|
|
17
|
+
span(tracked: readonly TimeBounds[]): {
|
|
18
|
+
readonly window: TimeBounds;
|
|
19
|
+
readonly startUtcMs: number;
|
|
20
|
+
};
|
|
21
|
+
/** The timeline as the public read states it, over the spans of the paths and activities. */
|
|
22
|
+
read(spans: readonly TimeBounds[]): SceneTimelineRead;
|
|
23
|
+
/** The clock's opening: 60 times real time unless set; with no timeline and no rate, frozen. */
|
|
24
|
+
clock(startUtcMs: number): ExperienceDefinition["clock"];
|
|
25
|
+
/** The pacing the timeline asked for, laid over the scene's events; a rule naming an event type with no events throws `bad-timeline`. */
|
|
26
|
+
pacing(events: readonly TimelineEvent[]): Pick<ExperienceDefinition, "pacing" | "eventZones">;
|
|
27
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { SceneError } from "./errors.js";
|
|
2
|
+
import { toUtcMs } from "./time.js";
|
|
3
|
+
import { eventZonesOf } from "../core/pacing.js";
|
|
4
|
+
import { pacingFor, timelineOf } from "./story.js";
|
|
5
|
+
const DAY_MS = 86_400_000;
|
|
6
|
+
/** What a `Scene` has planned for its timeline: the opening time, the timeline setting, and from them the span, clock, rates and pacing. */
|
|
7
|
+
export class TimelinePlan {
|
|
8
|
+
#timeUtcMs;
|
|
9
|
+
/** The timeline the caller set, if any. */
|
|
10
|
+
setting;
|
|
11
|
+
setTime(time) {
|
|
12
|
+
this.#timeUtcMs = toUtcMs(time, "setTime");
|
|
13
|
+
}
|
|
14
|
+
setTimeline(timeline) {
|
|
15
|
+
this.setting = timelineOf(timeline);
|
|
16
|
+
}
|
|
17
|
+
/** The speeds offered: the caller's, else 1 minute, 1 hour and 1 day per second. */
|
|
18
|
+
rates() {
|
|
19
|
+
return this.setting?.rates ?? [60, 3_600, DAY_MS / 1000];
|
|
20
|
+
}
|
|
21
|
+
/** The timeline span and the moment the clock opens at; a moment outside a span the caller set is a `bad-timeline`. */
|
|
22
|
+
span(tracked) {
|
|
23
|
+
const timeline = this.setting;
|
|
24
|
+
const setTime = (timeline?.none === true ? timeline.atUtcMs : undefined) ?? this.#timeUtcMs;
|
|
25
|
+
// With nothing setting a span or a moment, the month window is centred on now and the clock opens at now (not at the window's start).
|
|
26
|
+
const now = setTime === undefined && timeline?.window === undefined && tracked.length === 0 ? Date.now() : undefined;
|
|
27
|
+
const window = timeline?.window ?? windowOf(tracked, setTime ?? now);
|
|
28
|
+
if (timeline?.window !== undefined && setTime !== undefined && (setTime < window.startUtcMs || setTime > window.endUtcMs)) {
|
|
29
|
+
throw new SceneError("bad-timeline", `setTime ${new Date(setTime).toISOString()} is outside the timeline (${new Date(window.startUtcMs).toISOString()} to ${new Date(window.endUtcMs).toISOString()})`);
|
|
30
|
+
}
|
|
31
|
+
return { window, startUtcMs: setTime ?? now ?? window.startUtcMs };
|
|
32
|
+
}
|
|
33
|
+
/** The timeline as the public read states it, over the spans of the paths and activities. */
|
|
34
|
+
read(spans) {
|
|
35
|
+
const { window, startUtcMs } = this.span(spans);
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
windowStartUtcMs: window.startUtcMs,
|
|
38
|
+
windowEndUtcMs: window.endUtcMs,
|
|
39
|
+
openUtcMs: startUtcMs,
|
|
40
|
+
rates: Object.freeze([...this.rates()]),
|
|
41
|
+
rate: this.clock(startUtcMs).rate,
|
|
42
|
+
loop: this.setting?.none !== true && this.setting?.loop === true,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** The clock's opening: 60 times real time unless set; with no timeline and no rate, frozen. */
|
|
46
|
+
clock(startUtcMs) {
|
|
47
|
+
const timeline = this.setting;
|
|
48
|
+
return { startUtcMs, rate: timeline?.rate ?? 60, ...(timeline?.none === true && timeline.rate === undefined ? { playing: false } : {}) };
|
|
49
|
+
}
|
|
50
|
+
/** The pacing the timeline asked for, laid over the scene's events; a rule naming an event type with no events throws `bad-timeline`. */
|
|
51
|
+
pacing(events) {
|
|
52
|
+
const timeline = this.setting;
|
|
53
|
+
const pacing = timeline === undefined ? undefined : pacingFor(timeline, events, timeline.rate ?? 60);
|
|
54
|
+
const eventZones = eventZonesOf(events, pacing?.zones ?? []);
|
|
55
|
+
return { ...(pacing === undefined ? {} : { pacing }), ...(eventZones.length === 0 ? {} : { eventZones }) };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** The timeline span: the union of the trajectories' and activities' spans, else a month about the chosen time (or about now). */
|
|
59
|
+
function windowOf(tracked, timeUtcMs) {
|
|
60
|
+
if (tracked.length > 0) {
|
|
61
|
+
const start = Math.min(...tracked.map((bounds) => bounds.startUtcMs));
|
|
62
|
+
const end = Math.max(...tracked.map((bounds) => bounds.endUtcMs));
|
|
63
|
+
if (timeUtcMs === undefined || (timeUtcMs >= start && timeUtcMs <= end))
|
|
64
|
+
return { startUtcMs: start, endUtcMs: end };
|
|
65
|
+
}
|
|
66
|
+
const centre = timeUtcMs ?? Date.now();
|
|
67
|
+
return { startUtcMs: centre - 15 * DAY_MS, endUtcMs: centre + 15 * DAY_MS };
|
|
68
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DisplaySwitchSettings } from "../app/displaySwitches.js";
|
|
2
|
+
import type { ViewSettings } from "../app/views.js";
|
|
3
|
+
import type { StoryPanelSet } from "../core/storyPanels.js";
|
|
4
|
+
import { type SwitchesInput } from "./switches.js";
|
|
5
|
+
import type { SceneViewsRead } from "./sceneReads.js";
|
|
6
|
+
import { type ViewInput, type ViewScope, type ViewsOptions } from "./views.js";
|
|
7
|
+
/** What a `Scene` has planned for its presentation: the display switches and the named views. */
|
|
8
|
+
export declare class ViewPlan {
|
|
9
|
+
#private;
|
|
10
|
+
setSwitches(switches: SwitchesInput): void;
|
|
11
|
+
setViews(views: readonly ViewInput[], options: ViewsOptions): void;
|
|
12
|
+
/** The views as the public read states them, each with the objects, events and panels it shows (the lists the viewer uses, resolved against the finished scene); absent when none were named. `scope` is asked for only when views were named. */
|
|
13
|
+
read(scope: () => ViewScope): SceneViewsRead | undefined;
|
|
14
|
+
/** The `displaySwitches` entry of the definition (absent when none were placed). */
|
|
15
|
+
switchesEntry(): {
|
|
16
|
+
displaySwitches?: DisplaySwitchSettings;
|
|
17
|
+
};
|
|
18
|
+
/** The `views` entry of the definition: the views resolved against the finished scene once (absent when none was named). */
|
|
19
|
+
viewsEntry(scene: {
|
|
20
|
+
readonly objects: readonly string[];
|
|
21
|
+
readonly events: readonly string[];
|
|
22
|
+
}, storyPanels: StoryPanelSet | undefined): {
|
|
23
|
+
views?: ViewSettings;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { switchesOf } from "./switches.js";
|
|
2
|
+
import { resolveViews, viewsOf } from "./views.js";
|
|
3
|
+
import { frozenList } from "./sceneReads.js";
|
|
4
|
+
/** What a `Scene` has planned for its presentation: the display switches and the named views. */
|
|
5
|
+
export class ViewPlan {
|
|
6
|
+
#switches;
|
|
7
|
+
#views;
|
|
8
|
+
setSwitches(switches) {
|
|
9
|
+
this.#switches = switchesOf(switches, this.#switches);
|
|
10
|
+
}
|
|
11
|
+
setViews(views, options) {
|
|
12
|
+
this.#views = viewsOf(views, options);
|
|
13
|
+
}
|
|
14
|
+
/** The views as the public read states them, each with the objects, events and panels it shows (the lists the viewer uses, resolved against the finished scene); absent when none were named. `scope` is asked for only when views were named. */
|
|
15
|
+
read(scope) {
|
|
16
|
+
const plan = this.#views;
|
|
17
|
+
if (plan === undefined)
|
|
18
|
+
return undefined;
|
|
19
|
+
const { place, start, views } = resolveViews(plan, scope());
|
|
20
|
+
return Object.freeze({
|
|
21
|
+
startId: start, place,
|
|
22
|
+
items: frozenList(views.map(({ id, label, objects, events, panels }) => ({ id, label, objects: Object.freeze([...objects]), events: Object.freeze([...events]), panels: Object.freeze([...panels]) }))),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/** The `displaySwitches` entry of the definition (absent when none were placed). */
|
|
26
|
+
switchesEntry() {
|
|
27
|
+
return this.#switches === undefined ? {} : { displaySwitches: this.#switches };
|
|
28
|
+
}
|
|
29
|
+
/** The `views` entry of the definition: the views resolved against the finished scene once (absent when none was named). */
|
|
30
|
+
viewsEntry(scene, storyPanels) {
|
|
31
|
+
if (this.#views === undefined)
|
|
32
|
+
return {};
|
|
33
|
+
return { views: resolveViews(this.#views, { objects: scene.objects, events: scene.events, panels: storyPanels?.panels.map(({ id }) => id) ?? [] }) };
|
|
34
|
+
}
|
|
35
|
+
}
|