mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-24 04:02:19 +00:00
Turn the opening at planet size, then close in; keep its frames out of the address
This commit is contained in:
1 parent
dd18c5ad11
commit
f4d936989b
7 files changed
+237
-85
No files matched your search
@@ -1,7 +1,9 @@
|
||||
- The app opens with the loading screen's logo turning into the globe: the eye
|
||||
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 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).
|
||||
becomes the real globe, which grows to the whole planet, turns and stops over
|
||||
your country, taken from the browser's time zone. The title's logo goes back
|
||||
to that view. A link to only a view plays it too, closing in on that view
|
||||
after the turn; a link that follows or selects something, a Stories link,
|
||||
reduced motion and `?intro=0` open as before. The address no longer follows
|
||||
the flight, so a reload during it reopens on the view it ends at (gekh,
|
||||
#1909).
|
||||
+86
-38
@@ -1,3 +1,4 @@
|
||||
import { START_VIEW } from '../camera.js';
|
||||
import { cameraOf } from '../render/rendererOf.js';
|
||||
|
||||
/**
|
||||
@@ -5,10 +6,10 @@ import { cameraOf } from '../render/rendererOf.js';
|
||||
* into the globe. The words fade and the logo glides to the centre. The
|
||||
* screen is then shut but for the empty circle inside the eye's ring, which
|
||||
* flies at the viewer and opens onto the application as it grows past the
|
||||
* screen's edges. The drawn
|
||||
* planet in the pupil (its blue disc) gives way to the real one, drawn the
|
||||
* same size behind it; the real one spins and grows, slowing until it stops,
|
||||
* the whole planet in view, over the start view (the visitor's country).
|
||||
* screen's edges. The drawn planet in the pupil (its blue disc) gives way to
|
||||
* the real one, drawn the same size behind it, which grows to the whole
|
||||
* planet's size, turns there to a stop over the start view (the visitor's
|
||||
* country), and only then closes in on a closer view a link opened.
|
||||
* Everything is timed from one clock, in ms.
|
||||
*/
|
||||
export const OPENING = Object.freeze({
|
||||
@@ -23,10 +24,17 @@ export const OPENING = Object.freeze({
|
||||
veilMs: Object.freeze([200, 700]),
|
||||
/** The drawn planet fades into the real one. */
|
||||
pupilMs: Object.freeze([600, 1200]),
|
||||
/** The camera's flight in. */
|
||||
/** The camera's flight starts. */
|
||||
flightStartMs: 300,
|
||||
flightMs: 6000,
|
||||
/** How far the globe turns on the way in, degrees. */
|
||||
/** The globe grows to the whole planet's size. */
|
||||
zoomMs: 1600,
|
||||
/** It turns there, slowing to a stop over the start view. */
|
||||
spinMs: 2600,
|
||||
/** Then the camera closes in on a closer view (a shared one), per tenfold
|
||||
* change of height, within `approachMs`. */
|
||||
approachPerDecadeMs: 1100,
|
||||
approachMs: Object.freeze([1200, 4000]),
|
||||
/** How far the globe turns, degrees. */
|
||||
spinDeg: 360,
|
||||
});
|
||||
|
||||
@@ -43,6 +51,8 @@ const WINDOW = Object.freeze({ x: 567, y: 382, r: 226 });
|
||||
const WINDOW_COVER_MARGIN = 1.15;
|
||||
/** Never start further out than this, metres. */
|
||||
const MAX_FAR_HEIGHT_M = 4e8;
|
||||
/** The whole planet in view. */
|
||||
const PLANET_HEIGHT_M = START_VIEW.height;
|
||||
|
||||
/** Openings in progress on this page. */
|
||||
let playing = 0;
|
||||
@@ -67,11 +77,11 @@ const span = (t, [from, to]) => clamp01((t - from) / (to - from));
|
||||
* Where each part of the opening stands `t` ms after it starts.
|
||||
* @param {number} t
|
||||
*/
|
||||
export function openingStage(t, timing = OPENING) {
|
||||
export function openingStage(t, timing = OPENING, flightMs = flightLength()) {
|
||||
const move = clamp01(t / timing.centreMs);
|
||||
const after = t - timing.centreMs;
|
||||
const eye = clamp01(after / timing.eyeMs);
|
||||
const flight = clamp01((after - timing.flightStartMs) / timing.flightMs);
|
||||
const flight = clamp01((after - timing.flightStartMs) / flightMs);
|
||||
return {
|
||||
/** The words' opacity. */
|
||||
text: 1 - clamp01(t / timing.textMs),
|
||||
@@ -94,38 +104,71 @@ export function openingStage(t, timing = OPENING) {
|
||||
};
|
||||
}
|
||||
|
||||
/** How long the flight takes, ms, for a closing-in of `decades` (log10). */
|
||||
function flightLength(decades = 0, turns = false, timing = OPENING) {
|
||||
const [shortest, longest] = timing.approachMs;
|
||||
const approach =
|
||||
decades > 0.05 || turns
|
||||
? Math.min(
|
||||
longest,
|
||||
Math.max(shortest, decades * timing.approachPerDecadeMs),
|
||||
)
|
||||
: 0;
|
||||
return timing.zoomMs + timing.spinMs + approach;
|
||||
}
|
||||
|
||||
/**
|
||||
* The camera `flight` (0–1) of the way in: from `farHeight` over the
|
||||
* 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.
|
||||
* The camera's flight in, from `farHeight` over the equator, looking straight
|
||||
* down. The globe first grows to the whole planet's size (`planetHeight`, or
|
||||
* `target.height` when that is further out), turns `spinDeg` west to east
|
||||
* there, slowing to a stop over `target`, and only then closes in on a closer
|
||||
* `target`, turning to its heading and pitch (radians) on the way.
|
||||
* Returns its length, ms, and its pose `ms` into it.
|
||||
*/
|
||||
export function openingPose(
|
||||
flight,
|
||||
{ target, farHeight, spinDeg = OPENING.spinDeg },
|
||||
) {
|
||||
const f = clamp01(flight);
|
||||
// Half the peak speed of a cubic ease, so the imagery keeps up as the
|
||||
// globe grows.
|
||||
const closing = smoothstep(f);
|
||||
const height = Math.exp(
|
||||
Math.log(farHeight) +
|
||||
(Math.log(target.height) - Math.log(farHeight)) * closing,
|
||||
);
|
||||
const lon = target.lon + spinDeg * (1 - easeOutCubic(f));
|
||||
const turning = easeInOutCubic(span(f, [0.6, 1]));
|
||||
export function openingFlight({
|
||||
target,
|
||||
farHeight,
|
||||
planetHeight = PLANET_HEIGHT_M,
|
||||
timing = OPENING,
|
||||
}) {
|
||||
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;
|
||||
const headingTo = heading - 2 * Math.PI * Math.round(heading / (2 * Math.PI));
|
||||
const pitchTo = target.pitch ?? -Math.PI / 2;
|
||||
const turns =
|
||||
Math.abs(headingTo) > 1e-3 || Math.abs(pitchTo + Math.PI / 2) > 1e-3;
|
||||
const planet = Math.max(planetHeight, target.height);
|
||||
const decades = Math.log10(planet / target.height);
|
||||
const ms = flightLength(decades, turns, timing);
|
||||
const approachMs = ms - timing.zoomMs - timing.spinMs;
|
||||
const logLerp = (from, to, k) =>
|
||||
Math.exp(Math.log(from) + (Math.log(to) - Math.log(from)) * k);
|
||||
// The turn starts halfway through the zoom, while the drawn planet has
|
||||
// given way to the real one.
|
||||
const spinFrom = timing.zoomMs / 2;
|
||||
const spinLength = timing.zoomMs + timing.spinMs - spinFrom;
|
||||
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,
|
||||
ms,
|
||||
pose(at) {
|
||||
const t = Math.min(Math.max(at, 0), ms);
|
||||
const zoom = smoothstep(clamp01(t / timing.zoomMs));
|
||||
const spin = easeOutCubic(clamp01((t - spinFrom) / spinLength));
|
||||
const approach = approachMs
|
||||
? clamp01((t - timing.zoomMs - timing.spinMs) / approachMs)
|
||||
: 0;
|
||||
const turning = easeInOutCubic(approach);
|
||||
const lon = target.lon + timing.spinDeg * (1 - spin);
|
||||
return {
|
||||
lon: ((((lon + 180) % 360) + 360) % 360) - 180,
|
||||
lat: target.lat * spin,
|
||||
height:
|
||||
approach > 0
|
||||
? logLerp(planet, target.height, smoothstep(approach))
|
||||
: logLerp(farHeight, planet, zoom),
|
||||
heading: headingTo * turning,
|
||||
pitch: -Math.PI / 2 + (pitchTo + Math.PI / 2) * turning,
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -336,16 +379,21 @@ export function playOpeningIntro({
|
||||
resolveDone();
|
||||
}
|
||||
|
||||
const flight = openingFlight({ target, farHeight });
|
||||
const start = win.performance.now();
|
||||
const step = () => {
|
||||
frame = 0;
|
||||
if (finished) return;
|
||||
const stage = openingStage(win.performance.now() - start);
|
||||
const stage = openingStage(
|
||||
win.performance.now() - start,
|
||||
OPENING,
|
||||
flight.ms,
|
||||
);
|
||||
if (stage.done) {
|
||||
finish({ land: true });
|
||||
return;
|
||||
}
|
||||
const pose = openingPose(stage.flight, { target, farHeight });
|
||||
const pose = flight.pose(stage.flight * flight.ms);
|
||||
place(pose);
|
||||
const scale = globeRadiusPx(pose.height, lens) / startRadius;
|
||||
loadingScreen.style.setProperty('--opening-text', stage.text);
|
||||
|
||||
@@ -6,8 +6,8 @@ import {
|
||||
eyeCoverScale,
|
||||
globeRadiusPx,
|
||||
heightForGlobeRadius,
|
||||
openingFlight,
|
||||
openingPlaying,
|
||||
openingPose,
|
||||
openingStage,
|
||||
openingWanted,
|
||||
playOpeningIntro,
|
||||
@@ -16,7 +16,8 @@ import {
|
||||
const LENS = { fovy: Math.PI / 4, viewportHeight: 800 };
|
||||
const TARGET = { lon: 10.4, lat: 51.1, height: 23e6, heading: 0, pitch: -1 };
|
||||
const LANDED = { lon: TARGET.lon, lat: TARGET.lat, height: TARGET.height };
|
||||
const END_MS = OPENING.centreMs + OPENING.flightStartMs + OPENING.flightMs + 1;
|
||||
const PLANET_FLIGHT_MS = OPENING.zoomMs + OPENING.spinMs;
|
||||
const END_MS = OPENING.centreMs + OPENING.flightStartMs + PLANET_FLIGHT_MS + 1;
|
||||
|
||||
test('the words fade, then the eye opens past the screen before the globe arrives', () => {
|
||||
const start = openingStage(0);
|
||||
@@ -57,35 +58,46 @@ test("the eye's window reaches past the corners of any screen", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('the flight turns west to east, slows and stops over the target', () => {
|
||||
const far = 4e8;
|
||||
const start = openingPose(0, { target: TARGET, farHeight: far });
|
||||
assert.ok(Math.abs(start.height - far) < 1);
|
||||
const FAR = 4e8;
|
||||
const PLANET = { lon: 10.4, lat: 51.1, height: 23e6 };
|
||||
const unwrap = (lon, near) => lon + 360 * Math.round((near - lon) / 360);
|
||||
|
||||
test('the globe grows to the planet first, then turns there to a stop', () => {
|
||||
const flight = openingFlight({ target: PLANET, farHeight: FAR });
|
||||
assert.equal(flight.ms, PLANET_FLIGHT_MS, 'nothing to close in on');
|
||||
const start = flight.pose(0);
|
||||
assert.ok(Math.abs(start.height - FAR) < 1);
|
||||
assert.equal(start.lat, 0);
|
||||
const end = openingPose(1, { target: TARGET, farHeight: far });
|
||||
assert.ok(Math.abs(end.lon - TARGET.lon) < 1e-9);
|
||||
assert.ok(Math.abs(end.lat - TARGET.lat) < 1e-9);
|
||||
assert.ok(Math.abs(end.height - TARGET.height) < 1e-3);
|
||||
assert.ok(
|
||||
Math.abs(flight.pose(OPENING.zoomMs).height - PLANET.height) < 1,
|
||||
'the whole planet first',
|
||||
);
|
||||
// Unwrapped longitude falls all the way (the camera moves west, so the
|
||||
// surface turns east), fastest at first.
|
||||
let previous = Infinity;
|
||||
// surface turns east), from halfway through the zoom, slowing to a stop.
|
||||
const spinFrom = OPENING.zoomMs / 2;
|
||||
let previous = PLANET.lon + OPENING.spinDeg;
|
||||
let previousStep = Infinity;
|
||||
for (let i = 0; i <= 10; i++) {
|
||||
const f = i / 10;
|
||||
const unwrapped = TARGET.lon + OPENING.spinDeg * (1 - (1 - (1 - f) ** 3));
|
||||
assert.ok(unwrapped <= previous);
|
||||
if (i > 0) {
|
||||
const step = previous - unwrapped;
|
||||
assert.ok(step <= previousStep + 1e-9, 'the turn slows');
|
||||
previousStep = step;
|
||||
}
|
||||
previous = unwrapped;
|
||||
const pose = openingPose(f, { target: TARGET, farHeight: far });
|
||||
for (let i = 0; i <= 100; i++) {
|
||||
const at = spinFrom + ((flight.ms - spinFrom) * i) / 100;
|
||||
const pose = flight.pose(at);
|
||||
if (at >= OPENING.zoomMs)
|
||||
assert.ok(Math.abs(pose.height - PLANET.height) < 1, 'turns at size');
|
||||
assert.ok(pose.lon >= -180 && pose.lon < 180);
|
||||
const lon = unwrap(pose.lon, previous);
|
||||
const step = previous - lon;
|
||||
assert.ok(step >= -1e-9, 'west to east');
|
||||
if (i > 1) assert.ok(step <= previousStep + 1e-9, 'the turn slows');
|
||||
previous = lon;
|
||||
previousStep = step;
|
||||
}
|
||||
assert.ok(Math.abs(previous - PLANET.lon) < 1e-9, 'one whole turn');
|
||||
const end = flight.pose(flight.ms);
|
||||
assert.ok(Math.abs(end.lon - PLANET.lon) < 1e-9);
|
||||
assert.ok(Math.abs(end.lat - PLANET.lat) < 1e-9);
|
||||
assert.equal(end.pitch, -Math.PI / 2);
|
||||
});
|
||||
|
||||
test('a view at an angle is reached by turning over the last part', () => {
|
||||
test('a closer view at an angle is closed in on after the turn', () => {
|
||||
const angled = {
|
||||
lon: 2.35,
|
||||
lat: 48.86,
|
||||
@@ -93,15 +105,29 @@ test('a view at an angle is reached by turning over the last part', () => {
|
||||
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 });
|
||||
const flight = openingFlight({ target: angled, farHeight: FAR });
|
||||
assert.ok(flight.ms > PLANET_FLIGHT_MS);
|
||||
assert.ok(flight.ms <= PLANET_FLIGHT_MS + OPENING.approachMs[1]);
|
||||
const turned = flight.pose(PLANET_FLIGHT_MS);
|
||||
assert.ok(Math.abs(turned.height - 23e6) < 1, 'over the whole planet');
|
||||
assert.ok(Math.abs(turned.lon - angled.lon) < 1e-9);
|
||||
assert.ok(Math.abs(turned.lat - angled.lat) < 1e-9);
|
||||
assert.ok(Math.abs(turned.heading) < 1e-12);
|
||||
assert.equal(turned.pitch, -Math.PI / 2, 'straight down until then');
|
||||
const end = flight.pose(flight.ms);
|
||||
// 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);
|
||||
assert.ok(Math.abs(end.lon - angled.lon) < 1e-9);
|
||||
});
|
||||
|
||||
test('a view further out than the planet turns at that height', () => {
|
||||
const far = { lon: -97.74, lat: 0, height: 2.8e8 };
|
||||
const flight = openingFlight({ target: far, farHeight: FAR });
|
||||
assert.equal(flight.ms, PLANET_FLIGHT_MS);
|
||||
assert.ok(Math.abs(flight.pose(OPENING.zoomMs).height - far.height) < 1);
|
||||
assert.ok(Math.abs(flight.pose(flight.ms).height - far.height) < 1);
|
||||
});
|
||||
|
||||
test('the far start draws the globe the size of the pupil', () => {
|
||||
@@ -202,7 +228,7 @@ test('the opening runs to the start view, then hides the cover', async () => {
|
||||
assert.equal(s.screen.style.getPropertyValue('--opening-veil'), '0');
|
||||
s.advance(Math.max(OPENING.eyeMs, OPENING.pupilMs[1]));
|
||||
assert.ok(s.screen.classList.contains('hidden'));
|
||||
s.advance(OPENING.flightMs);
|
||||
s.advance(10000);
|
||||
await opening.done;
|
||||
const last = s.views.at(-1);
|
||||
assert.deepEqual(last.destination, LANDED);
|
||||
|
||||
@@ -35,15 +35,26 @@ export function startApplicationChrome({
|
||||
.then(([restored] = []) => {
|
||||
if (disposed || signal.aborted) return;
|
||||
// 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;
|
||||
// (it ends where the camera stands); welcome waits for its end. Its
|
||||
// frames stay out of the address, held before the first one: a reload
|
||||
// or a copied link mid-flight would open on a speck of a planet.
|
||||
const shareLink = styleManager.shareLinkManager;
|
||||
const wanted =
|
||||
!!playOpening &&
|
||||
(!styleManager.hasShareState || sharesOnlyAView(restored));
|
||||
if (wanted) shareLink?.holdWrites?.(true, 'opening');
|
||||
opening = wanted
|
||||
? playOpening({ viewer: styleManager.viewer, loadingScreen })
|
||||
: null;
|
||||
const release = () => shareLink?.holdWrites?.(false, 'opening');
|
||||
if (opening) {
|
||||
void opening.done.then(revealFirstRun);
|
||||
void opening.done.then(() => {
|
||||
release();
|
||||
revealFirstRun();
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (wanted) release();
|
||||
loadingScreen.classList.add('hidden');
|
||||
loadingScreen.addEventListener('transitionend', revealFirstRun, {
|
||||
once: true,
|
||||
|
||||
+13
-4
@@ -126,6 +126,8 @@ export class ShareLinkManager {
|
||||
this._panelStateProvider = null;
|
||||
this._styleParamStateProvider = null;
|
||||
this._initialRestorePending = false;
|
||||
// Who holds the hash writes (holdWrites).
|
||||
this._writeHolds = new Set();
|
||||
// Each incoming share (start-up or a later hash navigation) gets a token;
|
||||
// only the newest one may release URL-write suppression.
|
||||
this._restoreToken = 0;
|
||||
@@ -726,10 +728,12 @@ export class ShareLinkManager {
|
||||
/**
|
||||
* Hold the address's hash writes, for an owner that covers the view and
|
||||
* keeps the person's camera and layers out of the address while it does
|
||||
* (Stories). Releasing writes the current view again.
|
||||
* (Stories, the opening's flight). Each `owner` holds and releases its own
|
||||
* hold; once none holds, the current view is written again.
|
||||
* @param {boolean} held
|
||||
* @param {string} [owner]
|
||||
*/
|
||||
holdWrites(held) {
|
||||
holdWrites(held, owner = 'stories') {
|
||||
if (held && !this._writesHeld && this._debounceTimer) {
|
||||
// A view change still waiting for its debounce is written first, so
|
||||
// the address the owner saves is the live view.
|
||||
@@ -737,11 +741,16 @@ export class ShareLinkManager {
|
||||
this._debounceTimer = null;
|
||||
this._updateHash();
|
||||
}
|
||||
this._writesHeld = !!held;
|
||||
if (!held) this._scheduleUpdate();
|
||||
if (held) this._writeHolds.add(owner);
|
||||
else this._writeHolds.delete(owner);
|
||||
if (!this._writesHeld) this._scheduleUpdate();
|
||||
else clearTimeout(this._debounceTimer);
|
||||
}
|
||||
|
||||
get _writesHeld() {
|
||||
return this._writeHolds.size > 0;
|
||||
}
|
||||
|
||||
_scheduleUpdate() {
|
||||
if (this._destroyed || this._initialRestorePending || this._writesHeld)
|
||||
return;
|
||||
|
||||
@@ -193,6 +193,21 @@ test('holding writes first writes a view change still waiting for its debounce',
|
||||
manager.destroy();
|
||||
});
|
||||
|
||||
test('each owner releases only its own hold on writes', (t) => {
|
||||
installTab(t, SHARE_A);
|
||||
const timers = installManualTimers(t);
|
||||
const manager = new ShareLinkManager(bindFakeCesiumCamera(fakeViewer()));
|
||||
manager.completeInitialRestore(manager.parseInitialHash().restoreToken);
|
||||
manager.holdWrites(true, 'opening');
|
||||
manager.holdWrites(true);
|
||||
manager.holdWrites(false, 'opening');
|
||||
manager._scheduleUpdate();
|
||||
assert.equal(timers.size, 0, 'Stories still holds them');
|
||||
manager.holdWrites(false);
|
||||
assert.equal(timers.size, 1, 'written again once none holds');
|
||||
manager.destroy();
|
||||
});
|
||||
|
||||
test('a hash write keeps the state another owner stored on the entry', (t) => {
|
||||
installTab(t, SHARE_A);
|
||||
const written = [];
|
||||
@@ -526,7 +541,9 @@ test('a copied link carries the Data Library selection to a clean recipient', (t
|
||||
sharer.setLibraryParamsEncoder((params) => params.set('lib', '03.0a'));
|
||||
const code = new URL(sharer.buildLink()).pathname.split('/').at(-1);
|
||||
sharer.destroy();
|
||||
const opener = new ShareLinkManager(bindFakeCesiumCamera(fakeViewer()), { initialShareCode: code });
|
||||
const opener = new ShareLinkManager(bindFakeCesiumCamera(fakeViewer()), {
|
||||
initialShareCode: code,
|
||||
});
|
||||
assert.deepEqual(opener.parseInitialHash().library, ['03', '0a']);
|
||||
assert.deepEqual(opener.initialLibraryTokens, ['03', '0a']);
|
||||
opener.destroy();
|
||||
|
||||
@@ -10,7 +10,7 @@ const source = readFileSync(
|
||||
.replace(/^import .*;\n/gm, '')
|
||||
.replace('export function', 'function');
|
||||
|
||||
function fixture({ playOpening, hasShareState = false } = {}) {
|
||||
function fixture({ playOpening, hasShareState = false, shareLink } = {}) {
|
||||
const timers = new Map();
|
||||
const listeners = new Map();
|
||||
const events = [];
|
||||
@@ -48,6 +48,7 @@ function fixture({ playOpening, hasShareState = false } = {}) {
|
||||
styleManager: {
|
||||
hasShareState,
|
||||
viewer: 'viewer',
|
||||
shareLinkManager: shareLink,
|
||||
initialRestorePromise: new Promise((resolve) => {
|
||||
restored = resolve;
|
||||
}),
|
||||
@@ -163,6 +164,44 @@ test('a bare address plays the opening, and welcome waits for its end', async ()
|
||||
assert.ok(events.includes('opening:cancel'));
|
||||
});
|
||||
|
||||
test("the opening's frames stay out of the address until it ends", async () => {
|
||||
const events = [];
|
||||
const holds = [];
|
||||
const opening = openingStub(events);
|
||||
const f = fixture({
|
||||
playOpening: opening.play,
|
||||
shareLink: { holdWrites: (held, owner) => holds.push([held, owner]) },
|
||||
});
|
||||
f.restored();
|
||||
f.fire(1000);
|
||||
await flush();
|
||||
assert.deepEqual(holds, [[true, 'opening']]);
|
||||
opening.land();
|
||||
await flush();
|
||||
assert.deepEqual(holds, [
|
||||
[true, 'opening'],
|
||||
[false, 'opening'],
|
||||
]);
|
||||
await f.stop();
|
||||
});
|
||||
|
||||
test('an opening that does not play releases the address at once', async () => {
|
||||
const holds = [];
|
||||
const f = fixture({
|
||||
playOpening: () => null,
|
||||
shareLink: { holdWrites: (held, owner) => holds.push([held, owner]) },
|
||||
});
|
||||
f.restored();
|
||||
f.fire(1000);
|
||||
await flush();
|
||||
assert.deepEqual(holds, [
|
||||
[true, 'opening'],
|
||||
[false, 'opening'],
|
||||
]);
|
||||
assert.ok(f.events.includes('hidden'));
|
||||
await f.stop();
|
||||
});
|
||||
|
||||
const VIEW_ONLY = Object.freeze({
|
||||
status: 'settled',
|
||||
share: { camera: 'applied' },
|
||||
|
||||
Reference in new issue
Block a user