feat(cockpit): an application can add its own cockpit subjects; the Rail and Transit layers expose the read and hold APIs such a subject needs

GEV itself registers no new subject: with no provider, the Cockpit offers
aircraft, satellites and vessels as before, except that the most recently
selected of them now wins entry.

- services.cockpitSubjects: providers ({kind, layerId, entryFace, priority,
  isEntryAllowed, read, hold, release, hud}) are checked once by the
  coordinator; frames and HUD views on every update; a throwing provider
  ends its view or keeps the last HUD.
- Entry: the most recently selected subject wins, across all kinds.
- Camera: a frame may turn the ground clamp off, anchor exactly on the
  subject and update every frame.
- A generic HUD: kicker, title, cards, always-visible source rows, banner,
  a veil with light streaks (off under reduced motion) and a bottom
  progress line whose close ticks merge.
- Text comes from the provider, already in the page's language
  (./i18n/locale: getLocale, onLocaleChange).
- Rail and Transit read and hold APIs (getSelectedTrain/Vehicle,
  getCockpitSubject, setCockpitSubject, focusTrain/Vehicle); a held
  train's marker, card and route line are hidden, and its feed keeps
  polling while held.
- ./layers/rail/paths is exported.
This commit is contained in:
Denis Groshev committed 2026-11-12 10:50:26 +01:00
1 parent 10a788db78
commit f75179eea0
51 files changed
+4059 -129

No files matched your search

+146 -4
View File
@@ -35,6 +35,7 @@ import {
vesselCameraProfile,
} from '../cockpitSubjects.js';
import { lookIsOffset, lookReadoutParts, wrapLookYaw } from '../cockpitLook.js';
import { cockpitSubjectHudView } from '../cockpitSubjectProviders.js';
import {
RADAR_MAX_CONTACTS,
radarPicture,
@@ -90,6 +91,13 @@ export function publishInstrumentsView() {
compass: view.compass.map((division) => ({ ...division })),
compassMarkers: { ...view.compassMarkers },
look: { ...view.look },
// A provider's view model is rebuilt on each HUD update, never edited
// in place, so it is published as it stands.
readouts: view.readouts,
sources: view.sources,
banner: view.banner,
veil: view.veil,
progress: view.progress,
});
}
@@ -118,24 +126,158 @@ function wordLook({ side, bearingDeg, elevation, angleDeg }) {
*/
export function presentLook() {
const target = this.lookTarget;
// A provider's view words its own readout (its HUD view's `lookReadout`).
const provider = Boolean(this.subjectProvider);
const rest = provider ? this.lookRestPitch : VESSEL_BRIDGE_PITCH_DEG;
const offset =
this.active &&
this.subjectKind === 'vessel' &&
lookIsOffset(target, VESSEL_BRIDGE_PITCH_DEG);
(this.active && this.subjectKind === 'vessel') ||
(provider && this.looksAround)
? lookIsOffset(target, rest)
: false;
this.instruments.look = offset
? {
offset: true,
yawDeg: wrapLookYaw(target.yawDeg),
readout: wordLook(lookReadoutParts(target, VESSEL_BRIDGE_PITCH_DEG)),
readout: provider
? (this.subjectHud?.lookReadout ?? '')
: wordLook(lookReadoutParts(target, VESSEL_BRIDGE_PITCH_DEG)),
}
: { offset: false, yawDeg: 0, readout: '' };
}
/** Live Signals' tone for a provider's signal row. */
const SUBJECT_SIGNAL_TONES = Object.freeze({
warning: 'warning',
alert: 'warning',
});
/**
* Present a provider subject's HUD: its view model (cockpitSubjectHudView)
* in the generic readouts, the compass at the camera's heading, the route
* card, and its signals in Live Signals. A HUD view that is null, or a
* `hud()` that throws, keeps the last one. Contact navigation stays with
* aircraft, so the Contact card is withdrawn.
*/
function updateSubjectHud(info, nowMs, forceContext) {
const provider = this.subjectProvider;
this.lastSubjectInfo = info;
const frame = this.lastSubjectFrame;
const look = {
yawDeg: this.lookTarget?.yawDeg ?? 0,
pitchDeg: this.lookTarget?.pitchDeg ?? 0,
offset:
this.looksAround && lookIsOffset(this.lookTarget, this.lookRestPitch),
};
const raw = frame
? this.callSubject(
provider,
'hud',
[frame, Object.freeze({ ...this.subjectContext(), look })],
null,
)
: null;
if (raw != null) this.subjectHud = cockpitSubjectHudView(raw);
const hud = this.subjectHud ?? cockpitSubjectHudView(null);
const view = this.instruments;
view.kind = 'subject';
view.trackSource = null;
view.kicker = hud.kicker || provider.labels.kicker;
view.callsign = hud.title || info.name || '';
view.meta.text = hud.meta.text;
view.meta.tone = hud.meta.tone;
view.meta.emergency = hud.meta.tone === 'alert';
const speed = hud.speed?.value ?? null;
view.speed = hud.speed
? {
text: speed === null ? '---' : formatNumber(Math.round(speed)),
value: speed === null ? null : Math.round(speed),
immediate: forceContext,
}
: null;
view.speedUnit = hud.speed?.unit ?? '';
view.speedTag = hud.speed?.tag ?? '';
view.speedTone = hud.speed?.tone ?? 'normal';
view.speedRim.unavailable = true;
view.altitude = null;
view.altitudeRim.unavailable = true;
view.course = null;
const heading = normalizeHeading(this.heading ?? info.track ?? 0);
view.heading = {
text: formatHeadingReadout(heading),
value: heading,
immediate: forceContext,
};
const viewHeading = normalizeHeading(
heading + (provider.look ? (this.lookView?.yawDeg ?? 0) : 0),
);
view.compass = scrollingCompassDivisions(viewHeading).map((division) => ({
slot: division.slot,
heading: division.heading,
active: division.nearest,
label: compassPointLabel(formatCompassDivision(division.heading)),
}));
view.compassMarkers = {
prograde: compassMarkerSlot(heading, viewHeading),
retrograde: compassMarkerSlot(heading + 180, viewHeading),
};
view.clock = new Date().toISOString().slice(11, 19) + 'Z';
view.position = `${formatCockpitCoordinate(info.latitude, 'N', 'S')} · ${formatCockpitCoordinate(info.longitude, 'E', 'W')}`;
view.readouts = hud.readouts;
view.sources = hud.sources;
view.banner = hud.banner;
view.veil = hud.veil;
view.progress = hud.progress;
view.lookEnabled = Boolean(provider.look);
view.layer = provider.layerId;
this.presentLook();
this.publishInstrumentsView();
const route = this.routeView;
route.kind = 'subject';
route.title = hud.route?.title ?? '';
route.from = hud.route?.from ?? '';
route.to = hud.route?.to ?? '';
route.status = hud.route?.status ?? '';
route.visible = Boolean(hud.route);
// No destination arrow; clearing also publishes the card.
this.clearPredictiveRoute();
if (
forceContext ||
cockpitUiUpdateDue(
nowMs,
this.lastContextUpdateMs,
COCKPIT_CONTEXT_UPDATE_MS,
)
) {
this.lastContextUpdateMs = nowMs;
this.updateLocalPosition(info);
this.maybeRefreshRegionalBrief(info);
this.showContextCard(false);
const keys = new Set();
for (const signal of hud.signals) {
const key = `subject:${signal.id}`;
keys.add(key);
this.pushCockpitSignal(
key,
SUBJECT_SIGNAL_TONES[signal.tone] ?? 'info',
signal.title,
signal.detail || signal.title,
);
}
for (const key of this.subjectSignalKeys ?? [])
if (!keys.has(key)) this.dropCockpitSignal(key);
this.subjectSignalKeys = keys;
}
}
export function updateHud(
info,
nowMs = performance.now(),
forceContext = false,
) {
if (this.subjectProvider && info?.generic === true) {
updateSubjectHud.call(this, info, nowMs, forceContext);
return;
}
if (info?.kind === 'vessel') {
updateVesselHud.call(this, info, nowMs, forceContext);
return;