mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
Merge origin/main into space-missions-fixes
Main's single click rule (the card or label on top takes the click, read once per click through clickCard and isUnderOtherCard in src/data/pickRegistry.js) covers a click on a Space Missions label: a mission marker label is an interactive world-overlay entry, so the host's hit test names it as the card on top for every other layer. The per-layer label guards in CCTV, Drone Airspace, FIRMS, Ghost Maps, News, Perimeters, Shipwrecks, Vessels, Wildlife Sightings, ALPR, Local ADS-B and the cockpit orbital focus are dropped for main's versions. The mission-label tests are kept on main's API: fakeInputUnderLabel now also names the label as the card on top, and each test shows a click on the label never acts on the card, camera, vessel, fire, reader, aircraft or report under it, and leaves the selection as it is. A launches test checks that a mission label is interactive and is the card on top for every other layer. Docs, changelog and the dispatcher's `overlay` note describe the merged behaviour. Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
commit
0e5c5e624c
146 files changed
+9734
-1157
No files matched your search
@@ -23,7 +23,7 @@ export function createLifecycle({
|
||||
source,
|
||||
}) {
|
||||
const { activateCctvCameraFromWorldClick } = services.activation;
|
||||
const { resolvePickId, registerPickOwner, unregisterPickOwner } =
|
||||
const { resolvePickId, registerPickOwner, unregisterPickOwner, clickCard } =
|
||||
services.picking;
|
||||
const { onFocusTargetAppear } = services.focus;
|
||||
const { releaseContinuousRender } = services.render;
|
||||
@@ -391,6 +391,20 @@ export function createLifecycle({
|
||||
(event) => {
|
||||
if (!layerState._enabled) return;
|
||||
const picked = event.topHit;
|
||||
// The card or label painted on top takes the click, read once per
|
||||
// click so every layer agrees: a live card of ours acts whatever
|
||||
// is drawn under it; another layer's is that layer's click.
|
||||
const top = clickCard?.(event) ?? null;
|
||||
if (top && top.sourceId !== CCTV_OVERLAY_SOURCE_ID) return;
|
||||
if (top) {
|
||||
// A card of ours that is going away is still not the scene.
|
||||
if (layerState._recordById.has(top.entryId))
|
||||
activateCctvCameraFromWorldClick(
|
||||
top.entryId,
|
||||
parts.selection.setActiveCamera,
|
||||
);
|
||||
return;
|
||||
}
|
||||
const cameraId = parts.selection.extractPickedCameraId(
|
||||
event.drawHit ?? null,
|
||||
);
|
||||
@@ -401,32 +415,11 @@ export function createLifecycle({
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Any identified scene object owns this click even if its layer does not
|
||||
// register a shared pick predicate. This keeps selectable siblings ahead
|
||||
// of an overlapping CCTV card while ID-less globe/terrain/tile surfaces
|
||||
// remain eligible for true empty-space deselection.
|
||||
const pickedId = resolvePickId(picked);
|
||||
if (pickedId !== null) return;
|
||||
// Item A (owner round 2): the scene pick found no camera — try the
|
||||
// painted ambient cards. The cards canvas is pointer-events:none (this
|
||||
// handler owns the events), so a click landing on a card's rect selects
|
||||
// its camera exactly like a click on the icon. Click positions
|
||||
// and the recorded rects are both CSS px — direct comparison. A
|
||||
// click a label painted over the cards took is not on a card.
|
||||
const cardId = event.overlay
|
||||
? null
|
||||
: layerState._cctvOverlayHost.hitTest(
|
||||
event.screenPosition.x,
|
||||
event.screenPosition.y,
|
||||
{ sourceId: CCTV_OVERLAY_SOURCE_ID },
|
||||
)?.entryId;
|
||||
if (cardId && layerState._recordById.has(cardId)) {
|
||||
activateCctvCameraFromWorldClick(
|
||||
cardId,
|
||||
parts.selection.setActiveCamera,
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Any identified scene object owns this click even if its layer
|
||||
// does not register a shared pick predicate. This keeps selectable
|
||||
// siblings ahead of the CCTV selection while ID-less globe, terrain
|
||||
// and tile surfaces remain eligible for empty-space deselection.
|
||||
if (resolvePickId(picked) !== null) return;
|
||||
if (
|
||||
parts.selection.cctvEmptyClickDeselects(picked, {
|
||||
activeCameraId: layerState._activeCameraId,
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createLifecycle } from './lifecycle.js';
|
||||
import { createSelection } from './selection.js';
|
||||
import { CCTV_OVERLAY_SOURCE_ID } from '../../data/cctvCards.js';
|
||||
import { fakeInput, fakeInputUnderLabel } from '../../input/testDoubles.mjs';
|
||||
import * as picking from '../../data/pickRegistry.js';
|
||||
import { bindRenderer } from '../../render/rendererOf.js';
|
||||
import { fakeCameraPort } from '../../testSupport/fakeCameraPort.mjs';
|
||||
import { CCTV_OVERLAY_SOURCE_ID } from '../../data/cctvCards.js';
|
||||
import { resolvePickId } from '../../data/pickRegistry.js';
|
||||
import { fakeInputUnderLabel } from '../../input/testDoubles.mjs';
|
||||
|
||||
function viewerWithCamera() {
|
||||
const camera = fakeCameraPort();
|
||||
@@ -83,10 +84,13 @@ const inert = (own = {}) =>
|
||||
get: (target, name) => (name in target ? target[name] : () => {}),
|
||||
});
|
||||
|
||||
test("a click a label painted over a camera's card takes never turns that camera on, and lets go of the active one", async (t) => {
|
||||
test("a click on a mission label over a camera's card never turns that camera on, and keeps the active one", async (t) => {
|
||||
const { viewer } = viewerWithCamera();
|
||||
viewer.scene = { canvas: {}, pick: () => null };
|
||||
const fake = fakeInputUnderLabel(viewer);
|
||||
// The card of camera `cam-1` lies under every click, under the label.
|
||||
const fake = fakeInputUnderLabel(viewer, {
|
||||
beneath: () => ({ sourceId: CCTV_OVERLAY_SOURCE_ID, entryId: 'cam-1' }),
|
||||
});
|
||||
t.after(() => fake.destroy());
|
||||
const activated = [];
|
||||
const deactivated = [];
|
||||
@@ -97,7 +101,7 @@ test("a click a label painted over a camera's card takes never turns that camera
|
||||
activation: {
|
||||
activateCctvCameraFromWorldClick: (id) => activated.push(id),
|
||||
},
|
||||
picking: { resolvePickId },
|
||||
picking,
|
||||
focus: {},
|
||||
render: {},
|
||||
},
|
||||
@@ -125,7 +129,7 @@ test("a click a label painted over a camera's card takes never turns that camera
|
||||
bindCctvWorldClickGesture: (input, onClick) => input.onClick(onClick),
|
||||
extractPickedCameraId: () => null,
|
||||
cctvEmptyClickDeselects: (picked, { activeCameraId }) =>
|
||||
Boolean(activeCameraId) && resolvePickId(picked) === null,
|
||||
Boolean(activeCameraId) && picking.resolvePickId(picked) === null,
|
||||
deactivateActiveCamera: () => deactivated.push(state._activeCameraId),
|
||||
},
|
||||
},
|
||||
@@ -137,19 +141,200 @@ test("a click a label painted over a camera's card takes never turns that camera
|
||||
state._enabled = true;
|
||||
state._activeCameraId = 'cam-0';
|
||||
state._recordById.set('cam-1', {});
|
||||
// The card of camera `cam-1` lies under every click.
|
||||
state._cctvOverlayHost = {
|
||||
hitTest: (_x, _y, { sourceId }) =>
|
||||
sourceId === CCTV_OVERLAY_SOURCE_ID ? { entryId: 'cam-1' } : null,
|
||||
};
|
||||
|
||||
fake.label.over = true;
|
||||
fake.click();
|
||||
assert.deepEqual(activated, [], 'the camera under the label stays off');
|
||||
assert.deepEqual(deactivated, ['cam-0'], 'the active camera is let go');
|
||||
assert.deepEqual(deactivated, [], 'the active camera stays on');
|
||||
|
||||
// Off the label, a click on the card turns its camera on.
|
||||
fake.label.over = false;
|
||||
fake.click();
|
||||
assert.deepEqual(activated, ['cam-1']);
|
||||
});
|
||||
|
||||
test('the card painted on top takes world clicks, whatever is drawn under it', async (t) => {
|
||||
const noop = () => {};
|
||||
const { viewer } = viewerWithCamera();
|
||||
let picked = null;
|
||||
viewer.scene = {
|
||||
canvas: {},
|
||||
pick: () => (picked ? { id: picked } : undefined),
|
||||
drillPick: () => drilled.map((id) => ({ id })),
|
||||
};
|
||||
let drilled = [];
|
||||
const input = fakeInput(viewer);
|
||||
// An aircraft layer that runs before ours and tracks the plane it was
|
||||
// clicked on, standing aside under another layer's card.
|
||||
let tracked = null;
|
||||
input.input.onClick((event) => {
|
||||
if (picking.isUnderOtherCard(event)) return;
|
||||
if (event.hit?.id === 'plane:9') tracked = 'plane:9';
|
||||
});
|
||||
const ownCard = { sourceId: CCTV_OVERLAY_SOURCE_ID, entryId: 'cam-1' };
|
||||
const foreignCard = {
|
||||
sourceId: 'earthquake-card',
|
||||
entryId: 'earthquake-card:qa',
|
||||
};
|
||||
let painted = [];
|
||||
const actions = [];
|
||||
// The card on top at a click, as the host answers the pick registry.
|
||||
picking.setClickCardHitTest(() => painted[0] ?? null);
|
||||
const state = {
|
||||
_cctvOverlayHost: {
|
||||
hitTest: (_x, _y, options = {}) =>
|
||||
painted.find(
|
||||
(hit) => !options.sourceId || hit.sourceId === options.sourceId,
|
||||
) ?? null,
|
||||
},
|
||||
};
|
||||
const parts = {
|
||||
calibration: { loadCalibrationStore: () => new Map() },
|
||||
catalog: {
|
||||
loadCameraSources: async () => [],
|
||||
buildCatalogFromSources: () => [],
|
||||
seedCatalog: () => [],
|
||||
},
|
||||
ground: {
|
||||
resolveGroundPriors: async () => [],
|
||||
currentSurfaceRegime: () => 'terrain-globe',
|
||||
},
|
||||
cards: { teardownAmbientCards: noop },
|
||||
projection: { clearProjectionOverlay: noop },
|
||||
geometryQueue: { stopGeometryLoadQueue: noop },
|
||||
rendering: {
|
||||
createCameraIcons: noop,
|
||||
refreshHorizonCulling: () => false,
|
||||
refreshCoverageStyles: noop,
|
||||
extractPickedCameraId: (hit) =>
|
||||
hit?.set === 'cctv:fixture' ? hit.id : null,
|
||||
},
|
||||
hover: { handleHoverMove: noop },
|
||||
health: { syncHealthState: async () => {} },
|
||||
presentation: { notifyListeners: noop },
|
||||
};
|
||||
const services = {
|
||||
sprites: {},
|
||||
focus: { onFocusTargetAppear: () => noop },
|
||||
render: { releaseContinuousRender: noop },
|
||||
picking,
|
||||
activation: { activateCctvCameraFromWorldClick: (id) => actions.push(id) },
|
||||
};
|
||||
parts.selection = createSelection({ state, services, parts });
|
||||
parts.selection.deactivateActiveCamera = () => actions.push('clear');
|
||||
const lifecycle = createLifecycle({ state, services, parts });
|
||||
t.after(() => {
|
||||
state._clickSubscription?.();
|
||||
lifecycle.detachViewListeners();
|
||||
input.destroy();
|
||||
picking.setClickCardHitTest(null);
|
||||
picking.unregisterPickOwner('area-control');
|
||||
picking.unregisterPickOwner('test-trails');
|
||||
picking.unregisterPickOwner('test-planes');
|
||||
picking.unregisterPickOwner('test-tracking');
|
||||
picking.unregisterPickOwner('test-exact');
|
||||
});
|
||||
await lifecycle.methods.init(viewer);
|
||||
state._enabled = true;
|
||||
state._activeCameraId = 'cam-1';
|
||||
state._recordById.set('cam-1', { camera: { id: 'cam-1' } });
|
||||
const click = (hit, cards, expected) => {
|
||||
picked = hit;
|
||||
painted = cards;
|
||||
actions.length = 0;
|
||||
input.tap();
|
||||
assert.deepEqual(actions, expected, JSON.stringify({ hit, cards }));
|
||||
};
|
||||
const drone = {
|
||||
set: 'drone-airspace:1:fills',
|
||||
id: 'drone-airspace:zone:0',
|
||||
surface: false,
|
||||
};
|
||||
const perimeter = {
|
||||
set: 'fire-perimeters:1:lines',
|
||||
id: 'fire-perimeter:incident:0',
|
||||
surface: false,
|
||||
};
|
||||
const quake = { set: 'earthquakes:1', id: 'earthquake:q1', surface: false };
|
||||
const cable = { set: 'submarine-cables:1:lines', id: 'c:0', surface: false };
|
||||
const launch = {
|
||||
set: 'launches:1:markers',
|
||||
id: 'rocket-x:1',
|
||||
surface: false,
|
||||
};
|
||||
const backgrounds = [drone, perimeter, quake, cable, launch];
|
||||
for (const area of backgrounds) {
|
||||
click(area, [ownCard], ['cam-1']);
|
||||
click(area, [], []);
|
||||
click(area, [foreignCard, ownCard], []);
|
||||
}
|
||||
// The live top card acts over anything drawn under it; with no card an
|
||||
// identified object is not empty map.
|
||||
for (const hit of [
|
||||
{ set: 'flights:1', id: 'aircraft', surface: false },
|
||||
{ set: '', id: 'unregistered-local-entity', surface: false },
|
||||
{ ...drone, set: 'unrelated:1:fills' },
|
||||
{ ...drone, id: 'unregistered-local-entity' },
|
||||
]) {
|
||||
click(hit, [ownCard], ['cam-1']);
|
||||
click(hit, [], []);
|
||||
}
|
||||
// A trail under the live top card: the card keeps the click, and with no
|
||||
// card the owned pick is not empty map.
|
||||
const trail = { set: 'trails:1', id: 'gev-trail:fl-1:head', surface: false };
|
||||
picking.registerPickOwner('test-trails', (id) => id === trail.id);
|
||||
click(trail, [ownCard], ['cam-1']);
|
||||
click(trail, [], []);
|
||||
click(trail, [foreignCard, ownCard], []);
|
||||
picking.unregisterPickOwner('test-trails');
|
||||
// A coarse tap whose touch contact is an aircraft (a layer that acts on
|
||||
// nearby contacts) under a live CCTV card is the card's.
|
||||
const previousMatch = globalThis.matchMedia;
|
||||
const restoreMatch = () => {
|
||||
if (previousMatch) globalThis.matchMedia = previousMatch;
|
||||
else delete globalThis.matchMedia;
|
||||
};
|
||||
// Restored below for the fine-pointer clicks that follow; here too, so a
|
||||
// failing assertion cannot leave the coarse pointer for later tests.
|
||||
t.after(restoreMatch);
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
picking.registerPickOwner('test-planes', (id) => id === 'plane:1');
|
||||
drilled = ['plane:1'];
|
||||
click(null, [ownCard], ['cam-1']);
|
||||
// With no card, the bare tap near the aircraft still deselects.
|
||||
click(null, [], ['clear']);
|
||||
// A contact whose layer acts only on exact hits leaves the card its tap.
|
||||
picking.registerPickOwner('test-exact', (id) => id === 'exact:1');
|
||||
drilled = ['exact:1'];
|
||||
click(null, [ownCard], ['cam-1']);
|
||||
picking.unregisterPickOwner('test-exact');
|
||||
drilled = [];
|
||||
click(null, [ownCard], ['cam-1']);
|
||||
picking.unregisterPickOwner('test-planes');
|
||||
restoreMatch();
|
||||
// The live card over an aircraft takes the click; the aircraft layer,
|
||||
// run first, stands aside and does not track.
|
||||
picking.registerPickOwner('test-tracking', (id) => id === 'plane:9');
|
||||
click(
|
||||
{ set: 'flights:1', id: 'plane:9', surface: false },
|
||||
[ownCard],
|
||||
['cam-1'],
|
||||
);
|
||||
assert.equal(tracked, null, 'the aircraft did not track');
|
||||
picking.unregisterPickOwner('test-tracking');
|
||||
picking.registerPickOwner('area-control', (id) => id === drone.id);
|
||||
click(drone, [ownCard], ['cam-1']);
|
||||
picking.unregisterPickOwner('area-control');
|
||||
click(null, [foreignCard, ownCard], []);
|
||||
click(null, [ownCard], ['cam-1']);
|
||||
click(null, [], ['clear']);
|
||||
click(drone, [{ ...ownCard, entryId: 'stale-camera' }], []);
|
||||
// A card of ours that is going away is still not the scene under it: no
|
||||
// camera beneath it activates, and nothing clears.
|
||||
const staleCard = { ...ownCard, entryId: 'stale-camera' };
|
||||
click({ set: 'cctv:fixture', id: 'cam-1' }, [staleCard], []);
|
||||
click(null, [staleCard], []);
|
||||
// A camera icon under another layer's card is that card's click.
|
||||
click({ set: 'cctv:fixture', id: 'cam-1' }, [foreignCard, ownCard], []);
|
||||
click({ set: 'cctv:fixture', id: 'cam-1' }, [], ['cam-1']);
|
||||
});
|
||||
Reference in new issue
Block a user