mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 03:02:20 +00:00
Navara now matches Cesium where the review found it diverging: a flight holds the camera inputs, camera.changed counts turns as Cesium does, render requests made during a frame survive it, follow pinches zoom, ground widths follow the pixel ratio and Cyber sonar reaches glyph caches and models. On Cesium, a staged imagery swap keeps loading tiles, setView replaces a running flight, and a cleared weather detail goes away. The contract gains MoverSet.failed, maps.terrainRevision, render.maxTextureSize and surface.sampleTerrainMostDetailed on every engine, so layers retry failed models, key road heights by terrain, size weather textures to the GPU and place Bhote Koshi cards on detailed terrain. Engine switches keep the live view, follows, focus, layer options and cards: a pick hands over the exact pose, applies no address options and pans no carried-over card; a history visit still applies its entry. Layers put GhostMaps pins, cable landings, OSM Places and directions on the measured surface without per-frame sampling, draw the Cockpit contact dot, hide disabled CCTV on attach, and keep ALPR running outside secure contexts. KML imports draw raised polygon fills, rotated and coloured ground overlays and north-referenced icon headings, and report files with nothing to draw. QA scripts read the contract instead of Cesium internals (test:track is 109/109 again), wait for the camera to rest before clicking, and give cold switches and parked engines realistic time. Docs follow the code.
148 lines
4.2 KiB
JavaScript
148 lines
4.2 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createSceneVoice } from './gevRealtime.js';
|
|
import { createTestVoiceUi } from '../testSupport/voiceUi.mjs';
|
|
|
|
function fakeEngine(kind) {
|
|
const canvas = new EventTarget();
|
|
canvas.getBoundingClientRect = () => ({ left: 0, top: 0 });
|
|
return {
|
|
kind,
|
|
host: { canvas, size: () => ({ width: 0, height: 0 }) },
|
|
camera: { pose: () => ({}) },
|
|
};
|
|
}
|
|
|
|
function fixture() {
|
|
const previous = globalThis.window;
|
|
globalThis.window = {};
|
|
const lifetime = new AbortController();
|
|
const adapter = { starts: 0, stops: [], events: [] };
|
|
let runAction;
|
|
const built = [];
|
|
const voice = createSceneVoice({
|
|
signal: lifetime.signal,
|
|
createControl: () => createTestVoiceUi(),
|
|
createCard: () => null,
|
|
createReticle: () => null,
|
|
createRunner: (scene) => {
|
|
built.push(scene);
|
|
return async (name) => ({ ok: true, action: name });
|
|
},
|
|
createSession(hooks) {
|
|
runAction = hooks.runAction;
|
|
return {
|
|
async start() {
|
|
adapter.starts++;
|
|
hooks.emit({ type: 'state', state: 'listening' });
|
|
},
|
|
stop(options) {
|
|
adapter.stops.push(options);
|
|
},
|
|
sendText() {},
|
|
sendMapEvent(event) {
|
|
adapter.events.push(event);
|
|
return true;
|
|
},
|
|
};
|
|
},
|
|
});
|
|
return {
|
|
voice,
|
|
adapter,
|
|
built,
|
|
lifetime,
|
|
run: (...args) => runAction(...args),
|
|
restore: () => {
|
|
globalThis.window = previous;
|
|
},
|
|
};
|
|
}
|
|
|
|
test('an engine switch keeps the voice session and its transport', async () => {
|
|
const f = fixture();
|
|
try {
|
|
const cesium = fakeEngine('cesium');
|
|
f.voice.attachScene({ engine: cesium, viewer: {} });
|
|
await f.voice.commands.start();
|
|
assert.equal(f.adapter.starts, 1);
|
|
assert.equal(f.voice.commands.pointer.element, cesium.host.canvas);
|
|
assert.equal((await f.run('set_layer', {})).engine, 'cesium');
|
|
|
|
f.voice.detachScene();
|
|
assert.deepEqual(f.adapter.stops, [], 'a detach never stops the adapter');
|
|
assert.equal(f.voice.commands.isActive(), true);
|
|
assert.equal(f.voice.commands.pointer.element, null);
|
|
// A call made between the engines waits for the next one.
|
|
const pending = f.run('set_layer', {});
|
|
const navara = fakeEngine('navara');
|
|
f.voice.attachScene({ engine: navara, viewer: null });
|
|
assert.equal((await pending).engine, 'navara');
|
|
assert.equal(f.voice.commands.pointer.element, navara.host.canvas);
|
|
assert.deepEqual(f.adapter.events, [
|
|
{ type: 'engine-changed', engine: 'navara' },
|
|
]);
|
|
assert.equal(f.adapter.starts, 1);
|
|
assert.equal(f.built.length, 2);
|
|
assert.equal(f.built[1].engine, navara);
|
|
|
|
f.lifetime.abort();
|
|
assert.equal(f.adapter.stops.at(-1)?.removeUi, true);
|
|
} finally {
|
|
f.restore();
|
|
}
|
|
});
|
|
|
|
test('annotation outline events reach the session from the attached engine only', async () => {
|
|
const f = fixture();
|
|
try {
|
|
const listeners = new Set();
|
|
const annotations = {
|
|
onOutlineEvent(listener) {
|
|
listeners.add(listener);
|
|
return () => listeners.delete(listener);
|
|
},
|
|
};
|
|
f.voice.attachScene({ engine: fakeEngine('cesium'), annotations });
|
|
await f.voice.commands.start();
|
|
for (const listener of listeners) listener({ status: 'resolved' });
|
|
assert.deepEqual(f.adapter.events, [
|
|
{ type: 'map_annotation_outline', status: 'resolved' },
|
|
]);
|
|
f.voice.detachScene();
|
|
assert.equal(listeners.size, 0);
|
|
} finally {
|
|
f.restore();
|
|
}
|
|
});
|
|
|
|
test('area handles outlive an engine attachment', () => {
|
|
const f = fixture();
|
|
try {
|
|
f.voice.attachScene({ engine: fakeEngine('cesium') });
|
|
const store = f.built[0].areaOptions?.store;
|
|
assert.ok(store);
|
|
const area = store.put({
|
|
name: 'Area',
|
|
source: 'drawn',
|
|
geometry: {
|
|
type: 'Polygon',
|
|
coordinates: [
|
|
[
|
|
[0, 0],
|
|
[1, 0],
|
|
[1, 1],
|
|
[0, 0],
|
|
],
|
|
],
|
|
},
|
|
});
|
|
f.voice.detachScene();
|
|
f.voice.attachScene({ engine: fakeEngine('navara') });
|
|
assert.equal(f.built[1].areaOptions.store.get(area.areaId), area);
|
|
} finally {
|
|
f.lifetime.abort();
|
|
f.restore();
|
|
}
|
|
});
|