astraeus 0.9.1 → 0.9.2
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 +22 -0
- package/README.md +20 -13
- package/package.json +1 -1
- package/src/api/assembleScene.js +4 -4
- package/src/api/errors.d.ts +1 -1
- package/src/api/index.d.ts +2 -2
- package/src/api/look.d.ts +14 -0
- package/src/api/lookInput.d.ts +1 -1
- package/src/api/lookInput.js +6 -2
- package/src/api/planCamera.d.ts +19 -2
- package/src/api/planCamera.js +45 -6
- package/src/api/planPaths.js +2 -2
- package/src/api/planStory.d.ts +3 -1
- package/src/api/planStory.js +5 -0
- package/src/api/planTimeline.d.ts +1 -1
- package/src/api/planTimeline.js +10 -1
- package/src/api/planViews.d.ts +3 -1
- package/src/api/planViews.js +4 -0
- package/src/api/scene.d.ts +11 -5
- package/src/api/scene.js +16 -2
- package/src/api/sceneReads.d.ts +31 -1
- package/src/api/story.d.ts +9 -2
- package/src/api/story.js +10 -3
- package/src/api/switches.d.ts +1 -0
- package/src/api/switches.js +3 -1
- package/src/api/time.d.ts +1 -1
- package/src/api/time.js +4 -1
- package/src/app/App.js +26 -6
- package/src/app/App.node.js +26 -6
- package/src/app/AstraeusScene.d.ts +8 -1
- package/src/app/CameraController.d.ts +2 -0
- package/src/app/CameraController.js +11 -1
- package/src/app/SkyFiguresView.d.ts +2 -2
- package/src/app/SkyFiguresView.js +25 -14
- package/src/app/displaySwitches.d.ts +2 -0
- package/src/app/displaySwitches.js +1 -1
- package/src/app/liveLook.d.ts +4 -1
- package/src/app/liveLook.js +29 -1
- package/src/app/look.d.ts +5 -0
- package/src/app/look.js +8 -2
- package/src/app/sceneCamera.js +14 -2
- package/src/app/sceneContentsHooks.js +1 -1
- package/src/app/sceneFrame.js +2 -2
- package/src/app/scenePointer.d.ts +5 -1
- package/src/app/scenePointer.js +8 -3
- package/src/app/timeLook.d.ts +7 -0
- package/src/app/timeLook.js +8 -0
- package/src/core/clock.js +2 -1
- package/src/core/lookValues.d.ts +13 -0
- package/src/core/lookValues.js +39 -0
- package/src/core/state.d.ts +2 -0
- package/src/core/state.js +5 -1
- package/src/core/storyPanels.d.ts +8 -4
- package/src/core/storyPanels.js +17 -5
- package/src/shell/AstraeusShell.d.ts +5 -1
- package/src/shell/AstraeusShell.js +15 -8
- package/src/shell/AstraeusShell.node.js +15 -8
- package/src/shell/ObjectControls.js +1 -1
- package/src/shell/TimelineBar.d.ts +6 -2
- package/src/shell/TimelineBar.js +17 -12
- package/src/shell/TimelineBar.node.js +17 -12
- package/src/shell/experience.d.ts +2 -0
- package/src/shell/infoModel.d.ts +2 -1
- package/src/shell/infoModel.js +10 -10
- package/src/shell/storyPanels.d.ts +19 -1
- package/src/shell/storyPanels.js +34 -2
- package/src/shell/timelineModel.d.ts +11 -0
- package/src/shell/timelineModel.js +28 -0
- package/src/shell/useStoryPanels.d.ts +4 -0
- package/src/shell/useStoryPanels.js +27 -6
|
@@ -14,6 +14,7 @@ export function createOrbitCameraState(distance, focus) {
|
|
|
14
14
|
fixedPoint: null,
|
|
15
15
|
transition: [0, 0, 0],
|
|
16
16
|
lookOut: null,
|
|
17
|
+
targetFovDeg: null,
|
|
17
18
|
cameraAbsolute: [0, 0, 0],
|
|
18
19
|
targetAbsolute: [0, 0, 0],
|
|
19
20
|
};
|
|
@@ -110,8 +111,10 @@ export function attachOrbitGestures(element, state, getLimits, onTap) {
|
|
|
110
111
|
}
|
|
111
112
|
/** A wheel or pinch step: the distance in orbit, the field of view while looking out. */
|
|
112
113
|
function zoomBy(state, factor, limits) {
|
|
113
|
-
if (state.lookOut !== null)
|
|
114
|
+
if (state.lookOut !== null) {
|
|
115
|
+
state.targetFovDeg = null;
|
|
114
116
|
zoomLookOut(state.lookOut, factor);
|
|
117
|
+
}
|
|
115
118
|
else
|
|
116
119
|
state.distance = clampDistance(state.distance * factor, limits);
|
|
117
120
|
cancelCameraTransition(state);
|
|
@@ -151,6 +154,13 @@ export function resolveCamera(state, focusAbsolute, origin, deltaSeconds, rebase
|
|
|
151
154
|
state.distance = state.targetDistance;
|
|
152
155
|
state.azimuth += shortestAngleDelta(state.azimuth, state.targetAzimuth) * blend;
|
|
153
156
|
state.elevation += (state.targetElevation - state.elevation) * blend;
|
|
157
|
+
if (state.lookOut !== null && state.targetFovDeg !== null) {
|
|
158
|
+
state.lookOut.fovDeg += (state.targetFovDeg - state.lookOut.fovDeg) * blend;
|
|
159
|
+
if (Math.abs(state.targetFovDeg - state.lookOut.fovDeg) < 1e-6) {
|
|
160
|
+
state.lookOut.fovDeg = state.targetFovDeg;
|
|
161
|
+
state.targetFovDeg = null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
154
164
|
for (let i = 0; i < 3; i += 1) {
|
|
155
165
|
state.transition[i] *= decay;
|
|
156
166
|
if (Math.abs(state.transition[i]) < 1e-9)
|
|
@@ -36,8 +36,8 @@ export declare class SkyFiguresView {
|
|
|
36
36
|
}): readonly SkyPickFigure[];
|
|
37
37
|
/** Begins tracing the figure `request.id` (a trace already on it restarts). The trace is a separate set of lines drawn over the figure (the whole drawing of a figure shown only when traced); the figure itself is untouched. An id the view does not hold does nothing. */
|
|
38
38
|
startTrace(request: SkyTraceRequest): void;
|
|
39
|
-
/** Removes the trace of `request.id` over `request.seconds` (at once for 0 or reduced motion), keeping what it had drawn; a figure with no trace, or an id the view does not hold, is left alone. */
|
|
40
|
-
clearTrace(request: SkyClearRequest):
|
|
39
|
+
/** Removes the trace of `request.id` over `request.seconds` (at once for 0 or reduced motion), keeping what it had drawn; a figure with no trace, or an id the view does not hold, is left alone. Returns true when it removed the trace at once, so the caller wakes the draw rule (a timed clear wakes through `advanceTraces`). */
|
|
40
|
+
clearTrace(request: SkyClearRequest): boolean;
|
|
41
41
|
/**
|
|
42
42
|
* Moves every trace on by `deltaSeconds` of real time (the scene clock never enters): draws the segments reached so far, the last one part-grown from its first end, in the traced colour (the faded colour while fading),
|
|
43
43
|
* shows each with its figure's switch, and removes finished ones. Returns true while anything changed, so the caller wakes the draw rule.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BufferAttribute, BufferGeometry, Color, Group, LineBasicMaterial, LineSegments, Vector3 } from "three";
|
|
2
2
|
import { celestialEquatorSegments, eclipticSegments } from "./skyFigures.js";
|
|
3
|
+
import { splitColourAlpha } from "../core/lookValues.js";
|
|
3
4
|
import { stepFadeIn, stepHide, stepTrace } from "../core/skyTrace.js";
|
|
4
5
|
import { eqjToRenderVector } from "./renderCoordinates.js";
|
|
5
6
|
import { TRACK_LAYER } from "./TrackedBodyView.js";
|
|
@@ -10,6 +11,12 @@ const TRACE_OPACITY = 0.85;
|
|
|
10
11
|
const TRACE_LABEL_IN_SHARE = 0.5;
|
|
11
12
|
/** The opacity of an always-shown line once it has faded in. */
|
|
12
13
|
const LINE_OPACITY = 0.85;
|
|
14
|
+
/** Paints a material in a CSS colour's opaque part and returns the colour's alpha for the caller to multiply into the opacity. */
|
|
15
|
+
function paint(material, colour) {
|
|
16
|
+
const { colour: opaque, alpha } = splitColourAlpha(colour);
|
|
17
|
+
material.color.set(opaque);
|
|
18
|
+
return alpha;
|
|
19
|
+
}
|
|
13
20
|
function lines(segments, color, key) {
|
|
14
21
|
const positions = new Float32Array(segments.length * 6);
|
|
15
22
|
segments.forEach(([from, to], i) => positions.set([...eqjToRenderVector(from), ...eqjToRenderVector(to)], i * 6));
|
|
@@ -17,8 +24,9 @@ function lines(segments, color, key) {
|
|
|
17
24
|
geometry.setAttribute("position", new BufferAttribute(positions, 3));
|
|
18
25
|
// Depth is tested (a body in front of the sky hides the line) but never written. The lines are on the last render pass (TRACK_LAYER), after every body's pass, so the Sun's halo
|
|
19
26
|
// (drawn earlier, without depth) never covers them (owner decision 3, O-065).
|
|
20
|
-
const material = new LineBasicMaterial({
|
|
27
|
+
const material = new LineBasicMaterial({ transparent: true, opacity: LINE_OPACITY, depthTest: true, depthWrite: false });
|
|
21
28
|
const object = new LineSegments(geometry, material);
|
|
29
|
+
object.userData.alpha = paint(material, color);
|
|
22
30
|
object.name = key;
|
|
23
31
|
object.layers.set(TRACK_LAYER);
|
|
24
32
|
object.frustumCulled = false;
|
|
@@ -47,7 +55,7 @@ export class SkyFiguresView {
|
|
|
47
55
|
if (segments.length === 0)
|
|
48
56
|
return;
|
|
49
57
|
const object = lines(segments, own ?? "#ffffff", key);
|
|
50
|
-
this.#drawn.push({ object, shows, colour, own: own !== undefined });
|
|
58
|
+
this.#drawn.push({ object, shows, colour, own: own !== undefined, alpha: object.userData.alpha });
|
|
51
59
|
this.group.add(object);
|
|
52
60
|
};
|
|
53
61
|
// Figures that take the look's colour share one set of lines per kind; a figure with its own colour is drawn on its own so a live look change leaves it alone.
|
|
@@ -71,7 +79,7 @@ export class SkyFiguresView {
|
|
|
71
79
|
for (const [shows, colour, make, key] of [["ecliptic", "ecliptic", eclipticSegments, "sky-ecliptic"], ["celestialEquator", "equator", celestialEquatorSegments, "sky-celestial-equator"]]) {
|
|
72
80
|
if (on[shows] && !this.#drawn.some((entry) => entry.shows === shows)) {
|
|
73
81
|
const object = lines(make(), "#ffffff", key);
|
|
74
|
-
this.#drawn.push({ object, shows, colour, own: false });
|
|
82
|
+
this.#drawn.push({ object, shows, colour, own: false, alpha: 1 });
|
|
75
83
|
this.group.add(object);
|
|
76
84
|
this.#applied = null;
|
|
77
85
|
}
|
|
@@ -79,7 +87,7 @@ export class SkyFiguresView {
|
|
|
79
87
|
if (this.#applied === null || Object.keys(colours).some((name) => colours[name] !== this.#applied[name])) {
|
|
80
88
|
for (const entry of this.#drawn)
|
|
81
89
|
if (!entry.own)
|
|
82
|
-
entry.object.material
|
|
90
|
+
entry.alpha = paint(entry.object.material, colours[entry.colour]);
|
|
83
91
|
this.#applied = { ...colours };
|
|
84
92
|
}
|
|
85
93
|
for (const entry of this.#drawn)
|
|
@@ -113,8 +121,7 @@ export class SkyFiguresView {
|
|
|
113
121
|
this.#selected = { id: layer.id, object };
|
|
114
122
|
}
|
|
115
123
|
const material = this.#selected.object.material;
|
|
116
|
-
material.
|
|
117
|
-
material.opacity = LINE_OPACITY * (layer.whenTraced === true ? 1 : this.#shownShare[layer.kind === "figure" ? "figures" : "boundaries"]);
|
|
124
|
+
material.opacity = paint(material, colours.selected) * LINE_OPACITY * (layer.whenTraced === true ? 1 : this.#shownShare[layer.kind === "figure" ? "figures" : "boundaries"]);
|
|
118
125
|
// While the figure's trace is still drawing, the trace itself grows in the selected colour (`advanceTraces`) and the whole-figure emphasis waits, so it never covers the growing line (owner, T-306).
|
|
119
126
|
this.#selected.object.visible = this.#tappable(layer, on) && !this.#drawing(layer.id);
|
|
120
127
|
}
|
|
@@ -147,15 +154,17 @@ export class SkyFiguresView {
|
|
|
147
154
|
this.group.add(object);
|
|
148
155
|
this.#traces.set(request.id, { object, full, kind: layer.kind, run: { seconds: request.seconds, after: request.after, reduced: request.reduced, elapsed: 0 }, drawn: 0, fade: 0 });
|
|
149
156
|
}
|
|
150
|
-
/** Removes the trace of `request.id` over `request.seconds` (at once for 0 or reduced motion), keeping what it had drawn; a figure with no trace, or an id the view does not hold, is left alone. */
|
|
157
|
+
/** Removes the trace of `request.id` over `request.seconds` (at once for 0 or reduced motion), keeping what it had drawn; a figure with no trace, or an id the view does not hold, is left alone. Returns true when it removed the trace at once, so the caller wakes the draw rule (a timed clear wakes through `advanceTraces`). */
|
|
151
158
|
clearTrace(request) {
|
|
152
159
|
const trace = this.#traces.get(request.id);
|
|
153
160
|
if (trace === undefined)
|
|
154
|
-
return;
|
|
155
|
-
if (request.reduced || request.seconds <= 0)
|
|
161
|
+
return false;
|
|
162
|
+
if (request.reduced || request.seconds <= 0) {
|
|
156
163
|
this.#removeTrace(request.id);
|
|
157
|
-
|
|
158
|
-
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
trace.hide = { seconds: request.seconds, from: trace.fade, elapsed: 0 };
|
|
167
|
+
return false;
|
|
159
168
|
}
|
|
160
169
|
/**
|
|
161
170
|
* Moves every trace on by `deltaSeconds` of real time (the scene clock never enters): draws the segments reached so far, the last one part-grown from its first end, in the traced colour (the faded colour while fading),
|
|
@@ -185,8 +194,10 @@ export class SkyFiguresView {
|
|
|
185
194
|
positions.needsUpdate = true;
|
|
186
195
|
trace.object.geometry.setDrawRange(0, (last + 1) * 2);
|
|
187
196
|
const material = trace.object.material;
|
|
188
|
-
|
|
189
|
-
|
|
197
|
+
const base = splitColourAlpha(id === selectedId && frame.drawn < 1 && trace.hide === undefined ? colours.selected : colours.traced);
|
|
198
|
+
const faded = splitColourAlpha(colours.faded);
|
|
199
|
+
material.color.set(base.colour).lerp(FADED.set(faded.colour), frame.fade);
|
|
200
|
+
material.opacity = TRACE_OPACITY * (1 - frame.fade) * (base.alpha + (faded.alpha - base.alpha) * frame.fade);
|
|
190
201
|
trace.object.visible = on[trace.kind === "figure" ? "figures" : "boundaries"];
|
|
191
202
|
}
|
|
192
203
|
return moving;
|
|
@@ -205,7 +216,7 @@ export class SkyFiguresView {
|
|
|
205
216
|
moving = true;
|
|
206
217
|
}
|
|
207
218
|
for (const entry of this.#drawn)
|
|
208
|
-
entry.object.material.opacity = LINE_OPACITY * this.#shownShare[entry.shows];
|
|
219
|
+
entry.object.material.opacity = LINE_OPACITY * entry.alpha * this.#shownShare[entry.shows];
|
|
209
220
|
return moving;
|
|
210
221
|
}
|
|
211
222
|
/** How much of a label shows, 0 to 1: for a figure that is always shown, how far its kind has faded in; for one shown only when traced, 0 until a trace starts, then rising with the trace to 1 at half drawn (fading to 0 with a `fade` trace; 0 again once the trace is removed). */
|
|
@@ -14,6 +14,8 @@ export type DisplaySwitchPlace = (typeof DISPLAY_SWITCH_PLACES)[number];
|
|
|
14
14
|
export interface DisplaySwitchSetting {
|
|
15
15
|
readonly place: DisplaySwitchPlace;
|
|
16
16
|
readonly on?: boolean;
|
|
17
|
+
/** The switch's own name in the top bar and the switch panel; absent: the built-in one. */
|
|
18
|
+
readonly label?: string;
|
|
17
19
|
}
|
|
18
20
|
export type DisplaySwitchSettings = Readonly<Partial<Record<DisplaySwitchId, DisplaySwitchSetting>>>;
|
|
19
21
|
export declare const DISPLAY_SWITCH_LABELS: Readonly<Record<DisplaySwitchId, string>>;
|
|
@@ -57,7 +57,7 @@ export function displaySwitchItems(bindings) {
|
|
|
57
57
|
const place = settings[id]?.place;
|
|
58
58
|
if ((place !== "top-bar" && place !== "panel") || !state[id].applies)
|
|
59
59
|
return [];
|
|
60
|
-
return [{ id, label: DISPLAY_SWITCH_LABELS[id], place, on: state[id].on, onToggle: state[id].toggle }];
|
|
60
|
+
return [{ id, label: settings[id]?.label ?? DISPLAY_SWITCH_LABELS[id], place, on: state[id].on, onToggle: state[id].toggle }];
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
/** The settings with every placed switch counted as shown: a host reads and sets a switch placed only in the Developer drawer too. */
|
package/src/app/liveLook.d.ts
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* (the one place the Developer drawer, the host's `setLook` and the page address all end up), every one filled in; `applyLook` replaces the whole look. Presentation only (ARCH-02).
|
|
4
4
|
*/
|
|
5
5
|
import type { LookInput, LookRead } from "../api/look.js";
|
|
6
|
+
import type { BodyAsset } from "../assets/catalogue.js";
|
|
6
7
|
import type { SceneControls } from "./AstraeusScene.js";
|
|
7
8
|
import { type GlowLook } from "./bodyDraw.js";
|
|
8
9
|
import type { ExperienceDefinition } from "./experienceDefinition.js";
|
|
9
10
|
import type { DisplaySwitchItem } from "../shell/DisplaySwitches.js";
|
|
10
11
|
/** The sky settings in force: the experience's own, then the look (the scene's `setLook`, with the address over it). The Milky Way switch's start sits between the two. */
|
|
11
|
-
export declare function skySettingsOf(definition: ExperienceDefinition, look: LookInput): {
|
|
12
|
+
export declare function skySettingsOf(definition: Pick<ExperienceDefinition, "sky" | "displaySwitches">, look: LookInput): {
|
|
12
13
|
milkyWay: boolean;
|
|
13
14
|
starBrightness: number;
|
|
14
15
|
milkyWayBrightness: number;
|
|
@@ -19,6 +20,8 @@ export declare function skySettingsOf(definition: ExperienceDefinition, look: Lo
|
|
|
19
20
|
export declare function desktopPicturesOf(definition: Pick<ExperienceDefinition, "desktopTextures">, look: LookInput): boolean;
|
|
20
21
|
/** The looks the scene's live controls hold now, every one filled in. */
|
|
21
22
|
export declare function lookReadOf(controls: SceneControls): LookRead;
|
|
23
|
+
/** The looks a fresh viewer opens with, every one filled in, from the resolved look alone (no browser, no controls): the same resolvers `initialSceneControls` uses. `bodies` are the scene's mounted bodies, whose first halo (the Sun's) sets `sunGlow`. */
|
|
24
|
+
export declare function lookReadFrom(look: LookInput, definition: Pick<ExperienceDefinition, "sky" | "displaySwitches">, bodies: readonly BodyAsset[]): LookRead;
|
|
22
25
|
/**
|
|
23
26
|
* Replaces the whole look in the live controls with `input` (a look not named takes its default) and returns the looks now in force. The one resolver (`resolveLook`) takes it with no page address:
|
|
24
27
|
* a host's live set wins over the address, which only starts the viewer.
|
package/src/app/liveLook.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { DEFAULT_PHONE_LAYOUT } from "../shell/phoneLayout.js";
|
|
1
2
|
import { bootFadeSeconds } from "../shell/bootLoader.js";
|
|
2
|
-
import { glowLookOf, markerSettingsOf } from "./bodyDraw.js";
|
|
3
|
+
import { baseGlowOf, glowLookOf, markerSettingsOf } from "./bodyDraw.js";
|
|
3
4
|
import { featureMinBodyPxOf } from "./FeatureMarkers.js";
|
|
4
5
|
import { resolveLook } from "./look.js";
|
|
5
6
|
import { resolveSkySettings } from "./skyModel.js";
|
|
6
7
|
import { labelStyleOf } from "./labelStyle.js";
|
|
8
|
+
import { timeLookOf } from "./timeLook.js";
|
|
7
9
|
import { skyColoursOf, skyFadeInSecondsOf } from "./skyFigures.js";
|
|
8
10
|
/** The sky settings in force: the experience's own, then the look (the scene's `setLook`, with the address over it). The Milky Way switch's start sits between the two. */
|
|
9
11
|
export function skySettingsOf(definition, look) {
|
|
@@ -36,6 +38,30 @@ export function lookReadOf(controls) {
|
|
|
36
38
|
desktopPictures: controls.desktopPictures,
|
|
37
39
|
skyLines: { ...controls.skyColours },
|
|
38
40
|
labels: { ...controls.labelStyle },
|
|
41
|
+
time: { ...controls.timeLook },
|
|
42
|
+
sheetMaxPercent: controls.sheetMaxPercent,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** The looks a fresh viewer opens with, every one filled in, from the resolved look alone (no browser, no controls): the same resolvers `initialSceneControls` uses. `bodies` are the scene's mounted bodies, whose first halo (the Sun's) sets `sunGlow`. */
|
|
46
|
+
export function lookReadFrom(look, definition, bodies) {
|
|
47
|
+
const glowBase = baseGlowOf(bodies);
|
|
48
|
+
const sky = skySettingsOf(definition, look);
|
|
49
|
+
const glow = glowBase === null ? undefined : glowLookOf(look, glowBase);
|
|
50
|
+
return {
|
|
51
|
+
starBrightness: sky.starBrightness,
|
|
52
|
+
milkyWay: sky.milkyWay,
|
|
53
|
+
milkyWayBrightness: sky.milkyWayBrightness,
|
|
54
|
+
skyVisible: sky.visible,
|
|
55
|
+
...(glow === undefined ? {} : { sunGlow: { sizePx: glow.sizePx, brightness: glow.brightness, scale: glow.scale } }),
|
|
56
|
+
markerSwapRadiusPx: markerSettingsOf(look).minSpherePx,
|
|
57
|
+
featureMinBodyPx: featureMinBodyPxOf(look),
|
|
58
|
+
loadFadeSeconds: bootFadeSeconds(look),
|
|
59
|
+
skyFadeInSeconds: skyFadeInSecondsOf(look),
|
|
60
|
+
desktopPictures: desktopPicturesOf({ desktopTextures: undefined }, look),
|
|
61
|
+
skyLines: { ...skyColoursOf(look) },
|
|
62
|
+
labels: { ...labelStyleOf(look) },
|
|
63
|
+
time: { ...timeLookOf(look) },
|
|
64
|
+
sheetMaxPercent: look.sheetMaxPercent ?? DEFAULT_PHONE_LAYOUT.sheetMaxPercent,
|
|
39
65
|
};
|
|
40
66
|
}
|
|
41
67
|
/**
|
|
@@ -57,6 +83,8 @@ export function applyLook(controls, definition, glowBase, input) {
|
|
|
57
83
|
controls.skyColours = skyColoursOf(look);
|
|
58
84
|
controls.skyFadeInSeconds = skyFadeInSecondsOf(look);
|
|
59
85
|
controls.labelStyle = labelStyleOf(look);
|
|
86
|
+
controls.timeLook = timeLookOf(look);
|
|
87
|
+
controls.sheetMaxPercent = look.sheetMaxPercent ?? DEFAULT_PHONE_LAYOUT.sheetMaxPercent;
|
|
60
88
|
return lookReadOf(controls);
|
|
61
89
|
}
|
|
62
90
|
/** The host's view of the presentation: `items` (read fresh each time) are the display switches the scene placed (those with something to act on), so a switch is read and set exactly as its visible button does. */
|
package/src/app/look.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ export type LookKind = {
|
|
|
20
20
|
readonly kind: "colour";
|
|
21
21
|
} | {
|
|
22
22
|
readonly kind: "font";
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "zone";
|
|
25
|
+
} | {
|
|
26
|
+
readonly kind: "choice";
|
|
27
|
+
readonly values: readonly string[];
|
|
23
28
|
};
|
|
24
29
|
/** One look: where it sits in `LookInput` (`["sunGlow", "sizePx"]` for a nested one), its address parameter (null: the look has none, it is set only with `setLook`) and how it is written. */
|
|
25
30
|
export interface LookField {
|
package/src/app/look.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PHONE_LAYOUT_LIMITS } from "../shell/phoneLayout.js";
|
|
2
|
+
import { LABEL_SIZE_LIMITS, TIME_PRECISIONS } from "../core/lookValues.js";
|
|
2
3
|
const range = (path, param, min, max) => ({ path, param, spec: { kind: "range", min, max } });
|
|
3
4
|
const colour = (name) => ({ path: ["skyLines", name], param: null, spec: { kind: "colour" } });
|
|
4
5
|
/** Every look. The one table; the order is the order of `LookInput`. */
|
|
@@ -19,6 +20,11 @@ export const LOOK_FIELDS = [
|
|
|
19
20
|
colour("figure"), colour("label"), colour("boundary"), colour("ecliptic"), colour("equator"), colour("traced"), colour("faded"), colour("selected"),
|
|
20
21
|
{ path: ["labels", "fontFamily"], param: null, spec: { kind: "font" } },
|
|
21
22
|
range(["labels", "sizePx"], null, LABEL_SIZE_LIMITS.min, LABEL_SIZE_LIMITS.max),
|
|
23
|
+
// The zone and precision of the viewer's times (O-074 T-316) have no address parameter either: the address `t` stays UTC.
|
|
24
|
+
{ path: ["time", "zone"], param: null, spec: { kind: "zone" } },
|
|
25
|
+
{ path: ["time", "precision"], param: null, spec: { kind: "choice", values: TIME_PRECISIONS } },
|
|
26
|
+
// The tallest a phone's information or story sheet grows (O-075 T-317, review F-18): no address parameter; the Developer drawer's "Sheet height" slider is this same value.
|
|
27
|
+
range(["sheetMaxPercent"], null, PHONE_LAYOUT_LIMITS.sheetMaxPercent.min, PHONE_LAYOUT_LIMITS.sheetMaxPercent.max),
|
|
22
28
|
];
|
|
23
29
|
/** The name a look is called in a message: `sunGlow.sizePx`. */
|
|
24
30
|
export const lookName = (field) => field.path.join(".");
|
|
@@ -47,7 +53,7 @@ function fromAddress(search, field) {
|
|
|
47
53
|
if (raw === null)
|
|
48
54
|
return undefined;
|
|
49
55
|
const { spec } = field;
|
|
50
|
-
if (spec.kind === "colour" || spec.kind === "font")
|
|
56
|
+
if (spec.kind === "colour" || spec.kind === "font" || spec.kind === "zone" || spec.kind === "choice")
|
|
51
57
|
return undefined;
|
|
52
58
|
if (spec.kind === "onoff")
|
|
53
59
|
return raw === "on" ? true : raw === "off" ? false : undefined;
|
package/src/app/sceneCamera.js
CHANGED
|
@@ -113,17 +113,29 @@ function applyLookOut(input, request) {
|
|
|
113
113
|
camState.focus = request.body;
|
|
114
114
|
camState.fixedPoint = null;
|
|
115
115
|
camState.transition.fill(0);
|
|
116
|
-
|
|
116
|
+
const fovDeg = clampFov(request.fovDeg ?? camState.targetFovDeg ?? camState.lookOut?.fovDeg ?? LOOK_OUT_OPENING_FOV_DEG);
|
|
117
|
+
if (camState.lookOut !== null) {
|
|
118
|
+
// Already looking out: only the targets move, and resolveCamera eases the turn and the zoom (at once under reduced motion).
|
|
119
|
+
if (angles !== null && !keep) {
|
|
120
|
+
camState.targetAzimuth = angles.azimuth;
|
|
121
|
+
camState.targetElevation = clampLookElevation(angles.elevation);
|
|
122
|
+
}
|
|
123
|
+
camState.targetFovDeg = fovDeg;
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (angles !== null) {
|
|
117
127
|
camState.azimuth = camState.targetAzimuth = angles.azimuth;
|
|
118
128
|
camState.elevation = camState.targetElevation = clampLookElevation(angles.elevation);
|
|
119
129
|
}
|
|
120
|
-
camState.
|
|
130
|
+
camState.targetFovDeg = null;
|
|
131
|
+
camState.lookOut = { fovDeg };
|
|
121
132
|
}
|
|
122
133
|
/** Back to the orbit camera: the target tween starts from where the camera stood, not from the aiming point one unit out. */
|
|
123
134
|
function leaveLookOut(camState) {
|
|
124
135
|
if (camState.lookOut === null)
|
|
125
136
|
return;
|
|
126
137
|
camState.lookOut = null;
|
|
138
|
+
camState.targetFovDeg = null;
|
|
127
139
|
for (let i = 0; i < 3; i += 1)
|
|
128
140
|
camState.targetAbsolute[i] = camState.cameraAbsolute[i];
|
|
129
141
|
}
|
|
@@ -79,7 +79,7 @@ export function useOverlayLayers(canvas, controls, trackedViews, bodySetViews, s
|
|
|
79
79
|
export function useScenePointer(canvas, runtime, controls, catalogue, orbit, state) {
|
|
80
80
|
useEffect(() => {
|
|
81
81
|
const limits = () => focusLimits(bodyIdOf(runtime, catalogue, orbit.current.focus) ?? orbit.current.focus, { centre: runtime.sceneCenter, span: state.current.spanScaled, bodies: catalogue }, controls.policy, liveReach(runtime.cameraReach, controls.policy, canvas.clientHeight > 0 ? canvas.clientWidth / canvas.clientHeight : 1));
|
|
82
|
-
return attachScenePointer(canvas, orbit.current, state.current, limits, (id) => controls.onPickObject?.(id));
|
|
82
|
+
return attachScenePointer(canvas, orbit.current, state.current, limits, (id, options) => (options === undefined ? controls.onPickObject?.(id) : controls.onPickObject?.(id, options)));
|
|
83
83
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
84
84
|
}, [canvas, controls]);
|
|
85
85
|
}
|
package/src/app/sceneFrame.js
CHANGED
|
@@ -164,8 +164,8 @@ export function advanceSkyTraces(ctx) {
|
|
|
164
164
|
for (const request of controls.skyTraces.splice(0)) {
|
|
165
165
|
if ("after" in request)
|
|
166
166
|
views.skyFiguresView.startTrace(request);
|
|
167
|
-
else
|
|
168
|
-
|
|
167
|
+
else if (views.skyFiguresView.clearTrace(request))
|
|
168
|
+
state.wakes += 1;
|
|
169
169
|
}
|
|
170
170
|
if (views.skyFiguresView.advanceTraces(delta, controls.skyColours, controls.skyLines, controls.selectedObjectId))
|
|
171
171
|
state.wakes += 1;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type DistanceLimits, type OrbitCameraState } from "./CameraController.js";
|
|
2
2
|
import { type PickCandidate, type SkyPickFigure } from "./scenePicking.js";
|
|
3
|
+
/** `keepSky`: the tap came from a look-out camera, so the shell selects a body without flying away from the sky. */
|
|
4
|
+
export interface PickOptions {
|
|
5
|
+
readonly keepSky?: boolean;
|
|
6
|
+
}
|
|
3
7
|
/** The slice of the frame state the pointer listeners read and write. */
|
|
4
8
|
export interface PointerState {
|
|
5
9
|
readonly pickables: readonly PickCandidate[];
|
|
@@ -14,4 +18,4 @@ export interface PointerState {
|
|
|
14
18
|
* Wires orbit gestures, the mouse hover point and tap picking to the canvas. `state` is read live (the frame rebuilds `pickables`);
|
|
15
19
|
* returns the detach function, which also clears the cursor and the hover readout.
|
|
16
20
|
*/
|
|
17
|
-
export declare function attachScenePointer(canvas: HTMLCanvasElement, orbit: OrbitCameraState, state: PointerState, limits: () => DistanceLimits, onPickObject: ((id: string) => void) | undefined): () => void;
|
|
21
|
+
export declare function attachScenePointer(canvas: HTMLCanvasElement, orbit: OrbitCameraState, state: PointerState, limits: () => DistanceLimits, onPickObject: ((id: string, options?: PickOptions) => void) | undefined): () => void;
|
package/src/app/scenePointer.js
CHANGED
|
@@ -7,12 +7,17 @@ import { pickSkyFigure, pickTarget } from "./scenePicking.js";
|
|
|
7
7
|
*/
|
|
8
8
|
export function attachScenePointer(canvas, orbit, state, limits, onPickObject) {
|
|
9
9
|
const onTap = (x, y, pointer) => {
|
|
10
|
-
//
|
|
11
|
-
const
|
|
10
|
+
// Orbiting, bodies first: a body hit wins over any sky figure behind it. Looking out the sky is the subject, so a figure's name or line wins and a body pick keeps the sky view.
|
|
11
|
+
const lookingOut = orbit.lookOut !== null;
|
|
12
|
+
const figure = () => pickSkyFigure(state.skyFigures?.() ?? [], x, y);
|
|
13
|
+
const id = lookingOut ? figure() ?? pickTarget(state.pickables, x, y, pointer) : pickTarget(state.pickables, x, y, pointer) ?? figure();
|
|
12
14
|
if (id === null)
|
|
13
15
|
return;
|
|
14
16
|
canvas.dataset.pickTarget = id;
|
|
15
|
-
|
|
17
|
+
if (lookingOut)
|
|
18
|
+
onPickObject?.(id, { keepSky: true });
|
|
19
|
+
else
|
|
20
|
+
onPickObject?.(id);
|
|
16
21
|
};
|
|
17
22
|
const onHoverMove = (event) => {
|
|
18
23
|
if (event.pointerType !== "mouse") {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DEFAULT_TIME_LOOK, type TimeLook } from "../shell/timelineModel.js";
|
|
2
|
+
export { DEFAULT_TIME_LOOK };
|
|
3
|
+
export type { TimeLook };
|
|
4
|
+
/** The time look in force: the look's `time`, every part not named at its default. */
|
|
5
|
+
export declare function timeLookOf(look: {
|
|
6
|
+
readonly time?: Partial<TimeLook>;
|
|
7
|
+
}): TimeLook;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The zone and precision of the viewer's times: one look for every visitor-facing time (clock bar, slider text, bound dates, event list, event and window cards). It reaches them as a prop
|
|
2
|
+
// of the shell, with no address parameter, the way the label style does (T-316).
|
|
3
|
+
import { DEFAULT_TIME_LOOK } from "../shell/timelineModel.js";
|
|
4
|
+
export { DEFAULT_TIME_LOOK };
|
|
5
|
+
/** The time look in force: the look's `time`, every part not named at its default. */
|
|
6
|
+
export function timeLookOf(look) {
|
|
7
|
+
return { ...DEFAULT_TIME_LOOK, ...look.time };
|
|
8
|
+
}
|
package/src/core/clock.js
CHANGED
|
@@ -81,8 +81,9 @@ export class SimulationClock {
|
|
|
81
81
|
const now = this.now();
|
|
82
82
|
if (now >= window.startUtcMs && now <= window.endUtcMs)
|
|
83
83
|
return false;
|
|
84
|
-
|
|
84
|
+
// Pause first: a seek while playing re-anchors on a second monotonic read, so pausing after it would carry the time past the edge.
|
|
85
85
|
this.pause();
|
|
86
|
+
this.seek(now > window.endUtcMs ? window.endUtcMs : window.startUtcMs);
|
|
86
87
|
return true;
|
|
87
88
|
}
|
|
88
89
|
setRate(rate) {
|
package/src/core/lookValues.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/** True for a hex colour, a comma-form `rgb()`, `rgba()`, `hsl()` or `hsla()` or a named colour. */
|
|
2
2
|
export declare function isCssColour(value: unknown): value is string;
|
|
3
|
+
/** A CSS colour split into its opaque part (what the drawing library can take) and its alpha, 0 to 1 (1 for a colour with none): `#rrggbbaa`, `#rgba`, `rgba()` and `hsla()` carry one. The drawing library ignores an alpha in a colour, so a line multiplies it into its opacity. */
|
|
4
|
+
export declare function splitColourAlpha(colour: string): {
|
|
5
|
+
readonly colour: string;
|
|
6
|
+
readonly alpha: number;
|
|
7
|
+
};
|
|
3
8
|
/** True for a non-blank font family text (any CSS font-family list, or `inherit`). */
|
|
4
9
|
export declare function isFontFamily(value: unknown): value is string;
|
|
5
10
|
/** Label size range in pixels: small enough for a crowded sky, large enough to read on a phone. */
|
|
@@ -7,3 +12,11 @@ export declare const LABEL_SIZE_LIMITS: Readonly<{
|
|
|
7
12
|
min: 8;
|
|
8
13
|
max: 24;
|
|
9
14
|
}>;
|
|
15
|
+
/** The precisions a time can be shown to. */
|
|
16
|
+
export declare const TIME_PRECISIONS: readonly ["day", "minute", "second"];
|
|
17
|
+
/** How precisely a time reads: `"day"`, `"minute"` or `"second"`. */
|
|
18
|
+
export type TimePrecision = (typeof TIME_PRECISIONS)[number];
|
|
19
|
+
/** True for a time precision name. */
|
|
20
|
+
export declare function isTimePrecision(value: unknown): value is TimePrecision;
|
|
21
|
+
/** True for a zone the time look takes: `"UTC"`, `"local"` (the visitor's own) or an IANA name the runtime's `Intl` accepts. */
|
|
22
|
+
export declare function isTimeZone(value: unknown): value is string;
|
package/src/core/lookValues.js
CHANGED
|
@@ -16,9 +16,48 @@ export function isCssColour(value) {
|
|
|
16
16
|
const text = value.trim();
|
|
17
17
|
return HEX.test(text) || FUNCTION.test(text) || NAMED.has(text.toLowerCase());
|
|
18
18
|
}
|
|
19
|
+
const FUNCTION_PARTS = /^(rgb|hsl)a?\(\s*([\d.]+%?)\s*,\s*([\d.]+%?)\s*,\s*([\d.]+%?)\s*(?:,\s*([\d.]+%?)\s*)?\)$/i;
|
|
20
|
+
function alphaOf(text) {
|
|
21
|
+
if (text === undefined)
|
|
22
|
+
return 1;
|
|
23
|
+
const value = text.endsWith("%") ? Number.parseFloat(text) / 100 : Number.parseFloat(text);
|
|
24
|
+
return Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : 1;
|
|
25
|
+
}
|
|
26
|
+
/** A CSS colour split into its opaque part (what the drawing library can take) and its alpha, 0 to 1 (1 for a colour with none): `#rrggbbaa`, `#rgba`, `rgba()` and `hsla()` carry one. The drawing library ignores an alpha in a colour, so a line multiplies it into its opacity. */
|
|
27
|
+
export function splitColourAlpha(colour) {
|
|
28
|
+
const text = colour.trim();
|
|
29
|
+
if (/^#[0-9a-f]{4}$/i.test(text))
|
|
30
|
+
return { colour: `#${text[1]}${text[2]}${text[3]}`, alpha: Number.parseInt(text[4] + text[4], 16) / 255 };
|
|
31
|
+
if (/^#[0-9a-f]{8}$/i.test(text))
|
|
32
|
+
return { colour: text.slice(0, 7), alpha: Number.parseInt(text.slice(7), 16) / 255 };
|
|
33
|
+
const parts = FUNCTION_PARTS.exec(text);
|
|
34
|
+
if (parts === null || parts[5] === undefined)
|
|
35
|
+
return { colour: text, alpha: 1 };
|
|
36
|
+
return { colour: `${parts[1].toLowerCase()}(${parts[2]}, ${parts[3]}, ${parts[4]})`, alpha: alphaOf(parts[5]) };
|
|
37
|
+
}
|
|
19
38
|
/** True for a non-blank font family text (any CSS font-family list, or `inherit`). */
|
|
20
39
|
export function isFontFamily(value) {
|
|
21
40
|
return typeof value === "string" && value.trim() !== "" && !/[;{}]/.test(value);
|
|
22
41
|
}
|
|
23
42
|
/** Label size range in pixels: small enough for a crowded sky, large enough to read on a phone. */
|
|
24
43
|
export const LABEL_SIZE_LIMITS = Object.freeze({ min: 8, max: 24 });
|
|
44
|
+
/** The precisions a time can be shown to. */
|
|
45
|
+
export const TIME_PRECISIONS = Object.freeze(["day", "minute", "second"]);
|
|
46
|
+
/** True for a time precision name. */
|
|
47
|
+
export function isTimePrecision(value) {
|
|
48
|
+
return typeof value === "string" && TIME_PRECISIONS.includes(value);
|
|
49
|
+
}
|
|
50
|
+
/** True for a zone the time look takes: `"UTC"`, `"local"` (the visitor's own) or an IANA name the runtime's `Intl` accepts. */
|
|
51
|
+
export function isTimeZone(value) {
|
|
52
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
53
|
+
return false;
|
|
54
|
+
if (value === "UTC" || value === "local")
|
|
55
|
+
return true;
|
|
56
|
+
try {
|
|
57
|
+
new Intl.DateTimeFormat(undefined, { timeZone: value });
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/core/state.d.ts
CHANGED
|
@@ -28,6 +28,8 @@ export interface StateInput {
|
|
|
28
28
|
readonly velocityKmS?: ArrayLike<number>;
|
|
29
29
|
readonly orientation: Quaternion | null;
|
|
30
30
|
}
|
|
31
|
+
/** True for a whole-millisecond JavaScript UTC Unix time inside the Date range. */
|
|
32
|
+
export declare function isUtcUnixMs(timeUtcMs: number): boolean;
|
|
31
33
|
export declare function assertUtcUnixMs(timeUtcMs: number): void;
|
|
32
34
|
export declare function createCenteredPosition(input: Omit<StateInput, "orientation">): CenteredPosition;
|
|
33
35
|
/** Whether a body's definition says its State must carry a modelled orientation. */
|
package/src/core/state.js
CHANGED
|
@@ -4,8 +4,12 @@ import { MOON } from "./bodies/moon.js";
|
|
|
4
4
|
import { SUN } from "./bodies/sun.js";
|
|
5
5
|
export const EQJ = "EQJ";
|
|
6
6
|
const MAX_DATE_MS = 8.64e15;
|
|
7
|
+
/** True for a whole-millisecond JavaScript UTC Unix time inside the Date range. */
|
|
8
|
+
export function isUtcUnixMs(timeUtcMs) {
|
|
9
|
+
return Number.isSafeInteger(timeUtcMs) && Math.abs(timeUtcMs) <= MAX_DATE_MS;
|
|
10
|
+
}
|
|
7
11
|
export function assertUtcUnixMs(timeUtcMs) {
|
|
8
|
-
if (!
|
|
12
|
+
if (!isUtcUnixMs(timeUtcMs)) {
|
|
9
13
|
throw new RangeError("timeUtcMs must be an integer JavaScript UTC Unix-millisecond value");
|
|
10
14
|
}
|
|
11
15
|
}
|
|
@@ -48,9 +48,11 @@ export interface StoryPanel extends PanelActions {
|
|
|
48
48
|
readonly provenance: Provenance;
|
|
49
49
|
/** A shell object this panel is about; the scene draws a marker on it that reopens the panel. */
|
|
50
50
|
readonly objectId?: string;
|
|
51
|
+
/** This panel's own span, in simulated seconds: forward playback closes it once the clock passes its time plus this. Overrides the playback setting; absent, the playback setting (or none) applies. */
|
|
52
|
+
readonly closeAfterSeconds?: number;
|
|
51
53
|
}
|
|
52
|
-
/** A story step: a panel with no moment, shown in the order added with Back and Next. */
|
|
53
|
-
export type StoryStep = Omit<StoryPanel, "timeUtcMs"> & {
|
|
54
|
+
/** A story step: a panel with no moment, shown in the order added with Back and Next. A step never closes by itself. */
|
|
55
|
+
export type StoryStep = Omit<StoryPanel, "timeUtcMs" | "closeAfterSeconds"> & {
|
|
54
56
|
/** The step's place among the steps, counting from 1 in the order added. */
|
|
55
57
|
readonly step: number;
|
|
56
58
|
};
|
|
@@ -64,11 +66,13 @@ export interface StoryPanelSet {
|
|
|
64
66
|
readonly pauseSeconds: number;
|
|
65
67
|
/** Whether panels open by themselves as forward playback reaches them. */
|
|
66
68
|
readonly autoOpen: boolean;
|
|
69
|
+
/** Simulated seconds after a moment panel's time at which forward playback closes it; absent: never (a panel's own span wins). */
|
|
70
|
+
readonly closeAfterSeconds?: number;
|
|
67
71
|
}
|
|
68
72
|
export declare const DEFAULT_PANEL_PAUSE_SECONDS = 6;
|
|
69
73
|
export declare const MAX_PANEL_PAUSE_SECONDS = 20;
|
|
70
|
-
/** The
|
|
71
|
-
export type PanelPlayback = Pick<StoryPanelSet, "pauseSeconds" | "autoOpen">;
|
|
74
|
+
/** The playback settings of a scene's story panels. */
|
|
75
|
+
export type PanelPlayback = Pick<StoryPanelSet, "pauseSeconds" | "autoOpen" | "closeAfterSeconds">;
|
|
72
76
|
export declare const DEFAULT_PANEL_PLAYBACK: PanelPlayback;
|
|
73
77
|
/** A panel whose own shape is sound and whose moment is converted. What it names (an event, an anchor, an object) is left for `resolveStoryPanels`, because those may be added later. */
|
|
74
78
|
export interface CheckedPanel extends Omit<StoryPanel, "timeUtcMs" | "objectId"> {
|
package/src/core/storyPanels.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createProvenance, PROVENANCE_SOURCE_TYPES } from "./provenance.js";
|
|
2
|
+
import { isUtcUnixMs } from "./state.js";
|
|
2
3
|
import { timeInputMs } from "./timeInput.js";
|
|
3
4
|
/** The ids a camera request names: the bodies it points at, and the id a look-out turns toward (a body or a sky figure). */
|
|
4
5
|
export function cameraIdsOf(request) {
|
|
@@ -45,7 +46,7 @@ function atOf(panel, at) {
|
|
|
45
46
|
if (keys[0] === "anchor")
|
|
46
47
|
return { anchor: text(panel, "at.anchor", at.anchor) };
|
|
47
48
|
const timeUtcMs = timeInputMs(at.time);
|
|
48
|
-
if (!
|
|
49
|
+
if (!isUtcUnixMs(timeUtcMs))
|
|
49
50
|
throw new StoryPanelError(panel, "at.time", `must be a valid moment (ISO text, a Date or Unix milliseconds), got ${JSON.stringify(at.time)}`);
|
|
50
51
|
return { timeUtcMs };
|
|
51
52
|
}
|
|
@@ -62,6 +63,12 @@ function provenanceOf(panel, value) {
|
|
|
62
63
|
throw new StoryPanelError(panel, "provenance.notes", "must be text");
|
|
63
64
|
return createProvenance(value);
|
|
64
65
|
}
|
|
66
|
+
/** A close span: finite and above 0, in simulated seconds. */
|
|
67
|
+
function spanOf(panel, field, value) {
|
|
68
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0)
|
|
69
|
+
throw new StoryPanelError(panel, field, `must be a number of seconds above 0, got ${JSON.stringify(value)}`);
|
|
70
|
+
return value;
|
|
71
|
+
}
|
|
65
72
|
/** Checks the shape of one panel, the `index`th of the list it came in. Nothing here looks at the scene: links are `resolveStoryPanels`' job. */
|
|
66
73
|
export function checkStoryPanel(raw, index) {
|
|
67
74
|
if (!isRecord(raw))
|
|
@@ -69,6 +76,9 @@ export function checkStoryPanel(raw, index) {
|
|
|
69
76
|
const id = text(`#${index + 1}`, "id", raw.id);
|
|
70
77
|
const object = raw.object === undefined ? undefined : text(id, "object", raw.object);
|
|
71
78
|
const at = atOf(id, raw.at);
|
|
79
|
+
if (at === undefined && raw.closeAfterSeconds !== undefined)
|
|
80
|
+
throw new StoryPanelError(id, "closeAfterSeconds", "is for a moment panel: a step never closes by itself");
|
|
81
|
+
const closeAfterSeconds = raw.closeAfterSeconds === undefined ? undefined : spanOf(id, "closeAfterSeconds", raw.closeAfterSeconds);
|
|
72
82
|
return {
|
|
73
83
|
id,
|
|
74
84
|
...(at === undefined ? {} : { at }),
|
|
@@ -77,12 +87,13 @@ export function checkStoryPanel(raw, index) {
|
|
|
77
87
|
details: raw.details === undefined ? [] : lines(id, "details", raw.details),
|
|
78
88
|
provenance: provenanceOf(id, raw.provenance),
|
|
79
89
|
...(object === undefined ? {} : { object }),
|
|
90
|
+
...(closeAfterSeconds === undefined ? {} : { closeAfterSeconds }),
|
|
80
91
|
};
|
|
81
92
|
}
|
|
82
93
|
/** Checks the two playback settings; a setting left out takes its default, so the result is the whole setting. */
|
|
83
94
|
export function checkPanelPlayback(raw) {
|
|
84
95
|
if (!isRecord(raw))
|
|
85
|
-
throw new StoryPanelError("settings", "playback", "must be an object: { pauseSeconds?, autoOpen? }");
|
|
96
|
+
throw new StoryPanelError("settings", "playback", "must be an object: { pauseSeconds?, autoOpen?, closeAfterSeconds? }");
|
|
86
97
|
const pauseSeconds = raw.pauseSeconds ?? DEFAULT_PANEL_PLAYBACK.pauseSeconds;
|
|
87
98
|
if (typeof pauseSeconds !== "number" || !Number.isFinite(pauseSeconds) || pauseSeconds < 0 || pauseSeconds > MAX_PANEL_PAUSE_SECONDS) {
|
|
88
99
|
throw new StoryPanelError("settings", "pauseSeconds", `must be between 0 and ${MAX_PANEL_PAUSE_SECONDS}, got ${JSON.stringify(pauseSeconds)}`);
|
|
@@ -90,7 +101,8 @@ export function checkPanelPlayback(raw) {
|
|
|
90
101
|
const autoOpen = raw.autoOpen ?? DEFAULT_PANEL_PLAYBACK.autoOpen;
|
|
91
102
|
if (typeof autoOpen !== "boolean")
|
|
92
103
|
throw new StoryPanelError("settings", "autoOpen", "must be true or false");
|
|
93
|
-
|
|
104
|
+
const closeAfterSeconds = raw.closeAfterSeconds === undefined ? undefined : spanOf("settings", "closeAfterSeconds", raw.closeAfterSeconds);
|
|
105
|
+
return { pauseSeconds, autoOpen, ...(closeAfterSeconds === undefined ? {} : { closeAfterSeconds }) };
|
|
94
106
|
}
|
|
95
107
|
function timeOf(id, at, lookup) {
|
|
96
108
|
if ("timeUtcMs" in at)
|
|
@@ -126,13 +138,13 @@ function checkLinks({ id, object, camera, trace }, lookup) {
|
|
|
126
138
|
/** The actions a panel carries, in the order they apply. */
|
|
127
139
|
const actionsOf = ({ camera, select, trace }) => ({ ...(camera === undefined ? {} : { camera }), ...(select === undefined ? {} : { select }), ...(trace === undefined ? {} : { trace }) });
|
|
128
140
|
function resolvePanel(panel, lookup) {
|
|
129
|
-
const { id, at, title, body, details, provenance, object } = panel;
|
|
141
|
+
const { id, at, title, body, details, provenance, object, closeAfterSeconds } = panel;
|
|
130
142
|
const timeUtcMs = timeOf(id, at, lookup);
|
|
131
143
|
if (lookup.window !== undefined && (timeUtcMs < lookup.window.startUtcMs || timeUtcMs > lookup.window.endUtcMs)) {
|
|
132
144
|
throw new StoryPanelError(id, "at", "falls outside the timeline window");
|
|
133
145
|
}
|
|
134
146
|
checkLinks(panel, lookup);
|
|
135
|
-
return { id, timeUtcMs, title, body, details, provenance, ...(object === undefined ? {} : { objectId: object }), ...actionsOf(panel) };
|
|
147
|
+
return { id, timeUtcMs, title, body, details, provenance, ...(object === undefined ? {} : { objectId: object }), ...(closeAfterSeconds === undefined ? {} : { closeAfterSeconds }), ...actionsOf(panel) };
|
|
136
148
|
}
|
|
137
149
|
function resolveStep(panel, lookup, step) {
|
|
138
150
|
const { id, title, body, details, provenance, object } = panel;
|