mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-23 11:42:21 +00:00
When the world has loaded, the loading screen's words fade and the logo glides to the centre. The eye's arcs fly at the viewer, the drawn planet in the pupil gives way to the real globe drawn the same size behind it, and the globe spins west to east, growing and slowing until it stops with the whole planet in view over the visitor's country. The country comes from the browser's time zone (or, for UTC, a language's region), so nothing leaves the browser. scripts/build-home-countries.mjs writes the zone and country table from tzdata's zone.tab and the Natural Earth countries pack. The title's logo goes back to the same view. A share link, a Stories link, reduced motion and ?intro=0 open as before. A click, a key or the wheel skips to the end; any other camera move stops it. The globe-in-view recovery waits while it plays, since the far start shows the globe as a speck.
102 lines
3.6 KiB
JavaScript
102 lines
3.6 KiB
JavaScript
#!/usr/bin/env node
|
|
// Writes src/data/homeCountries.js: each time zone's country, and where the
|
|
// opening stops over that country.
|
|
//
|
|
// node scripts/build-home-countries.mjs [path/to/zone.tab]
|
|
//
|
|
// Zones come from tzdata's zone.tab (macOS and most Linux systems ship it at
|
|
// /usr/share/zoneinfo/zone.tab), with the older names ICU still reports for
|
|
// some of them (Asia/Calcutta for Asia/Kolkata): a browser may give either.
|
|
// A country's point is the centroid of its largest part in the Natural Earth
|
|
// countries pack (the contiguous United States, mainland France), or the
|
|
// zone's own place where the pack has no such country.
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { geometryOf } from '../src/data/adminBoundaries.js';
|
|
|
|
const root = new URL('../', import.meta.url);
|
|
const zoneTab = process.argv[2] ?? '/usr/share/zoneinfo/zone.tab';
|
|
const pack = JSON.parse(
|
|
readFileSync(
|
|
new URL('src/data/local_data/natural_earth/countries.json', root),
|
|
'utf8',
|
|
),
|
|
);
|
|
const out = new URL('src/data/homeCountries.js', root);
|
|
|
|
const round = (value) => Math.round(value * 10) / 10;
|
|
|
|
/** ISO 6709 `±DDMM[SS]±DDDMM[SS]` → [lat, lon]. */
|
|
function iso6709(text) {
|
|
const [, lat, lon] = text.match(/^([+-]\d+)([+-]\d+)$/);
|
|
const part = (s, degreeDigits) => {
|
|
const sign = s[0] === '-' ? -1 : 1;
|
|
const d = s.slice(1);
|
|
const deg = Number(d.slice(0, degreeDigits));
|
|
const min = Number(d.slice(degreeDigits, degreeDigits + 2));
|
|
const sec = Number(d.slice(degreeDigits + 2) || 0);
|
|
return sign * (deg + min / 60 + sec / 3600);
|
|
};
|
|
return [part(lat, 2), part(lon, 3)];
|
|
}
|
|
|
|
const largest = new Map();
|
|
for (const feature of pack.features) {
|
|
if (feature.type !== 'Country' || !/^[A-Z]{2}$/.test(feature.iso2)) continue;
|
|
const geometry = geometryOf({ feature, decimals: pack.meta.decimals });
|
|
const held = largest.get(feature.iso2);
|
|
if (!held || geometry.areaKm2 > held.areaKm2)
|
|
largest.set(feature.iso2, geometry);
|
|
}
|
|
|
|
const zones = new Map();
|
|
const centres = new Map();
|
|
const icuName = (zone) => {
|
|
try {
|
|
return new Intl.DateTimeFormat('en', { timeZone: zone }).resolvedOptions()
|
|
.timeZone;
|
|
} catch {
|
|
return null;
|
|
}
|
|
};
|
|
for (const line of readFileSync(zoneTab, 'utf8').split('\n')) {
|
|
if (!line || line.startsWith('#')) continue;
|
|
const [country, place, zone] = line.split('\t');
|
|
zones.set(zone, country);
|
|
const icu = icuName(zone);
|
|
if (icu && icu !== zone && !zones.has(icu)) zones.set(icu, country);
|
|
if (centres.has(country)) continue;
|
|
const label = largest.get(country)?.label;
|
|
centres.set(
|
|
country,
|
|
label ? [round(label.lat), round(label.lon)] : iso6709(place).map(round),
|
|
);
|
|
}
|
|
|
|
const sortedEntries = (map) =>
|
|
[...map].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
const lines = [
|
|
'// Generated by scripts/build-home-countries.mjs. Do not edit by hand.',
|
|
'// Sources: tzdata zone.tab (public domain) and the Natural Earth countries',
|
|
'// pack in src/data/local_data/natural_earth (public domain).',
|
|
'',
|
|
'/** ISO 3166 country → [lat, lon]: the centroid of its largest part. */',
|
|
'export const COUNTRY_CENTRES = {',
|
|
...sortedEntries(centres).map(
|
|
([country, [lat, lon]]) => ` ${country}: [${lat}, ${lon}],`,
|
|
),
|
|
'};',
|
|
'',
|
|
'/** Time zone (tzdata and ICU names) → ISO 3166 country. */',
|
|
'export const ZONE_COUNTRIES = {',
|
|
...sortedEntries(zones).map(
|
|
([zone, country]) => ` '${zone}': '${country}',`,
|
|
),
|
|
'};',
|
|
'',
|
|
];
|
|
writeFileSync(out, lines.join('\n'));
|
|
console.log(
|
|
`${fileURLToPath(out)}: ${centres.size} countries, ${zones.size} zones`,
|
|
);
|