mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
fix(cockpit): application subjects follow a change of language, never stand on the ellipsoid, and are guarded on every call; a re-selected subject takes entry again
- Labels, entry face and look may be functions, read again on every use and on a locale change; a failing read keeps the last good value. - A frame with no height keeps the eye's last height, or waits (surfaceAcquiring) until the floor is known; heights outside -1,000..50,000 m read as null. - Provider methods are synchronous: a returned promise is refused like a throw, and a hold that fails is released. - A candidate may carry selectedAt; Rail and Transit stamp selectedAtMs on every selection, so re-selecting moves a subject to the front. - A released Transit vehicle leaves the visible set at once. - docs/CURRENT-STATE.md states the new entry order; docs/APPLICATION.md documents cockpit subjects, ./i18n/locale and ./layers/rail/paths.
This commit is contained in:
1 parent
01a74fceec
commit
57d87d2bbf
18 files changed
+707
-199
No files matched your search
@@ -104,9 +104,11 @@ const BUILT_IN_ENTRY_ORDER = Object.freeze({
|
||||
* Every subject entry could ride now, the most recently selected first: a
|
||||
* tracked aircraft, the tracked satellite, the selected vessel and each
|
||||
* provider's candidate. A candidate's time is when this controller first saw
|
||||
* it (it looks on its entry cadence and on tracking changes); candidates
|
||||
* first seen together keep the fixed order (aircraft, satellite, vessel, then
|
||||
* providers by priority). Each carries `allowed()`, its kind's entry gate.
|
||||
* it (it looks on its entry cadence and on tracking changes), or saw it
|
||||
* selected again: a provider candidate whose `selectedAt` changes, the same
|
||||
* subject clicked again, moves to the front. Candidates first seen together
|
||||
* keep the fixed order (aircraft, satellite, vessel, then providers by
|
||||
* priority). Each carries `allowed()`, its kind's entry gate.
|
||||
* @param {number} [nowMs]
|
||||
* @returns {Array<{kind: string, id: string, seenAtMs: number, order: number,
|
||||
* allowed: () => boolean, provider?: object, candidate?: object}>}
|
||||
@@ -114,9 +116,10 @@ const BUILT_IN_ENTRY_ORDER = Object.freeze({
|
||||
export function entryCandidates(nowMs = performance.now()) {
|
||||
const seen = (this._entrySeen ??= new Map());
|
||||
const list = [];
|
||||
const note = (kind, id, entry) => {
|
||||
const note = (kind, id, entry, selectedAt = null) => {
|
||||
const last = seen.get(kind);
|
||||
if (!last || last.id !== id) seen.set(kind, { id, atMs: nowMs });
|
||||
if (!last || last.id !== id || last.selectedAt !== selectedAt)
|
||||
seen.set(kind, { id, selectedAt, atMs: nowMs });
|
||||
list.push({ kind, id, seenAtMs: seen.get(kind).atMs, ...entry });
|
||||
};
|
||||
const aircraft = this.readAircraftInfo();
|
||||
@@ -149,12 +152,17 @@ export function entryCandidates(nowMs = performance.now()) {
|
||||
this.subjectProviders.forEach((provider, index) => {
|
||||
const candidate = this.readSubjectCandidate(provider);
|
||||
if (candidate)
|
||||
note(provider.kind, candidate.id, {
|
||||
order: 3 + index,
|
||||
provider,
|
||||
candidate,
|
||||
allowed: () => this.isSubjectEntryAllowed(provider, candidate),
|
||||
});
|
||||
note(
|
||||
provider.kind,
|
||||
candidate.id,
|
||||
{
|
||||
order: 3 + index,
|
||||
provider,
|
||||
candidate,
|
||||
allowed: () => this.isSubjectEntryAllowed(provider, candidate),
|
||||
},
|
||||
candidate.selectedAt,
|
||||
);
|
||||
});
|
||||
// A subject gone and back counts as selected again.
|
||||
for (const kind of [...seen.keys()])
|
||||
@@ -268,6 +276,20 @@ export function syncTr3bToggle(info) {
|
||||
this.publishPresenceView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Word the ridden provider subject's labels and Look ahead button again,
|
||||
* after a change of the page's language: a provider may give them as
|
||||
* functions (cockpitSubjectProviders).
|
||||
*/
|
||||
export function refreshSubjectWords() {
|
||||
const provider = this.subjectProvider;
|
||||
if (!this.active || !provider) return;
|
||||
this.presence.subjectLabels = { ...provider.labels };
|
||||
const look = provider.look;
|
||||
this.presence.subjectLook = look ? { aheadLabel: look.aheadLabel } : null;
|
||||
this.publishPresenceView();
|
||||
}
|
||||
|
||||
export function syncEntry() {
|
||||
if (this.destroyed) return false;
|
||||
if (this.active) return;
|
||||
@@ -376,8 +398,14 @@ function enterSubject(provider) {
|
||||
const candidate = this.readSubjectCandidate(provider);
|
||||
if (!candidate || !this.isSubjectEntryAllowed(provider, candidate))
|
||||
return false;
|
||||
if (this.callSubject(provider, 'hold', [candidate.id], false) !== true)
|
||||
const failed = {};
|
||||
const held = this.callSubject(provider, 'hold', [candidate.id], failed);
|
||||
if (held === failed) {
|
||||
// A hold that threw (or broke the contract) may have half happened.
|
||||
this.callSubject(provider, 'release', [candidate.id, { restore: false }]);
|
||||
return false;
|
||||
}
|
||||
if (held !== true) return false;
|
||||
const frame = cockpitSubjectFrame(
|
||||
this.callSubject(
|
||||
provider,
|
||||
@@ -419,6 +447,7 @@ function enterSubject(provider) {
|
||||
this.surfaceAcquiring = false;
|
||||
this.surfaceFallback = false;
|
||||
this.cockpitAnchorValid = false;
|
||||
this.subjectHeightM = null;
|
||||
this.lookRestPitchDeg = provider.look?.restPitchDeg ?? null;
|
||||
this.resetLook({ immediate: true });
|
||||
this.active = true;
|
||||
|
||||
Reference in new issue
Block a user