[ui] ChairSunset: Move the chair, half a minute of sunset with nothing to press, then the real one's time

This commit is contained in:
2026-11-02 07:35:30 +01:00
parent a99dfe535d
commit 7a6cf4c6d1
4 changed files with 342 additions and 0 deletions
+14
View File
@@ -6,6 +6,7 @@
import { parseLetter } from './letter/parse.js';
import Rose from './rose/Rose.svelte';
import type { RoseWiring } from './rose/types.js';
import ChairSunset from './sunset/ChairSunset.svelte';
import SunsetLine from './sunset/SunsetLine.svelte';
import SunsetPlace from './sunset/SunsetPlace.svelte';
import type { SunsetChoice, SunsetWiring } from './sunset/types.js';
@@ -37,6 +38,15 @@
let kept = $state(true);
let now = $state(0);
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));
// 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>
{/if}
<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>
{#if watching}
<ChairSunset {place} guessed={choice?.kind === 'device-zone'} now={sunset.now} onclose={stopWatching} />
{/if}
{/if}
{#if blocks.length > 0}
<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. */
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: {
/** 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.',
+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>