mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
feat(cockpit): ride a tracked satellite in an orbital view
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.
This commit is contained in:
1 parent
a648c9b665
commit
048293fc2a
67 files changed
+6642
-172
No files matched your search
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* The owner mark beside a satellite's name: the owner country's flag (an SVG
|
||||
* from flag-icons — Windows draws no flag emoji), or a short text badge for
|
||||
* an organisation without one (ESA, EUMETSAT, "Multinational"). Each flag is
|
||||
* its own lazily fetched asset; only the shown one ever loads.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Flag URL loaders by path; empty under node:test, which has no glob. The
|
||||
* glob is eager so the bundle carries only the URL strings: a lazy glob would
|
||||
* emit a JS stub chunk per flag (~270), two requests for each flag shown.
|
||||
* The SVG itself is still fetched only when an <img> shows it.
|
||||
*/
|
||||
let FLAG_LOADERS = {};
|
||||
try {
|
||||
const urls = import.meta.glob('/node_modules/flag-icons/flags/4x3/*.svg', {
|
||||
query: '?url&no-inline',
|
||||
import: 'default',
|
||||
eager: true,
|
||||
// flag-icons lives in node_modules, which globs skip by default.
|
||||
exhaustive: true,
|
||||
});
|
||||
FLAG_LOADERS = Object.fromEntries(
|
||||
Object.entries(urls).map(([path, url]) => [path, () => url]),
|
||||
);
|
||||
} catch {
|
||||
/* Not under Vite. */
|
||||
}
|
||||
|
||||
const FLAG_PATH = (code) =>
|
||||
`/node_modules/flag-icons/flags/4x3/${code.toLowerCase()}.svg`;
|
||||
|
||||
/** An ISO 3166-1 alpha-2 code, upper case, or null. */
|
||||
function isoCode(value) {
|
||||
const code = String(value ?? '').trim();
|
||||
return /^[A-Za-z]{2}$/.test(code) ? code.toUpperCase() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A region's name in the locale, from the browser's own table.
|
||||
* @param {string} code ISO 3166-1 alpha-2.
|
||||
* @param {string} locale BCP 47 tag.
|
||||
* @returns {string|null}
|
||||
*/
|
||||
export function regionName(code, locale) {
|
||||
try {
|
||||
const name = new Intl.DisplayNames([locale || 'en'], {
|
||||
type: 'region',
|
||||
}).of(code);
|
||||
return name && name !== code ? name : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How to mark a satellite's owner.
|
||||
* @param {{countryCode: string|null, label: string|null}|null|undefined} owner
|
||||
* @param {{locale?: string, loaders?: object}} [options]
|
||||
* @returns {{kind: 'flag', code: string, label: string}
|
||||
* | {kind: 'badge', label: string, title: string}
|
||||
* | null} A flag (with the country's localized name as its label), a text
|
||||
* badge for an owner with no flag to show, or nothing when unknown.
|
||||
*/
|
||||
export function ownerMark(
|
||||
owner,
|
||||
{ locale = 'en', loaders = FLAG_LOADERS } = {},
|
||||
) {
|
||||
const code = isoCode(owner?.countryCode);
|
||||
const label = String(owner?.label ?? '').trim();
|
||||
if (code) {
|
||||
const name = regionName(code, locale) || label || code;
|
||||
if (loaders[FLAG_PATH(code)]) return { kind: 'flag', code, label: name };
|
||||
return { kind: 'badge', label: label || code, title: name };
|
||||
}
|
||||
return label ? { kind: 'badge', label, title: label } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* What the readout shows for an owner once its flag has loaded or failed: the
|
||||
* flag, or a badge (the country code when the flag would not load, so the
|
||||
* owner never disappears), or nothing for an unknown owner.
|
||||
* @param {ReturnType<typeof ownerMark>} mark
|
||||
* @param {{url?: string|null, failed?: boolean}} [flag] The flag's load state.
|
||||
* @returns {{kind: 'flag', url: string, label: string}
|
||||
* | {kind: 'badge', label: string, title: string} | null}
|
||||
*/
|
||||
export function shownOwnerMark(mark, { url = null, failed = false } = {}) {
|
||||
if (!mark) return null;
|
||||
if (mark.kind === 'badge') return mark;
|
||||
if (failed) {
|
||||
return { kind: 'badge', label: mark.code.toUpperCase(), title: mark.label };
|
||||
}
|
||||
return url ? { kind: 'flag', url, label: mark.label } : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a flag's URL.
|
||||
* @param {string} code ISO 3166-1 alpha-2.
|
||||
* @returns {Promise<string|null>}
|
||||
*/
|
||||
export async function loadFlagUrl(code, loaders = FLAG_LOADERS) {
|
||||
const load = loaders[FLAG_PATH(String(code))];
|
||||
if (!load) return null;
|
||||
try {
|
||||
return (await load()) || null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user