mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-19 17:52:21 +00:00
fix(touch): give each tap to the layer that acts on it
On a coarse pointer the dispatcher can name a contact near the tap instead of the exact pick. Only flights, military, vessels, radio and Street Level act on such a contact, so they now register as expanded pick owners, and a quake card or label yields only to them. A FIRMS fire or CCTV camera reached only as a nearby contact no longer swallows a quake card, a quake label or a vessel's own card tap, and FIRMS and CCTV cards yield to a contact whose layer does act on it. Radio and Street Level also pick through their own windows. A station or Street Level item found only there, not as the touch contact, yields to another layer's card painted over it, and Street Level takes its own touch contact beyond its narrower window. Fire, CCTV and vessel cards now act over a passive owner's pick (a flight trail, the directions route), as the quake card does. The Context panel leaves a passive route, or a fire or camera reached only as a nearby contact, to the card painted over it.
This commit is contained in:
1 parent
4804097ca1
commit
830c980ca6
26 files changed
+1095
-69
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { resolvePickedContext } from '../data/pickedContext.js';
|
||||
import { cardKeepsClick, resolvePickedContext } from '../data/pickedContext.js';
|
||||
import { followedOf, onFollowChanged } from '../data/followed.js';
|
||||
import { fromDegreesInto } from '../geo/ellipsoid.js';
|
||||
import { inputFor } from '../input/dispatcher.js';
|
||||
@@ -315,6 +315,12 @@ export function installEntityContext({
|
||||
dataManager: getDataManager(),
|
||||
});
|
||||
if (identity) {
|
||||
// A card or label painted over an item its layer does not act on here
|
||||
// (a quake card beside a fire, or over a route) is the card's click.
|
||||
const underCard = Boolean(
|
||||
overlayHit?.(event.screenPosition?.x, event.screenPosition?.y),
|
||||
);
|
||||
if (cardKeepsClick(event, underCard)) return;
|
||||
// These layers start following on their own click; following again
|
||||
// from here would fight them (the flights layer reads a second track
|
||||
// of the same plane as a click on empty map and lets go).
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createPinia } from 'pinia';
|
||||
import { installEntityContext } from './entityContextBridge.js';
|
||||
import { useEntityCardStore } from './stores/entityCard.js';
|
||||
import { fakeInput } from '../input/testDoubles.mjs';
|
||||
import {
|
||||
registerPickOwner,
|
||||
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) => {
|
||||
const previous = globalThis.matchMedia;
|
||||
globalThis.matchMedia = () => ({ matches: true });
|
||||
t.after(() => {
|
||||
if (previous) globalThis.matchMedia = previous;
|
||||
else delete globalThis.matchMedia;
|
||||
});
|
||||
const fire = { set: 'test-fires:1', id: 'fire:1' };
|
||||
registerPickOwner('test-fires', (id) => id === fire.id);
|
||||
t.after(() => unregisterPickOwner('test-fires'));
|
||||
let exact = false;
|
||||
const viewer = {
|
||||
scene: {
|
||||
pick: () => (exact ? { id: fire } : null),
|
||||
drillPick: () => [{ id: fire }],
|
||||
},
|
||||
};
|
||||
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 store = useEntityCardStore(pinia);
|
||||
const named = [];
|
||||
store.select = (identity) => named.push(identity.id);
|
||||
const tap = () => {
|
||||
named.length = 0;
|
||||
input.click();
|
||||
return [...named];
|
||||
};
|
||||
assert.deepEqual(tap(), ['fire:1'], 'open map: Context names the fire');
|
||||
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');
|
||||
});
|
||||
Reference in new issue
Block a user