Files
gods-eye-view/src/render/cesium/cameraInput.test.mjs
T
Sameh Khamis ad98c80118 Share a scene's camera-input holds beyond the dispatcher
The take-over of the camera controller's enableInputs moves, unchanged,
to src/render/cesium/cameraInput.js. acquireCameraInput(scene) gives every
user one set of counted holds per scene, so the renderer's input and
camera ports can hold camera input alongside the dispatcher; the
controller gets its own property back when the last user releases. The
dispatcher acquires its share once its handler is bound. The input guard
names the one module allowed to write the flag, and the new render files
join the format scope.
2026-11-05 18:29:38 -08:00

57 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert/strict';
import test from 'node:test';
import { acquireCameraInput } from './cameraInput.js';
test('users of one scene share its holds', () => {
const controller = { enableInputs: true };
const scene = { screenSpaceCameraController: controller };
const a = acquireCameraInput(scene);
const b = acquireCameraInput(scene);
const drag = a.suspend('drag');
assert.equal(controller.enableInputs, false);
assert.equal(b.enabled, false, 'b sees a’s hold');
assert.deepEqual(b.reasons(), ['drag']);
const flight = b.suspend(7);
assert.deepEqual(a.reasons(), ['drag', '7']);
drag();
assert.equal(controller.enableInputs, false, 'b’s hold is still out');
a.release();
assert.equal(controller.enableInputs, false, 'b still holds');
flight();
assert.equal(controller.enableInputs, true);
});
test('releasing a user gives back its holds, and the property with the last', () => {
const controller = { enableInputs: true };
const scene = { screenSpaceCameraController: controller };
const a = acquireCameraInput(scene);
const b = acquireCameraInput(scene);
a.suspend('drag');
b.suspend('cockpit');
a.release();
assert.deepEqual(b.reasons(), ['cockpit']);
assert.equal(
typeof Object.getOwnPropertyDescriptor(controller, 'enableInputs').get,
'function',
'still owned while b is a user',
);
b.release();
assert.deepEqual(
Object.getOwnPropertyDescriptor(controller, 'enableInputs'),
{
value: true,
writable: true,
enumerable: true,
configurable: true,
},
);
assert.deepEqual(
a.suspend('late')(),
undefined,
'a released user holds nothing',
);
const c = acquireCameraInput(scene);
assert.equal(c.enabled, true, 'a new user starts afresh');
c.release();
});