fix(cockpit): a place pack that will not load ends the loading batch failed; flags keep their neighbours out from under the border and out of a scaled flag's edge; a new ride asks again for a sheet that failed

This commit is contained in:
Sameh Khamis committed 2026-11-08 19:45:01 -08:00
1 parent 5a6cf22be1
commit e954734379
16 files changed
+198 -55

No files matched your search

+2 -1
View File
@@ -3,7 +3,8 @@
`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
order, 16 to a row, each followed by 2 transparent pixels so a scaled flag
never smooths into its neighbour. `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)
Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

+29 -13
View File
@@ -11,7 +11,7 @@
* 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, and the loading status names them while
* one is on its way (`placePacksLoading`); a country's division rings are decoded
* one is on its way (`placePacksStatus`); 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.
*/
@@ -47,8 +47,9 @@ const PACKS = {
),
};
/** The packs on their way now, for the loading status. */
/** The packs on their way now, and those whose last load failed. */
const loadingPacks = new Set();
const failedPacks = new Set();
const loadingListeners = new Set();
function notifyLoading() {
@@ -61,13 +62,25 @@ function notifyLoading() {
}
}
/** A pack load that the loading status counts while it runs. */
function reportedLoad(name, load) {
/**
* A pack load that the loading status follows: on its way while it runs,
* failed until a later load of it succeeds.
* @template T
* @param {string} name
* @param {() => Promise<T>} load
* @returns {() => Promise<T>}
*/
export function reportedPlacePackLoad(name, load) {
return async () => {
loadingPacks.add(name);
notifyLoading();
try {
return await load();
const result = await load();
failedPacks.delete(name);
return result;
} catch (error) {
failedPacks.add(name);
throw error;
} finally {
loadingPacks.delete(name);
notifyLoading();
@@ -76,12 +89,13 @@ function reportedLoad(name, load) {
}
/**
* 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}
* The place packs' state for the loading status. The packs load lazily, on
* the first lookup that needs them, so the status says so meanwhile, and
* says when one would not load.
* @returns {{loading: boolean, failed: boolean}}
*/
export function placePacksLoading() {
return loadingPacks.size > 0;
export function placePacksStatus() {
return { loading: loadingPacks.size > 0, failed: failedPacks.size > 0 };
}
/**
@@ -191,7 +205,9 @@ async function readPlaces() {
}
return { land, water };
}
const loadPlaces = createRetryableLoader(reportedLoad('places', readPlaces));
const loadPlaces = createRetryableLoader(
reportedPlacePackLoad('places', readPlaces),
);
/** Divisions grouped by country code; rings decoded per country on demand. */
async function readDivisions() {
@@ -208,7 +224,7 @@ async function readDivisions() {
return { byCountry, decoded: new Map() };
}
const loadDivisions = createRetryableLoader(
reportedLoad('divisions', readDivisions),
reportedPlacePackLoad('divisions', readDivisions),
);
/** The first-level division holding a point inside country `code`, or null. */
@@ -243,7 +259,7 @@ async function readPopulatedPlaces() {
);
}
const loadPopulatedPlaces = createRetryableLoader(
reportedLoad('populated-places', readPopulatedPlaces),
reportedPlacePackLoad('populated-places', readPopulatedPlaces),
);
/**
+18 -4
View File
@@ -8,16 +8,30 @@ test('a place pack load is reported from its start to its end', async () => {
const place = await import('./placeBelow.js?loading-status');
const heard = [];
const stop = place.onPlacePacksLoadingChange(() =>
heard.push(place.placePacksLoading()),
heard.push(place.placePacksStatus().loading),
);
assert.equal(place.placePacksLoading(), false);
assert.equal(place.placePacksStatus().loading, false);
const lookup = place.nearPlace(48.86, 2.35, 50);
assert.equal(place.placePacksLoading(), true, 'on its way');
assert.equal(place.placePacksStatus().loading, true, 'on its way');
assert.equal(await lookup, 'Paris');
assert.equal(place.placePacksLoading(), false, 'loaded');
assert.equal(place.placePacksStatus().loading, 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();
});
test('a pack that would not load stays failed until it loads', async () => {
const place = await import('./placeBelow.js?failed-status');
let fail = true;
const load = place.reportedPlacePackLoad('test', async () => {
if (fail) throw new Error('offline');
return 1;
});
await assert.rejects(load(), /offline/);
assert.deepEqual(place.placePacksStatus(), { loading: false, failed: true });
fail = false;
assert.equal(await load(), 1);
assert.deepEqual(place.placePacksStatus(), { loading: false, failed: false });
});