mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
fix(click): the card or label on top takes the click in every layer
Review fixes for #1781: - One rule for cards: the world-overlay host hands its hit test to the pick registry, and every click handler reads the topmost interactive card or label once per click (`clickCard`, `isUnderOtherCard` in src/data/pickRegistry.js), so all handlers agree in any listener order. A layer whose own card or label is on top acts on it whatever is drawn under it; a layer under another layer's card neither acts nor treats the click as empty space (a tracked aircraft stays tracked, a selection stays selected); Context names nothing under a card. A selected news card over a vessel no longer opens the link and selects the vessel. - With one rule, the per-owner arbitration options are no longer read and are removed: `passive`, `expanded` and `declinesClick` pick owners, `rememberClickPickActions`, `isActedOnByOtherLayer`, card backgrounds and `cardKeepsClick`. The dispatcher is unchanged from main. - A drag that ends on a quake disc, label or card does nothing; opening the USGS page or clearing the selection needs a clean click. - A click on the map under another layer's card opens no Street Level ground image. - A CCTV card that is going away is still not the scene under it. - Docs and changelog describe the new rule.
This commit is contained in:
1 parent
7312280817
commit
bb3bf9858b
87 files changed
+1398
-1775
No files matched your search
@@ -6,14 +6,14 @@ import { useEntityCardStore } from './stores/entityCard.js';
|
||||
import { fakeInput } from '../input/testDoubles.mjs';
|
||||
import {
|
||||
registerPickOwner,
|
||||
setClickCardHitTest,
|
||||
unregisterPickOwner,
|
||||
} from '../data/pickRegistry.js';
|
||||
|
||||
// A coarse tap that misses everything exactly finds a fire within the shared
|
||||
// touch window. On open map Context names it; under a quake card or label the
|
||||
// card takes the tap, since the fire layer acts only on exact hits; an exact
|
||||
// hit on the fire is the fire's, under a card or not.
|
||||
test('Context leaves a near-missed exact-only item to a card painted over it', (t) => {
|
||||
// The card or label painted on top takes the click: Context names nothing
|
||||
// under it, exact or nearby, an acting owner's item or a passive one, and
|
||||
// keeps its own card. On open map it names what the click found.
|
||||
test('Context names nothing under a card painted on top, and keeps its card', (t) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
@@ -21,17 +21,31 @@ test('Context leaves a near-missed exact-only item to a card painted over it', (
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const fire = { set: 'test-fires:1', id: 'fire:1' };
|
||||
const plane = { set: 'test-planes:1', id: 'plane:1' };
|
||||
const route = { set: 'test-route:1', id: 'route:line' };
|
||||
registerPickOwner('test-fires', (id) => id === fire.id);
|
||||
t.after(() => unregisterPickOwner('test-fires'));
|
||||
let exact = false;
|
||||
registerPickOwner('test-planes', (id) => id === plane.id);
|
||||
registerPickOwner('test-route', (id) => id.startsWith('route:'));
|
||||
let cardOnTop = false;
|
||||
// The card on top at a click, as the host answers the pick registry.
|
||||
setClickCardHitTest(() =>
|
||||
cardOnTop ? { sourceId: 'earthquake-card', entryId: 'q' } : null,
|
||||
);
|
||||
t.after(() => {
|
||||
setClickCardHitTest(null);
|
||||
unregisterPickOwner('test-fires');
|
||||
unregisterPickOwner('test-planes');
|
||||
unregisterPickOwner('test-route');
|
||||
});
|
||||
let exact = null;
|
||||
let near = null;
|
||||
const viewer = {
|
||||
scene: {
|
||||
pick: () => (exact ? { id: fire } : null),
|
||||
drillPick: () => [{ id: fire }],
|
||||
pick: () => (exact ? { id: exact } : null),
|
||||
drillPick: () => (near ? [{ id: near }] : []),
|
||||
},
|
||||
};
|
||||
const input = fakeInput(viewer);
|
||||
let cardOnTop = false;
|
||||
const pinia = createPinia();
|
||||
const disconnect = installEntityContext({
|
||||
viewer,
|
||||
@@ -41,8 +55,6 @@ test('Context leaves a near-missed exact-only item to a card painted over it', (
|
||||
getAll: () => [],
|
||||
}),
|
||||
pinia,
|
||||
overlayHit: () =>
|
||||
cardOnTop ? { sourceId: 'earthquake-card', entryId: 'q' } : null,
|
||||
});
|
||||
t.after(() => {
|
||||
disconnect();
|
||||
@@ -50,52 +62,24 @@ test('Context leaves a near-missed exact-only item to a card painted over it', (
|
||||
});
|
||||
const store = useEntityCardStore(pinia);
|
||||
const named = [];
|
||||
let clears = 0;
|
||||
store.select = (identity) => named.push(identity.id);
|
||||
const tap = () => {
|
||||
store.clear = () => clears++;
|
||||
const tap = (hitExact, hitNear) => {
|
||||
exact = hitExact;
|
||||
near = hitNear;
|
||||
named.length = 0;
|
||||
input.click();
|
||||
return [...named];
|
||||
};
|
||||
assert.deepEqual(tap(), ['fire:1'], 'open map: Context names the fire');
|
||||
assert.deepEqual(tap(null, fire), ['fire:1'], 'open map: a near fire');
|
||||
assert.deepEqual(tap(route, null), ['route:line'], 'open map: a route');
|
||||
cardOnTop = true;
|
||||
assert.deepEqual(tap(), [], 'under a card: the card keeps the tap');
|
||||
exact = true;
|
||||
assert.deepEqual(tap(), ['fire:1'], 'an exact hit is the fire’s');
|
||||
});
|
||||
|
||||
// Every card layer acts over a passive owner's pick (a directions route), so
|
||||
// Context leaves an exact route hit under a card to that card, and names it on
|
||||
// open map as before.
|
||||
test('Context leaves an exact passive route under a card to the card', (t) => {
|
||||
const route = { set: 'test-route:1', id: 'route:line' };
|
||||
registerPickOwner('test-route', (id) => id.startsWith('route:'), {
|
||||
passive: true,
|
||||
});
|
||||
t.after(() => unregisterPickOwner('test-route'));
|
||||
const viewer = { scene: { pick: () => ({ id: route }) } };
|
||||
const input = fakeInput(viewer);
|
||||
let cardOnTop = false;
|
||||
const pinia = createPinia();
|
||||
const disconnect = installEntityContext({
|
||||
viewer,
|
||||
getDataManager: () => ({
|
||||
isEnabled: () => true,
|
||||
layers: new Map(),
|
||||
getAll: () => [],
|
||||
}),
|
||||
pinia,
|
||||
overlayHit: () =>
|
||||
cardOnTop ? { sourceId: 'earthquake-card', entryId: 'q' } : null,
|
||||
});
|
||||
t.after(() => {
|
||||
disconnect();
|
||||
input.destroy();
|
||||
});
|
||||
const named = [];
|
||||
useEntityCardStore(pinia).select = (identity) => named.push(identity.id);
|
||||
input.click();
|
||||
assert.deepEqual(named, ['route:line'], 'open map: Context names the route');
|
||||
cardOnTop = true;
|
||||
input.click();
|
||||
assert.deepEqual(named, ['route:line'], 'under a card: the card keeps it');
|
||||
assert.deepEqual(tap(null, fire), [], 'under a card: a near fire');
|
||||
assert.deepEqual(tap(fire, fire), [], 'under a card: an exact fire');
|
||||
assert.deepEqual(tap(plane, plane), [], 'under a card: an aircraft');
|
||||
assert.deepEqual(tap(route, null), [], 'under a card: a route');
|
||||
const cleared = clears;
|
||||
tap(null, null);
|
||||
assert.equal(clears, cleared, 'a card over open map is not open map');
|
||||
});
|
||||
Reference in new issue
Block a user