mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
fix(picking): arbitrate card clicks over passive and background shapes
Flight trails register their ids so every layer reads a trail click as a
no-op, and the directions route claims its line and markers though it acts
only on its maneuver steps. The quake card and magnitude labels yielded to
any registered owner, so over a trail or a route they did nothing. Pick
owners can now name the picks they never act on (registerPickOwner(...,
{ passive })); isActedOnByOtherLayer leaves those out while
isOwnedByOtherLayer is unchanged, so they are still not empty space.
Submarine cables and rocket launches acted on any scene pick, so a card or
label over a cable or a launch marker made both layers act. Both now stand
aside when a world-overlay entry is under the click, as drone airspace and
fire perimeters do through the top-entry check. Each of these layers, and
the quake discs, registers its shapes with registerCardBackground. CCTV
asks isCardBackground instead of matching other layers' set and id formats,
so a live top CCTV card acts once over any of them, while unknown
identified objects and registered owners still block it.
This commit is contained in:
1 parent
836daf82b3
commit
133d022b29
23 files changed
+825
-78
No files matched your search
@@ -1022,10 +1022,6 @@ test('CCTV repeated in-world clicks dispatch focus only for the one real activat
|
||||
componentFunctionSource(cctvLayer.init),
|
||||
/_cctvOverlayHost\.hitTest/,
|
||||
);
|
||||
assert.match(
|
||||
componentFunctionSource(cctvLayer.init),
|
||||
/sourceId: CCTV_OVERLAY_SOURCE_ID/,
|
||||
);
|
||||
assert.match(
|
||||
componentFunctionSource(cctvLayer.init),
|
||||
/activateCctvCameraFromWorldClick\(cameraId, setActiveCamera\)/,
|
||||
@@ -1157,11 +1153,8 @@ test('CCTV empty-click gate excludes every identified scene object, ADJUST, and
|
||||
);
|
||||
|
||||
const initSource = componentFunctionSource(cctvLayer.init);
|
||||
assert.ok(
|
||||
initSource.indexOf('if (pickedId !== null) return') <
|
||||
initSource.indexOf('_cctvOverlayHost.hitTest'),
|
||||
'every identified sibling must win before an overlapping CCTV card hit test',
|
||||
);
|
||||
// The real init-bound click route, including identified-object barriers,
|
||||
// is exercised in layers/cctv/lifecycle.test.mjs.
|
||||
assert.match(initSource, /activeCameraId: _activeCameraId/);
|
||||
assert.match(initSource, /calibrationMode: _calibrationMode/);
|
||||
});
|
||||
|
||||
@@ -28,6 +28,8 @@ import {
|
||||
createApplicationDirectionsLayer,
|
||||
} from './directions.js';
|
||||
import { GROUND_FLOOR_LIFT_M } from './groundFloor.js';
|
||||
import { isActedOnByOtherLayer, isOwnedByOtherLayer } from './pickRegistry.js';
|
||||
import { fakeInput } from '../input/testDoubles.mjs';
|
||||
import { instructionFor } from './routeSteps.js';
|
||||
import { setLocale } from '../i18n/index.js';
|
||||
import {
|
||||
@@ -465,6 +467,45 @@ function ownershipFixture(t) {
|
||||
});
|
||||
}
|
||||
|
||||
// Directions acts only on its maneuver steps. The route line and the A/B
|
||||
// markers are passive picks: still not empty space to other layers, but a
|
||||
// card painted over them (a quake card) keeps its click.
|
||||
test('enabled, directions owns its picks and acts only on its steps', (t) => {
|
||||
ownershipFixture(t);
|
||||
const viewer = {
|
||||
scene: {
|
||||
pick: () => null,
|
||||
canvas: { clientWidth: 100, clientHeight: 100 },
|
||||
},
|
||||
};
|
||||
const input = fakeInput(viewer);
|
||||
t.after(() => input.destroy());
|
||||
directionsLayer.enable(viewer);
|
||||
try {
|
||||
for (const id of [
|
||||
'directions:route',
|
||||
'directions:marker:a',
|
||||
'directions:step:3',
|
||||
])
|
||||
assert.equal(isOwnedByOtherLayer('earthquakes', id), true, id);
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('earthquakes', 'directions:route'),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('earthquakes', 'directions:marker:a'),
|
||||
false,
|
||||
);
|
||||
assert.equal(
|
||||
isActedOnByOtherLayer('earthquakes', 'directions:step:3'),
|
||||
true,
|
||||
);
|
||||
} finally {
|
||||
directionsLayer.disable(viewer);
|
||||
}
|
||||
assert.equal(isOwnedByOtherLayer('earthquakes', 'directions:route'), false);
|
||||
});
|
||||
|
||||
test('placing an endpoint takes the pointer, and every exit path gives it back', (t) => {
|
||||
ownershipFixture(t);
|
||||
|
||||
|
||||
@@ -26,6 +26,19 @@ const isSurface = (hit) => !hit || hit.surface === true;
|
||||
|
||||
/** @type {Map<string, (pickedId: string) => boolean>} layerId -> ownership predicate */
|
||||
const _owners = new Map();
|
||||
/**
|
||||
* Owners that claim picks but never act on a click on them (flight trails, a
|
||||
* directions route line): `true` for all of an owner's picks, or a predicate
|
||||
* naming which. Their picks are still not empty space to other layers.
|
||||
* @type {Map<string, true | ((pickedId: string) => boolean)>}
|
||||
*/
|
||||
const _passive = new Map();
|
||||
/**
|
||||
* 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.
|
||||
* @type {Map<string, (hit: import('../render/contract/query').Hit) => boolean>}
|
||||
*/
|
||||
const _cardBackgrounds = new Map();
|
||||
|
||||
/**
|
||||
* A hit's canonical pick id, for the ownership scan: its item's id. Layers'
|
||||
@@ -47,11 +60,17 @@ 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]
|
||||
* `passive`: the layer never acts on a click on these picks (all of them,
|
||||
* or those the predicate names). See {@link isActedOnByOtherLayer}.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function registerPickOwner(layerId, predicate) {
|
||||
export function registerPickOwner(layerId, predicate, { passive } = {}) {
|
||||
if (!layerId || typeof predicate !== 'function') return;
|
||||
_owners.set(layerId, predicate);
|
||||
if (passive === true || typeof passive === 'function')
|
||||
_passive.set(layerId, passive);
|
||||
else _passive.delete(layerId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,6 +80,7 @@ export function registerPickOwner(layerId, predicate) {
|
||||
*/
|
||||
export function unregisterPickOwner(layerId) {
|
||||
_owners.delete(layerId);
|
||||
_passive.delete(layerId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,6 +119,31 @@ export function isOwnedByOtherLayer(layerId, pickedId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when some OTHER registered layer owns the picked id and acts on a
|
||||
* click on it: {@link isOwnedByOtherLayer} without passive owners. A card
|
||||
* 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.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isActedOnByOtherLayer(layerId, pickedId) {
|
||||
if (!pickedId) return false;
|
||||
for (const [ownerId, predicate] of _owners) {
|
||||
if (ownerId === layerId) continue;
|
||||
try {
|
||||
if (!predicate(pickedId)) continue;
|
||||
const passive = _passive.get(ownerId);
|
||||
if (passive === true) continue;
|
||||
if (typeof passive === 'function' && passive(pickedId)) continue;
|
||||
return true;
|
||||
} catch {
|
||||
// a broken predicate must never break click handling
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a moving-contact click without letting map tiles hide a nearby touch
|
||||
* target. Exact picks always win; only a coarse primary pointer may expand a
|
||||
@@ -145,3 +190,43 @@ export function pickContact(query, position, options = {}) {
|
||||
}
|
||||
return picked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a layer's unowned shapes that stand aside for a card painted over
|
||||
* them (its click handler returns when a world-overlay entry is on top).
|
||||
* @param {string} layerId - Registering layer id.
|
||||
* @param {(hit: import('../render/contract/query').Hit) => boolean} predicate
|
||||
* True when a click's draw hit is one of this layer's shapes.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function registerCardBackground(layerId, predicate) {
|
||||
if (!layerId || typeof predicate !== 'function') return;
|
||||
_cardBackgrounds.set(layerId, predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a layer's card-background predicate (call when its clicks stop).
|
||||
* @param {string} layerId - Registering layer id.
|
||||
* @returns {void}
|
||||
*/
|
||||
export function unregisterCardBackground(layerId) {
|
||||
_cardBackgrounds.delete(layerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* True when a click's draw hit is a shape whose layer stands aside for a card
|
||||
* painted over it, so that card may act on the click.
|
||||
* @param {import('../render/contract/query').Hit|null|undefined} hit
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isCardBackground(hit) {
|
||||
if (isSurface(hit)) return false;
|
||||
for (const predicate of _cardBackgrounds.values()) {
|
||||
try {
|
||||
if (predicate(hit)) return true;
|
||||
} catch {
|
||||
// a broken predicate must never break click handling
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -15,8 +15,13 @@ import {
|
||||
registerPickOwner,
|
||||
unregisterPickOwner,
|
||||
isOwnedByOtherLayer,
|
||||
isActedOnByOtherLayer,
|
||||
resolvePickId,
|
||||
pickContact,
|
||||
findPickOwner,
|
||||
registerCardBackground,
|
||||
unregisterCardBackground,
|
||||
isCardBackground,
|
||||
} from './pickRegistry.js';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -49,8 +54,11 @@ test('resolvePickId: the map and nothing → null', () => {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
test('ownership: sibling layers recognize each other via String-coerced ids', () => {
|
||||
const points = new Map([[25544, {}], [43013, {}]]); // satellites: numeric keys
|
||||
const vessels = new Map([['367123450', {}]]); // AIS: string id keys
|
||||
const points = new Map([
|
||||
[25544, {}],
|
||||
[43013, {}],
|
||||
]); // satellites: numeric keys
|
||||
const vessels = new Map([['367123450', {}]]); // AIS: string id keys
|
||||
registerPickOwner('satellites', (pickedId) => {
|
||||
const norad = Number(pickedId);
|
||||
return Number.isFinite(norad) && points.has(norad);
|
||||
@@ -58,9 +66,15 @@ test('ownership: sibling layers recognize each other via String-coerced ids', ()
|
||||
registerPickOwner('ais-live-vessels', (pickedId) => vessels.has(pickedId));
|
||||
try {
|
||||
// Flights asking about a satellite pick (raw numeric id → String upstream)
|
||||
assert.equal(isOwnedByOtherLayer('flights', resolvePickId(item('sat:1', '25544'))), true);
|
||||
assert.equal(
|
||||
isOwnedByOtherLayer('flights', resolvePickId(item('sat:1', '25544'))),
|
||||
true,
|
||||
);
|
||||
// Flights asking about a vessel pick (an icon row id: the vessel's id)
|
||||
assert.equal(isOwnedByOtherLayer('flights', resolvePickId(item('ais:1', '367123450'))), true);
|
||||
assert.equal(
|
||||
isOwnedByOtherLayer('flights', resolvePickId(item('ais:1', '367123450'))),
|
||||
true,
|
||||
);
|
||||
// A layer never owns its own pick via the sibling scan
|
||||
assert.equal(isOwnedByOtherLayer('satellites', '25544'), false);
|
||||
// Unknown ids belong to nobody
|
||||
@@ -73,7 +87,9 @@ test('ownership: sibling layers recognize each other via String-coerced ids', ()
|
||||
});
|
||||
|
||||
test('ownership: a throwing predicate never breaks click handling', () => {
|
||||
registerPickOwner('broken', () => { throw new Error('boom'); });
|
||||
registerPickOwner('broken', () => {
|
||||
throw new Error('boom');
|
||||
});
|
||||
registerPickOwner('cctv', (pickedId) => pickedId === 'atx-cam-3');
|
||||
try {
|
||||
assert.equal(isOwnedByOtherLayer('flights', 'atx-cam-3'), true);
|
||||
@@ -121,6 +137,49 @@ function query(picked, drillPick = () => assert.fail('must not drill')) {
|
||||
};
|
||||
}
|
||||
|
||||
test('ownership: passive owners still own their picks but act on none of them', () => {
|
||||
registerPickOwner('test-trails', (id) => id.startsWith('trail:'), {
|
||||
passive: true,
|
||||
});
|
||||
registerPickOwner('test-route', (id) => id.startsWith('route:'), {
|
||||
passive: (id) => !id.startsWith('route:step:'),
|
||||
});
|
||||
registerPickOwner('test-plane', (id) => id === 'plane:1');
|
||||
registerPickOwner('test-broken', () => {
|
||||
throw new Error('broken');
|
||||
});
|
||||
try {
|
||||
assert.equal(
|
||||
isOwnedByOtherLayer('cards', 'trail:9'),
|
||||
true,
|
||||
'not empty space',
|
||||
);
|
||||
assert.equal(isActedOnByOtherLayer('cards', 'trail:9'), false);
|
||||
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('test-plane', 'plane:1'),
|
||||
false,
|
||||
'never the asker',
|
||||
);
|
||||
assert.equal(isActedOnByOtherLayer('cards', null), false);
|
||||
// Registering again without the option makes the owner act.
|
||||
registerPickOwner('test-trails', (id) => id.startsWith('trail:'));
|
||||
assert.equal(isActedOnByOtherLayer('cards', 'trail:9'), true);
|
||||
// Unregistering drops the option with the predicate.
|
||||
registerPickOwner('test-trails', (id) => id.startsWith('trail:'), {
|
||||
passive: true,
|
||||
});
|
||||
unregisterPickOwner('test-trails');
|
||||
registerPickOwner('test-trails', (id) => id.startsWith('trail:'));
|
||||
assert.equal(isActedOnByOtherLayer('cards', 'trail:9'), true);
|
||||
} finally {
|
||||
for (const id of ['test-trails', 'test-route', 'test-plane', 'test-broken'])
|
||||
unregisterPickOwner(id);
|
||||
}
|
||||
});
|
||||
|
||||
test('touch contact pick expands only a surface miss, bounded to 8 hits in 14 CSS pixels', (t) => {
|
||||
primaryPointer(t, true);
|
||||
contactOwners(t);
|
||||
@@ -141,10 +200,14 @@ test("touch contact pick uses the click's own pick and drill", (t) => {
|
||||
contactOwners(t);
|
||||
const contact = item('flights:1', 'civil');
|
||||
const asked = [];
|
||||
const found = pickContact(query(null), { x: 1, y: 1 }, {
|
||||
picked: null,
|
||||
drill: (...args) => (asked.push(args), [contact]),
|
||||
});
|
||||
const found = pickContact(
|
||||
query(null),
|
||||
{ x: 1, y: 1 },
|
||||
{
|
||||
picked: null,
|
||||
drill: (...args) => (asked.push(args), [contact]),
|
||||
},
|
||||
);
|
||||
assert.equal(found, contact);
|
||||
assert.deepEqual(asked, [[8, 14, 14]]);
|
||||
});
|
||||
@@ -177,7 +240,13 @@ test('touch expansion stops at an unowned item and respects the drill bound', (t
|
||||
[...Array(8).fill(item('notes:1', 'x')), item('flights:1', 'civil')],
|
||||
[],
|
||||
])
|
||||
assert.equal(pickContact(query(SURFACE, () => hits), { x: 1, y: 1 }), SURFACE);
|
||||
assert.equal(
|
||||
pickContact(
|
||||
query(SURFACE, () => hits),
|
||||
{ x: 1, y: 1 },
|
||||
),
|
||||
SURFACE,
|
||||
);
|
||||
});
|
||||
|
||||
test('fine primary pointers keep the exact mouse pick without a drill', (t) => {
|
||||
@@ -197,3 +266,23 @@ test('touch picking tolerates a failing drill and preserves empty sky', (t) => {
|
||||
])
|
||||
assert.equal(pickContact(query(null, drillPick), { x: 1, y: 1 }), null);
|
||||
});
|
||||
|
||||
test('card backgrounds: a registered shape, never the map, and safe to break', () => {
|
||||
const shape = { set: 'zones:1:fills', id: 'zone:1', surface: false };
|
||||
assert.equal(isCardBackground(shape), false);
|
||||
registerCardBackground('test-zones', (hit) => hit.set === shape.set);
|
||||
registerCardBackground('test-broken', () => {
|
||||
throw new Error('broken predicate');
|
||||
});
|
||||
try {
|
||||
assert.equal(isCardBackground(shape), true);
|
||||
assert.equal(isCardBackground({ ...shape, set: 'other:1' }), false);
|
||||
assert.equal(isCardBackground({ surface: true }), false);
|
||||
assert.equal(isCardBackground(null), false);
|
||||
assert.equal(findPickOwner(shape.id), null, 'not an owner');
|
||||
} finally {
|
||||
unregisterCardBackground('test-zones');
|
||||
unregisterCardBackground('test-broken');
|
||||
}
|
||||
assert.equal(isCardBackground(shape), false);
|
||||
});
|
||||
@@ -36,8 +36,12 @@ import { registerPickOwner } from './pickRegistry.js';
|
||||
// plane being tracked. Claiming the 'gev-trail:' id namespace makes
|
||||
// isOwnedByOtherLayer() true for every layer — clicking a trail is a no-op
|
||||
// everywhere. Registered once at module load; the predicate is pure.
|
||||
registerPickOwner('trails', (pickedId) =>
|
||||
String(pickedId).startsWith('gev-trail:'),
|
||||
// Passive: no layer acts on a trail click, so a card painted over a trail
|
||||
// still takes its click (isActedOnByOtherLayer).
|
||||
registerPickOwner(
|
||||
'trails',
|
||||
(pickedId) => String(pickedId).startsWith('gev-trail:'),
|
||||
{ passive: true },
|
||||
);
|
||||
|
||||
/** @type {number} Uniquifier for trail set and line ids. */
|
||||
|
||||
Reference in new issue
Block a user