mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
CONTACTS takes the selected vessel as its subject instead of following the nearest flight
Turning CONTACTS on with a vessel selected made the nearest flight to the view the subject and followed it. The selected vessel is now adopted as if it had been selected while CONTACTS was on; a followed flight still comes first, and with nothing selected the nearest flight is still focused.
This commit is contained in:
1 parent
725f2f2998
commit
2ac157aca2
4 files changed
+146
-1
No files matched your search
@@ -17,11 +17,25 @@ export function createDependencies({
|
||||
parts.subject.refreshSelectedSubject(true);
|
||||
return;
|
||||
}
|
||||
if (adoptSelectedVessel()) return;
|
||||
if (layerState.autoFocusRetryPending) {
|
||||
layerState.autoFocusRetryPending = !parts.focus.focusAttentionTarget();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Take the selected AIS vessel as the subject, as its selection would have
|
||||
* had Contacts been on. A followed flight is checked first by the callers.
|
||||
* @returns {boolean} Whether a vessel became the subject.
|
||||
*/
|
||||
function adoptSelectedVessel() {
|
||||
const vessel = parts.subject.currentSelectedVesselSubject();
|
||||
if (!vessel) return false;
|
||||
layerState.autoFocusRetryPending = false;
|
||||
parts.subject.selectSubject(vessel);
|
||||
return Boolean(layerState.subject);
|
||||
}
|
||||
|
||||
async function enableDependencies(activationId = layerState.activationId) {
|
||||
const aircraftPending = [];
|
||||
for (const layerId of DEPENDENCIES) {
|
||||
@@ -104,6 +118,7 @@ export function createDependencies({
|
||||
const initialTrackedSubject = parts.subject.currentTrackedFlightSubject();
|
||||
if (initialTrackedSubject)
|
||||
parts.subject.selectSubject(initialTrackedSubject);
|
||||
else adoptSelectedVessel();
|
||||
return enableDependencies(activationId)
|
||||
.then(() => {
|
||||
if (
|
||||
@@ -121,6 +136,7 @@ export function createDependencies({
|
||||
parts.subject.selectSubject(layerState.subject);
|
||||
return;
|
||||
}
|
||||
if (adoptSelectedVessel()) return;
|
||||
if (layerState.autoFocusAttempted) return;
|
||||
layerState.autoFocusRetryPending = !parts.focus.focusAttentionTarget();
|
||||
})
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
// src/layers/awareness/selectedVessel.test.mjs — Contacts turned on while an
|
||||
// AIS vessel is selected takes that vessel as its subject.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { summarizeAwarenessCohort } from '../../data/militaryAwarenessEngine.js';
|
||||
import { createState } from './state.js';
|
||||
import { createModel } from './model.js';
|
||||
import { createQueries } from './queries.js';
|
||||
import { createSubject } from './subject.js';
|
||||
import { createHistory } from './history.js';
|
||||
import { createDependencies } from './dependencies.js';
|
||||
|
||||
const VESSEL_ID = '367000001';
|
||||
|
||||
/** Contacts parts over fake sources; focus records each nearest-flight pick. */
|
||||
function contacts(selection) {
|
||||
globalThis.document ??= { body: null };
|
||||
const noAircraft = {
|
||||
getAllPositions: () => [],
|
||||
getNearby: () => [],
|
||||
getTrackedSubject: () => null,
|
||||
};
|
||||
const services = {
|
||||
flights: noAircraft,
|
||||
military: noAircraft,
|
||||
vessels: {
|
||||
getNearby: () => [],
|
||||
getAllPositions: () => [],
|
||||
getSelectedInfo: () => selection.vessel,
|
||||
},
|
||||
installations: {
|
||||
getNearby: () => [],
|
||||
getStats: () => ({}),
|
||||
setContextAnchor() {},
|
||||
},
|
||||
};
|
||||
const state = createState({ services });
|
||||
state.enabled = true;
|
||||
state.passive = false;
|
||||
state.dataManager = {
|
||||
isEnabled: () => true,
|
||||
isEffectivelyEnabled: () => true,
|
||||
setEnabled: async () => true,
|
||||
getLayerLifecycleState: () => ({
|
||||
enabled: true,
|
||||
lifecycleState: 'enabled',
|
||||
}),
|
||||
layers: new Map(),
|
||||
};
|
||||
const focused = [];
|
||||
const parts = {
|
||||
navigation: {
|
||||
summarizeAwarenessCohortForNavigation: (items, source) =>
|
||||
summarizeAwarenessCohort(items, source),
|
||||
isFlightLayer: (id) => id === 'flights' || id === 'military',
|
||||
},
|
||||
rendering: { renderVisual() {}, scheduleDirectionOverlayUpdate() {} },
|
||||
panel: { renderResults() {}, startAwarenessPageRotation() {} },
|
||||
focus: {
|
||||
focusAttentionTarget() {
|
||||
focused.push('nearest');
|
||||
return true;
|
||||
},
|
||||
},
|
||||
};
|
||||
const context = { state, services, parts };
|
||||
parts.model = createModel(context);
|
||||
parts.queries = createQueries(context);
|
||||
parts.subject = createSubject(context);
|
||||
parts.history = createHistory(context);
|
||||
parts.dependencies = createDependencies(context);
|
||||
return { state, parts, focused };
|
||||
}
|
||||
|
||||
/** The vessel layer's answer for a selected Royal Prince. */
|
||||
const ROYAL_PRINCE = Object.freeze({
|
||||
id: VESSEL_ID,
|
||||
mmsi: VESSEL_ID,
|
||||
name: 'ROYAL PRINCE',
|
||||
latitude: 37.8,
|
||||
longitude: -122.4,
|
||||
});
|
||||
|
||||
test('Contacts turned on with a vessel selected takes it as the subject', async () => {
|
||||
const { state, parts, focused } = contacts({ vessel: ROYAL_PRINCE });
|
||||
await parts.dependencies.activateOperationalContext();
|
||||
assert.deepEqual(focused, [], 'no nearest flight is picked or followed');
|
||||
assert.equal(state.subject?.layerId, 'ais-live-vessels');
|
||||
assert.equal(state.subject?.id, VESSEL_ID);
|
||||
assert.match(state.subject.label, /ROYAL PRINCE/);
|
||||
});
|
||||
|
||||
test('a late source settling keeps the selected vessel, not a nearest flight', () => {
|
||||
const selection = { vessel: null };
|
||||
const { state, parts, focused } = contacts(selection);
|
||||
state.autoFocusRetryPending = true;
|
||||
selection.vessel = ROYAL_PRINCE;
|
||||
parts.dependencies.refreshAfterDeferredDependency(state.activationId);
|
||||
assert.deepEqual(focused, []);
|
||||
assert.equal(state.subject?.id, VESSEL_ID);
|
||||
});
|
||||
|
||||
test('with no vessel selected, Contacts still picks the nearest flight', async () => {
|
||||
const { state, parts, focused } = contacts({ vessel: null });
|
||||
await parts.dependencies.activateOperationalContext();
|
||||
assert.deepEqual(focused, ['nearest']);
|
||||
assert.equal(state.subject, null);
|
||||
});
|
||||
@@ -531,6 +531,26 @@ export function createSubject({ state: layerState, services, parts, source }) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The AIS vessel the user has selected, as a subject. Contacts turned on
|
||||
* after the selection never heard its `gev:entity-selected`, so activation
|
||||
* asks the vessel layer and shapes its answer as that event's record.
|
||||
* @returns {object|null} Detached subject, or null when no vessel is selected.
|
||||
*/
|
||||
|
||||
function currentSelectedVesselSubject() {
|
||||
const info = aisLiveVesselsLayer.getSelectedInfo?.();
|
||||
if (!info?.id) return null;
|
||||
return subjectFromContext({
|
||||
layerId: 'ais-live-vessels',
|
||||
id: info.id,
|
||||
label: info.name || (info.mmsi ? `MMSI ${info.mmsi}` : info.id),
|
||||
latitude: info.latitude,
|
||||
longitude: info.longitude,
|
||||
properties: { vesselId: info.id, mmsi: info.mmsi },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Record that the current subject left its feed on its own.
|
||||
*
|
||||
@@ -579,6 +599,7 @@ export function createSubject({ state: layerState, services, parts, source }) {
|
||||
resolveSubjectPhoto,
|
||||
refreshSelectedSubject,
|
||||
subjectFromContext,
|
||||
currentSelectedVesselSubject,
|
||||
markSubjectEvicted,
|
||||
clearAwarenessSubject,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user