Compare commits

...

4 Commits

12 changed files with 483 additions and 5 deletions
+1
View File
@@ -8,6 +8,7 @@ One row per feature, with its analysis document (CLAUDE.md §5.1). Gaps live in
| Workspace, contracts, gates, PWA shell | 0 | Merged to `main` 2026-11-01 (`d11d242`); built, not deployed. Phase 0 gate still open | [phase0-workspace.md](features/phase0-workspace.md) | [feature-phase0-workspace.md](reviews/feature-phase0-workspace.md) | | Workspace, contracts, gates, PWA shell | 0 | Merged to `main` 2026-11-01 (`d11d242`); built, not deployed. Phase 0 gate still open | [phase0-workspace.md](features/phase0-workspace.md) | [feature-phase0-workspace.md](reviews/feature-phase0-workspace.md) |
| Roadmap and gameplay docs, read against the code | 0 | Merged 2026-11-01; Q1–Q7 answered by the author | — | [docs-roadmap-gameplay.md](reviews/docs-roadmap-gameplay.md) | | Roadmap and gameplay docs, read against the code | 0 | Merged 2026-11-01; Q1–Q7 answered by the author | — | [docs-roadmap-gameplay.md](reviews/docs-roadmap-gameplay.md) |
| The Letter slot: page at `#letter`, empty `docs/LETTER.md` | 0 | Merged to `main`; built, not deployed. Invisible until the author writes | [letter-slot.md](features/letter-slot.md) | [feature-letter-slot.md](reviews/feature-letter-slot.md) | | The Letter slot: page at `#letter`, empty `docs/LETTER.md` | 0 | Merged to `main`; built, not deployed. Invisible until the author writes | [letter-slot.md](features/letter-slot.md) | [feature-letter-slot.md](reviews/feature-letter-slot.md) |
| The in-game sunset: move the chair, half a minute of silence, then the real sunset's time | 1 | Merged to `main`; built, not deployed | [chair-sunset.md](features/chair-sunset.md) | [feature-chair-sunset.md](reviews/feature-chair-sunset.md) |
| A calm refresh: a waiting new version is offered in one line, never swapped in by itself | 0 | Merged to `main`; built, not deployed | [calm-refresh.md](features/calm-refresh.md) | [feature-calm-refresh.md](reviews/feature-calm-refresh.md) | | A calm refresh: a waiting new version is offered in one line, never swapped in by itself | 0 | Merged to `main`; built, not deployed | [calm-refresh.md](features/calm-refresh.md) | [feature-calm-refresh.md](reviews/feature-calm-refresh.md) |
| The CPU guard: full runs wait for, then refuse, a busy machine | 0 | Merged to `main` | — | [fix-cpu-guard.md](reviews/fix-cpu-guard.md) | | The CPU guard: full runs wait for, then refuse, a busy machine | 0 | Merged to `main` | — | [fix-cpu-guard.md](reviews/fix-cpu-guard.md) |
| Keep her safe: the browser's promise, save her to a file, bring her back | 0–1 | Merged to `main`; built, not deployed | [keep-her-safe.md](features/keep-her-safe.md) | [feature-keep-her-safe.md](reviews/feature-keep-her-safe.md) | | Keep her safe: the browser's promise, save her to a file, bring her back | 0–1 | Merged to `main`; built, not deployed | [keep-her-safe.md](features/keep-her-safe.md) | [feature-keep-her-safe.md](reviews/feature-keep-her-safe.md) |
+2 -1
View File
@@ -56,7 +56,8 @@ sentences). Nothing in Phase 1 is visible to the player yet.
| ~~G1.1~~ | ~~No module computes the sun (CLAUDE.md §7); polar and DST traps only predicted~~ | Closed 2026-11-01 on `feature/sun`. `engine/src/sun/sun.ts`: 26 published days in 6 cities within 2 min, polar day and night at Tromsø, 50 tests, 5 of 5 put-back bugs caught. Both traps measured (CLAUDE.md §8). | | ~~G1.1~~ | ~~No module computes the sun (CLAUDE.md §7); polar and DST traps only predicted~~ | Closed 2026-11-01 on `feature/sun`. `engine/src/sun/sun.ts`: 26 published days in 6 cities within 2 min, polar day and night at Tromsø, 50 tests, 5 of 5 put-back bugs caught. Both traps measured (CLAUDE.md §8). |
| ~~G1.2~~ | ~~The player cannot choose a city; no time-zone guess; no sunset time on screen~~ | Closed 2026-11-02 on `feature/sunset-place`. 7,342 public-domain towns searched on the device, a guess for every zone a browser reports, the town kept in IndexedDB, tonight's sunset in the garden. 299 unit, 10 e2e, offline choosing and changing a town; 6 of 6 put-back bugs caught. | | ~~G1.2~~ | ~~The player cannot choose a city; no time-zone guess; no sunset time on screen~~ | Closed 2026-11-02 on `feature/sunset-place`. 7,342 public-domain towns searched on the device, a guess for every zone a browser reports, the town kept in IndexedDB, tonight's sunset in the garden. 299 unit, 10 e2e, offline choosing and changing a town; 6 of 6 put-back bugs caught. |
| ~~G1.4~~ | ~~No rose~~ | Closed 2026-11-02 on `feature/rose-care`: care with a touch of skill (water by holding, shade, weeds, petals), growth from days of care, drift, moods, her numbers; the care log in IndexedDB, replayed by the engine. Tuning R2/R4/R5/R6 is the author's. 7 of 7 put-back bugs caught after two test holes were closed. | | ~~G1.4~~ | ~~No rose~~ | Closed 2026-11-02 on `feature/rose-care`: care with a touch of skill (water by holding, shade, weeds, petals), growth from days of care, drift, moods, her numbers; the care log in IndexedDB, replayed by the engine. Tuning R2/R4/R5/R6 is the author's. 7 of 7 put-back bugs caught after two test holes were closed. |
| G1.5 | The day's sentence and the folded petal; the in-game sunset with the chair | Open. The sentence needs the library (G0.18). | | G1.5 | The day's sentence and the folded petal | Open. Needs the library (G0.18). |
| ~~G1.6~~ | ~~The in-game sunset: move the chair, watch it again~~ | Closed 2026-11-02 on `feature/chair-sunset`: half a minute with nothing to press, then the real sunset's time; Escape and a tap leave; the offline suite watches one with the server gone. 4 of 4 put-back bugs caught. |
| G1.3 | Towns have no Czech names (*Vídeň*) | Open. Natural Earth has none; arrives with Czech copy. | | G1.3 | Towns have no Czech names (*Vídeň*) | Open. Natural Earth has none; arrives with Czech copy. |
## Design questions — answered ## Design questions — answered
+53
View File
@@ -0,0 +1,53 @@
# The in-game sunset — move the chair, watch it again
Status: built on `feature/chair-sunset`. ROADMAP Phase 1: *the in-game sunset — move the chair, watch
it again — as comfort and rehearsal; it tells the player when the real one is tonight.* CLAUDE.md §1,
§7 (*silence is a feature: sunset … has moments with no buttons at all*). Review:
[`feature-chair-sunset.md`](../reviews/feature-chair-sunset.md).
## 1. Why and what, in the player's terms
Under tonight's sunset line there is **Move the chair**. The garden turns into a quiet scene: the chair
on the hillside, the sky going from day to amber to coral to dusk, the sun sinking behind the western
horizon. **Half a minute, and nothing to press.** Then one line says when the real one is tonight, and
two quiet choices: *Watch it again*, *Back to the rose*.
It is a rehearsal, never a replacement: it counts for nothing, logs nothing, and its last words point
at the real sky.
## 2. Technical architecture
```mermaid
flowchart LR
shell["Shell.svelte<br/>Move the chair"] --> scene["ChairSunset.svelte<br/>dialog: sky + sun in CSS,<br/>garden-sunset and chair stand-ins"]
scene -->|"after 30 s"| line["SunsetLine<br/>tonight's real sunset"]
line --> engine["engine nextInvitation"]
```
| # | Decision | Why |
|:--|:--|:--|
| C1 | The sky and the sun are **drawn in code** (CSS gradients and one disc) behind the garden layer, which is transparent above its horizon. | STYLE.md S5: the sky is never painted, so the same layer serves the real-time sky later. |
| C2 | **No visible button for 30 s.** Escape, or a tap anywhere, comes back early; a screen-reader-only line says so. | Silence (CLAUDE.md §7) without a trap: a keyboard or screen-reader user is never stuck. |
| C3 | It is a modal dialog; focus goes into it and returns to *Move the chair*. | Accessibility is not a phase. |
| C4 | **Nothing is logged.** No event kind, no count. | Rehearsal, not achievement; the real sunset's event (`sunset`, CLAUDE.md §6.2) belongs to the real one. |
| C5 | With reduced motion, the scene shows dusk at once, still, for the same half minute. | Global `prefers-reduced-motion` rule in `tokens.css`. |
## 3. Risk analysis
| Risk | Answer |
|:--|:--|
| **Dependence**: the screen sunset replaces the real one. | Its last line is the real sunset's time; nothing rewards watching it. |
| **A trap**: a full-screen scene with no buttons. | C2, C3; tested by keyboard. |
| **Motion** for people sensitive to it. | C5. |
| Privacy, reachability | None: nothing is stored or sent. |
## 4. Verification matrix
| Case | Kind | Where |
|:--|:--|:--|
| Move the chair opens a labelled dialog with no button in it; after 30 s, the real sunset's line, *Watch it again*, *Back to the rose* | unit | `ui/test/chair-sunset.test.ts` |
| Escape and a tap come back early; focus returns to *Move the chair* | unit | same |
| Watch it again starts it over | unit | same |
| With no town and no guess, the line asks for a town | unit | same |
| Built app: watch it with the clock driven; axe during and after | e2e | `e2e/shell.spec.ts` |
| Offline: watch an in-game sunset with the server gone (CLAUDE.md §3) | offline | `e2e/offline.spec.ts` |
+40
View File
@@ -0,0 +1,40 @@
# Review — `feature/chair-sunset`
Adversarial self-review (CLAUDE.md §5.3). Analysis: [`features/chair-sunset.md`](../features/chair-sunset.md).
Reviewed 2026-11-02 on Node 22.11.0, Windows 10. There is no PR: the only remote is Gitea.
## Gates
Counts are on the merge; HANDOVER repeats them. New: ui +7, e2e +1 (watch, again, Escape, focus,
axe during and after), and the offline suite now watches an in-game sunset with the server gone,
which CLAUDE.md §3 has always promised.
**The app changed** (CLAUDE.md §5.4): *Move the chair* under tonight's sunset line. Rebuilt by the
e2e and offline runs; **not deployed** (G0.13). Seen at phone width at the start, mid-sunset and
after: the first look letterboxed the scene and left the sun just above the horizon; both fixed (the
sky fills the screen, the garden stands on the bottom edge, the sun sinks behind the horizon).
## Bug drills
| Put back | Result |
|:--|:--|
| Buttons shown during the sunset | CAUGHT: 3 |
| Escape does nothing | CAUGHT |
| The half minute never ends | CAUGHT: 4 |
| Focus not given back to *Move the chair* | CAUGHT |
## Findings
| # | Area | Finding | Resolution |
|:--|:--|:--|:--|
| 1 | Accessibility | A full-screen scene with no buttons can trap a keyboard or screen-reader user. | Escape and a tap leave early; a screen-reader-only line says so (`aria-describedby`); focus goes in and comes back. Tested; axe passes during and after. Not tried with a real screen reader. |
| 2 | Soul | A screen sunset could stand in for the real one. | Its last words are the real sunset's time; it logs and counts nothing. |
| 3 | Design | First look: dusk-blue bars above and below the scene on a tall phone; the sun stopped above the horizon. | Fixed after the screenshots. |
| 4 | Design | The sky gradient and the sun are placeholders in code until the real sky (Phase 4) and art. | Accepted: the layer split (STYLE.md S5) is what the real sky needs. |
| 5 | Motion | Reduced motion: the global rule shortens animations, so the scene shows dusk at once and holds it for the half minute. | Accepted (C5); not seen with the setting on. |
| 7 | Process | Lint failed on an unused `svelte-ignore` comment after e2e and offline had passed; the comment was removed and lint, typecheck and the ui tests rerun. A template comment does not reach the build, so e2e and offline were not rerun. | Fixed. |
| 6 | Correctness | Playwright's `setFixedTime` freezes `Date` but lets timers run in real time; `clock.install` drives them. | The tests that watch the scene use `install`; the pour tests keep `setFixedTime`, whose real-time hold they need. |
## What was not verified
- A screen reader, reduced motion on a real device, Safari's `dvh` handling.
+1 -1
View File
@@ -39,7 +39,7 @@ that is not a whole number in range is refused, never quietly the default.
| 2 | `ROSEA_CPU_MAX=100` is a way round the rule. | Documented as for dedicated machines only, in CLAUDE.md §5.7 and the lesson. An override nobody can use would push people to edit the script instead. | | 2 | `ROSEA_CPU_MAX=100` is a way round the rule. | Documented as for dedicated machines only, in CLAUDE.md §5.7 and the lesson. An override nobody can use would push people to edit the script instead. |
| 3 | The guard adds 2 s to every full run on a quiet machine. | Accepted. | | 3 | The guard adds 2 s to every full run on a quiet machine. | Accepted. |
| 4 | Filtered runs (`pnpm --filter X test`) and drills are not guarded. | By design: they are not full runs. | | 4 | Filtered runs (`pnpm --filter X test`) and drills are not guarded. | By design: they are not full runs. |
| 5 | Its own 2 s sample could read its own start-up as load. | It samples after Node has started. Not measured on a quiet machine: this one was busy all session. Beside Windows' counter it read 2–11 points lower, never higher. | | 5 | Its own 2 s sample could read its own start-up as load. | It samples after Node has started. Later, on a quiet machine, it read 2.4–4.1 % beside Windows' 1.5–3.3 %; busy, 2–11 points lower. Close enough for an 80 % line. |
## Not verified ## Not verified
+8 -2
View File
@@ -12,8 +12,8 @@ Rewritten at the end of each session (CLAUDE.md §5.1).
Gitea hashes match. Analysis: [`.agents/features/phase0-workspace.md`](.agents/features/phase0-workspace.md). Gitea hashes match. Analysis: [`.agents/features/phase0-workspace.md`](.agents/features/phase0-workspace.md).
Review, with counts and the mutation results: Review, with counts and the mutation results:
[`.agents/reviews/feature-phase0-workspace.md`](.agents/reviews/feature-phase0-workspace.md). [`.agents/reviews/feature-phase0-workspace.md`](.agents/reviews/feature-phase0-workspace.md).
- **Gates:** all pass on this machine. Unit tests: 389 (cpu-guard 13, identity 5, schema 16, - **Gates:** all pass on this machine. Unit tests: 396 (cpu-guard 13, identity 5, schema 16,
content 71, storage 51, art-prep 56, engine 136, ui 41). E2E: 14. Offline: 1. `lint:copy`: 19 files, 0 problems. content 71, storage 51, art-prep 56, engine 136, ui 48). E2E: 15. Offline: 1. `lint:copy`: 20 files, 0 problems.
`validate:library`: 13 of 13 fixtures rejected. `validate:library`: 13 of 13 fixtures rejected.
- **Built, not deployed:** there is no host yet. - **Built, not deployed:** there is no host yet.
- **Roadmap and gameplay docs:** `docs/ROADMAP.md` and `docs/GAMEPLAY.md` are on - **Roadmap and gameplay docs:** `docs/ROADMAP.md` and `docs/GAMEPLAY.md` are on
@@ -71,6 +71,12 @@ Rewritten at the end of each session (CLAUDE.md §5.1).
*Refresh*. Nothing reloads by itself. With this, fixes can reach a phone once the app is hosted. *Refresh*. Nothing reloads by itself. With this, fixes can reach a phone once the app is hosted.
Review: [`.agents/reviews/feature-calm-refresh.md`](.agents/reviews/feature-calm-refresh.md). Review: [`.agents/reviews/feature-calm-refresh.md`](.agents/reviews/feature-calm-refresh.md).
- **The in-game sunset (Phase 1):** merged to `main`. *Move the chair* under tonight's sunset line
opens a quiet scene: the sky drawn in code from day to dusk, the sun setting behind the garden,
half a minute with nothing to press; then the real sunset's time, *Watch it again*, *Back to the
rose*. Escape or a tap leaves early. Review:
[`.agents/reviews/feature-chair-sunset.md`](.agents/reviews/feature-chair-sunset.md).
**Phase 0 is not finished.** The roadmap's Phase 0 is more than the workspace. Its **Phase 0 is not finished.** The roadmap's Phase 0 is more than the workspace. Its
gate needs 60 verified sentences (G0.18) and one illustration through the art gate needs 60 verified sentences (G0.18) and one illustration through the art
pipeline (G0.24). The pipeline and the board are built; the first real picture is not made yet. Also open: a GitHub remote (G0.13). The Letter slot is built (G0.25). pipeline (G0.24). The pipeline and the board are built; the first real picture is not made yet. Also open: a GitHub remote (G0.13). The Letter slot is built (G0.25).
+8 -1
View File
@@ -78,7 +78,8 @@ test('the shell opens from the service worker with the server gone', async ({ br
// coming back days later with no signal. // coming back days later with no signal.
await page.close(); await page.close();
const again = await context.newPage(); const again = await context.newPage();
await again.clock.setFixedTime(Date.parse('2026-03-29T12:00:00+02:00')); // An installed clock, so the in-game sunset's half minute can be run below.
await again.clock.install({ time: Date.parse('2026-03-29T12:00:00+02:00') });
await again.goto(server.url); await again.goto(server.url);
await expect(again.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME); await expect(again.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
await expect(again.locator('.sun p').first()).toHaveText(/in Plzeň\.$/); await expect(again.locator('.sun p').first()).toHaveText(/in Plzeň\.$/);
@@ -86,6 +87,12 @@ test('the shell opens from the service worker with the server gone', async ({ br
await again.getByRole('button', { name: en.rose.numbers }).click(); await again.getByRole('button', { name: en.rose.numbers }).click();
await expect(again.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`); await expect(again.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`);
// Watching an in-game sunset with no network (CLAUDE.md §3, the offline suite).
await again.getByRole('button', { name: en.chair.move }).click();
await again.clock.runFor(30_000);
await expect(again.getByRole('dialog').getByText(/in Plzeň\.$/)).toBeVisible();
await again.keyboard.press('Escape');
// 3. A deep link inside the scope falls back to the shell, not an error page. // 3. A deep link inside the scope falls back to the shell, not an error page.
await again.goto(`${server.url}somewhere/deeper`); await again.goto(`${server.url}somewhere/deeper`);
await expect(again.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME); await expect(again.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
+28
View File
@@ -279,3 +279,31 @@ test.describe('keep her safe, in Prague at 08:00 on 1 March 2026', () => {
} }
}); });
}); });
// --- The in-game sunset (.agents/features/chair-sunset.md) ---------------------
test.describe('the in-game sunset, in Prague at noon on 29 March 2026', () => {
test.use({ timezoneId: 'Europe/Prague', locale: 'en-US' });
test('move the chair: half a minute with nothing to press, then the real sunset\'s time; again; back', async ({ page }) => {
// An installed clock, so the scene's half minute can be run in a moment.
await page.clock.install({ time: Date.parse('2026-03-29T12:00:00+02:00') });
await open(page);
await page.getByRole('button', { name: /^Not now/ }).click();
await page.getByRole('button', { name: en.chair.move }).click();
const scene = page.getByRole('dialog', { name: en.chair.scene });
await expect(scene).toBeVisible();
await expect(scene.getByRole('button')).toHaveCount(0);
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
await page.clock.runFor(30_000);
await expect(scene.getByText(/^Tonight the sun sets at .* in Prague\.$/)).toBeVisible();
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
await scene.getByRole('button', { name: en.chair.again }).click();
await expect(scene.getByRole('button')).toHaveCount(0);
await page.keyboard.press('Escape');
await expect(scene).toHaveCount(0);
await expect(page.getByRole('button', { name: en.chair.move })).toBeFocused();
});
});
+14
View File
@@ -6,6 +6,7 @@
import { parseLetter } from './letter/parse.js'; import { parseLetter } from './letter/parse.js';
import Rose from './rose/Rose.svelte'; import Rose from './rose/Rose.svelte';
import type { RoseWiring } from './rose/types.js'; import type { RoseWiring } from './rose/types.js';
import ChairSunset from './sunset/ChairSunset.svelte';
import SunsetLine from './sunset/SunsetLine.svelte'; import SunsetLine from './sunset/SunsetLine.svelte';
import SunsetPlace from './sunset/SunsetPlace.svelte'; import SunsetPlace from './sunset/SunsetPlace.svelte';
import type { SunsetChoice, SunsetWiring } from './sunset/types.js'; import type { SunsetChoice, SunsetWiring } from './sunset/types.js';
@@ -37,6 +38,15 @@
let kept = $state(true); let kept = $state(true);
let now = $state(0); let now = $state(0);
let sunLine = $state<HTMLElement>(); let sunLine = $state<HTMLElement>();
/** The in-game sunset is showing (chair-sunset.md). */
let watching = $state(false);
let chairButton = $state<HTMLButtonElement>();
async function stopWatching(): Promise<void> {
watching = false;
await tick();
chairButton?.focus();
}
const place = $derived(choice?.kind === 'town' ? choice.town : (sunset?.guess ?? null)); const place = $derived(choice?.kind === 'town' ? choice.town : (sunset?.guess ?? null));
// One zone for the sunset and the rose's days: the chosen town's, else the device's (rose.md R8). // One zone for the sunset and the rose's days: the chosen town's, else the device's (rose.md R8).
@@ -141,7 +151,11 @@
<p class="hint">{en.sunset.notKept}</p> <p class="hint">{en.sunset.notKept}</p>
{/if} {/if}
<button type="button" class="quiet" onclick={() => (changing = true)}>{place ? en.sunset.change : en.sunset.choose}</button> <button type="button" class="quiet" onclick={() => (changing = true)}>{place ? en.sunset.change : en.sunset.choose}</button>
<button type="button" class="quiet" bind:this={chairButton} onclick={() => (watching = true)}>{en.chair.move}</button>
</div> </div>
{#if watching}
<ChairSunset {place} guessed={choice?.kind === 'device-zone'} now={sunset.now} onclose={stopWatching} />
{/if}
{/if} {/if}
{#if blocks.length > 0} {#if blocks.length > 0}
<a href={LETTER_HASH}>{en.letter.title}</a> <a href={LETTER_HASH}>{en.letter.title}</a>
+9
View File
@@ -88,6 +88,15 @@ export const en = {
/** When the device refuses to keep anything (a private window). Calm, and true. */ /** When the device refuses to keep anything (a private window). Calm, and true. */
notKept: 'This device could not keep your choice, so the garden will ask again next time.' notKept: 'This device could not keep your choice, so the garden will ask again next time.'
}, },
chair: {
/** ROADMAP Phase 1: "move the chair, watch it again". */
move: 'Move the chair',
scene: 'A sunset in the garden',
/** Read by screen readers only: the scene has no buttons on purpose (chair-sunset.md C2). */
leave: 'Press Escape or tap to come back.',
again: 'Watch it again',
back: 'Back to the rose'
},
update: { update: {
/** One quiet line when a new version waits; nothing reloads by itself (calm-refresh.md U2). */ /** One quiet line when a new version waits; nothing reloads by itself (calm-refresh.md U2). */
ready: 'A new version of the garden is ready.', ready: 'A new version of the garden is ready.',
+219
View File
@@ -0,0 +1,219 @@
<script lang="ts">
import type { NamedPlace } from '@rosea/engine';
import { en } from '../copy/en.js';
import SunsetLine from './SunsetLine.svelte';
// The art board's stand-ins until real art is accepted. The garden layer is
// transparent above its horizon (40 %): the sky is drawn here, in code (STYLE.md S5).
import garden from '../../../../art/placeholders/garden-sunset.svg?url';
import chair from '../../../../art/placeholders/garden-chair.svg?url';
/**
* The in-game sunset (chair-sunset.md): half a minute with nothing to press, then
* the real sunset's time. A rehearsal: it decides nothing and logs nothing.
*/
let {
place,
guessed = false,
now,
durationMs = SUNSET_MS,
onclose
}: { place: NamedPlace | null; guessed?: boolean; now: () => number; durationMs?: number; onclose: () => void } = $props();
const uid = $props.id();
let phase = $state<'watching' | 'after'>('watching');
/** Bumped by Watch it again, so the animation starts over. */
let showing = $state(0);
let dialog = $state<HTMLElement>();
let afterAt = $state(0);
$effect(() => {
// Read what the effect depends on first: it reruns on Watch it again.
const run = showing;
void run;
phase = 'watching';
dialog?.focus();
const timer = setTimeout(() => {
afterAt = now();
phase = 'after';
}, durationMs);
return () => clearTimeout(timer);
});
function leave(): void {
onclose();
}
</script>
<script lang="ts" module>
/** Half a minute: long enough to breathe, short enough to come back to the rose. */
export const SUNSET_MS = 30_000;
</script>
<div
class="scene"
role="dialog"
aria-modal="true"
aria-labelledby="{uid}-title"
aria-describedby="{uid}-leave"
tabindex="-1"
bind:this={dialog}
style="--duration: {durationMs}ms"
onkeydown={(e) => {
if (e.key === 'Escape') leave();
}}
onclick={() => {
if (phase === 'watching') leave();
}}
>
<h2 id="{uid}-title" class="sr-only">{en.chair.scene}</h2>
<p id="{uid}-leave" class="sr-only">{en.chair.leave}</p>
{#key showing}
<!-- The sky fills the whole screen; the garden stands on the bottom edge. -->
<div class="sky" class:after={phase === 'after'}></div>
<div class="frame" class:after={phase === 'after'}>
<div class="sun"></div>
<img class="garden" src={garden} alt="" />
<img class="chair" src={chair} alt="" />
</div>
{/key}
{#if phase === 'after'}
<div class="after-words">
{#if place}
<SunsetLine {place} {guessed} now={afterAt} />
{:else}
<p>{en.sunset.noTown}</p>
{/if}
<div class="choices">
<button type="button" onclick={(e) => { e.stopPropagation(); showing += 1; }}>{en.chair.again}</button>
<button type="button" class="quiet" onclick={(e) => { e.stopPropagation(); leave(); }}>{en.chair.back}</button>
</div>
</div>
{/if}
</div>
<style>
.scene {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: end center;
overflow: hidden;
background: #2e3561;
color: #fbf6f1;
outline: none;
}
.frame {
position: relative;
height: min(100dvh, 150vw);
aspect-ratio: 2 / 3;
overflow: hidden;
}
/* Day to amber to coral to dusk, drawn in code (STYLE.md §2 palette). */
.sky {
position: absolute;
inset: 0;
background: linear-gradient(to bottom, #a9cbe0 0%, #f4d58d 30%, #f2b860 45%, #e9846a 62%, #7a4f6e 80%, #2e3561 100%);
background-size: 100% 300%;
background-position: 0 0;
animation: dusk var(--duration) linear forwards;
}
.sun {
position: absolute;
left: 22%;
top: 12%;
width: 13%;
aspect-ratio: 1;
border-radius: 50%;
background: radial-gradient(circle, #fff4cf 0%, #f4d58d 55%, #f2b860 100%);
box-shadow: 0 0 2.5rem #f2b86099;
animation: set var(--duration) ease-in forwards;
}
/* The garden layer: its sky is transparent, so the sun sets behind its horizon. */
.garden {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
.chair {
position: absolute;
left: 10%;
top: 58%;
width: 24%;
}
.sky.after,
.after .sun {
animation-play-state: paused;
}
@keyframes dusk {
to {
background-position: 0 100%;
}
}
@keyframes set {
to {
/* From 12 % down past the horizon at 40 %, where the garden hides it. */
transform: translateY(380%);
opacity: 0.85;
}
}
.after-words {
position: absolute;
inset: auto 0 0 0;
display: grid;
justify-items: center;
gap: var(--space-2);
padding: var(--space-4) var(--space-3) calc(var(--space-4) + env(safe-area-inset-bottom));
background: linear-gradient(to top, #2e3561ee 60%, transparent);
text-align: center;
/* The words below read on dusk, whatever the page's own theme. */
--ink: #fbf6f1;
--ink-soft: #e8dccf;
}
.choices {
display: flex;
gap: var(--space-3);
}
button {
font: inherit;
padding: var(--space-2) var(--space-3);
border-radius: 999px;
border: 1px solid #f4d58d;
background: transparent;
color: #fbf6f1;
cursor: pointer;
}
.quiet {
border: none;
text-decoration: underline;
}
button:focus-visible {
outline: 2px solid #f4d58d;
outline-offset: 2px;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
</style>
+100
View File
@@ -0,0 +1,100 @@
import type { NamedPlace } from '@rosea/engine';
import { cleanup, fireEvent, render, screen, within } from '@testing-library/svelte';
import { tick } from 'svelte';
import { afterEach, describe, expect, it, vi } from 'vitest';
import Shell from '../src/Shell.svelte';
import { en } from '../src/copy/en.js';
import { SUNSET_MS } from '../src/sunset/ChairSunset.svelte';
import type { SunsetWiring } from '../src/sunset/types.js';
const brno: NamedPlace = { name: 'Brno', region: '', country: 'Czechia', lat: 49.2, lon: 16.61, timeZone: 'Europe/Prague' };
const NOON = Date.parse('2026-03-29T12:00:00+02:00');
const wiring = (over: Partial<SunsetWiring> = {}): SunsetWiring => ({
guess: brno,
search: async () => [],
load: async () => ({ kind: 'town', town: brno }),
save: async () => undefined,
now: () => NOON,
...over
});
/** Renders the garden with a town set and opens the in-game sunset; the scene's own timer is faked. */
async function openScene(over: Partial<SunsetWiring> = {}): Promise<HTMLElement> {
render(Shell, { sunset: wiring(over) });
const move = await screen.findByRole('button', { name: en.chair.move });
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
await fireEvent.click(move);
await tick();
return screen.getByRole('dialog', { name: en.chair.scene });
}
afterEach(() => {
vi.useRealTimers();
cleanup();
});
describe('the in-game sunset (chair-sunset.md)', () => {
it('Move the chair opens a quiet scene: labelled, focused, and with nothing to press', async () => {
const scene = await openScene();
expect(document.activeElement).toBe(scene);
expect(within(scene).queryAllByRole('button')).toEqual([]);
expect(scene.getAttribute('aria-describedby')).toBeTruthy();
expect(document.getElementById(scene.getAttribute('aria-describedby')!)?.textContent).toBe(en.chair.leave);
});
it('after half a minute, it says when the real one is, and offers to watch again or go back', async () => {
const scene = await openScene();
vi.advanceTimersByTime(SUNSET_MS - 1);
await tick();
expect(within(scene).queryAllByRole('button')).toEqual([]);
vi.advanceTimersByTime(1);
await tick();
expect(within(scene).getByText(/^Tonight the sun sets at .* in Brno\.$/)).toBeTruthy();
expect(within(scene).getByRole('button', { name: en.chair.again })).toBeTruthy();
expect(within(scene).getByRole('button', { name: en.chair.back })).toBeTruthy();
});
it('Watch it again starts it over, with nothing to press again', async () => {
const scene = await openScene();
vi.advanceTimersByTime(SUNSET_MS);
await tick();
await fireEvent.click(within(scene).getByRole('button', { name: en.chair.again }));
await tick();
expect(within(scene).queryAllByRole('button')).toEqual([]);
vi.advanceTimersByTime(SUNSET_MS);
await tick();
expect(within(scene).getByRole('button', { name: en.chair.again })).toBeTruthy();
});
it('Escape comes back early, and focus returns to Move the chair', async () => {
const scene = await openScene();
await fireEvent.keyDown(scene, { key: 'Escape' });
await tick();
expect(screen.queryByRole('dialog')).toBeNull();
expect(document.activeElement).toBe(screen.getByRole('button', { name: en.chair.move }));
});
it('a tap anywhere comes back early too', async () => {
const scene = await openScene();
await fireEvent.click(scene);
await tick();
expect(screen.queryByRole('dialog')).toBeNull();
});
it('Back to the rose closes it after the sunset', async () => {
const scene = await openScene();
vi.advanceTimersByTime(SUNSET_MS);
await tick();
await fireEvent.click(within(scene).getByRole('button', { name: en.chair.back }));
await tick();
expect(screen.queryByRole('dialog')).toBeNull();
});
it('with no town and no guess, the words after it ask for a town', async () => {
const scene = await openScene({ guess: null, load: async () => ({ kind: 'device-zone' }) });
vi.advanceTimersByTime(SUNSET_MS);
await tick();
expect(within(scene).getByText(en.sunset.noTown)).toBeTruthy();
});
});