mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +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);
|
if (_selectedLink) openExternal(_selectedLink);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// A marker's item id is its pick id, `shipwreck:<id>`.
|
// A marker's item id is its pick id, `shipwreck:<id>`. Read from what is
|
||||||
const pickId = click.id ?? null;
|
// 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);
|
const id = pickedRecordId(pickId);
|
||||||
if (id) {
|
if (id) {
|
||||||
_selectedId = id;
|
_selectedId = id;
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ function harness({ snapshots, now = () => 1 } = {}) {
|
|||||||
const handlers = [];
|
const handlers = [];
|
||||||
const opened = [];
|
const opened = [];
|
||||||
let pickResult = null;
|
let pickResult = null;
|
||||||
|
// A touch's wider contact search, when it finds what the exact pick missed.
|
||||||
|
let nearResult = null;
|
||||||
const viewer = {};
|
const viewer = {};
|
||||||
const { draw } = bindFakeDraw(viewer);
|
const { draw } = bindFakeDraw(viewer);
|
||||||
const queue = [...(snapshots || [])];
|
const queue = [...(snapshots || [])];
|
||||||
@@ -63,7 +65,14 @@ function harness({ snapshots, now = () => 1 } = {}) {
|
|||||||
input: () => ({
|
input: () => ({
|
||||||
onClick(callback) {
|
onClick(callback) {
|
||||||
const handler = {
|
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,
|
destroyed: false,
|
||||||
};
|
};
|
||||||
handlers.push(handler);
|
handlers.push(handler);
|
||||||
@@ -101,6 +110,11 @@ function harness({ snapshots, now = () => 1 } = {}) {
|
|||||||
pick(id) {
|
pick(id) {
|
||||||
pickResult = id ? `shipwreck:${id}` : null;
|
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),
|
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);
|
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 () => {
|
test('the year pickers list only years with a wreck, and each era is counted', async () => {
|
||||||
const h = harness({
|
const h = harness({
|
||||||
snapshots: [
|
snapshots: [
|
||||||
|
|||||||
Reference in new issue
Block a user