mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
fix(cctv): a count click yields to what is on top and keeps its group in frame
- A count click stands aside when an overlay label or another layer's card already took the click, and CCTV now claims a count click in the shared pick registry, so the flights layer no longer reads it as an empty-map click and keeps tracking its aircraft. - The flight to a group halves the distance only while the group stays in frame; otherwise it flies to the nearest ground cell of the group, so a tilted click no longer ends with no camera on screen. - Counts hidden under the HUD no longer push the active icon aside, and a lone camera that would move a merged count under the HUD leaves the original count and its icon as they were. - Cameras on one mount are spread before counts merge, so a spread icon no longer slides under a neighbouring count. - The ground module comment says how a camera without a batch height takes the drawn terrain.
This commit is contained in:
1 parent
2b7a6b0c63
commit
f6982dc934
16 files changed
+452
-70
No files matched your search
@@ -86,6 +86,8 @@ const RETRY_BASE_MS = 15_000;
|
||||
const RETRY_MAX_MS = 5 * 60 * 1000;
|
||||
|
||||
export const CCTV_OVERLAY_SOURCE_ID = 'cctv';
|
||||
/** The source a CCTV count marker takes clicks as. */
|
||||
export const CCTV_COUNT_CARD_SOURCE_ID = 'cctv-count';
|
||||
export const CCTV_THUMBNAIL_ALTITUDE_SCALE = Object.freeze({
|
||||
fullEnd: CCTV_CARD_SCALE_FULL_M,
|
||||
midEnd: CCTV_CARD_SCALE_MID_M,
|
||||
|
||||
@@ -136,7 +136,8 @@ function visitNeighbors(marker, grid, gap, visit) {
|
||||
* one grid bucket. Even the widest pill can only touch its eight neighbors.
|
||||
* A cell with one camera takes the footprint `sizeFor(1)` gives its icon and
|
||||
* joins the nearest count it touches. Lone cameras never join each other
|
||||
* or bridge two counts.
|
||||
* or bridge two counts. A spread icon's `offsetPx` shifts its footprint sideways.
|
||||
* A merged group lists its ground cells in `parts`.
|
||||
* Ground cells stay intact for the camera picker and individual-icon pass.
|
||||
*/
|
||||
export function mergeCountCells(cells, project, sizeFor, gap) {
|
||||
@@ -150,7 +151,7 @@ export function mergeCountCells(cells, project, sizeFor, gap) {
|
||||
// The view projector reuses its result object.
|
||||
return {
|
||||
cell,
|
||||
x: screen?.x,
|
||||
x: screen ? screen.x + (cell.offsetPx ?? 0) : undefined,
|
||||
y: screen?.y,
|
||||
halfSegment: (width - height) / 2,
|
||||
radius: height / 2,
|
||||
@@ -201,8 +202,10 @@ export function mergeCountCells(cells, project, sizeFor, gap) {
|
||||
} else {
|
||||
const group = createCameraCell(seed.cell.key);
|
||||
group.lone = [];
|
||||
group.parts = [];
|
||||
for (const { cell } of members) {
|
||||
addCell(group, cell);
|
||||
group.parts.push(...(cell.parts ?? [cell]));
|
||||
if (cell.count === 1) group.lone.push(cell);
|
||||
else if (cell.lone) group.lone.push(...cell.lone);
|
||||
}
|
||||
@@ -218,3 +221,13 @@ export function mergeCountCells(cells, project, sizeFor, gap) {
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
/** Rebuild a group's count under its original key, excluding lone cameras. */
|
||||
export function withoutLoneCameras(group) {
|
||||
const counts = (group.parts ?? []).filter((cell) => cell.count > 1);
|
||||
if (!counts.length) return null;
|
||||
const core = createCameraCell(group.key);
|
||||
core.parts = counts;
|
||||
for (const cell of counts) addCell(core, cell);
|
||||
return core;
|
||||
}
|
||||
@@ -154,6 +154,24 @@ export function pickContact(query, position, options = {}) {
|
||||
let _overlayHitTest = null;
|
||||
/** @type {WeakMap<object, {sourceId: string, entryId: string}|null>} */
|
||||
const clickCards = new WeakMap();
|
||||
const _clickClaims = new Map();
|
||||
|
||||
/**
|
||||
* Register a target drawn outside the world overlay's entries, such as a CCTV
|
||||
* count. A claim runs once per click where no card or label is painted above
|
||||
* it and must not call `clickCard`.
|
||||
* @param {string} layerId
|
||||
* @param {(click: object) => ({sourceId: string, entryId: string}|null)} claim
|
||||
*/
|
||||
export function registerClickClaim(layerId, claim) {
|
||||
if (!layerId || typeof claim !== 'function') return;
|
||||
_clickClaims.set(layerId, claim);
|
||||
}
|
||||
|
||||
/** Remove a layer's claim when it is disabled or destroyed. */
|
||||
export function unregisterClickClaim(layerId) {
|
||||
_clickClaims.delete(layerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets (or with null, clears) the hit test that names the card or label
|
||||
@@ -166,8 +184,8 @@ export function setClickCardHitTest(hitTest) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The topmost interactive card or label painted at a click, read once per
|
||||
* click so every handler of it sees the same one whatever ran first.
|
||||
* The topmost interactive card or label painted at a click, or a target a
|
||||
* layer claims (`registerClickClaim`). All handlers share one result per click.
|
||||
* @param {{screenPosition?: {x: number, y: number}}|null|undefined} click
|
||||
* @returns {{sourceId: string, entryId: string}|null}
|
||||
*/
|
||||
@@ -179,14 +197,28 @@ export function clickCard(click) {
|
||||
try {
|
||||
card = _overlayHitTest?.(at?.x, at?.y) ?? null;
|
||||
} catch {
|
||||
// a broken hit test must never break click handling
|
||||
clickCards.set(click, null);
|
||||
return null;
|
||||
}
|
||||
if (!card) {
|
||||
// A claim that reads this click again cannot re-enter the claims loop.
|
||||
clickCards.set(click, null);
|
||||
for (const claim of _clickClaims.values()) {
|
||||
try {
|
||||
card = claim(click) ?? null;
|
||||
} catch {
|
||||
card = null;
|
||||
}
|
||||
if (card) break;
|
||||
}
|
||||
}
|
||||
clickCards.set(click, card);
|
||||
return card;
|
||||
}
|
||||
|
||||
/**
|
||||
* True when another layer's card or label is painted on top at a click. The
|
||||
* True when another layer has the top card, label, or claimed target
|
||||
* (`registerClickClaim`) at a click. The
|
||||
* card on top takes the click: a scene item under it does not act, and is
|
||||
* not empty space either, so the layer leaves its selection alone.
|
||||
* @param {object} click The shared dispatcher event.
|
||||
|
||||
@@ -20,6 +20,8 @@ import {
|
||||
clickCard,
|
||||
isUnderOtherCard,
|
||||
setClickCardHitTest,
|
||||
registerClickClaim,
|
||||
unregisterClickClaim,
|
||||
} from './pickRegistry.js';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -237,3 +239,42 @@ test("the card on top is read once per click, and only another layer's card coun
|
||||
setClickCardHitTest(null);
|
||||
}
|
||||
});
|
||||
|
||||
test('a click claim is the card on top only where no card or label is painted', () => {
|
||||
const event = (x) => ({ screenPosition: { x, y: 5 } });
|
||||
let calls = 0;
|
||||
registerClickClaim('counts', (click) => {
|
||||
calls++;
|
||||
return click.screenPosition.x === 4
|
||||
? { sourceId: 'counts', entryId: 'k' }
|
||||
: null;
|
||||
});
|
||||
try {
|
||||
registerClickClaim('counts', null);
|
||||
const click = event(4);
|
||||
assert.equal(isUnderOtherCard(click), true);
|
||||
assert.equal(isUnderOtherCard(click, ['counts']), false);
|
||||
assert.equal(calls, 1);
|
||||
assert.equal(clickCard(event(9)), null);
|
||||
const quake = { sourceId: 'quake-card', entryId: 'q1' };
|
||||
setClickCardHitTest(() => quake);
|
||||
assert.deepEqual(clickCard(event(4)), quake);
|
||||
assert.equal(calls, 2);
|
||||
setClickCardHitTest(() => {
|
||||
throw new Error('broken overlay hit test');
|
||||
});
|
||||
assert.equal(clickCard(event(4)), null);
|
||||
assert.equal(calls, 2);
|
||||
setClickCardHitTest(null);
|
||||
|
||||
unregisterClickClaim('counts');
|
||||
assert.equal(clickCard(event(4)), null);
|
||||
registerClickClaim('counts', () => {
|
||||
throw new Error('broken claim');
|
||||
});
|
||||
assert.equal(clickCard(event(4)), null);
|
||||
} finally {
|
||||
unregisterClickClaim('counts');
|
||||
setClickCardHitTest(null);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user