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
@@ -3,6 +3,7 @@ import {
|
||||
cellLonLat,
|
||||
formatCameraCount,
|
||||
mergeCountCells,
|
||||
withoutLoneCameras,
|
||||
} from '../../data/cctvCellCounts.js';
|
||||
import { WORLD_OVERLAY_STYLE } from '../../overlays/worldOverlayTokens.js';
|
||||
import {
|
||||
@@ -200,7 +201,27 @@ export function createCountMarkers(
|
||||
ground(visible);
|
||||
let changed = visible.length !== markers.length;
|
||||
for (let i = 0; i < visible.length; i++) {
|
||||
const cell = visible[i];
|
||||
let cell = visible[i];
|
||||
// If the merged count is under the HUD, restore the count and its lone icons.
|
||||
if (hardUi && cell.lone?.length) {
|
||||
const at = project(cellCenter(cell));
|
||||
const { width, height } = sizeFor(cell.count);
|
||||
const rect = at && {
|
||||
x: at.x - width / 2,
|
||||
y: at.y - height / 2,
|
||||
w: width,
|
||||
h: height,
|
||||
};
|
||||
if (rect && hardUi(rect)) {
|
||||
for (const lone of cell.lone) lone.absorbed = false;
|
||||
const core = withoutLoneCameras(cell);
|
||||
if (core) {
|
||||
core.releasedAt = rect;
|
||||
ground([core]);
|
||||
cell = core;
|
||||
}
|
||||
}
|
||||
}
|
||||
const marker = (markers[i] ??= { focus: 1 });
|
||||
const last = marker.cell;
|
||||
const size = sizeFor(cell.count);
|
||||
@@ -217,20 +238,6 @@ export function createCountMarkers(
|
||||
marker.hudHidden = undefined;
|
||||
changed = true;
|
||||
}
|
||||
// A count hidden by the HUD leaves its lone cameras visible as icons.
|
||||
if (hardUi && cell.lone?.length) {
|
||||
const at = project(marker.pos);
|
||||
if (
|
||||
at &&
|
||||
hardUi({
|
||||
x: at.x - size.width / 2,
|
||||
y: at.y - size.height / 2,
|
||||
w: size.width,
|
||||
h: size.height,
|
||||
})
|
||||
)
|
||||
for (const lone of cell.lone) lone.absorbed = false;
|
||||
}
|
||||
changed ||=
|
||||
size.text !== marker.text ||
|
||||
size.width !== marker.width ||
|
||||
@@ -267,6 +274,8 @@ export function createCountMarkers(
|
||||
ctx.textBaseline = 'middle';
|
||||
for (let i = 0; i < markers.length; i++) {
|
||||
const marker = markers[i];
|
||||
// The core can stay visible while the HUD uncovers the merged count.
|
||||
if (marker.cell.releasedAt) refresh ||= !hardUi(marker.cell.releasedAt);
|
||||
const { height } = marker;
|
||||
const { x: px, y: py, z: pz } = marker.pos;
|
||||
const w = m[3] * px + m[7] * py + m[11] * pz + m[15];
|
||||
@@ -291,12 +300,14 @@ export function createCountMarkers(
|
||||
)
|
||||
continue;
|
||||
const hidden = Boolean(hardUi?.(rect));
|
||||
if (marker.hudHidden !== hidden) {
|
||||
const previous = marker.hudHidden;
|
||||
if (previous !== hidden) {
|
||||
marker.hudHidden = hidden;
|
||||
// A first frame or moving HUD can change which lone icons must show.
|
||||
refresh ||= marker.cell.lone?.some(
|
||||
(cell) => cell.absorbed === hidden,
|
||||
);
|
||||
// The active icon steps aside only for visible counts.
|
||||
refresh ||=
|
||||
hidden ||
|
||||
previous !== undefined ||
|
||||
marker.cell.lone?.some((cell) => cell.absorbed === hidden);
|
||||
}
|
||||
if (hidden) continue;
|
||||
const fade =
|
||||
|
||||
@@ -126,6 +126,25 @@ test('a lone camera clear of the HUD keeps its icon when the count beside it is
|
||||
}
|
||||
});
|
||||
|
||||
test('a count stays visible when a lone camera would move it under the HUD', async () => {
|
||||
const cells = [cellAt('a', 200, 2), cellAt('b', 234, 1)];
|
||||
const hud = { overlapsHardUi: (rect) => rect.x + rect.w > 225 };
|
||||
const m = counts(() => m.update(cells, project));
|
||||
paint(hud);
|
||||
m.update(cells, project);
|
||||
assert.equal(paint(hud)[0]?.text, '2');
|
||||
assert.equal(cells[1].absorbed, false);
|
||||
await Promise.resolve();
|
||||
paint(hud);
|
||||
await Promise.resolve();
|
||||
|
||||
paint();
|
||||
await Promise.resolve();
|
||||
assert.equal(cells[1].absorbed, true);
|
||||
assert.equal(paint()[0]?.text, '3');
|
||||
m.dispose();
|
||||
});
|
||||
|
||||
test('counts fade with the Scope keyhole like the callouts', () => {
|
||||
const m = counts(undefined, (_x, _y, keyhole) => keyhole.alpha);
|
||||
m.update([cellAt('a', 400, 2)], project);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { bindRenderer } from '../../render/rendererOf.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { distance } from '../../geo/vector.js';
|
||||
import {
|
||||
addCellCamera,
|
||||
createCameraCell,
|
||||
mergeCountCells,
|
||||
} from '../../data/cctvCellCounts.js';
|
||||
import { createNavigation } from './navigation.js';
|
||||
|
||||
// A count of four merged in a tilted view: two pairs 10 km and 40 km north of
|
||||
// an eye 800 m up. After the click, at least one member must be in frame.
|
||||
test('a count click from a tilted view keeps the group members in the frame', () => {
|
||||
const viewer = {};
|
||||
const flights = [];
|
||||
const fovy = Math.PI / 3;
|
||||
const aspectRatio = 800 / 600;
|
||||
const unbind = bindRenderer(viewer, {
|
||||
camera: {
|
||||
pose: () => ({ fovy, aspectRatio, position: fromDegrees(0, 0, 800) }),
|
||||
flyToBounds: (bounds, options) => flights.push({ bounds, options }),
|
||||
},
|
||||
canvas: { clientHeight: 600, clientWidth: 800 },
|
||||
});
|
||||
try {
|
||||
const metresPerDegree = 111_320;
|
||||
const members = [];
|
||||
const cells = [10_000, 40_000].map((start) => {
|
||||
const cell = createCameraCell(String(start));
|
||||
for (const northM of [start, start + 10]) {
|
||||
const lat = northM / metresPerDegree;
|
||||
addCellCamera(cell, { lat, lon: 0, absoluteHeightM: 8 });
|
||||
members.push(fromDegrees(0, lat, 8));
|
||||
}
|
||||
return cell;
|
||||
});
|
||||
const screens = [
|
||||
{ x: 400, y: 300 },
|
||||
{ x: 433, y: 300 },
|
||||
];
|
||||
const groups = mergeCountCells(
|
||||
cells,
|
||||
() => screens.shift(),
|
||||
() => ({ width: 40, height: 40 }),
|
||||
2,
|
||||
);
|
||||
assert.equal(groups.length, 1);
|
||||
assert.equal(groups[0].count, 4);
|
||||
const state = { _viewer: viewer };
|
||||
const navigation = createNavigation({ state, parts: {} });
|
||||
navigation.zoomToCell(groups[0]);
|
||||
assert.equal(flights.length, 1);
|
||||
const { range, pitch } = flights[0].options.offset;
|
||||
assert.equal(pitch, -Math.PI / 2);
|
||||
const { center } = flights[0].bounds;
|
||||
const halfSpanM = range * Math.tan(fovy / 2);
|
||||
assert.ok(
|
||||
members.some((point) => distance(point, center) <= halfSpanM),
|
||||
'no member of the group is in the final frame',
|
||||
);
|
||||
assert.ok(range < distance(fromDegrees(0, 0, 800), center));
|
||||
} finally {
|
||||
unbind();
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,65 @@
|
||||
import * as picking from '../../data/pickRegistry.js';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { createSelection } from './selection.js';
|
||||
|
||||
function setup() {
|
||||
let zooms = 0,
|
||||
clicks = 0;
|
||||
const selection = createSelection({
|
||||
services: { activation: {}, picking },
|
||||
state: {
|
||||
_enabled: true,
|
||||
_counts: { pickedCell: () => ({}) },
|
||||
_cctvOverlayHost: { hitTest: () => null },
|
||||
},
|
||||
parts: {
|
||||
navigation: { zoomToCell: () => zooms++ },
|
||||
rendering: { extractPickedCameraId: () => null },
|
||||
},
|
||||
});
|
||||
const click = selection.bindCctvWorldClickGesture(
|
||||
{ onClick: (fn) => fn },
|
||||
() => clicks++,
|
||||
);
|
||||
return { click, counts: () => [zooms, clicks] };
|
||||
}
|
||||
|
||||
test('a click a painted overlay target took (Space Missions label) does not fly to the count', () => {
|
||||
const { click, counts } = setup();
|
||||
// What the dispatcher hands subscribers after an onOverlayClick handler returned true.
|
||||
click({
|
||||
screenPosition: { x: 20, y: 26 },
|
||||
overlay: true,
|
||||
topHit: { set: '', id: null, surface: false },
|
||||
drawHit: null,
|
||||
gesture: { travelPx: 0, durationMs: 20 },
|
||||
});
|
||||
assert.equal(
|
||||
counts()[0],
|
||||
0,
|
||||
'count flight ran although an overlay target handled the click',
|
||||
);
|
||||
});
|
||||
|
||||
test("another layer's world-overlay card on top (clickCard) takes the click from the count", () => {
|
||||
const { click, counts } = setup();
|
||||
picking.setClickCardHitTest(() => ({
|
||||
sourceId: 'earthquakes',
|
||||
entryId: 'eq-1',
|
||||
}));
|
||||
try {
|
||||
click({
|
||||
screenPosition: { x: 20, y: 26 },
|
||||
topHit: null,
|
||||
drawHit: null,
|
||||
gesture: { travelPx: 0, durationMs: 20 },
|
||||
});
|
||||
assert.ok(
|
||||
picking.isUnderOtherCard({ screenPosition: { x: 1, y: 1 } }, ['cctv']),
|
||||
);
|
||||
assert.equal(counts()[0], 0, 'count flight ran under another layer card');
|
||||
} finally {
|
||||
picking.setClickCardHitTest(null);
|
||||
}
|
||||
});
|
||||
@@ -22,11 +22,12 @@ export function createGround({ state: layerState, services, parts, source }) {
|
||||
* - `google-3d` — photoreal stack: globe hidden, the visible Google 3D
|
||||
* tileset IS the surface → one-shot scene sampling refines.
|
||||
* - `terrain-globe` — any globe stack: the Re:Earth point-height prior IS the
|
||||
* resolution (zero scene queries).
|
||||
* resolution. A camera the batch left unanswered takes the
|
||||
* drawn terrain from the view pass (`adoptDrawnGround`).
|
||||
*
|
||||
* Only an explicit `false` (the photoreal stack hides the globe) selects
|
||||
* `google-3d`; undefined/null (no viewer / torn down) must fall to the regime
|
||||
* that never touches the scene. Pure — exported for the unit suite.
|
||||
* that never samples the scene's tiles. Pure — exported for the unit suite.
|
||||
* @param {boolean|undefined|null} globeShow - Whether the renderer shows the
|
||||
* globe (`globe.isGlobeVisible()`).
|
||||
* @returns {'google-3d'|'terrain-globe'}
|
||||
|
||||
@@ -23,8 +23,14 @@ export function createLifecycle({
|
||||
source,
|
||||
}) {
|
||||
const { activateCctvCameraFromWorldClick } = services.activation;
|
||||
const { resolvePickId, registerPickOwner, unregisterPickOwner, clickCard } =
|
||||
services.picking;
|
||||
const {
|
||||
resolvePickId,
|
||||
registerPickOwner,
|
||||
unregisterPickOwner,
|
||||
clickCard,
|
||||
registerClickClaim,
|
||||
unregisterClickClaim,
|
||||
} = services.picking;
|
||||
const { onFocusTargetAppear } = services.focus;
|
||||
const { releaseContinuousRender } = services.render;
|
||||
|
||||
@@ -510,6 +516,7 @@ export function createLifecycle({
|
||||
);
|
||||
return Boolean(coverage && layerState._recordById.has(coverage[1]));
|
||||
});
|
||||
registerClickClaim?.('cctv', parts.selection.countClickCard);
|
||||
if (!layerState._activeCameraId && layerState._records.length) {
|
||||
layerState._activeCameraId = parts.navigation.openingCameraId();
|
||||
layerState._autoHopSuspended = false;
|
||||
@@ -546,6 +553,7 @@ export function createLifecycle({
|
||||
services.credits?.hideOsmCredit?.(layerState._viewer, 'cctv');
|
||||
layerState._enabled = false;
|
||||
unregisterPickOwner('cctv');
|
||||
unregisterClickClaim?.('cctv');
|
||||
// ADJUST mode does not survive a layer toggle — predictable re-entry.
|
||||
layerState._calibrationMode = false;
|
||||
releaseContinuousRender('cctv-adjust');
|
||||
@@ -580,6 +588,7 @@ export function createLifecycle({
|
||||
parts.cards.handleVisibilityChange,
|
||||
);
|
||||
unregisterPickOwner('cctv');
|
||||
unregisterClickClaim?.('cctv');
|
||||
if (layerState._mapStackListener && typeof window !== 'undefined') {
|
||||
window.removeEventListener(
|
||||
'gev:map-stack-changed',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { distance } from '../../geo/vector.js';
|
||||
import { rangeForBoundingSphere } from '../../data/cameraFraming.js';
|
||||
import { isFollowing } from '../../data/followed.js';
|
||||
import { cellBounds } from '../../data/cctvCellCounts.js';
|
||||
import { cellBounds, cellCenter } from '../../data/cctvCellCounts.js';
|
||||
import { CCTV_FOCUS_RESULT, VIEW_CELL_PX, VIEW_MIN_CELL_M } from './policy.js';
|
||||
import { cameraOf, canvasOf } from '../../render/rendererOf.js';
|
||||
|
||||
@@ -131,6 +131,20 @@ export function createNavigation({
|
||||
return CCTV_FOCUS_RESULT.FOCUSED;
|
||||
}
|
||||
|
||||
/** The ground cell of a group nearest the eye, or the group itself if unmerged. */
|
||||
function nearestPart(cell, eye) {
|
||||
let nearest = cell;
|
||||
let best = Infinity;
|
||||
for (const part of cell.parts ?? []) {
|
||||
const d = distance(eye, cellCenter(part));
|
||||
if (d < best) {
|
||||
best = d;
|
||||
nearest = part;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
/** Frame a group's padded bounds from above, including coincident mounts. */
|
||||
function zoomToCell(cell) {
|
||||
const viewer = layerState._viewer;
|
||||
@@ -140,18 +154,23 @@ export function createNavigation({
|
||||
const tanHalfY = Math.tan((pose.fovy || Math.PI / 3) / 2);
|
||||
const canvas = canvasOf(viewer);
|
||||
const height = canvas?.clientHeight || canvas?.height || 1;
|
||||
const bounds = cellBounds(cell);
|
||||
// Half the range where cells stop grouping, so even coincident mounts split.
|
||||
const closeRange =
|
||||
(VIEW_MIN_CELL_M * height) / (4 * VIEW_CELL_PX * tanHalfY);
|
||||
const fitRange = (bounds) =>
|
||||
Math.max(closeRange, rangeForBoundingSphere(viewer, bounds.radius));
|
||||
// Approach long groups in halves so every click gets closer.
|
||||
const halfway = pose.position
|
||||
? distance(pose.position, bounds.center) / 2
|
||||
: Infinity;
|
||||
const range = Math.min(
|
||||
halfway,
|
||||
Math.max(closeRange, rangeForBoundingSphere(viewer, bounds.radius)),
|
||||
);
|
||||
const halfway = (bounds) =>
|
||||
pose.position ? distance(pose.position, bounds.center) / 2 : Infinity;
|
||||
let bounds = cellBounds(cell);
|
||||
const fit = fitRange(bounds);
|
||||
let range = Math.min(halfway(bounds), fit);
|
||||
// If the group exceeds the narrower side of the frame, approach its nearest part.
|
||||
const tanHalf = tanHalfY * Math.min(1, pose.aspectRatio || 1);
|
||||
if (range < fit && range * tanHalf < bounds.radius) {
|
||||
bounds = cellBounds(nearestPart(cell, pose.position));
|
||||
range = Math.min(halfway(bounds), fitRange(bounds));
|
||||
}
|
||||
camera.flyToBounds(bounds, {
|
||||
offset: { heading: 0, pitch: -Math.PI / 2, range },
|
||||
durationS: 1.2,
|
||||
|
||||
@@ -546,6 +546,17 @@ export function createRendering({
|
||||
cell.rank = rank;
|
||||
}
|
||||
}
|
||||
// Check each mount mate against counts where its icon will be drawn.
|
||||
const lone = visibleCells.filter((cell) => cell.count === 1);
|
||||
spreadSharedMounts(
|
||||
shown.concat(lone.map((cell) => cell.winner)),
|
||||
pose,
|
||||
metresPerPixelPerMetre,
|
||||
pass,
|
||||
);
|
||||
for (const cell of lone)
|
||||
cell.offsetPx =
|
||||
cell.winner.spreadPass === pass ? cell.winner.spreadPx : 0;
|
||||
// A count stands on the drawn terrain too: its cell may be too far for
|
||||
// its cameras to have been read. Marks each lone camera that a count
|
||||
// marker beside it has taken in.
|
||||
@@ -559,7 +570,6 @@ export function createRendering({
|
||||
shown.push(record);
|
||||
}
|
||||
}
|
||||
spreadSharedMounts(shown, pose, metresPerPixelPerMetre, pass);
|
||||
clearActiveOfCounts(project, pose, metresPerPixelPerMetre, pass);
|
||||
const writes = [];
|
||||
let coverageChanged = false;
|
||||
@@ -626,10 +636,10 @@ export function createRendering({
|
||||
|
||||
/**
|
||||
* Cameras on one mount would draw as one icon with several callouts. Among
|
||||
* the cameras shown, those within VIEW_SITE_M horizontally get draw
|
||||
* positions side by side along the screen's horizontal, in id order,
|
||||
* `VIEW_SITE_SPREAD_PX` apart at the distance they are seen from. The
|
||||
* record's own position is untouched: geometry and cards keep the mount.
|
||||
* icon candidates, those within VIEW_SITE_M horizontally get draw positions
|
||||
* side by side in id order, `VIEW_SITE_SPREAD_PX` apart on screen. A mate
|
||||
* absorbed by a count keeps its place in the row. Geometry and cards stay
|
||||
* on the mount.
|
||||
*/
|
||||
function spreadSharedMounts(shown, pose, metresPerPixelPerMetre, pass) {
|
||||
const { right, direction, position: eye } = pose;
|
||||
@@ -669,11 +679,9 @@ export function createRendering({
|
||||
(p.x - eye.x) * direction.x +
|
||||
(p.y - eye.y) * direction.y +
|
||||
(p.z - eye.z) * direction.z;
|
||||
const metres =
|
||||
(i - (mates.length - 1) / 2) *
|
||||
VIEW_SITE_SPREAD_PX *
|
||||
metresPerPixelPerMetre *
|
||||
depth;
|
||||
const px = (i - (mates.length - 1) / 2) * VIEW_SITE_SPREAD_PX;
|
||||
record.spreadPx = px;
|
||||
const metres = px * metresPerPixelPerMetre * depth;
|
||||
record.spreadOffset = scale(right, metres);
|
||||
record.spreadPosition = add(p, record.spreadOffset);
|
||||
record.spreadPass = pass;
|
||||
@@ -681,7 +689,7 @@ export function createRendering({
|
||||
}
|
||||
}
|
||||
|
||||
/** Move the active camera's icon beside any count marker that would cover it. */
|
||||
/** Only counts visible outside the HUD push the active icon aside. */
|
||||
function clearActiveOfCounts(project, pose, metresPerPixelPerMetre, pass) {
|
||||
if (!layerState._activeCameraId) return;
|
||||
const record = layerState._recordById.get(layerState._activeCameraId);
|
||||
@@ -702,6 +710,7 @@ export function createRendering({
|
||||
(CAMERA_ICON_PX * 1.25 * iconScaleAt(distance(p, pose.position))) / 2;
|
||||
const spans = [];
|
||||
for (const marker of markers) {
|
||||
if (marker.hudHidden) continue;
|
||||
const at = project(marker.pos);
|
||||
if (
|
||||
!at ||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { CCTV_OVERLAY_SOURCE_ID } from '../../data/cctvCards.js';
|
||||
import {
|
||||
CCTV_COUNT_CARD_SOURCE_ID,
|
||||
CCTV_OVERLAY_SOURCE_ID,
|
||||
} from '../../data/cctvCards.js';
|
||||
import { isTrackingClickGesture } from '../../data/trackingClickGesture.js';
|
||||
|
||||
export function createSelection({
|
||||
@@ -8,7 +11,8 @@ export function createSelection({
|
||||
source,
|
||||
}) {
|
||||
const { CCTV_ACTIVATION_RESULT } = services.activation;
|
||||
const { resolvePickId, findPickOwner } = services.picking;
|
||||
const { resolvePickId, findPickOwner, isUnderOtherCard } = services.picking;
|
||||
const OWN_CARD_SOURCES = [CCTV_OVERLAY_SOURCE_ID, CCTV_COUNT_CARD_SOURCE_ID];
|
||||
|
||||
/**
|
||||
* Returns the camera record for the currently active camera. A stale ID falls
|
||||
@@ -30,15 +34,8 @@ export function createSelection({
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/** A card painted above the count, or another layer's object, owns the click. */
|
||||
function countYields(event) {
|
||||
const { x, y } = event.screenPosition;
|
||||
if (
|
||||
layerState._cctvOverlayHost?.hitTest(x, y, {
|
||||
sourceId: CCTV_OVERLAY_SOURCE_ID,
|
||||
})?.entryId
|
||||
)
|
||||
return true;
|
||||
/** Whether another layer's scene object owns the click at this count. */
|
||||
function sceneTakesCountClick(event) {
|
||||
const top = event.topHit;
|
||||
if (!top) return false;
|
||||
const drawHit = event.drawHit;
|
||||
@@ -47,6 +44,34 @@ export function createSelection({
|
||||
return id !== null && findPickOwner?.(id) !== 'cctv';
|
||||
}
|
||||
|
||||
/** Leave other layers' cards to the caller since clickCard also calls this. */
|
||||
function clickedCount(event) {
|
||||
if (
|
||||
!isTrackingClickGesture(event.gesture) ||
|
||||
!layerState._enabled ||
|
||||
event.overlay
|
||||
)
|
||||
return null;
|
||||
const cell = layerState._counts?.pickedCell(event.screenPosition);
|
||||
if (!cell) return null;
|
||||
const { x, y } = event.screenPosition;
|
||||
if (
|
||||
layerState._cctvOverlayHost?.hitTest(x, y, {
|
||||
sourceId: CCTV_OVERLAY_SOURCE_ID,
|
||||
})?.entryId
|
||||
)
|
||||
return null;
|
||||
return sceneTakesCountClick(event) ? null : cell;
|
||||
}
|
||||
|
||||
/** The count marker as the card on top of a click it takes, for every layer's clickCard. */
|
||||
function countClickCard(event) {
|
||||
const cell = clickedCount(event);
|
||||
return cell
|
||||
? { sourceId: CCTV_COUNT_CARD_SOURCE_ID, entryId: String(cell.key ?? '') }
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind CCTV activation to clean taps. Drag-like and long-press gestures do
|
||||
* not reach camera activation or focus dispatch.
|
||||
@@ -59,10 +84,9 @@ export function createSelection({
|
||||
function bindCctvWorldClickGesture(input, onClick) {
|
||||
return input.onClick((event) => {
|
||||
if (!isTrackingClickGesture(event.gesture)) return;
|
||||
const cell =
|
||||
layerState._enabled &&
|
||||
layerState._counts?.pickedCell(event.screenPosition);
|
||||
if (cell && !countYields(event)) {
|
||||
const cell = clickedCount(event);
|
||||
// Another layer's card or label painted above the count takes the click.
|
||||
if (cell && !isUnderOtherCard?.(event, OWN_CARD_SOURCES)) {
|
||||
parts.navigation.zoomToCell(cell);
|
||||
return;
|
||||
}
|
||||
@@ -243,6 +267,7 @@ export function createSelection({
|
||||
return {
|
||||
getActiveRecord,
|
||||
bindCctvWorldClickGesture,
|
||||
countClickCard,
|
||||
setActiveCamera,
|
||||
deactivateActiveCamera,
|
||||
cctvEmptyClickDeselects,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import * as picking from '../../data/pickRegistry.js';
|
||||
import { CCTV_COUNT_CARD_SOURCE_ID } from '../../data/cctvCards.js';
|
||||
import { test } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { CCTV_ACTIVATION_RESULT } from '../../cctvFocusRequest.js';
|
||||
@@ -150,3 +151,63 @@ test("a count click yields to a card above it and to another layer's object, not
|
||||
picking.unregisterPickOwner('cctv');
|
||||
}
|
||||
});
|
||||
|
||||
test('a count click is the card on top for every layer, unless the count yields', () => {
|
||||
let zooms = 0;
|
||||
let clicks = 0;
|
||||
const selection = createSelection({
|
||||
services: { activation: {}, picking },
|
||||
state: {
|
||||
_enabled: true,
|
||||
_counts: { pickedCell: (p) => (p?.x === 20 ? { key: 'g' } : null) },
|
||||
_cctvOverlayHost: { hitTest: () => null },
|
||||
},
|
||||
parts: {
|
||||
navigation: { zoomToCell: () => zooms++ },
|
||||
rendering: {
|
||||
extractPickedCameraId: (hit) =>
|
||||
hit?.set === 'cctv-icons' ? hit.id : null,
|
||||
},
|
||||
},
|
||||
});
|
||||
const click = selection.bindCctvWorldClickGesture(
|
||||
{ onClick: (fn) => fn },
|
||||
() => clicks++,
|
||||
);
|
||||
const event = (topHit = null, x = 20, durationMs = 20) => ({
|
||||
screenPosition: { x, y: 26 },
|
||||
topHit,
|
||||
drawHit: topHit,
|
||||
gesture: { travelPx: 0, durationMs },
|
||||
});
|
||||
picking.registerClickClaim('cctv', selection.countClickCard);
|
||||
try {
|
||||
const aircraftFirst = event();
|
||||
assert.equal(picking.isUnderOtherCard(aircraftFirst), true);
|
||||
assert.deepEqual(picking.clickCard(aircraftFirst), {
|
||||
sourceId: CCTV_COUNT_CARD_SOURCE_ID,
|
||||
entryId: 'g',
|
||||
});
|
||||
click(aircraftFirst);
|
||||
assert.deepEqual([zooms, clicks], [1, 0]);
|
||||
|
||||
const cctvFirst = event();
|
||||
click(cctvFirst);
|
||||
assert.equal(picking.isUnderOtherCard(cctvFirst), true);
|
||||
assert.deepEqual([zooms, clicks], [2, 0]);
|
||||
|
||||
for (const [e, claimed, expected] of [
|
||||
[event({ set: 'flights', id: 'abc' }), false, [2, 1]],
|
||||
[event({ set: 'cctv-icons', id: 'cam-2' }), true, [3, 1]],
|
||||
[event(null, 20, 1000), false, [3, 1]],
|
||||
[event(null, 60), false, [3, 2]],
|
||||
[{ ...event(), overlay: true }, false, [3, 3]],
|
||||
]) {
|
||||
assert.equal(picking.isUnderOtherCard(e), claimed);
|
||||
click(e);
|
||||
assert.deepEqual([zooms, clicks], expected);
|
||||
}
|
||||
} finally {
|
||||
picking.unregisterClickClaim('cctv');
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user