mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
The map stacks' imagery, terrain and Google 3D factories move into the Cesium adapter (src/render/cesium/mapImagery.js, mapTerrain.js, google3d.js); the ./maps/imagery, ./maps/terrain and ./maps/3d exports point there. The catalog names its ion stacks by asset number, and the map source controller and default sources are Cesium-free: they build providers and switch imagery layers, terrain, tilesets and the globe's visibility through a map engine (src/maps/engine.js) that the Cesium adapter provides as it loads (mapEngine.js), through the application's renderer or the ./render/cesium/unbound export. The controller and createDefaultMapSources also take it as an `engine` option. src/maps/catalog.js, controller.js, imagery.js, terrain.js and google3d.js leave the allow-list.
89 lines
2.6 KiB
JavaScript
89 lines
2.6 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { MapSourceController } from './controller.js';
|
|
// The controller switches stacks through the Cesium map engine.
|
|
import '../render/cesium/mapEngine.js';
|
|
function fixture() {
|
|
return new MapSourceController(
|
|
{
|
|
scene: {
|
|
globe: { show: true },
|
|
requestRender() {},
|
|
primitives: { add() {}, remove() {} },
|
|
},
|
|
imageryLayers: { add() {}, remove() {} },
|
|
},
|
|
{
|
|
registry: {
|
|
defaultId: 'fixture',
|
|
sources: [
|
|
{
|
|
descriptor: { id: 'fixture', label: 'Fixture', kind: 'imagery' },
|
|
imagery: async () => ({}),
|
|
},
|
|
],
|
|
},
|
|
createImageryLayer: (provider) => ({ provider }),
|
|
},
|
|
);
|
|
}
|
|
test('an unsubscribed owner is skipped in the same map settlement delivery', async () => {
|
|
const controller = fixture();
|
|
const calls = [];
|
|
let detach;
|
|
controller.subscribe(() => {
|
|
calls.push('first');
|
|
detach();
|
|
});
|
|
detach = controller.subscribe(() => calls.push('detached'));
|
|
controller.subscribe(() => calls.push('last'));
|
|
await controller.setStack('fixture');
|
|
assert.deepEqual(calls, ['first', 'last']);
|
|
controller.destroy();
|
|
});
|
|
test('destroying the controller during delivery stops remaining listeners', async () => {
|
|
const controller = fixture();
|
|
const calls = [];
|
|
controller.subscribe(() => {
|
|
calls.push('destroy');
|
|
controller.destroy();
|
|
});
|
|
controller.subscribe(() => calls.push('detached'));
|
|
await controller.setStack('fixture');
|
|
assert.deepEqual(calls, ['destroy']);
|
|
});
|
|
|
|
test('a listener re-added after destroy during delivery is not called', async () => {
|
|
const controller = fixture();
|
|
const calls = [];
|
|
const later = () => calls.push('later');
|
|
controller.subscribe(() => {
|
|
calls.push('destroy');
|
|
controller.destroy();
|
|
controller.subscribe(later);
|
|
});
|
|
controller.subscribe(later);
|
|
await controller.setStack('fixture');
|
|
assert.deepEqual(calls, ['destroy']);
|
|
});
|
|
|
|
test('delivery order: added during delivery waits, duplicates run once, re-added runs', async () => {
|
|
const controller = fixture();
|
|
const calls = [];
|
|
const twice = () => calls.push('twice');
|
|
const readded = () => calls.push('readded');
|
|
let offReadded;
|
|
controller.subscribe(() => {
|
|
calls.push('first');
|
|
controller.subscribe(() => calls.push('added-late'));
|
|
offReadded();
|
|
controller.subscribe(readded);
|
|
});
|
|
controller.subscribe(twice);
|
|
controller.subscribe(twice);
|
|
offReadded = controller.subscribe(readded);
|
|
await controller.setStack('fixture');
|
|
assert.deepEqual(calls, ['first', 'twice', 'readded']);
|
|
controller.destroy();
|
|
});
|