123 lines
8.8 KiB
Markdown
123 lines
8.8 KiB
Markdown
# Where the sunset is — choosing a town, the guess, tonight's sunset
|
|
|
|
Status: built on `feature/sunset-place`. ROADMAP Phase 1, *the sun*: "the player is asked *Where do
|
|
you want your sunset?* (a city, skippable); if skipped, it is guessed from the device time zone.
|
|
**Never GPS.**" Gap G1.2. Review: [`feature-sunset-place.md`](../reviews/feature-sunset-place.md).
|
|
Builds on [`sun.md`](sun.md).
|
|
|
|
---
|
|
|
|
## 1. Why and what, in the player's terms
|
|
|
|
The first time the player opens the garden, under the name, it asks one quiet question:
|
|
**Where do you want your sunset?** A box to type a town, and below it a way to say *not now*.
|
|
|
|
- **Typing a town** shows matching towns at once, with no network: *Brno*, *Praha*, *plzen* all
|
|
work. Choosing one says, in the garden, **"Tonight the sun sets at 7:29 PM in Brno."**
|
|
- **Not now** uses a guess from the device's clock: in Prague's time zone, Prague. The garden says
|
|
so: the line ends with *a guess from this device's time zone*. A player who travels gets the guess
|
|
for wherever their phone's clock is.
|
|
- **Change town** is always there, under the line. Choosing again replaces the town; nothing else
|
|
changes.
|
|
- **After the sunset** the line speaks of tomorrow's. **In the far north** it speaks of the lowest
|
|
light, or of the noon twilight (`sun.md` D4).
|
|
- **The town stays on this device.** It is the only place Rosea knows about the player, and it never
|
|
leaves. If the device will not keep it (a private window that blocks storage), the garden still
|
|
shows the sunset and says, calmly, that it will ask again next time.
|
|
|
|
What it never does: ask for GPS, look up an address, guess from the network, or say anything about a
|
|
missed sunset.
|
|
|
|
## 2. Technical architecture
|
|
|
|
```mermaid
|
|
flowchart LR
|
|
subgraph app["apps/rosea"]
|
|
main["App.svelte<br/>device zone, now, wiring"]
|
|
end
|
|
subgraph ui["packages/ui"]
|
|
shell["Shell.svelte"] --> ask["SunsetPlace.svelte<br/>the question and the search"]
|
|
shell --> line["SunsetLine.svelte<br/>tonight's sunset"]
|
|
end
|
|
subgraph content["packages/content"]
|
|
guess["places/guess.ts<br/>zone-guesses.json (25 KB)"]
|
|
towns["places/places.ts<br/>places.json (496 KB, loaded on demand)"]
|
|
end
|
|
subgraph storage["packages/storage (new)"]
|
|
profile["profile store<br/>sunset place"]
|
|
end
|
|
subgraph engine["packages/engine"]
|
|
next["sun.nextInvitation(now, place)"]
|
|
day["time.addDays / localDay"]
|
|
end
|
|
main --> shell
|
|
main -->|"guessTown(zone)"| guess
|
|
main -->|"import() on first search"| towns
|
|
main -->|"load / save"| profile
|
|
line --> next --> day
|
|
build["scripts/build-places.ts<br/>run by hand"] -.-> guess & towns
|
|
```
|
|
|
|
- **`@rosea/content/places`** — `searchTowns(query)`: accent- and case-blind, by English name,
|
|
local name (*Praha*) and Latin-script language names; best match first, then the larger town;
|
|
*"Sydney, Canada"* narrows by country or region. Imported dynamically, so the garden does not
|
|
carry 7,342 towns.
|
|
- **`@rosea/content/guess`** — `guessTown(zone)`: the largest town in that zone, or the zone's own
|
|
location from the time zone database. Keyed by the names browsers report (`Asia/Calcutta`) as well
|
|
as the database's (`Asia/Kolkata`). `UTC` and `Etc/*` guess nothing.
|
|
- **`@rosea/storage`** — Dexie over the IndexedDB database `rosea`. One store so far, `profile`,
|
|
holding `sunsetPlace`: either `{ kind: 'town', town }` or `{ kind: 'device-zone' }`. A record of
|
|
the wrong shape reads as *no choice yet*, with a warning in the console.
|
|
- **`@rosea/engine`** — `nextInvitation(now, place)`: the first invitation at or after now, checking
|
|
yesterday, today and tomorrow (Reykjavík, 00:02 in June). `addDays` for calendar steps.
|
|
- **`@rosea/ui`** — renders. It receives the device zone, the clock, the guess, a search function
|
|
and load/save as props; it imports neither content nor storage (CLAUDE.md §2 dependency
|
|
direction).
|
|
|
|
### Decisions
|
|
|
|
| # | Decision | Why |
|
|
|:--|:--|:--|
|
|
| P1 | **Natural Earth's populated places** (public domain), 7,342 towns. Downloaded by hand with the author's approval; only the derived JSON is committed. | The only public-domain town list with time zones. GeoNames is better but CC BY, which would need an attribution line in the product. |
|
|
| P2 | **Natural Earth's time zones are cross-checked, not trusted.** A town keeps its zone only if its clock is identical all through 2026 to one of its country's zones in the IANA database and fits its longitude (within 3.5 h, across the date line). Otherwise the five nearest trusted towns in the same country vote; with none, the country's nearest zone location. 1,205 towns were corrected. | Measured: Prague was *America/Chicago*, Cardiff *Australia/Sydney*, Sydney had none. A wrong zone shows the right sunset at the wrong clock time. |
|
|
| P3 | The guess is the **largest town in the device's zone**. | Recognisable ("Prague"), and the zone is all the device tells. |
|
|
| P4 | *Not now* stores `device-zone`, not a town. | The guess then follows the phone's clock when the player travels. |
|
|
| P5 | The town list loads **on first search**, as its own precached chunk. | 208 KB compressed is too much to parse on every open of a quiet garden. Offline it is already cached. |
|
|
| P6 | The time is shown in the **town's** zone, in the device's locale format. | It is the clock the player will see out there. |
|
|
| P7 | Storage failing is **not an error page**: the choice lives for the session and the garden says it will ask again. | CLAUDE.md §1: network and device features degrade to a calm state with an explanation. |
|
|
| P8 | `navigator.storage.persist()` is **not** called yet. | Firefox shows a prompt; asking for it on choosing a town would be strange. It belongs to G0.11 (eviction), with export-my-rose. |
|
|
|
|
## 3. Risk analysis
|
|
|
|
| Risk | Answer |
|
|
|:--|:--|
|
|
| **Location** — the chosen town is where the player lives, near enough. | It is stored only in this device's IndexedDB. Nothing in this feature makes a request: the e2e test asserts no request leaves the origin while searching and choosing. Never GPS, never IP. |
|
|
| **A wrong clock** sends someone out an hour early or late. | P2, and a test that every town's clock fits its longitude; the known bad zones are pinned by name. Residual: a town Natural Earth filed under a *same-country, same-looking* wrong zone (e.g. Dunhuang, Gansu, under Xinjiang time by its neighbours' vote) is not caught. Stated in the review. |
|
|
| **Feeling worse** — a question on the first screen can feel like a demand. | It is skippable in one tap, the skip still gives a sunset, and nothing ever counts or mentions a missed sunset. |
|
|
| **Feeling judged for where one lives** — a small town not in the list. | The empty search says *"A larger one nearby will do."*, never *not found* as an error. |
|
|
| **Reachability** | None. The town is never shared. |
|
|
|
|
## 4. Gap analysis and the designed solution
|
|
|
|
| Gap | Solution | State |
|
|
|:--|:--|:--|
|
|
| G1.2: no way to choose a town, no guess, no sunset on screen | This feature | Built |
|
|
| G0.15: `packages/storage` deferred until its first feature | `@rosea/storage` with the `profile` store | Built |
|
|
| G0.11: eviction — `persist()`, export-my-rose | Not here (P8) | Open |
|
|
| Czech names for towns (*Vídeň*) | Natural Earth has no Czech column; local names cover *Praha*, *Wien* | Open, with Czech copy |
|
|
| Planetary twins of the sunset (the in-game sunset, the chair) | Phase 1, later | Open |
|
|
|
|
## 5. Verification matrix
|
|
|
|
| Case | Kind | Where |
|
|
|:--|:--|:--|
|
|
| 7,342 towns, every zone valid, every clock fits its longitude; Prague, Cardiff, Sydney, Anchorage, Kryvyi Rih, Apia, Pristina keep the right zone | unit | `content/test/places.test.ts` |
|
|
| Search by English, local and accent-free names; larger first; comma narrows; empty and unknown are `[]` | unit | same |
|
|
| Guess for 7 zones including browser names; UTC guesses nothing; every zone Intl knows is covered | unit | same |
|
|
| `nextInvitation`: today before sunset, tomorrow after; Reykjavík after midnight; never past, ≤ 48 h, nothing earlier in between | unit, property | `engine/test/sun.test.ts` |
|
|
| `addDays` across DST, years, leap days; inverse property | unit, property | `engine/test/localDay.test.ts` |
|
|
| Storage: nothing saved reads `null`; town and device-zone round-trip; a malformed record reads `null` with a warning; a database that cannot open rejects | unit (fake-indexeddb) | `storage/test/profile.test.ts` |
|
|
| UI: asks when nothing is saved; search lists towns; choosing shows the line; *not now* shows the guess and says so; tomorrow after sunset; polar wording; storage failure says it will ask again; change and keep | unit (testing-library) | `ui/test/sunset.test.ts` |
|
|
| Built app: choose Brno, see Brno's sunset at the time the engine computes, reload and it is still Brno; nothing requested from another origin; no axe violations | e2e | `e2e/shell.spec.ts` |
|
|
| Offline: choose a town, close the server, reload: the town and the line survive | offline | `e2e/offline.spec.ts` |
|