23 lines
1.0 KiB
TypeScript
23 lines
1.0 KiB
TypeScript
/**
|
|
* The guess when a player skips choosing a town: the largest town in the device's
|
|
* time zone, or the zone's own location from the time zone database (ROADMAP Phase 1:
|
|
* "if skipped, it is guessed from the device time zone"). Never GPS, never a lookup.
|
|
* Small, so the garden can load it without the town list.
|
|
*/
|
|
import data from './zone-guesses.json' with { type: 'json' };
|
|
import type { Town } from './places.js';
|
|
|
|
type Guess = readonly [name: string, country: string, lat: number, lon: number];
|
|
const guesses = data.guesses as unknown as Readonly<Record<string, Guess>>;
|
|
|
|
/**
|
|
* A town for `timeZone`, the name the device reports (Intl's, so Asia/Calcutta and
|
|
* Asia/Kolkata both work). Null for a zone that names no place, such as UTC: then
|
|
* the player has to choose.
|
|
*/
|
|
export function guessTown(timeZone: string): Town | null {
|
|
const g = Object.hasOwn(guesses, timeZone) ? guesses[timeZone] : undefined;
|
|
if (!g) return null;
|
|
return { name: g[0], region: '', country: g[1], lat: g[2], lon: g[3], timeZone };
|
|
}
|