mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Take the timeline commits back out before merging their reviewed versions from main
5150279cc,97bd61711,900c76425and4f23ad330went to main, reviewed and changed, as #1745. They are taken out here so main brings them in as merged, rather than as two copies of the same changes in conflict.
This commit is contained in:
1 parent
4f23ad330c
commit
961e6321a5
45 files changed
+1316
-1078
No files matched your search
+8
-85
@@ -14,55 +14,11 @@
|
||||
* src/time/snapshotTimeline.js); otherwise they stay live.
|
||||
*
|
||||
* Playback is continuous (`cursor + elapsed × rate`) unless a driver takes
|
||||
* it: a driver steps the clock itself and moves it as it goes, so play and
|
||||
* pause hand over to it. Several drivers may be attached; play goes to the
|
||||
* newest that can play, pause to the one playing. Layers that load frames
|
||||
* (weather) do not drive it: they gate continuous play at their next frame.
|
||||
* it: weather replay steps its observed frames itself and moves the clock as
|
||||
* it goes, so play and pause hand over to it. Several drivers may be attached;
|
||||
* play goes to the newest that can play, pause to the one playing.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A timeline mark as a layer gives it: its time in epoch ms, and optionally
|
||||
* a short label to show for it, the layer's own id for it and its kind.
|
||||
* @typedef {{time: number, label?: string, id?: string, kind?: string}} WorldClockMarkInput
|
||||
*/
|
||||
|
||||
/**
|
||||
* A timeline mark as `coverage().markDetails` returns it: a finite time, and
|
||||
* only those of `label`, `id` and `kind` that are non-empty strings.
|
||||
* @typedef {Readonly<{time: number, label?: string, id?: string, kind?: string}>} WorldClockMark
|
||||
*/
|
||||
|
||||
const MARK_TEXT = ['label', 'id', 'kind'];
|
||||
|
||||
/**
|
||||
* A mark (a number, or `{time, label?, id?, kind?}`) in its one shape, or
|
||||
* null for one with no finite time.
|
||||
* @param {unknown} input
|
||||
* @returns {WorldClockMark | null}
|
||||
*/
|
||||
function readMark(input) {
|
||||
if (typeof input === 'number')
|
||||
return Number.isFinite(input) ? Object.freeze({ time: input }) : null;
|
||||
if (!input || typeof input !== 'object') return null;
|
||||
const { time } = input;
|
||||
if (typeof time !== 'number' || !Number.isFinite(time)) return null;
|
||||
const mark = { time };
|
||||
for (const key of MARK_TEXT) {
|
||||
const value = input[key];
|
||||
if (typeof value === 'string' && value.trim()) mark[key] = value.trim();
|
||||
}
|
||||
return Object.freeze(mark);
|
||||
}
|
||||
|
||||
// Marks in time order; at one time, by kind, label and id, so the order
|
||||
// never depends on which source registered first.
|
||||
const byText = (a = '', b = '') => (a < b ? -1 : a > b ? 1 : 0);
|
||||
const byMark = (a, b) =>
|
||||
a.time - b.time ||
|
||||
byText(a.kind, b.kind) ||
|
||||
byText(a.label, b.label) ||
|
||||
byText(a.id, b.id);
|
||||
|
||||
/** The span a JS Date can hold, either side of 1970. */
|
||||
const MAX_DATE_MS = 8.64e15;
|
||||
|
||||
@@ -415,15 +371,7 @@ export function createWorldClock({
|
||||
/**
|
||||
* A layer's span of time it can show, for a host's timeline; null while
|
||||
* it has none (off, or nothing loaded). Returns the unregister.
|
||||
*
|
||||
* `marks` are the moments in that span worth going to (a launch, a strong
|
||||
* earthquake), drawn as ticks the timeline's arrow keys step to. Each is
|
||||
* an epoch ms number, or `{time, label?, id?, kind?}`: `label` is short
|
||||
* text the timeline shows for it (a name, `M6.4 · a place`), `id` the
|
||||
* layer's own key for the event and `kind` what sort of event it is.
|
||||
* Numbers and objects may be mixed; a mark with no finite time is
|
||||
* ignored, as are a label, id or kind that is not a non-empty string.
|
||||
* @param {{id: string, coverage: () => ({start: number, end: number, marks?: Array<number | WorldClockMarkInput>} | null)}} source
|
||||
* @param {{id: string, coverage: () => ({start: number, end: number, marks?: number[]} | null)}} source
|
||||
*/
|
||||
register(source) {
|
||||
// Each registration is its own, even under a shared id.
|
||||
@@ -438,45 +386,20 @@ export function createWorldClock({
|
||||
coverageChanged: () => changed(),
|
||||
/** Whether a followed layer has time to show; see getState().supported. */
|
||||
isSupported,
|
||||
/**
|
||||
* The union of the registered sources' coverage, or null with none:
|
||||
* `{start, end, marks, markDetails}`. `marks` is every mark's time, once
|
||||
* each, in order, as numbers. `markDetails` is the marks themselves, in
|
||||
* time order, each `{time, label?, id?, kind?}` (frozen): a mark several
|
||||
* sources give alike is there once, and a bare time is dropped where a
|
||||
* mark with more to say shares it.
|
||||
* @returns {{start: number, end: number, marks: number[], markDetails: WorldClockMark[]} | null}
|
||||
*/
|
||||
/** The union of the registered sources' coverage, or null with none. */
|
||||
coverage() {
|
||||
let start = Infinity;
|
||||
let end = -Infinity;
|
||||
const details = new Map();
|
||||
const marks = new Set();
|
||||
for (const { source } of sources) {
|
||||
const span = spanOf(source);
|
||||
if (!span) continue;
|
||||
start = Math.min(start, span.start);
|
||||
end = Math.max(end, span.end);
|
||||
for (const input of span.marks ?? []) {
|
||||
const mark = readMark(input);
|
||||
if (!mark) continue;
|
||||
const key = JSON.stringify([
|
||||
mark.time,
|
||||
mark.label,
|
||||
mark.id,
|
||||
mark.kind,
|
||||
]);
|
||||
if (!details.has(key)) details.set(key, mark);
|
||||
}
|
||||
for (const mark of span.marks ?? []) marks.add(mark);
|
||||
}
|
||||
if (start > end) return null;
|
||||
const told = new Set();
|
||||
for (const mark of details.values())
|
||||
if (Object.keys(mark).length > 1) told.add(mark.time);
|
||||
const markDetails = [...details.values()]
|
||||
.filter((mark) => Object.keys(mark).length > 1 || !told.has(mark.time))
|
||||
.sort(byMark);
|
||||
const marks = [...new Set(markDetails.map((mark) => mark.time))];
|
||||
return { start, end, marks, markDetails };
|
||||
return { start, end, marks: [...marks].sort((a, b) => a - b) };
|
||||
},
|
||||
|
||||
getState,
|
||||
|
||||
Reference in new issue
Block a user