mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
A wreck is selected only by a tap exactly on it
The shipwrecks layer reads the click's top hit, as it read the scene's exact pick before, not the touch contact search's wider hit: a tap that misses everything near a wreck selects nothing, and a tap near another layer's contact closes an open wreck card.
This commit is contained in:
1 parent
46c98796de
commit
6fc1aaff02
2 files changed
+38
-3
No files matched your search
@@ -285,8 +285,11 @@ export function createShipwrecksLayer({
|
||||
if (_selectedLink) openExternal(_selectedLink);
|
||||
return;
|
||||
}
|
||||
// A marker's item id is its pick id, `shipwreck:<id>`.
|
||||
const pickId = click.id ?? null;
|
||||
// A marker's item id is its pick id, `shipwreck:<id>`. Read from what is
|
||||
// exactly under the click: a touch's wider contact search would pick a
|
||||
// wreck the tap missed, or a contact near one.
|
||||
const picked = click.topHit;
|
||||
const pickId = picked ? (picking.resolvePickId(picked) ?? null) : null;
|
||||
const id = pickedRecordId(pickId);
|
||||
if (id) {
|
||||
_selectedId = id;
|
||||
|
||||
@@ -41,6 +41,8 @@ function harness({ snapshots, now = () => 1 } = {}) {
|
||||
const handlers = [];
|
||||
const opened = [];
|
||||
let pickResult = null;
|
||||
// A touch's wider contact search, when it finds what the exact pick missed.
|
||||
let nearResult = null;
|
||||
const viewer = {};
|
||||
const { draw } = bindFakeDraw(viewer);
|
||||
const queue = [...(snapshots || [])];
|
||||
@@ -63,7 +65,14 @@ function harness({ snapshots, now = () => 1 } = {}) {
|
||||
input: () => ({
|
||||
onClick(callback) {
|
||||
const handler = {
|
||||
click: (event) => callback({ ...event, id: pickResult }),
|
||||
click: (event) =>
|
||||
callback({
|
||||
...event,
|
||||
topHit: pickResult
|
||||
? { set: 'shipwrecks:', id: pickResult, surface: false }
|
||||
: null,
|
||||
id: pickResult ?? nearResult,
|
||||
}),
|
||||
destroyed: false,
|
||||
};
|
||||
handlers.push(handler);
|
||||
@@ -101,6 +110,11 @@ function harness({ snapshots, now = () => 1 } = {}) {
|
||||
pick(id) {
|
||||
pickResult = id ? `shipwreck:${id}` : null;
|
||||
},
|
||||
// What a touch's contact search finds near the tap, the exact pick
|
||||
// being `pick`'s.
|
||||
near(pickId) {
|
||||
nearResult = pickId;
|
||||
},
|
||||
lastCard: () => cards.at(-1),
|
||||
};
|
||||
}
|
||||
@@ -195,6 +209,24 @@ test('a click opens the card; a period that excludes the wreck closes it', async
|
||||
assert.equal(h.layer.getStats().count, 1);
|
||||
});
|
||||
|
||||
test('a tap selects only the wreck exactly under it, as a click does', async () => {
|
||||
const h = harness({ snapshots: [snapshot([wreck('a')])] });
|
||||
h.layer.enable();
|
||||
await h.layer.update();
|
||||
// Near a wreck but on nothing: no card.
|
||||
h.near('shipwreck:a');
|
||||
h.handlers[0].click({ screenPosition: { x: 1, y: 1 } });
|
||||
assert.equal(h.cards.flat().length, 0);
|
||||
h.pick('a');
|
||||
h.handlers[0].click({ screenPosition: { x: 1, y: 1 } });
|
||||
assert.equal(h.lastCard()[0].id, 'shipwreck-card:a');
|
||||
// On nothing, near another layer's contact: the card is closed.
|
||||
h.pick(null);
|
||||
h.near('flight:abc');
|
||||
h.handlers[0].click({ screenPosition: { x: 1, y: 1 } });
|
||||
assert.deepEqual(h.lastCard(), []);
|
||||
});
|
||||
|
||||
test('the year pickers list only years with a wreck, and each era is counted', async () => {
|
||||
const h = harness({
|
||||
snapshots: [
|
||||
|
||||
Reference in new issue
Block a user