Files
gods-eye-view/src/ui/stores/cockpit.js
T
Sameh Khamis a2bca0fb22 feat(ui): render the Cockpit instruments, route and vision selector from a store
The Cockpit controller no longer writes the HUD's instruments, the flight
plan card, the visor's destination arrow or the vision selector. It keeps
them as plain state, starting from cockpitInstrumentState.js, and
publishes copies to the gev-cockpit store: the instruments on every HUD
update, the route only when it changed, the vision selector when the mode
changes. CockpitView renders the callsign, aircraft meta and emergency
mark, speed and altitude rims and ticks, compass tape, clock, position,
HUD layer, destination arrow and vision selector; a new CockpitRoute
component renders the flight plan card inside the briefing card.

The odometer readouts become CockpitRollingValue components. Their
throttle and digit roll move unchanged from setCockpitRollingValue into
cockpitRollingValue.js: every accepted reading restamps the throttle, a
change inside it is dropped, and each accepted change draws fresh glyphs
so the roll animation restarts. A rim tick with no reading still hides
where it stood, and a hidden arrow keeps its last angle and label.

In a dev build the HUD's Vue patch costs about 0.5 ms per update (1.4 ms
at 4x CPU throttle), against 0.4 ms (2.1 ms) for the DOM writes it
replaces, at about 10 updates a second.
2026-10-31 14:36:32 -07:00

65 lines
2.0 KiB
JavaScript

import { defineStore } from 'pinia';
import { markRaw, shallowRef } from 'vue';
/**
* Cockpit content as its views render it. The Cockpit controller presents
* the briefing card's pages, cycle toggle, regional news and local
* conditions, the Contact card's readouts and weather toggle, the
* instruments, the flight plan and the vision selector, and publishes them
* here; it keeps the controls' listeners.
*/
export const useCockpitStore = defineStore('gev-cockpit', () => {
/** The presented briefing; null until the controller first presents it. */
const brief = shallowRef(null);
/** @param {?object} next A fresh presentation of the briefing card. */
function publishBrief(next) {
brief.value = next && markRaw(next);
}
/** The presented Contact card; null until the controller first presents it. */
const context = shallowRef(null);
/** @param {?object} next A fresh presentation of the Contact card. */
function publishContext(next) {
context.value = next && markRaw(next);
}
/** The presented instruments; null until the first HUD update. */
const instruments = shallowRef(null);
/** @param {?object} next A fresh presentation of the instruments. */
function publishInstruments(next) {
instruments.value = next && markRaw(next);
}
/** The presented flight plan and destination arrow; null until the first. */
const route = shallowRef(null);
/** @param {?object} next A fresh presentation of the route. */
function publishRoute(next) {
route.value = next && markRaw(next);
}
/** The presented vision selector; null until the first vision change. */
const vision = shallowRef(null);
/** @param {?object} next A fresh presentation of the vision selector. */
function publishVision(next) {
vision.value = next && markRaw(next);
}
return {
brief,
publishBrief,
context,
publishContext,
instruments,
publishInstruments,
route,
publishRoute,
vision,
publishVision,
};
});