mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 10:42:22 +00:00
fix(satellites): releasing a tracked satellite clears its focus dimming (#1887)
_clearTracking cleared the focus rectangle, then told the camera to stop following before marking the satellite released. A follow listener that read the tracked position in between (the Cockpit entry button does) published the rectangle again, and nothing cleared it: every icon inside a centred screen rectangle stayed at 25% opacity once the camera was farther than the old follow distance. The satellite is now marked released before the camera hears of it.
This commit is contained in:
1 parent
aac6be7773
commit
deff042265
2 files changed
+62
-11
No files matched your search
@@ -21,6 +21,11 @@ import { ISS_NORAD, TRACKED_ORBIT_COLOR } from './policy.js';
|
||||
import { toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import { bindFakeDraw } from '../../testSupport/fakeDrawPort.mjs';
|
||||
import { fakeInput } from '../../input/testDoubles.mjs';
|
||||
import {
|
||||
clearFocusTarget,
|
||||
getFocusTarget,
|
||||
publishFocusTargetAt,
|
||||
} from '../../data/focusDeemphasis.js';
|
||||
|
||||
const COMPANION = 25545;
|
||||
const GPS = 32711;
|
||||
@@ -70,7 +75,14 @@ function fakeFollowCamera() {
|
||||
camera.flightsCancelled += 1;
|
||||
},
|
||||
flyTo() {},
|
||||
pose: () => ({ lon: 0, lat: 0, height: 2e7, heading: 0, pitch: -1.57 }),
|
||||
pose: () => ({
|
||||
lon: 0,
|
||||
lat: 0,
|
||||
height: 2e7,
|
||||
heading: 0,
|
||||
pitch: -1.57,
|
||||
position: { x: 2.6378e7, y: 0, z: 0 },
|
||||
}),
|
||||
on(event, cb) {
|
||||
if (event !== 'followChanged') return () => {};
|
||||
listeners.add(cb);
|
||||
@@ -135,7 +147,13 @@ const SENSORS = indexImagingSensors({
|
||||
],
|
||||
});
|
||||
|
||||
async function fixture(t) {
|
||||
/**
|
||||
* @param {object} t The test context.
|
||||
* @param {{realFocus?: boolean}} [options] `realFocus` publishes through the
|
||||
* shared focus rectangle, with a query port that projects every point to
|
||||
* the screen centre.
|
||||
*/
|
||||
async function fixture(t, { realFocus = false } = {}) {
|
||||
const source = {
|
||||
async readGroup(group) {
|
||||
const text = GROUP_TEXT[group] || '';
|
||||
@@ -165,6 +183,9 @@ async function fixture(t) {
|
||||
getFocusTarget: () => null,
|
||||
focusNowMs: (now) => now,
|
||||
focusPassIsNeeded: () => false,
|
||||
...(realFocus
|
||||
? { clearFocusTarget, getFocusTarget, publishFocusTargetAt }
|
||||
: {}),
|
||||
},
|
||||
context: {
|
||||
clearTrackedSubjectContext: noop,
|
||||
@@ -203,7 +224,12 @@ async function fixture(t) {
|
||||
const viewer = { canvas: new EventTarget(), scene: {} };
|
||||
const camera = fakeFollowCamera();
|
||||
const frame = fakeFrame();
|
||||
const { draw, unbind } = bindFakeDraw(viewer, { camera, frame });
|
||||
const query = { project: () => ({ x: 720, y: 450 }) };
|
||||
const { draw, unbind } = bindFakeDraw(viewer, {
|
||||
camera,
|
||||
frame,
|
||||
...(realFocus ? { query } : {}),
|
||||
});
|
||||
const input = fakeInput(viewer);
|
||||
let frameNumber = 1;
|
||||
const { log, warn } = console;
|
||||
@@ -221,6 +247,7 @@ async function fixture(t) {
|
||||
console.log = log;
|
||||
input.destroy();
|
||||
unbind();
|
||||
if (realFocus) clearFocusTarget();
|
||||
if (previousDocument === undefined) delete globalThis.document;
|
||||
else globalThis.document = previousDocument;
|
||||
});
|
||||
@@ -412,6 +439,27 @@ test('holding the subject hides its dot, ring, docked companions and bracket', a
|
||||
assert.ok(f.detected().includes(ISS_NORAD));
|
||||
});
|
||||
|
||||
test('releasing a satellite leaves no focus rectangle, even when a follow listener reads it', async (t) => {
|
||||
const f = await fixture(t, { realFocus: true });
|
||||
// As the Cockpit entry button does: every follow change asks for the subject.
|
||||
let readsOnRelease = 0;
|
||||
f.camera.on('followChanged', (followed) => {
|
||||
if (followed) return;
|
||||
readsOnRelease += 1;
|
||||
f.methods.getCockpitSubject();
|
||||
});
|
||||
assert.equal(f.track(GPS), true);
|
||||
f.nextFrame();
|
||||
f.methods.getCockpitSubject();
|
||||
assert.equal(getFocusTarget()?.ownerLayer, 'satellites');
|
||||
assert.equal(getFocusTarget()?.id, GPS);
|
||||
|
||||
f.methods.stopTracking();
|
||||
assert.equal(readsOnRelease, 1, 'the listener ran during the release');
|
||||
assert.equal(f.methods.getCockpitSubject(), null);
|
||||
assert.equal(getFocusTarget(), null);
|
||||
});
|
||||
|
||||
test('a subject that is not tracked holds nothing', async (t) => {
|
||||
const f = await fixture(t);
|
||||
f.track(GPS);
|
||||
|
||||
@@ -90,18 +90,18 @@ export function createTracking({ state: layerState, services, parts, source }) {
|
||||
return;
|
||||
}
|
||||
const clearedNorad = layerState._trackedNorad;
|
||||
clearFocusTarget('satellites', layerState._trackedNorad);
|
||||
clearFocusTarget('satellites', clearedNorad);
|
||||
|
||||
// Re-show the dot (hidden while the tracked dot drew it) and
|
||||
// restore the original group palette from the shared style table (WS-D3)
|
||||
parts.rendering._restorePoint(
|
||||
layerState._trackedNorad,
|
||||
clearedNorad,
|
||||
parts.controls._pointStyleFor(
|
||||
layerState._trackedNorad,
|
||||
layerState._catalog.get(layerState._trackedNorad)?.group,
|
||||
clearedNorad,
|
||||
layerState._catalog.get(clearedNorad)?.group,
|
||||
),
|
||||
// Back to its class's visibility: a hidden class stays hidden.
|
||||
parts.controls._classVisible(layerState._trackedNorad),
|
||||
parts.controls._classVisible(clearedNorad),
|
||||
);
|
||||
|
||||
// Invalidate the per-frame tracked-position cache (WS-D2)
|
||||
@@ -109,9 +109,13 @@ export function createTracking({ state: layerState, services, parts, source }) {
|
||||
layerState._trackedFrameGeo = null;
|
||||
|
||||
// Remove the tracked dot and orbit path (unless ISS — keep its path)
|
||||
if (layerState._trackedNorad !== ISS_NORAD) {
|
||||
parts.rendering._hideOrbitPath(layerState._trackedNorad);
|
||||
if (clearedNorad !== ISS_NORAD) {
|
||||
parts.rendering._hideOrbitPath(clearedNorad);
|
||||
}
|
||||
// Released before the camera hears of it: a follow listener that reads
|
||||
// the tracked position mid-release must find nothing, or it would publish
|
||||
// the focus rectangle again after it was cleared above.
|
||||
layerState._trackedNorad = null;
|
||||
if (layerState._viewer && !skipViewerUntrack)
|
||||
stopFollowing(layerState._viewer);
|
||||
layerState._followTarget = null;
|
||||
@@ -119,7 +123,6 @@ export function createTracking({ state: layerState, services, parts, source }) {
|
||||
parts.rendering._removeTrackedEntity(layerState._trackedEntity);
|
||||
layerState._trackedEntity = null;
|
||||
}
|
||||
layerState._trackedNorad = null;
|
||||
layerState._trackedDockedToStation = null;
|
||||
layerState._trackedDockedToIss = false;
|
||||
parts.controls._syncIssOrbit?.();
|
||||
|
||||
Reference in new issue
Block a user