mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
Brings in main up to f24abfc88: cockpit subject providers, the render
failure notice, aircraft drawn in their own mesh colours, airport ground
vehicles, and an aircraft with no ground track facing its true heading.
Under the seam:
- The render failure notice lives in the Cesium adapter
(src/render/cesium/renderFailure.js) and is the application hook
renderFailureNotice({allowReload, store}); its private Cesium fields
(Event's raise queue, the widget's render loop flag) are read through
internals.js. The inline panel's timer waits while the frame port reports
the loop stopped, and goes on after a Retry.
- Ordinary aircraft models draw white with the 'highlight' colour blend
through the draw port; tracked and emergency colours tint the mesh.
- Held trains and transit vehicles hide their route set and markers through
the draw port; the fleet model test fakes answer loads through the fake
draw port instead of Cesium's glTF loader.
- The Cockpit's subject view follows and places the camera through the
camera port.
305 lines
14 KiB
JavaScript
305 lines
14 KiB
JavaScript
import { readLayerSource } from '../testSupport/readLayerSource.mjs';
|
|
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readFile } from 'node:fs/promises';
|
|
import {
|
|
_setTrackedOverlayHostForTest,
|
|
cachedTrackedDisplayPosition,
|
|
cachedTrackedVisualPosition,
|
|
createTrackedOverlayEntry,
|
|
destroyTrackedReadout,
|
|
getActiveTrackedReadoutId,
|
|
initTrackedReadout,
|
|
refreshTrackedReadout,
|
|
trackedLabelModelFromText,
|
|
} from './trackedReadout.js';
|
|
import { entityRecord, readEntityRecord, withEntityRecord } from './entityRecords.js';
|
|
import { entityFollowTarget } from './followed.js';
|
|
import { bindRenderer } from '../render/rendererOf.js';
|
|
|
|
function makeCesiumEvent() {
|
|
const listeners = new Set();
|
|
return {
|
|
addEventListener(callback) {
|
|
listeners.add(callback);
|
|
return () => listeners.delete(callback);
|
|
},
|
|
raise() { for (const callback of [...listeners]) callback(); },
|
|
get size() { return listeners.size; },
|
|
};
|
|
}
|
|
|
|
/**
|
|
* A viewer whose camera port follows `entity` (null: nothing), with
|
|
* `follow(next)` to change it and announce the change on `changed`.
|
|
*/
|
|
function followingViewer(entity, changed) {
|
|
const camera = {
|
|
followed: null,
|
|
on: (event, callback) =>
|
|
event === 'followChanged' ? changed.addEventListener(callback) : () => {},
|
|
};
|
|
const viewer = {};
|
|
bindRenderer(viewer, { camera });
|
|
const follow = (next) => {
|
|
camera.followed = next ? entityFollowTarget(next, {}) : null;
|
|
};
|
|
follow(entity);
|
|
return {
|
|
viewer,
|
|
follow(next) {
|
|
follow(next);
|
|
changed.raise();
|
|
},
|
|
};
|
|
}
|
|
|
|
function makeHostRecorder() {
|
|
const calls = [];
|
|
return {
|
|
calls,
|
|
host: {
|
|
setEntries(sourceId, entries, options) { calls.push({ op: 'set', sourceId, entries, options }); },
|
|
setVisible(sourceId, visible) { calls.push({ op: 'visible', sourceId, visible }); },
|
|
clearSource(sourceId) { calls.push({ op: 'clear', sourceId }); },
|
|
},
|
|
};
|
|
}
|
|
|
|
test('tracked label text becomes an explicit title/details/accent model', () => {
|
|
assert.deepEqual(
|
|
trackedLabelModelFromText('UAL123 · FL350 · 451 kts', '#39d0ff'),
|
|
{ title: 'UAL123', details: ['FL350 · 451 kts'], accent: '#39d0ff' },
|
|
);
|
|
assert.deepEqual(
|
|
trackedLabelModelFromText('RCH123\nC-17 · 01-0186\nUSAF · FL310', '#ffd166'),
|
|
{
|
|
title: 'RCH123',
|
|
details: ['C-17 · 01-0186', 'USAF · FL310'],
|
|
accent: '#ffd166',
|
|
},
|
|
);
|
|
});
|
|
|
|
test('tracked position source reads only the record\'s displayPosition and never entity.position', () => {
|
|
const cached = { x: 1, y: 2, z: 3 };
|
|
let propertyReads = 0;
|
|
const entity = withEntityRecord({ position: {
|
|
getValue() { propertyReads += 1; throw new Error('fresh position read is forbidden'); },
|
|
} }, { displayPosition: () => cached });
|
|
assert.equal(cachedTrackedDisplayPosition(entity), cached);
|
|
assert.equal(propertyReads, 0);
|
|
assert.equal(cachedTrackedDisplayPosition({ position: entity.position }), null);
|
|
assert.equal(propertyReads, 0);
|
|
});
|
|
|
|
test('the tracked card anchors to the visual position without repurposing the display accessor', () => {
|
|
// A grounded aircraft's 3D model rides a ground snap while its billboard stays
|
|
// at the reported (buried) altitude — ~100 m apart. The card must follow the
|
|
// model you can see, while the record's `displayPosition` keeps returning the cached
|
|
// dead-reckoned value the follow camera settled on (anti-jitter contract).
|
|
const display = { x: 1, y: 2, z: 3 };
|
|
const visual = { x: 1, y: 2, z: 103 };
|
|
let displayReads = 0;
|
|
const entity = withEntityRecord({}, { trackedId: 'flights:aaa077', displayPosition: () => { displayReads += 1; return display; }, visualPosition: () => visual, labelModel: { title: 'SWA143', details: ['ON GROUND'], accent: '#6be8ff' } });
|
|
assert.equal(cachedTrackedVisualPosition(entity), visual);
|
|
assert.equal(displayReads, 0, 'the visual accessor short-circuits the display read');
|
|
assert.equal(cachedTrackedDisplayPosition(entity), display,
|
|
'the display accessor is untouched and still reports the dead-reckoned position');
|
|
assert.equal(createTrackedOverlayEntry(entity).position(), visual,
|
|
'the published tracked entry anchors to the visual position');
|
|
|
|
// Layers with no 3D visual, and any layer before its model is ready, are
|
|
// unchanged: the accessor falls back to the display position.
|
|
const spriteOnly = withEntityRecord({}, { displayPosition: () => display });
|
|
assert.equal(cachedTrackedVisualPosition(spriteOnly), display);
|
|
assert.equal(cachedTrackedVisualPosition(withEntityRecord({}, { displayPosition: () => display, visualPosition: () => null })), display,
|
|
'a null visual position falls back rather than blanking the card');
|
|
assert.equal(
|
|
cachedTrackedVisualPosition(withEntityRecord({}, { displayPosition: () => display, visualPosition: () => { throw new Error('model gone'); } })),
|
|
display,
|
|
'a throwing visual accessor falls back instead of dropping the card',
|
|
);
|
|
assert.equal(cachedTrackedVisualPosition(null), null);
|
|
});
|
|
|
|
test('tracked entry factory pins the production protected-lane policy', () => {
|
|
const display = { x: 4, y: 5, z: 6 };
|
|
const entry = createTrackedOverlayEntry(withEntityRecord({}, { trackedId: 'satellites:25544', displayPosition: () => display, labelModel: { title: 'ISS', details: ['420 km · NORAD 25544'], accent: '#ffd84d' } }));
|
|
assert.equal(entry.id, 'satellites:25544');
|
|
assert.equal(entry.position(), display);
|
|
assert.equal(entry.protected, true);
|
|
assert.equal(entry.paintLane, 'tracked');
|
|
assert.equal(entry.collisionGroup, 'ambient-card');
|
|
assert.equal(entry.edgeFade, 'keyhole');
|
|
});
|
|
|
|
test('selected camera readout carries tactical animation and fixed badge clearance', () => {
|
|
const entry = createTrackedOverlayEntry(withEntityRecord({ id: 'alpr:42' }, { displayPosition: () => ({ x: 1, y: 2, z: 3 }), labelModel: {
|
|
title: 'ALPR-0042', details: ['OSM MAPPED'], accent: '#ff6474',
|
|
cardStyle: 'tactical', selected: true, leaderStyle: 'elbow',
|
|
leaderAnimationMs: 440, leaderAnimationStartedAt: 100, leaderDrawRatio: 0.68,
|
|
anchorRadiusPx: 30, anchorRadiusScale: null,
|
|
} }));
|
|
assert.equal(entry.cardStyle, 'tactical');
|
|
assert.equal(entry.selected, true);
|
|
assert.equal(entry.leaderStyle, 'elbow');
|
|
assert.equal(entry.leaderAnimationMs, 440);
|
|
assert.equal(entry.leaderAnimationStartedAt, 100);
|
|
assert.equal(entry.leaderDrawRatio, 0.68);
|
|
assert.equal(entry.anchorRadiusPx, 30);
|
|
assert.equal(entry.anchorRadiusScale, null);
|
|
});
|
|
|
|
test('tracked entity publishes a protected host entry backed by the frame cache', () => {
|
|
const originalWindow = globalThis.window;
|
|
const fakeWindow = new EventTarget();
|
|
const changed = makeCesiumEvent();
|
|
const display = { x: 10, y: 20, z: 30 };
|
|
const entity = withEntityRecord({ id: 'generated' }, { trackedId: 'flights:abc123', displayPosition: () => display, labelModel: { title: 'UAL123', details: ['FL350 · 451 kts'], accent: '#39d0ff' } });
|
|
const { viewer, follow } = followingViewer(entity, changed);
|
|
const recorder = makeHostRecorder();
|
|
globalThis.window = fakeWindow;
|
|
_setTrackedOverlayHostForTest(recorder.host);
|
|
try {
|
|
initTrackedReadout(viewer);
|
|
const publication = recorder.calls.find(({ op }) => op === 'set');
|
|
assert.ok(publication);
|
|
assert.equal(publication.sourceId, 'tracked');
|
|
assert.equal(publication.entries.length, 1);
|
|
const entry = publication.entries[0];
|
|
assert.equal(entry.id, 'flights:abc123');
|
|
assert.equal(entry.variant, 'tracked');
|
|
assert.equal(entry.tracked, true);
|
|
assert.equal(entry.protected, true);
|
|
assert.equal(entry.paintLane, 'tracked');
|
|
assert.equal(entry.collisionGroup, 'ambient-card');
|
|
assert.equal(entry.position(), display);
|
|
assert.equal(publication.options.collisionCapacity, 0);
|
|
assert.equal(publication.options.hideInCockpit, true);
|
|
assert.equal(getActiveTrackedReadoutId(), 'flights:abc123');
|
|
|
|
entityRecord(entity).labelModel = { ...readEntityRecord(entity)?.labelModel, details: ['FL360 · 455 kts'] };
|
|
refreshTrackedReadout(entity);
|
|
assert.deepEqual(recorder.calls.filter(({ op }) => op === 'set').at(-1).entries[0].details, [
|
|
'FL360 · 455 kts',
|
|
]);
|
|
|
|
follow(null);
|
|
assert.equal(getActiveTrackedReadoutId(), null);
|
|
assert.equal(recorder.calls.at(-1).op, 'clear');
|
|
} finally {
|
|
destroyTrackedReadout();
|
|
_setTrackedOverlayHostForTest();
|
|
globalThis.window = originalWindow;
|
|
}
|
|
});
|
|
|
|
test('selection lifecycle leaves installations to their own entry and retains ALPR cards', () => {
|
|
const originalWindow = globalThis.window;
|
|
const fakeWindow = new EventTarget();
|
|
const changed = makeCesiumEvent();
|
|
const { viewer } = followingViewer(null, changed);
|
|
const recorder = makeHostRecorder();
|
|
const installation = withEntityRecord({}, { trackedId: 'installations:fort-test', displayPosition: () => ({ x: 1, y: 2, z: 3 }), labelModel: { title: 'FORT TEST', details: ['AIRFIELD'], accent: '#5aa9ff' } });
|
|
globalThis.window = fakeWindow;
|
|
_setTrackedOverlayHostForTest(recorder.host);
|
|
try {
|
|
initTrackedReadout(viewer);
|
|
const setsBefore = recorder.calls.filter(({ op }) => op === 'set').length;
|
|
fakeWindow.dispatchEvent(new CustomEvent('gev:entity-selected', {
|
|
detail: { layerId: 'ais-live-vessels', entity: installation },
|
|
}));
|
|
assert.equal(recorder.calls.filter(({ op }) => op === 'set').length, setsBefore);
|
|
|
|
fakeWindow.dispatchEvent(new CustomEvent('gev:entity-selected', {
|
|
detail: { layerId: 'military-installations', entity: installation },
|
|
}));
|
|
assert.equal(getActiveTrackedReadoutId(), null);
|
|
assert.equal(recorder.calls.filter(({ op }) => op === 'set').length, setsBefore, 'installation selection cannot create a second overlay');
|
|
|
|
// ALPR cameras are static context too: a click publishes the same card.
|
|
const camera = withEntityRecord({}, { trackedId: 'alpr:42', displayPosition: () => ({ x: 4, y: 5, z: 6 }), labelModel: { title: 'FLOCK SAFETY ALPR', details: ['CITY PD'], accent: '#ff66c4' } });
|
|
fakeWindow.dispatchEvent(new CustomEvent('gev:entity-selected', {
|
|
detail: { layerId: 'alpr-cameras', entity: camera },
|
|
}));
|
|
assert.equal(getActiveTrackedReadoutId(), 'alpr:42');
|
|
assert.equal(recorder.calls.filter(({ op }) => op === 'set').at(-1).entries[0].title, 'FLOCK SAFETY ALPR');
|
|
|
|
fakeWindow.dispatchEvent(new CustomEvent('gev:entity-selected', {
|
|
detail: { layerId: 'ais-live-vessels', entity: installation },
|
|
}));
|
|
assert.equal(getActiveTrackedReadoutId(), null, 'sibling selection clears an installation card');
|
|
|
|
fakeWindow.dispatchEvent(new CustomEvent('gev:entity-selected', {
|
|
detail: { layerId: 'military-installations', entity: installation },
|
|
}));
|
|
|
|
fakeWindow.dispatchEvent(new CustomEvent('gev:entity-selection-cleared', {
|
|
detail: { layerId: 'military-installations' },
|
|
}));
|
|
assert.equal(getActiveTrackedReadoutId(), null);
|
|
assert.ok(recorder.calls.some(({ op }) => op === 'clear'));
|
|
|
|
const clearsBeforeDestroy = recorder.calls.filter(({ op }) => op === 'clear').length;
|
|
destroyTrackedReadout();
|
|
assert.ok(recorder.calls.filter(({ op }) => op === 'clear').length > clearsBeforeDestroy);
|
|
assert.equal(changed.size, 0, 'the followChanged listener was removed');
|
|
assert.ok(recorder.calls.some(({ op, visible }) => op === 'visible' && visible === false));
|
|
} finally {
|
|
destroyTrackedReadout();
|
|
_setTrackedOverlayHostForTest();
|
|
globalThis.window = originalWindow;
|
|
}
|
|
});
|
|
|
|
test('trackedReadout cannot resurrect a dedicated canvas or render listener', async () => {
|
|
const source = await readFile(new URL('./trackedReadout.js', import.meta.url), 'utf8');
|
|
for (const forbidden of [
|
|
'document.createElement',
|
|
"createElement('canvas')",
|
|
'postRender.addEventListener',
|
|
'worldToWindowCoordinates',
|
|
"id = 'tracked-readout'",
|
|
'keyholeLabelAlpha',
|
|
]) {
|
|
assert.equal(source.includes(forbidden), false, `dedicated renderer token returned: ${forbidden}`);
|
|
}
|
|
});
|
|
|
|
test('tracking layers write the record\'s labelModel and expose only their cached display positions', async () => {
|
|
const files = await Promise.all([
|
|
'flights.js',
|
|
'militaryFlights.js',
|
|
'satellites.js',
|
|
'militaryInstallations.js',
|
|
].map(async (name) => [name, readLayerSource(new URL(`./${name}`, import.meta.url))]));
|
|
const sources = Object.fromEntries(files);
|
|
for (const [name, source] of files) {
|
|
assert.match(source, /entityRecord\([^)]*\)\.labelModel\s*=/, `${name} writes the explicit model into the entity record`);
|
|
assert.match(source, /entityRecord\([^)]*\)\.displayPosition\s*=/, `${name} exposes a display-position cache in the entity record`);
|
|
assert.doesNotMatch(source, /\.gev(LabelModel|DisplayPosition|VisualPosition|TrackedId|SelectionOrigin)\b/, `${name} hangs no tracked state on the entity`);
|
|
}
|
|
assert.match(sources['flights.js'], /entityRecord\([^)]*\)\.displayPosition\s*=\s*parts\.motion\._trackedDisplayCached/);
|
|
assert.match(sources['militaryFlights.js'], /entityRecord\([^)]*\)\.displayPosition\s*=\s*parts\.motion\._trackedDisplayCached/);
|
|
assert.match(
|
|
sources['satellites.js'],
|
|
/entityRecord\([^)]*\)\.displayPosition\s*=\s*_trackedDisplayCached/,
|
|
);
|
|
assert.equal(sources['flights.js'].includes('_trackedEntity.label.text'), false);
|
|
assert.equal(sources['militaryFlights.js'].includes('_trackedEntity.label.text'), false);
|
|
assert.equal(sources['satellites.js'].includes('_trackedEntity.label.text'), false);
|
|
});
|
|
|
|
test('civilian and military trail heads use the lower-centre model anchor', async () => {
|
|
const files = await Promise.all(['flights.js', 'militaryFlights.js'].map(async (name) => (
|
|
[name, readLayerSource(new URL(`./${name}`, import.meta.url))]
|
|
)));
|
|
for (const [name, source] of files) {
|
|
assert.ok(
|
|
(/const\s*head\s*=\s*(?:parts\.motion\.)?_trackedTrailCached\(\s*,?\s*\)\s*\|\|\s*(?:parts\.motion\.)?_trackedDisplayPosition\(\s*(?:flightState\.)?_trackedIcao,?\s*\);/).test(source),
|
|
`${name} trail head uses the dedicated lower-centre model anchor`,
|
|
);
|
|
}
|
|
});
|