mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
fix(touch): give each tap to the layer that acts on it
On a coarse pointer the dispatcher can name a contact near the tap instead of the exact pick. Only flights, military, vessels, radio and Street Level act on such a contact, so they now register as expanded pick owners, and a quake card or label yields only to them. A FIRMS fire or CCTV camera reached only as a nearby contact no longer swallows a quake card, a quake label or a vessel's own card tap, and FIRMS and CCTV cards yield to a contact whose layer does act on it. Radio and Street Level also pick through their own windows. A station or Street Level item found only there, not as the touch contact, yields to another layer's card painted over it, and Street Level takes its own touch contact beyond its narrower window. Fire, CCTV and vessel cards now act over a passive owner's pick (a flight trail, the directions route), as the quake card does. The Context panel leaves a passive route, or a fire or camera reached only as a nearby contact, to the card painted over it.
This commit is contained in:
1 parent
4804097ca1
commit
830c980ca6
26 files changed
+1095
-69
No files matched your search
@@ -1012,7 +1012,7 @@ function makeCesiumEvent() {
|
||||
};
|
||||
}
|
||||
|
||||
function installWireHarness(picked, stateOverrides = {}) {
|
||||
function installWireHarness(picked, stateOverrides = {}, sceneExtras = {}) {
|
||||
const hadWindow = Object.hasOwn(globalThis, 'window');
|
||||
const hadDocument = Object.hasOwn(globalThis, 'document');
|
||||
const priorWindow = globalThis.window;
|
||||
@@ -1038,7 +1038,7 @@ function installWireHarness(picked, stateOverrides = {}) {
|
||||
},
|
||||
};
|
||||
const viewer = {
|
||||
scene: { pick: () => picked },
|
||||
scene: { pick: () => picked, ...sceneExtras },
|
||||
};
|
||||
const input = fakeInput(viewer);
|
||||
// The camera port other layers follow through, with no pose to read; its
|
||||
@@ -1993,6 +1993,75 @@ test('vessel interaction wire: a sibling-owned pick wins without selection mutat
|
||||
}
|
||||
});
|
||||
|
||||
// A trail acts for nobody: the vessel's card painted over it still selects,
|
||||
// and a bare trail pick stays a no-op that keeps the selection.
|
||||
test('vessel interaction wire: a card over a trail selects; a bare trail is a no-op', () => {
|
||||
for (const carded of [true, false]) {
|
||||
const harness = installWireHarness(
|
||||
{ id: 'gev-trail:fl-a1b2c3:head' },
|
||||
{ selectedRecord: null },
|
||||
);
|
||||
const requests = [];
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
hostWithCardHit(carded ? `vessel:${harness.record.mmsi}` : null),
|
||||
);
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(requests.length, carded ? 1 : 0, `card: ${carded}`);
|
||||
assert.equal(
|
||||
aisLiveVesselsLayer.getSelectedInfo()?.mmsi ?? null,
|
||||
carded ? harness.record.mmsi : null,
|
||||
);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// A coarse tap on the vessel's card finds a fire nearby through the shared
|
||||
// touch contact. The fire layer acts only on exact hits, so the card keeps the
|
||||
// tap; an exact fire pick under the card still belongs to the fire.
|
||||
test('vessel interaction wire: a coarse near miss of an exact-only item keeps the card tap', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const fire = 'fire:near-miss';
|
||||
registerPickOwner('test-exact-fires', (pickedId) => pickedId === fire);
|
||||
t.after(() => unregisterPickOwner('test-exact-fires'));
|
||||
for (const exact of [false, true]) {
|
||||
const harness = installWireHarness(
|
||||
exact ? { id: fire } : null,
|
||||
{ selectedRecord: null },
|
||||
{ drillPick: () => [{ id: fire }] },
|
||||
);
|
||||
const requests = [];
|
||||
harness.windowTarget.addEventListener(WORLD_FOCUS_REQUEST_EVENT, (event) =>
|
||||
requests.push(event.detail),
|
||||
);
|
||||
_setVesselOverlayHostForTest(
|
||||
hostWithCardHit(`vessel:${harness.record.mmsi}`),
|
||||
);
|
||||
try {
|
||||
harness.handler.click({ position: { x: 10, y: 20 } });
|
||||
assert.equal(requests.length, exact ? 0 : 1, `exact fire: ${exact}`);
|
||||
assert.equal(
|
||||
aisLiveVesselsLayer.getSelectedInfo()?.mmsi ?? null,
|
||||
exact ? null : harness.record.mmsi,
|
||||
);
|
||||
} finally {
|
||||
_setVesselOverlayHostForTest(null);
|
||||
harness.cleanup();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (const card of ['live', 'stale', 'absent', 'covered']) {
|
||||
test(`vessel interaction wire: ${card} foreground card over registered cyclone`, () => {
|
||||
const id = 'cyclone:fixture:cone:0';
|
||||
|
||||
@@ -63,6 +63,7 @@ function harness({
|
||||
withDataSource = false,
|
||||
withGlobe = false,
|
||||
feed = null,
|
||||
drilled = null,
|
||||
} = {}) {
|
||||
const hadWindow = Object.hasOwn(globalThis, 'window');
|
||||
const priorWindow = globalThis.window;
|
||||
@@ -112,6 +113,7 @@ function harness({
|
||||
const viewer = {
|
||||
scene: {
|
||||
pick,
|
||||
...(drilled ? { drillPick: () => drilled } : {}),
|
||||
canvas: { clientWidth: 1280, clientHeight: 800 },
|
||||
camera: cameraPosition ? { positionWC: cameraPosition } : undefined,
|
||||
globe: { ellipsoid: Cesium.Ellipsoid.WGS84 },
|
||||
@@ -162,6 +164,9 @@ function harness({
|
||||
cover: (hit) => {
|
||||
topCard = hit;
|
||||
},
|
||||
setPicked: (next) => {
|
||||
picked = next;
|
||||
},
|
||||
cleanup() {
|
||||
Cesium.SceneTransforms.worldToWindowCoordinates = priorProjection;
|
||||
if (hadWindow) globalThis.window = priorWindow;
|
||||
@@ -461,6 +466,116 @@ for (const [layerId, ownedId, picked] of SIBLING_PICKS) {
|
||||
});
|
||||
}
|
||||
|
||||
// A passive owner's pick (a directions route, a flight trail) acts for nobody:
|
||||
// a fire card over it still takes the click, and with no card the pick is
|
||||
// still not empty space, so the selection stays.
|
||||
test('a fire card acts over a passive pick; the bare pick leaves the selection', () => {
|
||||
const fire = makeFire();
|
||||
registerPickOwner('test-route', (pickedId) => pickedId === 'route:line', {
|
||||
passive: true,
|
||||
});
|
||||
const carded = harness({
|
||||
fires: [fire],
|
||||
picked: { id: 'route:line' },
|
||||
cardHit: `fire:${fireDetectionKey(fire)}`,
|
||||
});
|
||||
try {
|
||||
carded.click();
|
||||
assert.equal(carded.requests.length, 1, 'the card acts over the route');
|
||||
assert.ok(carded.layer.getSelectedInfo());
|
||||
} finally {
|
||||
carded.cleanup();
|
||||
}
|
||||
const bare = harness({ fires: [fire], picked: { id: 'route:line' } });
|
||||
try {
|
||||
bare.click();
|
||||
assert.equal(bare.requests.length, 0);
|
||||
assert.equal(
|
||||
bare.layer.getSelectedInfo(),
|
||||
null,
|
||||
'nothing to clear or pick',
|
||||
);
|
||||
} finally {
|
||||
bare.cleanup();
|
||||
unregisterPickOwner('test-route');
|
||||
}
|
||||
});
|
||||
|
||||
// A coarse tap on a fire card finds an aircraft nearby through the shared
|
||||
// touch contact. The flights layer acts on that contact, so the card yields:
|
||||
// one action, not two.
|
||||
test('a fire card yields to a touch contact its layer acts on', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const fire = makeFire();
|
||||
registerPickOwner('test-planes', (pickedId) => pickedId === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
t.after(() => unregisterPickOwner('test-planes'));
|
||||
const h = harness({
|
||||
fires: [fire],
|
||||
drilled: [{ id: 'plane:1' }],
|
||||
cardHit: `fire:${fireDetectionKey(fire)}`,
|
||||
});
|
||||
try {
|
||||
h.click();
|
||||
assert.equal(h.requests.length, 0, 'the aircraft takes the tap');
|
||||
assert.equal(h.layer.getSelectedInfo(), null);
|
||||
} finally {
|
||||
h.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
// A touch contact whose layer acts only on exact hits does not take the tap
|
||||
// from our card; with no card, a coarse tap near an aircraft still clears.
|
||||
test('a fire card keeps a tap whose contact does not act; bare taps still clear', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const fire = makeFire();
|
||||
registerPickOwner('test-cameras', (pickedId) => pickedId === 'cam:1');
|
||||
registerPickOwner('test-planes', (pickedId) => pickedId === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
t.after(() => {
|
||||
unregisterPickOwner('test-cameras');
|
||||
unregisterPickOwner('test-planes');
|
||||
});
|
||||
const carded = harness({
|
||||
fires: [fire],
|
||||
drilled: [{ id: 'cam:1' }],
|
||||
cardHit: `fire:${fireDetectionKey(fire)}`,
|
||||
});
|
||||
try {
|
||||
carded.click();
|
||||
assert.equal(carded.requests.length, 1, 'the card acts');
|
||||
} finally {
|
||||
carded.cleanup();
|
||||
}
|
||||
const bare = harness({
|
||||
fires: [fire],
|
||||
picked: glowPick('firms-7'),
|
||||
drilled: [{ id: 'plane:1' }],
|
||||
});
|
||||
try {
|
||||
bare.click();
|
||||
assert.ok(bare.layer.getSelectedInfo(), 'a fire is selected');
|
||||
// Nothing exact now; the touch contact is an aircraft, with no card.
|
||||
bare.setPicked(null);
|
||||
bare.click();
|
||||
assert.equal(bare.layer.getSelectedInfo(), null, 'the bare tap clears');
|
||||
} finally {
|
||||
bare.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('a stale card id resolves to nothing instead of an arbitrary fire', () => {
|
||||
const h = harness({
|
||||
picked: { primitive: {}, content: {}, featureId: 0 },
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/**
|
||||
* Which pick owners select nearby contacts. A coarse tap's shared contact
|
||||
* hit (`pickContact`) can land on a contact near an exact miss; only owners
|
||||
* whose click handlers act on such a hit, or on their own pick window,
|
||||
* register `expanded`, so a quake card or label yields to them and not to
|
||||
* exact-only owners (FIRMS, CCTV). Each case runs the layer's own
|
||||
* registration code (its enable or install step) with stand-in services.
|
||||
*/
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createLifecycle as createFlightLifecycle } from '../layers/flights/lifecycle.js';
|
||||
import { createLifecycle as createMilitaryLifecycle } from '../layers/military/lifecycle.js';
|
||||
import { createLifecycle as createVesselLifecycle } from '../layers/vessels/lifecycle.js';
|
||||
import { createInteraction as createRadioInteraction } from '../layers/radio/interaction.js';
|
||||
import { createSelection as createStreetSelection } from '../layers/streetLevel/selection.js';
|
||||
import { fakeInput } from '../input/testDoubles.mjs';
|
||||
import { STREET_LEVEL_LAYER_ID } from '../layers/streetLevel/policy.js';
|
||||
import * as picking from './pickRegistry.js';
|
||||
|
||||
/**
|
||||
* A stand-in for any collaborator: every property is another stand-in and
|
||||
* every call returns one, except the keys `given` names. Not a thenable.
|
||||
*/
|
||||
function stub(given = {}) {
|
||||
return new Proxy(function stand() {}, {
|
||||
get(target, key) {
|
||||
if (key in given) return given[key];
|
||||
if (key === 'then' || typeof key === 'symbol') return undefined;
|
||||
return stub();
|
||||
},
|
||||
set(target, key, value) {
|
||||
given[key] = value;
|
||||
return true;
|
||||
},
|
||||
apply: () => stub(),
|
||||
});
|
||||
}
|
||||
|
||||
/** Picking services that record each registration's options. */
|
||||
function recordingPicking() {
|
||||
const registered = new Map();
|
||||
return {
|
||||
registered,
|
||||
services: {
|
||||
...picking,
|
||||
registerPickOwner(layerId, predicate, options) {
|
||||
registered.set(layerId, options ?? {});
|
||||
picking.registerPickOwner(layerId, predicate, options);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function withDocument(t) {
|
||||
const previous = globalThis.document;
|
||||
globalThis.document = {
|
||||
body: { classList: { contains: () => false } },
|
||||
addEventListener() {},
|
||||
removeEventListener() {},
|
||||
};
|
||||
t.after(() => {
|
||||
if (previous === undefined) delete globalThis.document;
|
||||
else globalThis.document = previous;
|
||||
});
|
||||
}
|
||||
|
||||
/** A quake card over `pickedId` reached as a nearby touch contact. */
|
||||
const actsOnNearbyHit = (pickedId) =>
|
||||
picking.isActedOnByOtherLayer('earthquakes', pickedId, { expanded: true });
|
||||
|
||||
for (const [name, layerId, create] of [
|
||||
['flights', 'flights', createFlightLifecycle],
|
||||
['military', 'military', createMilitaryLifecycle],
|
||||
]) {
|
||||
test(`${name} registers its aircraft as acting on nearby touch hits`, (t) => {
|
||||
withDocument(t);
|
||||
const { registered, services } = recordingPicking();
|
||||
const flightState = stub({
|
||||
_icons: { show: false, has: (id) => id === `${name}-1` },
|
||||
records: { geoidReady: true },
|
||||
timeline: null,
|
||||
_trackedIcao: null,
|
||||
});
|
||||
const { methods: lifecycle } = create({
|
||||
flightState,
|
||||
services: stub({ picking: services }),
|
||||
parts: stub(),
|
||||
layer: stub(),
|
||||
resolveAsset: () => '',
|
||||
});
|
||||
t.after(() => picking.unregisterPickOwner(layerId));
|
||||
lifecycle.enable({});
|
||||
assert.equal(registered.get(layerId)?.expanded, true);
|
||||
assert.equal(actsOnNearbyHit(`${name}-1`), true);
|
||||
// A click on the aircraft already tracked is ignored, so it is passive.
|
||||
flightState._trackedIcao = `${name}-1`;
|
||||
assert.equal(actsOnNearbyHit(`${name}-1`), false);
|
||||
});
|
||||
}
|
||||
|
||||
test('vessels register their icons as acting on nearby touch hits', (t) => {
|
||||
withDocument(t);
|
||||
const { registered, services } = recordingPicking();
|
||||
const state = {
|
||||
feed: { enabled: true, sessionId: 1 },
|
||||
records: { byId: new Map([['vessel-1', {}]]) },
|
||||
viewer: {},
|
||||
};
|
||||
const created = createVesselLifecycle({
|
||||
vesselState: stub({ state, _geoidReady: true }),
|
||||
services: stub({ picking: services }),
|
||||
parts: stub(),
|
||||
});
|
||||
const lifecycle = created.methods ?? created;
|
||||
t.after(() => picking.unregisterPickOwner('ais-live-vessels'));
|
||||
lifecycle.enable({});
|
||||
assert.equal(registered.get('ais-live-vessels')?.expanded, true);
|
||||
assert.equal(actsOnNearbyHit('vessel-1'), true);
|
||||
});
|
||||
|
||||
test('radio registers its stations as acting on nearby touch hits', (t) => {
|
||||
const { registered, services } = recordingPicking();
|
||||
const viewer = { scene: { canvas: new EventTarget(), pick: () => null } };
|
||||
const input = fakeInput(viewer);
|
||||
const state = { _viewer: viewer, _clickSubscription: null };
|
||||
const interaction = createRadioInteraction({
|
||||
state,
|
||||
services: { picking: services, overlays: stub() },
|
||||
parts: stub(),
|
||||
});
|
||||
t.after(() => {
|
||||
interaction.removeInteraction();
|
||||
input.destroy();
|
||||
});
|
||||
interaction.installInteraction();
|
||||
assert.equal(registered.get('radio')?.expanded, true);
|
||||
assert.equal(actsOnNearbyHit('radio:kexp'), true);
|
||||
interaction.removeInteraction();
|
||||
assert.equal(actsOnNearbyHit('radio:kexp'), false);
|
||||
});
|
||||
|
||||
test('Street Level registers its picks as acting on nearby touch hits', (t) => {
|
||||
withDocument(t);
|
||||
const { registered, services } = recordingPicking();
|
||||
const viewer = { scene: { canvas: new EventTarget(), pick: () => null } };
|
||||
const input = fakeInput(viewer);
|
||||
const state = { services: { picking: services }, clickSubscription: null };
|
||||
const selection = createStreetSelection({
|
||||
state,
|
||||
parts: stub({
|
||||
router: {
|
||||
ownsPick: (id) => id === 'mly:seq-1',
|
||||
resolve: (id) => (id === 'mly:seq-1' ? { id, instance: {} } : null),
|
||||
},
|
||||
}),
|
||||
});
|
||||
t.after(() => {
|
||||
state.clickSubscription?.();
|
||||
picking.unregisterPickOwner(STREET_LEVEL_LAYER_ID);
|
||||
input.destroy();
|
||||
});
|
||||
selection.install(viewer);
|
||||
assert.equal(registered.get(STREET_LEVEL_LAYER_ID)?.expanded, true);
|
||||
assert.equal(actsOnNearbyHit('mly:seq-1'), true);
|
||||
});
|
||||
@@ -33,6 +33,8 @@ const _owners = new Map();
|
||||
* @type {Map<string, true | ((pickedId: string) => boolean)>}
|
||||
*/
|
||||
const _passive = new Map();
|
||||
/** Owners whose click handlers also select nearby contacts. */
|
||||
const _expanded = new Set();
|
||||
/**
|
||||
* Layers whose shapes are background to any card painted over them: their
|
||||
* click handlers stand aside under a card, so the card's layer may act there.
|
||||
@@ -60,14 +62,22 @@ export function resolvePickId(hit) {
|
||||
* @param {string} layerId - Owning layer id (e.g. 'flights').
|
||||
* @param {(pickedId: string) => boolean} predicate - Returns true when the
|
||||
* picked primitive/entity id belongs to this layer.
|
||||
* @param {{passive?: boolean | ((pickedId: string) => boolean)}} [options]
|
||||
* @param {{passive?: boolean | ((pickedId: string) => boolean), expanded?: boolean}} [options]
|
||||
* `passive`: the layer never acts on a click on these picks (all of them,
|
||||
* or those the predicate names). See {@link isActedOnByOtherLayer}.
|
||||
* `expanded`: preserve precedence for handlers that select nearby contacts,
|
||||
* through the shared contact hit or their own pick window.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function registerPickOwner(layerId, predicate, { passive } = {}) {
|
||||
export function registerPickOwner(
|
||||
layerId,
|
||||
predicate,
|
||||
{ passive, expanded = false } = {},
|
||||
) {
|
||||
if (!layerId || typeof predicate !== 'function') return;
|
||||
_owners.set(layerId, predicate);
|
||||
if (expanded) _expanded.add(layerId);
|
||||
else _expanded.delete(layerId);
|
||||
if (passive === true || typeof passive === 'function')
|
||||
_passive.set(layerId, passive);
|
||||
else _passive.delete(layerId);
|
||||
@@ -80,6 +90,7 @@ export function registerPickOwner(layerId, predicate, { passive } = {}) {
|
||||
*/
|
||||
export function unregisterPickOwner(layerId) {
|
||||
_owners.delete(layerId);
|
||||
_expanded.delete(layerId);
|
||||
_passive.delete(layerId);
|
||||
}
|
||||
|
||||
@@ -125,12 +136,18 @@ export function isOwnedByOtherLayer(layerId, pickedId) {
|
||||
* painted over a passive pick (a flight trail) is still the card's click.
|
||||
* @param {string} layerId - The asking layer's id (excluded from the scan).
|
||||
* @param {string} pickedId - Picked primitive/entity id.
|
||||
* @param {{expanded?: boolean}} [options] A nearby rather than exact hit:
|
||||
* only owners whose handlers select nearby contacts take precedence.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isActedOnByOtherLayer(layerId, pickedId) {
|
||||
export function isActedOnByOtherLayer(
|
||||
layerId,
|
||||
pickedId,
|
||||
{ expanded = false } = {},
|
||||
) {
|
||||
if (!pickedId) return false;
|
||||
for (const [ownerId, predicate] of _owners) {
|
||||
if (ownerId === layerId) continue;
|
||||
if (ownerId === layerId || (expanded && !_expanded.has(ownerId))) continue;
|
||||
try {
|
||||
if (!predicate(pickedId)) continue;
|
||||
const passive = _passive.get(ownerId);
|
||||
|
||||
@@ -158,6 +158,40 @@ test('ownership: passive owners still own their picks but act on none of them',
|
||||
assert.equal(isActedOnByOtherLayer('cards', 'route:line'), false);
|
||||
assert.equal(isActedOnByOtherLayer('cards', 'route:step:3'), true);
|
||||
assert.equal(isActedOnByOtherLayer('cards', 'plane:1'), true);
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('cards', 'plane:1', { expanded: true }),
|
||||
false,
|
||||
);
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('cards', 'plane:1', { expanded: true }),
|
||||
true,
|
||||
);
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
passive: true,
|
||||
});
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('cards', 'plane:1', { expanded: true }),
|
||||
false,
|
||||
);
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1');
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('cards', 'plane:1', { expanded: true }),
|
||||
false,
|
||||
);
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
unregisterPickOwner('test-plane');
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1');
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('cards', 'plane:1', { expanded: true }),
|
||||
false,
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('test-plane', 'plane:1'),
|
||||
false,
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { getContextStore, isContextRecordActive } from './contextStore.js';
|
||||
import { readEntityRecord } from './entityRecords.js';
|
||||
import { findPickOwner, resolvePickId } from './pickRegistry.js';
|
||||
import {
|
||||
findPickOwner,
|
||||
isActedOnByOtherLayer,
|
||||
resolvePickId,
|
||||
} from './pickRegistry.js';
|
||||
|
||||
/**
|
||||
* Resolve a pick (the contract's `Hit`, as `pickAt` in
|
||||
@@ -123,3 +127,25 @@ export function resolvePickedContext(picked, { dataManager = null } = {}) {
|
||||
altitudeM: finite(found?.altitudeM),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a world-overlay card or label under a click keeps it from the item
|
||||
* the click names, because that item's owner does not act on this hit: a
|
||||
* passive owner (a directions route) acts on none, and an owner that acts
|
||||
* only on exact hits (a fire, a camera) does not act on a coarse pointer's
|
||||
* nearby contact (`hit` is not the exact `topHit`). The card's layer takes
|
||||
* such a click (quake, fire, camera, vessel, news and wildlife cards act over
|
||||
* it; an inert card, such as a selected drone-zone card, does nothing), so
|
||||
* Context leaves the item; owners that act on it (an aircraft, a vessel, a
|
||||
* directions step) still name it.
|
||||
* @param {{hit?: object|null, topHit?: object|null}} click
|
||||
* @param {boolean} underCard Whether a world-overlay entry is under it.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function cardKeepsClick(click, underCard) {
|
||||
if (!underCard || !click?.hit) return false;
|
||||
const pickId = resolvePickId(click.hit);
|
||||
if (!pickId) return false;
|
||||
const expanded = pickId !== resolvePickId(click.topHit ?? null);
|
||||
return !isActedOnByOtherLayer('', pickId, { expanded });
|
||||
}
|
||||
@@ -12,7 +12,7 @@ globalThis.dispatchEvent ||= () => true;
|
||||
|
||||
const { registerEntityContext } = await import('./contextStore.js');
|
||||
const { registerPickOwner, unregisterPickOwner, findPickOwner } = await import('./pickRegistry.js');
|
||||
const { resolvePickedContext, pickedKindForLayer } = await import('./pickedContext.js');
|
||||
const { resolvePickedContext, pickedKindForLayer, cardKeepsClick } = await import('./pickedContext.js');
|
||||
|
||||
function manager({ enabled = new Set(['flights', 'local-datacenters']), modules = {} } = {}) {
|
||||
return {
|
||||
@@ -97,3 +97,53 @@ test('disabled layers, trails and empty picks never resolve', () => {
|
||||
assert.equal(resolvePickedContext(hit('unknown'), { dataManager: manager() }), null);
|
||||
assert.equal(pickedKindForLayer('ais-live-vessels'), 'vessel');
|
||||
});
|
||||
|
||||
test('a card keeps a click from items whose layer does not act on that hit', (t) => {
|
||||
registerPickOwner('test-fires', (id) => id === 'fire:1');
|
||||
registerPickOwner('test-planes', (id) => id === 'plane:1', {
|
||||
expanded: true,
|
||||
});
|
||||
registerPickOwner('test-route', (id) => id.startsWith('route:'), {
|
||||
passive: (id) => !id.startsWith('route:step:'),
|
||||
});
|
||||
t.after(() => {
|
||||
unregisterPickOwner('test-fires');
|
||||
unregisterPickOwner('test-planes');
|
||||
unregisterPickOwner('test-route');
|
||||
});
|
||||
const fire = { set: 'fires:1', id: 'fire:1' };
|
||||
const plane = { set: 'planes:1', id: 'plane:1' };
|
||||
const exact = (hit) => ({ topHit: { ...hit }, hit });
|
||||
// A coarse tap: nothing exact, the contact found nearby.
|
||||
const near = (hit) => ({ topHit: null, hit });
|
||||
assert.equal(
|
||||
cardKeepsClick(near(fire), true),
|
||||
true,
|
||||
'fires act only on exact hits',
|
||||
);
|
||||
assert.equal(cardKeepsClick(near(plane), true), false, 'aircraft act nearby');
|
||||
assert.equal(
|
||||
cardKeepsClick(near(fire), false),
|
||||
false,
|
||||
'open map: Context names it',
|
||||
);
|
||||
assert.equal(
|
||||
cardKeepsClick(exact(fire), true),
|
||||
false,
|
||||
"an exact fire is the fire's",
|
||||
);
|
||||
const line = { set: 'route:1', id: 'route:line' };
|
||||
const step = { set: 'route:1', id: 'route:step:2' };
|
||||
// Every card layer acts over a passive route, so the card keeps the click.
|
||||
assert.equal(
|
||||
cardKeepsClick(exact(line), true),
|
||||
true,
|
||||
'a route acts for nobody',
|
||||
);
|
||||
assert.equal(
|
||||
cardKeepsClick(exact(step), true),
|
||||
false,
|
||||
"a step is directions' own",
|
||||
);
|
||||
assert.equal(cardKeepsClick({ topHit: null, hit: null }, true), false);
|
||||
});
|
||||
Reference in new issue
Block a user