mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
fix(picking): settle which layers act on a click when it resolves
The flights and military layers treat the aircraft they already track as a passive pick, but they start tracking during the click itself. A card handler running later in the same click then saw the plane as passive and acted too: a quake card opened its source while the plane started tracking, and fire, CCTV and vessel cards could do the same. The pick registry now records the acting owners of a click's exact hit and touch contact when the dispatcher first resolves them, and the quake, FIRMS, CCTV, vessel and Context checks read that record for the rest of the click. Calls without a click keep the live lookup.
This commit is contained in:
1 parent
830c980ca6
commit
54fd3d3bed
13 files changed
+239
-48
No files matched your search
@@ -437,7 +437,7 @@ export function createLifecycle({
|
||||
typeof pickedId === 'string' &&
|
||||
Boolean(isActedOnByOtherLayer) &&
|
||||
isOwnedByOtherLayer?.('cctv', pickedId) &&
|
||||
!isActedOnByOtherLayer('cctv', pickedId);
|
||||
!isActedOnByOtherLayer('cctv', pickedId, { click: event });
|
||||
if (pickedId !== null && !cardBackground && !passiveUnderCard) return;
|
||||
// A coarse tap's touch contact (not the exact pick) that its layer
|
||||
// acts on (an aircraft, a vessel, a radio station) is that layer's
|
||||
@@ -447,7 +447,10 @@ export function createLifecycle({
|
||||
cardId &&
|
||||
contactId &&
|
||||
contactId !== pickedId &&
|
||||
isActedOnByOtherLayer?.('cctv', contactId, { expanded: true })
|
||||
isActedOnByOtherLayer?.('cctv', contactId, {
|
||||
expanded: true,
|
||||
click: event,
|
||||
})
|
||||
)
|
||||
return;
|
||||
if (cardHit && cardHit.sourceId !== CCTV_OVERLAY_SOURCE_ID) return;
|
||||
|
||||
@@ -88,6 +88,12 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
};
|
||||
let drilled = [];
|
||||
const input = fakeInput(viewer);
|
||||
// An aircraft layer that runs before ours and starts tracking the plane
|
||||
// it was clicked on, which makes that plane passive mid-click.
|
||||
let tracked = null;
|
||||
input.input.onClick((event) => {
|
||||
if (event.hit?.id === 'plane:9') tracked = 'plane:9';
|
||||
});
|
||||
const ownCard = { sourceId: CCTV_OVERLAY_SOURCE_ID, entryId: 'cam-1' };
|
||||
const foreignCard = {
|
||||
sourceId: 'earthquake-card',
|
||||
@@ -145,6 +151,7 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
picking.unregisterPickOwner('area-control');
|
||||
picking.unregisterPickOwner('test-trails');
|
||||
picking.unregisterPickOwner('test-planes');
|
||||
picking.unregisterPickOwner('test-tracking');
|
||||
picking.unregisterCardBackground('area-fixture');
|
||||
});
|
||||
await lifecycle.methods.init(viewer);
|
||||
@@ -225,6 +232,15 @@ test('world clicks respect the painted top card and registered card backgrounds'
|
||||
picking.unregisterPickOwner('test-planes');
|
||||
if (previousMatch) globalThis.matchMedia = previousMatch;
|
||||
else delete globalThis.matchMedia;
|
||||
// The live card reads the owners that acted when the click resolved, so it
|
||||
// yields to the aircraft even though tracking made it passive meanwhile.
|
||||
picking.registerPickOwner('test-tracking', (id) => id === 'plane:9', {
|
||||
expanded: true,
|
||||
passive: (id) => id === tracked,
|
||||
});
|
||||
click({ set: 'flights:1', id: 'plane:9', surface: false }, [ownCard], []);
|
||||
assert.equal(tracked, 'plane:9', 'the aircraft started tracking');
|
||||
picking.unregisterPickOwner('test-tracking');
|
||||
picking.registerPickOwner('area-control', (id) => id === drone.id);
|
||||
click(drone, [ownCard], []);
|
||||
picking.unregisterPickOwner('area-control');
|
||||
|
||||
@@ -356,7 +356,8 @@ export function createEarthquakesLayer({
|
||||
// since the dispatcher may expose distinct objects for the same pick.
|
||||
const expanded =
|
||||
'topHit' in click && picking.resolvePickId(click.topHit) !== pickId;
|
||||
if (pickId && actedOn(EARTHQUAKES_LAYER_ID, pickId, { expanded })) return;
|
||||
if (pickId && actedOn(EARTHQUAKES_LAYER_ID, pickId, { expanded, click }))
|
||||
return;
|
||||
const cardHit = overlayHost.hitTest?.(at?.x, at?.y, {
|
||||
sourceId: EARTHQUAKE_CARD_SOURCE_ID,
|
||||
});
|
||||
|
||||
@@ -701,33 +701,70 @@ test("another layer's card over a quake disc takes the click, and the disc yield
|
||||
}
|
||||
});
|
||||
|
||||
test("another layer's object under the quake card takes the click", async () => {
|
||||
const h = harness([quake('ak1')]);
|
||||
picking.registerPickOwner('test-plane', (id) => id === 'plane-9');
|
||||
try {
|
||||
for (const coarse of [false, true]) {
|
||||
test(`a quake card yields while an aircraft starts tracking (${coarse ? 'coarse' : 'exact'} hit)`, async (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: coarse });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const plane = { set: 'flights:1', id: 'plane-9' };
|
||||
let sceneHit = null;
|
||||
let nearby = null;
|
||||
let tracked = null;
|
||||
let tracks = 0;
|
||||
let input;
|
||||
const h = harness([quake('ak1')], {
|
||||
input(viewer) {
|
||||
viewer.scene = {
|
||||
pick: () => (sceneHit ? { id: sceneHit } : null),
|
||||
drillPick: () => (nearby ? [{ id: nearby }] : []),
|
||||
};
|
||||
input = fakeInput(viewer);
|
||||
// The aircraft layer runs first and changes its passive predicate
|
||||
// synchronously after reading the dispatched hit.
|
||||
input.input.onClick((event) => {
|
||||
const id = event.hit?.id;
|
||||
if (id !== plane.id || tracked === id) return;
|
||||
tracked = id;
|
||||
tracks++;
|
||||
});
|
||||
return input.input;
|
||||
},
|
||||
});
|
||||
picking.registerPickOwner('test-plane', (id) => id === plane.id, {
|
||||
expanded: true,
|
||||
passive: (id) => id === tracked,
|
||||
});
|
||||
t.after(() => {
|
||||
picking.unregisterPickOwner('test-plane');
|
||||
h.layer.destroy();
|
||||
input?.destroy();
|
||||
});
|
||||
h.layer.enable(h.viewer);
|
||||
await h.layer.update(h.viewer);
|
||||
h.clickDisc('ak1');
|
||||
sceneHit = { set: h.discs().spec.id, id: 'earthquake:ak1' };
|
||||
input.click();
|
||||
const card = h.lastCard()[0];
|
||||
// The card is painted over a plane: the flight layer acts on the click,
|
||||
// so the card neither opens its link nor changes.
|
||||
overlayHitCard(h, card.id, { set: 'flights:1', id: 'plane-9' });
|
||||
assert.deepEqual(h.opened, []);
|
||||
h.overlayHits.set(EARTHQUAKE_CARD_SOURCE_ID, {
|
||||
sourceId: EARTHQUAKE_CARD_SOURCE_ID,
|
||||
entryId: card.id,
|
||||
});
|
||||
sceneHit = coarse ? null : plane;
|
||||
nearby = coarse ? plane : null;
|
||||
|
||||
input.click();
|
||||
assert.equal(tracks, 1, 'the aircraft starts tracking');
|
||||
assert.deepEqual(h.opened, [], 'the quake card yields for the whole click');
|
||||
assert.equal(h.lastCard()[0].id, card.id, 'the card stays');
|
||||
// Over open ground the card opens the USGS page.
|
||||
h.clickCard(card.id);
|
||||
|
||||
input.click();
|
||||
assert.equal(tracks, 1, 'already tracking the aircraft');
|
||||
assert.deepEqual(h.opened, [
|
||||
'https://earthquake.usgs.gov/earthquakes/eventpage/ak1',
|
||||
]);
|
||||
} finally {
|
||||
picking.unregisterPickOwner('test-plane');
|
||||
h.layer.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
/** Click this layer's card with `hit` (another layer's object) under it. */
|
||||
function overlayHitCard(h, entryId, hit) {
|
||||
h.clickOverlayWith(EARTHQUAKE_CARD_SOURCE_ID, entryId, hit);
|
||||
});
|
||||
}
|
||||
|
||||
for (const kind of ['card', 'label']) {
|
||||
|
||||
@@ -51,7 +51,7 @@ export function createSelection({
|
||||
if (pickedId && isOwnedByOtherLayer(id, pickedId)) {
|
||||
passivePick =
|
||||
Boolean(isActedOnByOtherLayer) &&
|
||||
!isActedOnByOtherLayer(id, pickedId);
|
||||
!isActedOnByOtherLayer(id, pickedId, { click: event });
|
||||
if (!passivePick) return;
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ export function createSelection({
|
||||
cardHit &&
|
||||
contactId &&
|
||||
contactId !== resolvePickId(picked ?? null) &&
|
||||
isActedOnByOtherLayer?.(id, contactId, { expanded: true })
|
||||
isActedOnByOtherLayer?.(id, contactId, { expanded: true, click: event })
|
||||
)
|
||||
return;
|
||||
if (cardHit) {
|
||||
|
||||
@@ -62,7 +62,9 @@ export function createSelection({
|
||||
(String(pickedId).startsWith('gev-trail:') ||
|
||||
(Boolean(isActedOnByOtherLayer) &&
|
||||
isOwnedByOtherLayer('ais-live-vessels', pickedId) &&
|
||||
!isActedOnByOtherLayer('ais-live-vessels', pickedId)));
|
||||
!isActedOnByOtherLayer('ais-live-vessels', pickedId, {
|
||||
click: event,
|
||||
})));
|
||||
if (passivePick && !ownCardUnder()) return;
|
||||
|
||||
// A sibling layer already owns this click. Preserve the current vessel
|
||||
@@ -85,6 +87,7 @@ export function createSelection({
|
||||
resolvePickId?.(event.topHit ?? null) !== pickedId &&
|
||||
!isActedOnByOtherLayer('ais-live-vessels', pickedId, {
|
||||
expanded: true,
|
||||
click: event,
|
||||
});
|
||||
if (!nearMissOfExactOnly || !ownCardUnder()) return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user