From 31ce6cbf79e97265d3b93b760d9da7cfbfd3701e Mon Sep 17 00:00:00 2001 From: German Khokhlov Date: Mon, 23 Nov 2026 16:08:30 +0400 Subject: [PATCH] A link to only a view opens with the opening too, stopping at that view The app writes its view into the address, so a reload or a bookmark is a share link and opened without the opening. A start-up share whose camera landed and that follows or selects nothing now plays it as well, ending where the link points; the share restore says when the share is of a thing. The flight turns to the target's heading and pitch over its last part, so a view at an angle is reached without a jump. A camera held in a target's frame plays no opening. --- changelog.d/1909-opening-globe.md | 5 ++-- src/app/openingIntro.js | 40 ++++++++++++++++++--------- src/app/openingIntro.test.mjs | 27 ++++++++++++++++++ src/app/startupChrome.js | 26 +++++++++++++---- src/standalone/startupChrome.test.mjs | 36 +++++++++++++++++++++--- src/ui/shareRestoration.js | 11 +++++++- 6 files changed, 120 insertions(+), 25 deletions(-) diff --git a/changelog.d/1909-opening-globe.md b/changelog.d/1909-opening-globe.md index 1706c55c2b..9f8119e069 100644 --- a/changelog.d/1909-opening-globe.md +++ b/changelog.d/1909-opening-globe.md @@ -2,5 +2,6 @@ flies at you and opens onto the app as it grows, and the planet in the pupil becomes the real globe, which spins, grows and stops with the whole planet in view over your country, taken from the browser's time zone. The title's logo - goes back to that view. A share link, a Stories link, reduced motion and - `?intro=0` open as before (gekh, #1909). + goes back to that view. A link to only a view plays it too and stops at that + view; a link that follows or selects something, a Stories link, reduced + motion and `?intro=0` open as before (gekh, #1909). diff --git a/src/app/openingIntro.js b/src/app/openingIntro.js index e3c7d0084a..0b07c1594f 100644 --- a/src/app/openingIntro.js +++ b/src/app/openingIntro.js @@ -95,8 +95,10 @@ export function openingStage(t, timing = OPENING) { /** * The camera `flight` (0–1) of the way in: from `farHeight` over the - * equator, a turn of `spinDeg` west to east that slows to a stop over - * `target`, closing in on `target.height`. + * equator, looking straight down, a turn of `spinDeg` west to east that + * slows to a stop over `target`, closing in on `target.height`. Over the + * last part it turns to `target`'s heading and pitch (radians), so a view + * at an angle (a shared one) is reached without a jump. */ export function openingPose( flight, @@ -109,10 +111,18 @@ export function openingPose( (Math.log(target.height) - Math.log(farHeight)) * closing, ); const lon = target.lon + spinDeg * (1 - easeOutCubic(f)); + const turning = easeInOutCubic(span(f, [0.6, 1])); + const heading = target.heading ?? 0; + // The short way round to the target's heading. + const headingFrom = + heading - 2 * Math.PI * Math.round(heading / (2 * Math.PI)); + const pitch = target.pitch ?? -Math.PI / 2; return { lon: ((((lon + 180) % 360) + 360) % 360) - 180, lat: target.lat * closing, height, + heading: headingFrom * turning, + pitch: -Math.PI / 2 + (pitch + Math.PI / 2) * turning, }; } @@ -191,10 +201,11 @@ export function openingWanted(win = globalThis.window) { } /** - * Play the opening over `loadingScreen`, from where the camera stands (the - * start view). Returns null when it does not play; else `done`, which - * settles when the camera has stopped, and `cancel()`. A click, a key or the - * wheel skips to the start view; any other camera move stops it where it is. The loading + * Play the opening over `loadingScreen`, ending where the camera stands (the + * start view, or the view a link opened). Returns null when it does not + * play, as for a camera held in a target's frame; else `done`, which settles + * when the camera has stopped, and `cancel()`. A click, a key or the wheel + * skips to the end; any other camera move stops it where it is. The loading * screen is `hidden` once the real globe shows, or at once on a cancel. * @param {{viewer: object, loadingScreen: HTMLElement, win?: Window, * camera?: object}} options `camera` is the viewer's camera port unless given. @@ -213,6 +224,7 @@ export function playOpeningIntro({ } const target = camera.pose(); if ( + target?.frameIsIdentity === false || !Number.isFinite(target?.height) || !Number.isFinite(target.lon) || !Number.isFinite(target.lat) @@ -273,11 +285,11 @@ export function playOpeningIntro({ : 1; let driving = false; - const place = (pose, heading = 0, pitch = -Math.PI / 2) => { + const place = ({ lon, lat, height, heading, pitch }) => { driving = true; try { camera.setView({ - destination: pose, + destination: { lon, lat, height }, orientation: { heading, pitch, roll: 0 }, }); } finally { @@ -310,11 +322,13 @@ export function playOpeningIntro({ for (const type of inputs) win.removeEventListener(type, onInput, { capture: true }); if (land) - place( - { lon: target.lon, lat: target.lat, height: target.height }, - target.heading ?? 0, - target.pitch ?? -Math.PI / 2, - ); + place({ + lon: target.lon, + lat: target.lat, + height: target.height, + heading: target.heading ?? 0, + pitch: target.pitch ?? -Math.PI / 2, + }); hide(); resolveDone(); } diff --git a/src/app/openingIntro.test.mjs b/src/app/openingIntro.test.mjs index b3491cc0e3..81a1f05efc 100644 --- a/src/app/openingIntro.test.mjs +++ b/src/app/openingIntro.test.mjs @@ -85,6 +85,25 @@ test('the flight turns west to east, slows and stops over the target', () => { } }); +test('a view at an angle is reached by turning over the last part', () => { + const angled = { + lon: 2.35, + lat: 48.86, + height: 5000, + heading: 5.5, + pitch: -0.5, + }; + const far = 4e8; + const early = openingPose(0.5, { target: angled, farHeight: far }); + assert.ok(Math.abs(early.heading) < 1e-12); + assert.equal(early.pitch, -Math.PI / 2, 'straight down while far out'); + const end = openingPose(1, { target: angled, farHeight: far }); + // 5.5 rad turns the short way round: -0.78 rad. + assert.ok(Math.abs(end.heading - (5.5 - 2 * Math.PI)) < 1e-9); + assert.ok(Math.abs(end.pitch - angled.pitch) < 1e-9); + assert.ok(Math.abs(end.height - angled.height) < 1e-6); +}); + test('the far start draws the globe the size of the pupil', () => { for (const radius of [12, 20, 64]) { const height = heightForGlobeRadius(radius, LENS); @@ -187,11 +206,19 @@ test('the opening runs to the start view, then hides the cover', async () => { await opening.done; const last = s.views.at(-1); assert.deepEqual(last.destination, LANDED); + assert.equal(last.orientation.heading, TARGET.heading); assert.equal(last.orientation.pitch, TARGET.pitch); assert.equal(openingPlaying(), false); assert.equal(s.commandListeners.size, 0); }); +test('a camera held in a target frame plays no opening', () => { + const s = stage(); + s.camera.pose = () => ({ ...TARGET, frameIsIdentity: false }); + assert.equal(s.play(), null); + assert.ok(!s.screen.classList.contains('opening')); +}); + test("the person's input skips to the start view", async () => { const s = stage(); const opening = s.play(); diff --git a/src/app/startupChrome.js b/src/app/startupChrome.js index 42bf1b0e24..0f1799168f 100644 --- a/src/app/startupChrome.js +++ b/src/app/startupChrome.js @@ -32,12 +32,14 @@ export function startApplicationChrome({ .catch(() => { /* Restoration reports its own outcome through the controls. */ }) - .then(() => { + .then(([restored] = []) => { if (disposed || signal.aborted) return; - // A bare address opens with the opening; welcome waits for its end. - opening = styleManager.hasShareState - ? null - : playOpening?.({ viewer: styleManager.viewer, loadingScreen }); + // A bare address, or a share of only a view, opens with the opening + // (it ends where the camera stands); welcome waits for its end. + opening = + !styleManager.hasShareState || sharesOnlyAView(restored) + ? playOpening?.({ viewer: styleManager.viewer, loadingScreen }) + : null; if (opening) { void opening.done.then(revealFirstRun); return; @@ -66,3 +68,17 @@ export function startApplicationChrome({ (await keySetup.catch(() => null))?.destroy(); }; } + +/** + * Whether a start-up share restore left only a view: the camera landed where + * the link points and nothing is followed or selected for it. + */ +function sharesOnlyAView(restored) { + return ( + restored?.status === 'settled' && + restored.share?.camera === 'applied' && + restored.tracking?.status === 'skipped' && + restored.tracking.reason === 'no-shared-target' && + !restored.thing + ); +} diff --git a/src/standalone/startupChrome.test.mjs b/src/standalone/startupChrome.test.mjs index 84ba38664f..07a0810841 100644 --- a/src/standalone/startupChrome.test.mjs +++ b/src/standalone/startupChrome.test.mjs @@ -163,18 +163,46 @@ test('a bare address plays the opening, and welcome waits for its end', async () assert.ok(events.includes('opening:cancel')); }); -test('a shared view opens without the opening', async () => { +const VIEW_ONLY = Object.freeze({ + status: 'settled', + share: { camera: 'applied' }, + tracking: { status: 'skipped', reason: 'no-shared-target' }, + thing: false, +}); + +test('a link to only a view opens with the opening, ending at that view', async () => { const events = []; const opening = openingStub(events); const f = fixture({ playOpening: opening.play, hasShareState: true }); - f.restored(); + f.restored(VIEW_ONLY); f.fire(1000); await flush(); - assert.equal(opening.calls.length, 0); - assert.deepEqual(f.events, ['hidden']); + assert.equal(opening.calls.length, 1); await f.stop(); }); +for (const [name, restored] of [ + ['a followed target', { ...VIEW_ONLY, tracking: { status: 'restored' } }], + ['a shared thing', { ...VIEW_ONLY, thing: true }], + [ + 'a camera the person moved first', + { ...VIEW_ONLY, share: { camera: 'superseded' } }, + ], + ['a failed restore', { status: 'failed' }], +]) { + test(`a link to ${name} opens without the opening`, async () => { + const events = []; + const opening = openingStub(events); + const f = fixture({ playOpening: opening.play, hasShareState: true }); + f.restored(restored); + f.fire(1000); + await flush(); + assert.equal(opening.calls.length, 0); + assert.deepEqual(f.events, ['hidden']); + await f.stop(); + }); +} + test('without an opening to play the cover hides as before', async () => { const f = fixture({ playOpening: () => null }); f.restored(); diff --git a/src/ui/shareRestoration.js b/src/ui/shareRestoration.js index 0b34ffbd55..c49dfca95d 100644 --- a/src/ui/shareRestoration.js +++ b/src/ui/shareRestoration.js @@ -324,7 +324,16 @@ export class ShareRestoration { if (vessel) void this._restoreSharedVessel(vessel, current); // The token tells listeners whether anyone navigated after the // restore's flight landed (while the layers were still loading). - settle({ status: 'settled', share, layers, tracking, navigationToken }); + // `thing` says the share is of a thing (a followed or selected one), + // not only a view. + settle({ + status: 'settled', + share, + layers, + tracking, + navigationToken, + thing: state?.shareView?.kind === 'thing', + }); } catch (error) { if (!current()) return; this.shareLinkManager.completeInitialRestore(state.restoreToken);