Files
gods-eye-view/src/layers/cctv/lifecycle.test.mjs
T
Sameh Khamis 2b60531c3c Merge main through #1634 into the renderer seam
Brings in the CCTV opening camera, the Iceland, Giroc HLS, Taiwan, Quebec,
Ottawa and world camera packs, the world clock and timeline, the zoom-out
limit and registered-only layer state, ported onto the renderer contract:
the sky follows the world time through the frame port's setTime in
preUpdate, the Quebec overlay reads the eye, projects and redraws through
the camera, query and frame ports, launches hide pending missions through
their draw records, and mission orbit rings turn on the scene clock.
2026-11-10 00:31:23 -08:00

75 lines
2.3 KiB
JavaScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createLifecycle } from './lifecycle.js';
import { bindRenderer } from '../../render/rendererOf.js';
import { fakeCameraPort } from '../../testSupport/fakeCameraPort.mjs';
function viewerWithCamera() {
const camera = fakeCameraPort();
const viewer = {};
bindRenderer(viewer, { camera: camera.port });
return { viewer, camera };
}
function lifecycleFor(state) {
const passes = [];
const lifecycle = createLifecycle({
state,
services: {
sprites: {},
activation: {},
picking: {},
focus: {},
render: {},
},
parts: {
rendering: {
refreshHorizonCulling: () => {
passes.push('view');
return false;
},
},
geometryQueue: { enqueueViewGeometry() {} },
cards: { refreshAmbientCards() {} },
presentation: { notifyListeners() {} },
navigation: { reopenNearestCamera() {} },
},
});
return { lifecycle, passes };
}
test('the view listeners follow the camera port and let go on teardown', () => {
const first = viewerWithCamera();
const state = { _viewer: first.viewer, _enabled: false };
const { lifecycle, passes } = lifecycleFor(state);
const counts = (camera) => [
camera.listenerCount('moveStart'),
camera.listenerCount('moveEnd'),
];
lifecycle.attachViewListeners();
assert.deepEqual(counts(first.camera), [1, 1]);
first.camera.emit('moveStart');
assert.equal(state._cameraMoving, true, 'hover pauses while moving');
first.camera.emit('moveEnd');
assert.equal(state._cameraMoving, false);
assert.deepEqual(passes, ['view'], 'a settled move reruns the view pass');
// A re-init on the same viewer keeps its listeners.
lifecycle.attachViewListeners();
assert.deepEqual(counts(first.camera), [1, 1]);
// One on a new viewer moves them to its camera.
const second = viewerWithCamera();
state._viewer = second.viewer;
first.camera.emit('moveStart');
lifecycle.attachViewListeners();
assert.equal(state._cameraMoving, false, 'the old move is forgotten');
assert.deepEqual(counts(first.camera), [0, 0]);
assert.deepEqual(counts(second.camera), [1, 1]);
lifecycle.detachViewListeners();
assert.deepEqual(counts(second.camera), [0, 0]);
assert.equal(state._viewListenerCamera, null);
});