mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
src/data/followed.js answers what the camera follows: the camera port's target, or the entity a layer still tracks itself, seen through the same fields. Ownership checks, render holds, guards, voice actions, the CCTV pacing and the navigation release paths read it instead of Cesium's trackedEntity, so they keep working when layers follow through the port. The release paths stop following, cancel the flight and release the camera through the port. The rotate refusal names the followed target by its name or label title.
120 lines
3.6 KiB
JavaScript
120 lines
3.6 KiB
JavaScript
import { readShellSource } from './testSupport/readShellSource.mjs';
|
|
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
runCctvLayerEnableFocus,
|
|
runCctvLayerEnableTransition,
|
|
} from './cctvFocusPolicy.js';
|
|
|
|
test('CCTV layer enable activates nearest without stealing a tracked or cockpit view', () => {
|
|
for (const ownership of [
|
|
{ followed: { key: 'tracked-plane' }, cockpitActive: false },
|
|
{ followed: null, cockpitActive: true },
|
|
]) {
|
|
const calls = [];
|
|
const result = runCctvLayerEnableFocus({
|
|
...ownership,
|
|
activate: () => {
|
|
calls.push(['nearest', { focus: false }]);
|
|
return 'cam-near';
|
|
},
|
|
fly: (cameraId) => {
|
|
calls.push(['fly', cameraId]);
|
|
return 'focused';
|
|
},
|
|
});
|
|
|
|
assert.equal(result, 'cam-near');
|
|
assert.deepEqual(calls, [['nearest', { focus: false }]]);
|
|
}
|
|
|
|
const calls = [];
|
|
const result = runCctvLayerEnableFocus({
|
|
activate: () => {
|
|
calls.push(['nearest', { focus: false }]);
|
|
return 'cam-near';
|
|
},
|
|
fly: (cameraId) => {
|
|
calls.push(['fly', cameraId]);
|
|
return 'focused';
|
|
},
|
|
});
|
|
|
|
assert.equal(result, 'focused');
|
|
assert.deepEqual(calls, [
|
|
['nearest', { focus: false }],
|
|
['fly', 'cam-near'],
|
|
]);
|
|
});
|
|
|
|
test('CCTV enable retains a pre-await tracking snapshot when tracking clears during enable', async () => {
|
|
let followed = { key: 'tracked-plane' };
|
|
let flyCalls = 0;
|
|
const diagnostics = [];
|
|
const result = await runCctvLayerEnableTransition({
|
|
target: true,
|
|
readOwnership: () => ({ followed, cockpitActive: false }),
|
|
setEnabled: async () => {
|
|
await Promise.resolve();
|
|
followed = null;
|
|
},
|
|
shouldFocus: () => true,
|
|
activate: () => 'cam-near',
|
|
fly: () => {
|
|
flyCalls += 1;
|
|
return 'focused';
|
|
},
|
|
debug: (...args) => diagnostics.push(args),
|
|
});
|
|
|
|
assert.equal(result, 'cam-near');
|
|
assert.equal(flyCalls, 0, 'a pre-await owner must suppress the post-await focus flight');
|
|
assert.deepEqual(diagnostics.map(([, identity]) => identity.trackedId), ['tracked-plane', null]);
|
|
assert.match(diagnostics[0][0], /before setEnabled await/);
|
|
assert.match(diagnostics[1][0], /after setEnabled await/);
|
|
|
|
const uiSource = readShellSource();
|
|
assert.match(uiSource, /await runCctvLayerEnableTransition\(\{/);
|
|
});
|
|
|
|
test('CCTV disable transition does not emit enable-ownership diagnostics', async () => {
|
|
const diagnostics = [];
|
|
const transitions = [];
|
|
|
|
const result = await runCctvLayerEnableTransition({
|
|
target: false,
|
|
readOwnership: () => ({ followed: { key: 'tracked-plane' }, cockpitActive: false }),
|
|
setEnabled: async (target) => transitions.push(target),
|
|
shouldFocus: () => true,
|
|
activate: () => 'cam-near',
|
|
fly: () => 'focused',
|
|
debug: (...args) => diagnostics.push(args),
|
|
});
|
|
|
|
assert.equal(result, null);
|
|
assert.deepEqual(transitions, [false]);
|
|
assert.deepEqual(diagnostics, []);
|
|
});
|
|
|
|
|
|
test('a disposed UI cannot activate a camera when enabling finishes late', async () => {
|
|
let release;
|
|
let disposed = false;
|
|
let activations = 0;
|
|
const pending = runCctvLayerEnableTransition({
|
|
target: true,
|
|
setEnabled: () => new Promise((resolve) => { release = resolve; }),
|
|
readOwnership: () => ({}),
|
|
shouldFocus: () => !disposed,
|
|
activate: () => { activations++; return 'camera-a'; },
|
|
fly: () => assert.fail('disposed UI must not fly'),
|
|
debug: () => {},
|
|
});
|
|
disposed = true;
|
|
release();
|
|
await pending;
|
|
assert.equal(activations, 0);
|
|
const uiSource = readShellSource();
|
|
assert.match(uiSource, /shouldFocus: \(\) =>\s*!this\._disposed\s*&&\s*this\._dataManager\.isEnabled\('cctv'\)/);
|
|
});
|