mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
Stories: GEV scenes as stories on the live globe
A Stories button (top right) opens Explore: a feed of GEV scenes over GEV's own Cesium globe, with a pin per story. Explore opens at country level over the first story and, while idle, flies on from story to story for a minute. A picked story is framed in the middle of the view; a pin plays its story on a second click. The Story page plays the scene through SceneDirector with a timeline, chapters, key moments, sources and background, then Close (or Back) puts the person's camera, clock, layers, style and AUTHORING selection back. Open in GEV hands the scene to the Scenes panel at its current shot. Stories lists the scenes GEV ships with a camera path (while they are in the project), the scenes saved with SAVE TO STORIES in AUTHORING, and the person's other scenes as drafts. The person's own stories live in the project on this device, so they have no Share; a link to a story that is not here opens Explore and says so. Each shipped story's context comes from what GEV knows: what it shows, the place each shot goes, and each layer's data sources as DATA_SOURCES.md lists them; the Nepal story carries the event pack's facts and CC BY-NC sources. Card images are a captured THUMBNAIL or drawn from the keyless Esri World Imagery. AUTHORING has no scene picker: it starts with no scene, NEW SCENE (or CAPTURE SHOT) makes one, and Stories' Open in GEV selects one. Before SAVE TO STORIES it offers topic tags and THUMBNAIL. A scene's stories flag, storyThumb and storyTags are saved with the project and kept through export and import. Only the closed state loads with the page; the screens, styles, story data and controller load on first open. Stories keeps its place in the query (one history entry per screen) and holds the share link's hash writes while open. Keyboard input and voice tools stay with Stories while it is open. Explore's pins move on every drawn frame without asking for frames; the idle tour and tile settling are bounded. All strings are translated in the 13 locales.
This commit is contained in:
1 parent
da81cf743b
commit
5418438339
77 files changed
+14975
-260
No files matched your search
@@ -0,0 +1,143 @@
|
||||
import { chapterAt } from './format.js';
|
||||
|
||||
/** Longest Stories waits for a scene to tear down before going on anyway. */
|
||||
export const SETTLE_LIMIT_MS = 15000;
|
||||
|
||||
/**
|
||||
* Resolves once the director is idle: no run, and every LOAD, seek and
|
||||
* interaction settled (SceneDirector.whenIdle). A teardown that never
|
||||
* finishes is given SETTLE_LIMIT_MS, so a stuck scene cannot leave Stories
|
||||
* unable to close; that case is logged.
|
||||
* @param {import('../scenes/director.js').SceneDirector} director
|
||||
*/
|
||||
export function directorSettled(director) {
|
||||
let timer = 0;
|
||||
const limit = new Promise((resolve) => {
|
||||
timer = setTimeout(() => {
|
||||
console.warn('Stories: the scene did not finish tearing down; going on');
|
||||
resolve();
|
||||
}, SETTLE_LIMIT_MS);
|
||||
});
|
||||
// A failure to wait counts as settled: the view still comes back.
|
||||
const idle = Promise.resolve()
|
||||
.then(() => director.whenIdle())
|
||||
.catch(() => {});
|
||||
return Promise.race([idle, limit]).finally(() => clearTimeout(timer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Plays a scene GEV already ships through SceneDirector, the way the Scene
|
||||
* panel plays it, and reports the scene clock in the shape the Stories
|
||||
* timeline reads. SceneDirector has no pause: pausing seeks to the current
|
||||
* moment (which stops the run and frames it), and playing again starts the
|
||||
* run at the shot that moment is in.
|
||||
*
|
||||
* @param {import('../scenes/director.js').SceneDirector} director
|
||||
* @param {object} story A catalog story of kind 'gev'.
|
||||
* @param {{onTick?: (state: object) => void}} [hooks]
|
||||
*/
|
||||
export function createGevPlayer(director, story, hooks = {}) {
|
||||
const sceneId = story.sceneId;
|
||||
let wallMs = 0;
|
||||
let durationMs = story.durationMs;
|
||||
let playing = false;
|
||||
let shotIndex = 0;
|
||||
let destroyed = false;
|
||||
// Each Play, Pause, Seek and Destroy takes a new number; a Play that waited
|
||||
// for a teardown or a start goes ahead only if nothing came after it.
|
||||
let request = 0;
|
||||
|
||||
const state = () => ({
|
||||
wallMs,
|
||||
worldMs: null,
|
||||
durationMs,
|
||||
playing,
|
||||
exploring: false,
|
||||
chapterIndex: Math.min(shotIndex, story.chapters.length - 1),
|
||||
});
|
||||
const tick = () => {
|
||||
if (!destroyed) hooks.onTick?.(state());
|
||||
};
|
||||
|
||||
const unsubscribe = director.subscribeSceneClock((snap) => {
|
||||
if (destroyed || !snap || snap.sceneId !== sceneId) return;
|
||||
if (snap.sceneDurationSec) durationMs = snap.sceneDurationSec * 1000;
|
||||
wallMs = (snap.sceneElapsedSec ?? 0) * 1000;
|
||||
shotIndex = snap.shotIndex ?? shotIndex;
|
||||
playing = !!snap.running && !snap.seeking;
|
||||
if (!playing && wallMs >= durationMs - 250) wallMs = durationMs;
|
||||
tick();
|
||||
});
|
||||
|
||||
// A run from the previous story may still be releasing the camera.
|
||||
async function idle() {
|
||||
if (!director.running) return;
|
||||
director.stopScene();
|
||||
await directorSettled(director);
|
||||
}
|
||||
|
||||
return {
|
||||
kind: 'gev',
|
||||
story,
|
||||
get state() {
|
||||
return state();
|
||||
},
|
||||
async play() {
|
||||
const mine = ++request;
|
||||
await idle();
|
||||
if (destroyed || mine !== request || director.running) return;
|
||||
if (wallMs >= durationMs - 250) {
|
||||
wallMs = 0;
|
||||
shotIndex = 0;
|
||||
}
|
||||
const shots = director.listShots(sceneId);
|
||||
const afterShotId =
|
||||
shotIndex > 0 ? (shots[shotIndex - 1]?.id ?? null) : null;
|
||||
playing = true;
|
||||
tick();
|
||||
const result = await director.startScene(sceneId, {
|
||||
single: true,
|
||||
afterShotId,
|
||||
preview: true,
|
||||
});
|
||||
if (destroyed) return;
|
||||
if (mine !== request) {
|
||||
// Paused or scrubbed while the run was starting: that wins.
|
||||
if (result?.started)
|
||||
director.seekScene(sceneId, durationMs ? wallMs / durationMs : 0);
|
||||
return;
|
||||
}
|
||||
if (!result?.started) {
|
||||
playing = false;
|
||||
tick();
|
||||
}
|
||||
},
|
||||
pause() {
|
||||
request += 1;
|
||||
playing = false;
|
||||
director.seekScene(sceneId, durationMs ? wallMs / durationMs : 0);
|
||||
tick();
|
||||
},
|
||||
seek(ms) {
|
||||
request += 1;
|
||||
wallMs = Math.max(0, Math.min(durationMs, ms));
|
||||
shotIndex = chapterAt(story, wallMs);
|
||||
playing = false;
|
||||
director.seekScene(sceneId, durationMs ? wallMs / durationMs : 0);
|
||||
tick();
|
||||
},
|
||||
resume() {
|
||||
return this.play();
|
||||
},
|
||||
/** A key moment: go to that point of the scene. */
|
||||
focus(event) {
|
||||
if (event?.wallMs != null) this.seek(event.wallMs);
|
||||
},
|
||||
destroy() {
|
||||
request += 1;
|
||||
destroyed = true;
|
||||
unsubscribe?.();
|
||||
director.stopScene();
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user