mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat(cockpit): the owner flags load at startup from one generated 15 KB sheet; the loading status names the place packs while they load on first lookup
This commit is contained in:
1 parent
63aa45c520
commit
5a6cf22be1
35 files changed
+643
-216
No files matched your search
@@ -0,0 +1,17 @@
|
||||
# Owner flags
|
||||
|
||||
`owner_flags.png` is one sheet of every owner country a satellite can be
|
||||
marked with (`OWNER_COUNTRY_CODES` in `src/layers/satellites/classes.js`),
|
||||
drawn at 40 × 30 px (twice the orbital readout's 20 × 15) in sorted code
|
||||
order, 16 to a row. `src/ui/ownerFlag.js` loads it once at startup and draws
|
||||
each flag from its cell; the layout is `src/ui/ownerFlagSheet.js`.
|
||||
|
||||
**Source:** the 4:3 SVGs of [flag-icons](https://github.com/lipis/flag-icons)
|
||||
7.5.0 (a devDependency, used only to build the sheet).
|
||||
|
||||
**License:** flag-icons is MIT licensed (© Panayiotis Lipiridis). Country
|
||||
flags themselves are not copyrightable designs in most jurisdictions.
|
||||
|
||||
**Regenerate:** `node scripts/build-owner-flags.mjs` (after adding an owner
|
||||
country, or updating flag-icons). With the same flag-icons and sharp versions
|
||||
a rerun reproduces both files byte for byte.
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
+62
-7
@@ -10,7 +10,8 @@
|
||||
*
|
||||
* PURE data module: no Cesium, node-testable. Each pack loads lazily on the
|
||||
* first lookup that needs it (divisions on the first land hit, places on the
|
||||
* first radius) and is indexed once; a country's division rings are decoded
|
||||
* first radius) and is indexed once, and the loading status names them while
|
||||
* one is on its way (`placePacksLoading`); a country's division rings are decoded
|
||||
* the first time a point falls inside it. A failed load is retried later
|
||||
* (see `createRetryableLoader`). No network.
|
||||
*/
|
||||
@@ -46,6 +47,53 @@ const PACKS = {
|
||||
),
|
||||
};
|
||||
|
||||
/** The packs on their way now, for the loading status. */
|
||||
const loadingPacks = new Set();
|
||||
const loadingListeners = new Set();
|
||||
|
||||
function notifyLoading() {
|
||||
for (const listener of [...loadingListeners]) {
|
||||
try {
|
||||
listener();
|
||||
} catch {
|
||||
/* A status listener never breaks a lookup. */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A pack load that the loading status counts while it runs. */
|
||||
function reportedLoad(name, load) {
|
||||
return async () => {
|
||||
loadingPacks.add(name);
|
||||
notifyLoading();
|
||||
try {
|
||||
return await load();
|
||||
} finally {
|
||||
loadingPacks.delete(name);
|
||||
notifyLoading();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a place pack is loading now. The packs load lazily, on the first
|
||||
* lookup that needs them, so the loading status says so meanwhile.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function placePacksLoading() {
|
||||
return loadingPacks.size > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hear each start and end of a place pack load.
|
||||
* @param {() => void} listener
|
||||
* @returns {() => void} Stops listening.
|
||||
*/
|
||||
export function onPlacePacksLoadingChange(listener) {
|
||||
loadingListeners.add(listener);
|
||||
return () => loadingListeners.delete(listener);
|
||||
}
|
||||
|
||||
/** Test seam: count pack loads (lazy-loading contract). */
|
||||
export const placePackLoads = { divisions: 0, places: 0 };
|
||||
|
||||
@@ -106,7 +154,7 @@ function ringRank(ring) {
|
||||
return (Math.abs(sum) / 2) * Math.cos((meanLat * Math.PI) / 180);
|
||||
}
|
||||
|
||||
const loadPlaces = createRetryableLoader(async () => {
|
||||
async function readPlaces() {
|
||||
const [countries, marine] = await Promise.all([
|
||||
loadBundledJson(PACKS.countries),
|
||||
loadBundledJson(PACKS.marine),
|
||||
@@ -142,10 +190,11 @@ const loadPlaces = createRetryableLoader(async () => {
|
||||
});
|
||||
}
|
||||
return { land, water };
|
||||
});
|
||||
}
|
||||
const loadPlaces = createRetryableLoader(reportedLoad('places', readPlaces));
|
||||
|
||||
/** Divisions grouped by country code; rings decoded per country on demand. */
|
||||
const loadDivisions = createRetryableLoader(async () => {
|
||||
async function readDivisions() {
|
||||
placePackLoads.divisions += 1;
|
||||
const pack = await loadBundledJson(PACKS.divisions);
|
||||
const decimals = pack.meta?.decimals ?? 3;
|
||||
@@ -157,7 +206,10 @@ const loadDivisions = createRetryableLoader(async () => {
|
||||
byCountry.set(feature.iso2, list);
|
||||
}
|
||||
return { byCountry, decoded: new Map() };
|
||||
});
|
||||
}
|
||||
const loadDivisions = createRetryableLoader(
|
||||
reportedLoad('divisions', readDivisions),
|
||||
);
|
||||
|
||||
/** The first-level division holding a point inside country `code`, or null. */
|
||||
async function divisionAt(code, lat, lon) {
|
||||
@@ -179,7 +231,7 @@ async function divisionAt(code, lat, lon) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const loadPopulatedPlaces = createRetryableLoader(async () => {
|
||||
async function readPopulatedPlaces() {
|
||||
placePackLoads.places += 1;
|
||||
const pack = await loadBundledJson(PACKS.places);
|
||||
return (pack.places || []).filter(
|
||||
@@ -189,7 +241,10 @@ const loadPopulatedPlaces = createRetryableLoader(async () => {
|
||||
Number.isFinite(row[1]) &&
|
||||
Number.isFinite(row[2]),
|
||||
);
|
||||
});
|
||||
}
|
||||
const loadPopulatedPlaces = createRetryableLoader(
|
||||
reportedLoad('populated-places', readPopulatedPlaces),
|
||||
);
|
||||
|
||||
/**
|
||||
* The most prominent populated place within `radiusKm` of a point (lowest
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// src/data/placePacksLoading.test.mjs — the loading status hears the place
|
||||
// packs while they are on their way.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
test('a place pack load is reported from its start to its end', async () => {
|
||||
// A module of its own, so no other test has loaded the packs yet.
|
||||
const place = await import('./placeBelow.js?loading-status');
|
||||
const heard = [];
|
||||
const stop = place.onPlacePacksLoadingChange(() =>
|
||||
heard.push(place.placePacksLoading()),
|
||||
);
|
||||
assert.equal(place.placePacksLoading(), false);
|
||||
const lookup = place.nearPlace(48.86, 2.35, 50);
|
||||
assert.equal(place.placePacksLoading(), true, 'on its way');
|
||||
assert.equal(await lookup, 'Paris');
|
||||
assert.equal(place.placePacksLoading(), false, 'loaded');
|
||||
assert.deepEqual(heard, [true, false]);
|
||||
// Loaded once: a later lookup is not reported again.
|
||||
await place.nearPlace(48.86, 2.35, 50);
|
||||
assert.deepEqual(heard, [true, false]);
|
||||
stop();
|
||||
});
|
||||
Reference in new issue
Block a user