mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 09:42:21 +00:00
fix(touch): keep radio and Street Level contacts under a card
Under another layer's card, radio and Street Level yielded whenever their own pick window found an item that was not the tap's touch contact. If the contact was a different station or Street Level item of theirs, the card yielded to that contact too, and the tap did nothing. Under a card they now act on their own touch contact, and still yield when the contact is not theirs. On bare map the window keeps its precedence.
This commit is contained in:
1 parent
54fd3d3bed
commit
99bd0443cd
5 files changed
+76
-5
No files matched your search
@@ -2064,7 +2064,9 @@ vessels act on that contact, and so do radio and Street Level, which also pick
|
||||
through their own windows (17 and 9 px). A station or Street Level item found
|
||||
only through that window, not as the exact hit or the touch contact, yields to
|
||||
another layer's card or label painted over it, so a quake card or label beside
|
||||
one acts alone, with a mouse or a coarse pointer. Fire and CCTV cards in turn
|
||||
one acts alone, with a mouse or a coarse pointer; under such a card, their own
|
||||
touch contact stays theirs even when the window names another item. Fire and
|
||||
CCTV cards in turn
|
||||
yield to a touch contact whose layer acts on it. The aircraft a layer already
|
||||
tracks and Street Level's position marker are passive picks, since a click on
|
||||
either does nothing. The pick registry records which owners act on a click's
|
||||
|
||||
@@ -51,9 +51,11 @@ export function createInteraction({
|
||||
if (!stationId) continue;
|
||||
// Found only through our wider window, not as the tap's touch contact:
|
||||
// another layer's card or label painted here is that layer's click,
|
||||
// since its handler never sees this window.
|
||||
if (stationFromPick(event.hit) !== stationId && foreignCardAt(event))
|
||||
return null;
|
||||
// since its handler never sees this window. A station of ours that is
|
||||
// the contact is still ours: that card yields to it.
|
||||
const contactStationId = stationFromPick(event.hit);
|
||||
if (contactStationId !== stationId && foreignCardAt(event))
|
||||
return contactStationId;
|
||||
return stationId;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -101,3 +101,35 @@ test('a window-only station yields to a card painted over it', () => {
|
||||
top = { sourceId: 'radio', entryId: 'radio:kexp' };
|
||||
assert.equal(radio.pickedRadioStationAt(near()), 'kexp', 'our own card');
|
||||
});
|
||||
|
||||
// Under another layer's card, radio's window can name a different station
|
||||
// from the tap's touch contact. The card yields to that contact, a station of
|
||||
// ours, so radio acts on it instead of leaving the click dead.
|
||||
test('under a card, the touch contact station is ours even when the window names another', () => {
|
||||
const radio = createInteraction({
|
||||
state: { _stationById: new Map([['kexp', {}], ['kuow', {}]]) },
|
||||
services: {
|
||||
picking: {
|
||||
resolvePickId: (picked) => picked?.id ?? null,
|
||||
isOwnedByOtherLayer: () => false,
|
||||
registerPickOwner() {},
|
||||
unregisterPickOwner() {},
|
||||
},
|
||||
overlays: {
|
||||
setOverlaySourceVisible() {},
|
||||
hitTestWorldOverlay: () => ({
|
||||
sourceId: 'earthquake-card',
|
||||
entryId: 'earthquake-card:ak1',
|
||||
}),
|
||||
},
|
||||
},
|
||||
parts: { rendering: { radioStationIdFromPick } },
|
||||
});
|
||||
const tap = (contact) => ({
|
||||
...clickEvent({ windowHits: [hit('radio:kexp')] }),
|
||||
hit: contact,
|
||||
screenPosition: { x: 5, y: 5 },
|
||||
});
|
||||
assert.equal(radio.pickedRadioStationAt(tap(hit('radio:kuow'))), 'kuow');
|
||||
assert.equal(radio.pickedRadioStationAt(tap(null)), null, 'no contact');
|
||||
});
|
||||
@@ -36,9 +36,14 @@ export function createSelection({ state, parts }) {
|
||||
// Found only through our window, not as the contact (which is the exact
|
||||
// hit whenever there is one): another layer's card or label painted here
|
||||
// is that layer's click, since its handler never sees this window.
|
||||
// An item of ours that is the contact is still ours: that card yields
|
||||
// to it.
|
||||
if (route && windowId !== contactId) {
|
||||
const at = event.screenPosition;
|
||||
if (state.services.overlayHit?.(at?.x, at?.y)) return;
|
||||
if (state.services.overlayHit?.(at?.x, at?.y)) {
|
||||
route = contactId ? parts.router.resolve(contactId) : null;
|
||||
if (!route) return;
|
||||
}
|
||||
}
|
||||
if (!route && contactId) route = parts.router.resolve(contactId);
|
||||
// Not ours: the ground handler decides whether it is the map itself.
|
||||
|
||||
@@ -424,3 +424,33 @@ test('the position marker is a passive pick; our items act', () => {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
|
||||
// Under another layer's card, our window can name a different item from the
|
||||
// tap's touch contact. The card yields to that contact, an item of ours, so
|
||||
// Street Level opens it instead of leaving the click dead.
|
||||
test('under a card, the touch contact item is ours even when the window names another', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const h = harness({
|
||||
services: {
|
||||
picking: pickRegistry,
|
||||
overlayHit: () => ({ sourceId: 'earthquake-card', entryId: 'q' }),
|
||||
},
|
||||
sceneExtras: {
|
||||
pick: (_position, width = 3) =>
|
||||
width >= 9 ? { id: 'mly:img:window' } : null,
|
||||
drillPick: () => [{ id: 'mly:img:contact' }],
|
||||
},
|
||||
});
|
||||
try {
|
||||
h.click();
|
||||
assert.deepEqual(h.opened, ['contact']);
|
||||
assert.equal(h.groundClicks.length, 0);
|
||||
} finally {
|
||||
h.restore();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user