mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
With a satellite tracked and no aircraft tracked, Cockpit can ride the satellite. Entry needs only the Satellites layer; debris can be tracked but not entered, and voice stays aircraft-only. Double-clicking the tracked satellite or the entry buttons (reading ORBIT) enter it. The camera sits on the satellite's per-frame SGP4 position and looks straight down, turned to the ground track (north-up for a satellite with none). The optical zoom steps 1x to 8x with a focus pull, the arrows tilt the view up to 45 degrees off nadir, and Home or 0 returns to nadir. Off nadir the tilt reads its total angle first and the swath readout becomes an approximation marked with ≈. While in orbit the map leases flat Esri imagery, the cloud pass stays off and the view opens in the optical style. The orbital HUD names the satellite with its owner's flag (from the flag-icons package, loaded per country) or an organisation badge, its operator, class, NORAD and COSPAR ids and TLE epoch with the element lines on request, altitude, orbital speed and the sub-satellite point. CURRENTLY OVER names the country and its first-level division, or the sea, and from 8x the most prominent populated place nearby, looked up offline from the bundled Natural Earth packs (populated places are a new pack). The satellites layer hides the ridden satellite's own marks, dims the other orbit rings and ignores scene clicks and Escape while held. Exit restores the camera's field of view and the satellite's follow camera. C no longer enters or leaves Cockpit, bridge or orbit: it is left to the app-wide CCTV shortcut, and Escape or the exit button leave first person.
179 lines
5.7 KiB
JavaScript
179 lines
5.7 KiB
JavaScript
/** Pure formatting and fixed presentation constants used by Cockpit components. */
|
||
import { formatNumber, getLocale, isolate, t, msg } from '../i18n/index.js';
|
||
import { formatQuantity } from './unitLabels.js';
|
||
import {
|
||
normalizeHeading,
|
||
roundHeadingDegrees,
|
||
} from '../data/headingDegrees.js';
|
||
import { kilometreDigits } from '../data/distanceFormat.js';
|
||
|
||
export const COCKPIT_HEADING_SLEW_DPS = 28;
|
||
|
||
export const COCKPIT_FORWARD_OFFSET_M = 7;
|
||
|
||
export const COCKPIT_UP_OFFSET_M = 2.6;
|
||
|
||
export const COCKPIT_MIN_GROUND_CLEARANCE_M = 12;
|
||
|
||
export const COCKPIT_VIEW_PITCH_DEG = -4;
|
||
|
||
export const COCKPIT_CAMERA_UPDATE_MS = 50;
|
||
|
||
export const COCKPIT_HUD_UPDATE_MS = 100;
|
||
|
||
export const COCKPIT_CONTEXT_UPDATE_MS = 250;
|
||
|
||
export const COCKPIT_UTILITY_REC_GAP_PX = 12;
|
||
|
||
export const COCKPIT_UTILITY_SIGNAL_GAP_PX = 8;
|
||
|
||
export const COCKPIT_UTILITY_MIN_TOP_PX = 96;
|
||
|
||
export const COCKPIT_UTILITY_MIN_TOP_RATIO = 0.12;
|
||
|
||
export const COCKPIT_UTILITY_LAUNCHER_MIN_HEIGHT_PX = 50;
|
||
|
||
export const COCKPIT_GROUND_PROBE_MS = 500;
|
||
|
||
export const COCKPIT_GROUND_WAIT_TIMEOUT_MS = 5000;
|
||
|
||
export const COCKPIT_BRIEF_ROTATE_MS = 9000;
|
||
|
||
export const COCKPIT_REGIONAL_REFRESH_MS = 5 * 60_000;
|
||
|
||
export const COCKPIT_REGIONAL_REFRESH_DISTANCE_M = 25_000;
|
||
|
||
export function isRenderedOnScreen(element) {
|
||
if (!element) return false;
|
||
for (let node = element; node instanceof Element; node = node.parentElement) {
|
||
const style = getComputedStyle(node);
|
||
if (
|
||
style.display === 'none' ||
|
||
style.visibility === 'hidden' ||
|
||
Number(style.opacity) === 0
|
||
) {
|
||
return false;
|
||
}
|
||
}
|
||
const rect = element.getBoundingClientRect();
|
||
return rect.width > 0 && rect.height > 0;
|
||
}
|
||
|
||
export function formatCockpitBriefAge(value) {
|
||
const timestamp = Date.parse(value);
|
||
if (!Number.isFinite(timestamp)) return t('TIME UNKNOWN');
|
||
const minutes = Math.max(0, Math.round((Date.now() - timestamp) / 60_000));
|
||
if (minutes < 60) return t('{count}M AGO', { count: minutes });
|
||
const hours = Math.round(minutes / 60);
|
||
return hours < 48
|
||
? t('{count}H AGO', { count: hours })
|
||
: t('{count}D AGO', { count: Math.round(hours / 24) });
|
||
}
|
||
|
||
/** Compass point codes in display order and the label shown for each. */
|
||
const COMPASS_POINT_LABELS = Object.freeze({
|
||
N: msg('N'),
|
||
NE: msg('NE'),
|
||
E: msg('E'),
|
||
SE: msg('SE'),
|
||
S: msg('S'),
|
||
SW: msg('SW'),
|
||
W: msg('W'),
|
||
NW: msg('NW'),
|
||
});
|
||
|
||
/**
|
||
* The shown label for a compass point code (`N`, `SW`…): С, ЮЗ… in Russian.
|
||
* Anything else (a degree reading such as `030`) passes through unchanged.
|
||
*/
|
||
export function compassPointLabel(code) {
|
||
return Object.hasOwn(COMPASS_POINT_LABELS, code)
|
||
? t(COMPASS_POINT_LABELS[code])
|
||
: code;
|
||
}
|
||
|
||
/** `30.203°N` in the active language: `30,203° с. ш.` in Russian. */
|
||
export function formatCockpitCoordinate(value, positive, negative) {
|
||
const amount = formatNumber(Math.abs(value), {
|
||
useGrouping: false,
|
||
minimumFractionDigits: 3,
|
||
maximumFractionDigits: 3,
|
||
});
|
||
const code = value >= 0 ? positive : negative;
|
||
// Not «30,203°С»: after a degree sign «С» reads as Celsius. Isolated, so
|
||
// an Arabic hemisphere letter does not pull the next number into its run.
|
||
switch (code) {
|
||
case 'N':
|
||
return isolate(t('{value}°N', { value: amount }));
|
||
case 'S':
|
||
return isolate(t('{value}°S', { value: amount }));
|
||
case 'E':
|
||
return isolate(t('{value}°E', { value: amount }));
|
||
case 'W':
|
||
return isolate(t('{value}°W', { value: amount }));
|
||
default:
|
||
return isolate(`${amount}°${compassPointLabel(code)}`);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* A contact distance such as `4.2 KM` / `44 KM` in the active language
|
||
* (`4,2 КМ`): one decimal under 10 km, whole kilometres beyond.
|
||
*/
|
||
export function formatCockpitDistance(distanceM) {
|
||
const digits = kilometreDigits(distanceM);
|
||
const distance = formatQuantity(distanceM / 1000, 'km', {
|
||
minimumFractionDigits: digits,
|
||
maximumFractionDigits: digits,
|
||
});
|
||
return cockpitUnitCase(distance);
|
||
}
|
||
|
||
/**
|
||
* Upper-case a cockpit unit the HUD way (`9.5 KM`), except in Chinese and
|
||
* Japanese, which have no case and keep units as the catalog writes them.
|
||
*/
|
||
export function cockpitUnitCase(text) {
|
||
return /^(zh|ja)(-|$)/.test(getLocale()) ? text : text.toUpperCase();
|
||
}
|
||
|
||
export function formatCockpitWindDirection(value) {
|
||
if (!Number.isFinite(value)) return t('DIR UNKNOWN');
|
||
const labels = Object.keys(COMPASS_POINT_LABELS);
|
||
const normalized = normalizeHeading(value);
|
||
const degrees = roundHeadingDegrees(value);
|
||
return `${compassPointLabel(labels[Math.round(normalized / 45) % labels.length])} · ${degrees}°`;
|
||
}
|
||
|
||
/**
|
||
* A TLE epoch as compact UTC, `2026-11-04 08:12Z`, or '' when unknown.
|
||
* @param {number|null|undefined} epochMs
|
||
*/
|
||
export function formatTleEpochUtc(epochMs) {
|
||
// Beyond ±8.64e15 ms a Date is invalid and toISOString throws.
|
||
if (!Number.isFinite(epochMs) || Math.abs(epochMs) > 8.64e15) return '';
|
||
const iso = new Date(epochMs).toISOString();
|
||
return `${iso.slice(0, 10)} ${iso.slice(11, 16)}Z`;
|
||
}
|
||
|
||
/**
|
||
* The Cockpit entry for each subject it can ride: an aircraft's cockpit, a
|
||
* vessel's bridge or a satellite's orbit. Both entry buttons (Contacts and
|
||
* the Intel HUD readout) show it.
|
||
*/
|
||
const COCKPIT_ENTRY_FACES = Object.freeze({
|
||
aircraft: Object.freeze({ icon: 'flight', label: msg('COCKPIT') }),
|
||
vessel: Object.freeze({ icon: 'directions_boat', label: msg('BRIDGE') }),
|
||
satellite: Object.freeze({ icon: 'satellite_alt', label: msg('ORBIT') }),
|
||
});
|
||
|
||
/**
|
||
* The entry's glyph and localized label for the subject it would ride.
|
||
* @param {'aircraft'|'vessel'|'satellite'|null|undefined} kind
|
||
* @returns {{icon: string, label: string}}
|
||
*/
|
||
export function cockpitEntryFace(kind) {
|
||
const face = COCKPIT_ENTRY_FACES[kind] ?? COCKPIT_ENTRY_FACES.aircraft;
|
||
return { icon: face.icon, label: t(face.label) };
|
||
}
|