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:
manjunath22466 committed 2026-11-17 01:33:06 +05:30
1 parent 836daf82b3
commit 133d022b29
23 files changed
+825 -78

No files matched your search

+99 -10
View File
@@ -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);
});