[ui] PlanetGarden: Her round planet, the player's gardener, the ring of care, and care by gesture

This commit is contained in:
2026-11-17 19:07:57 +01:00
parent 9eef8a3bf7
commit 5576af4fac
18 changed files with 1268 additions and 79 deletions
+60 -3
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { PRODUCT_NAME } from '@rosea/schema';
import { PRODUCT_NAME, type Gardener } from '@rosea/schema';
import { tick } from 'svelte';
import { en } from './copy/en.js';
import Letter from './letter/Letter.svelte';
@@ -9,6 +9,8 @@
import ChairSunset from './sunset/ChairSunset.svelte';
import SunsetLine from './sunset/SunsetLine.svelte';
import SunsetPlace from './sunset/SunsetPlace.svelte';
import GardenerChoice from './scene/GardenerChoice.svelte';
import { FIRST_LOOK } from './scene/look.js';
import type { SunsetChoice, SunsetWiring } from './sunset/types.js';
let {
@@ -30,6 +32,43 @@
onrefresh?: () => void;
} = $props();
// --- The gardener (planet-garden.md G6) -----------------------------------
/** Without gardener wiring the garden asks nothing and shows the first look. */
let gardenerStatus = $state<'loading' | 'asking' | 'set'>('set');
let look = $state.raw<Gardener | null>(null);
let choosingGardener = $state(false);
let gardenerKept = $state(true);
$effect(() => {
const g = rose?.gardener;
if (!g) return;
gardenerStatus = 'loading';
g.load().then(
(saved) => {
look = saved;
gardenerStatus = saved ? 'set' : 'asking';
},
(error: unknown) => {
console.error('gardener: the device could not read the saved gardener; asking again', error);
gardenerKept = false;
gardenerStatus = 'asking';
}
);
});
function chooseGardener(next: Gardener): void {
look = next;
gardenerStatus = 'set';
choosingGardener = false;
rose?.gardener?.save(next).then(
() => (gardenerKept = true),
(error: unknown) => {
console.error('gardener: the device could not keep the gardener', error);
gardenerKept = false;
}
);
}
// --- The sunset (sunset-place.md) ---------------------------------------
let status = $state<'loading' | 'asking' | 'set'>('loading');
let choice = $state<SunsetChoice | null>(null);
@@ -144,8 +183,25 @@
<main class="shell">
<h1 bind:this={heading} tabindex="-1">{PRODUCT_NAME}</h1>
<p>{en.shell.preparing}</p>
{#if rose}
<Rose wiring={rose} timeZone={roseZone} {place} />
{#if rose && (gardenerStatus === 'asking' || choosingGardener)}
<!-- The first open, or Change gardener: Who tends her? (planet-garden.md §1) -->
<GardenerChoice
current={choosingGardener ? look : null}
onchoose={chooseGardener}
{...choosingGardener ? { oncancel: () => (choosingGardener = false) } : {}}
/>
{:else}
{#if rose && gardenerStatus === 'set'}
{#if !gardenerKept}
<p class="hint">{en.gardener.notKept}</p>
{/if}
<Rose
wiring={rose}
timeZone={roseZone}
{place}
look={look ?? FIRST_LOOK}
{...rose.gardener ? { onchangegardener: () => (choosingGardener = true) } : {}}
/>
{/if}
{#if sunset && (status === 'asking' || changing)}
<SunsetPlace
@@ -173,6 +229,7 @@
<ChairSunset {place} guessed={choice?.kind === 'device-zone'} now={sunset.now} onclose={stopWatching} />
{/if}
{/if}
{/if}
{#if blocks.length > 0}
<a href={LETTER_HASH}>{en.letter.title}</a>
{/if}
+36
View File
@@ -125,6 +125,42 @@ export const en = {
again: 'Watch it again',
back: 'Back to the rose'
},
/** Her planet (planet-garden.md). The gardener is the player's own; nothing names a person. */
scene: {
planet: 'Her planet',
ring: 'What she needs',
close: 'Close',
can: 'The watering can. Press it and tilt sideways to pour.',
weed: 'A weed. Swipe up from it to pull it out.',
petals: 'Fallen petals. Sweep across them to gather them.',
windbreak: 'The windbreak. Drag it to her windward side.',
/** What the gardener did, said once, politely. */
did: {
water: 'Your gardener waters her.',
weed: 'Your gardener pulls a weed.',
weeds: 'Your gardener pulls the weeds.',
petals: 'Your gardener gathers her petals.',
shade: 'Your gardener sets the windbreak against the wind.',
touch: 'Your gardener touches her petals.'
}
},
gardener: {
question: 'Who tends her?',
why: 'Choose your gardener. You can change this later.',
preview: 'Your gardener',
done: 'This is me',
change: 'Change gardener',
notKept: 'This device could not keep your gardener, so the garden will ask again next time.',
labels: { presentation: 'Gardener', skin: 'Skin', hair: 'Hair', hairColour: 'Hair colour', clothes: 'Clothes', hat: 'Hat' },
values: {
presentation: { girl: 'A girl', boy: 'A boy' },
skin: { 'skin-1': 'Tone 1', 'skin-2': 'Tone 2', 'skin-3': 'Tone 3', 'skin-4': 'Tone 4', 'skin-5': 'Tone 5', 'skin-6': 'Tone 6' },
hair: { short: 'Short', curly: 'Curly', ponytail: 'Ponytail', braids: 'Braids', bob: 'Bob', bun: 'Bun' },
hairColour: { black: 'Black', 'dark-brown': 'Dark brown', brown: 'Brown', auburn: 'Auburn', red: 'Red', fair: 'Fair' },
clothes: { sage: 'Sage', rose: 'Rose', honey: 'Honey', dusk: 'Dusk blue', plum: 'Plum' },
hat: { 'straw-hat': 'Straw hat', cap: 'Cap', none: 'No hat' }
}
},
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.',
+105 -60
View File
@@ -1,9 +1,13 @@
<script lang="ts">
import {
careEvent, goodMoment, localDay, newCare, newOpened, petalAt, pour, roseAt, ROSE, sentenceOpened, touch, TOUCH, UNTOUCHED,
type Mood, type PetalNow, type Place, type RoseNow, type Stage, type TouchState
careEvent, goodMoment, lightAt, localDay, newCare, newOpened, petalAt, petalsToday, pour, roseAt, ROSE, sentenceOpened, touch, TOUCH,
UNTOUCHED, weedsToday, type Mood, type PetalNow, type Place, type RoseNow, type Stage, type TouchState
} from '@rosea/engine';
import type { CareEvent, SentenceOpened } from '@rosea/schema';
import type { CareEvent, Gardener as Look, SentenceOpened } from '@rosea/schema';
import { tick } from 'svelte';
import Planet from '../scene/Planet.svelte';
import { pourRate } from '../scene/gestures.js';
import { FIRST_LOOK } from '../scene/look.js';
import { en } from '../copy/en.js';
import KeepSafe from './KeepSafe.svelte';
import Petal from './Petal.svelte';
@@ -23,7 +27,13 @@
* The rose. Everything she is comes from the engine's replay of her care log
* (rose.md); this renders it and turns the player's hands into care events.
*/
let { wiring, timeZone, place = null }: { wiring: RoseWiring; timeZone: string; place?: Place | null } = $props();
let {
wiring,
timeZone,
place = null,
look = FIRST_LOOK,
onchangegardener
}: { wiring: RoseWiring; timeZone: string; place?: Place | null; look?: Look; onchangegardener?: () => void } = $props();
const STAGE_PICTURE: Record<Stage, string> = { bud, opening, 'half-bloom': halfBloom, 'full-bloom': fullBloom };
const MOOD_PICTURE: Record<Mood, string> = { content: fullBloom, thirsty, 'too-full': overwatered, windblown, blushing, waiting };
@@ -114,14 +124,17 @@
const TICK_MS = 50;
let amount = $state(0);
let pouring = $state(false);
/** How far the can is tipped (planet-garden.md G4): a held button pours at a steady 0.55. */
let tilt = $state(0.55);
let pourTimer: ReturnType<typeof setInterval> | undefined;
const can = $derived(rose ? pour(rose.water, amount) : null);
function startPour(): void {
function startPour(tipped = 0.55): void {
if (pouring || rose === null) return;
pouring = true;
amount = 0;
pourTimer = setInterval(() => (amount = Math.min(1, amount + TICK_MS / FULL_CAN_MS)), TICK_MS);
tilt = tipped;
pourTimer = setInterval(() => (amount = Math.min(1, amount + (TICK_MS / FULL_CAN_MS) * pourRate(tilt))), TICK_MS);
}
function stopPour(): void {
if (!pouring) return;
@@ -157,6 +170,33 @@
const isPourKey = (e: KeyboardEvent): boolean => e.key === ' ' || e.key === 'Enter';
// --- Her planet and the ring of care (planet-garden.md) ------------------
let planet = $state<Planet>();
let roseTarget = $state<SVGElement>();
let ringOpen = $state(false);
let ring = $state<HTMLElement>();
const today = $derived(localDay(now, timeZone));
const weedCount = $derived(rose?.needs.weeds && seed ? weedsToday(seed, today) : 0);
const petalCount = $derived(rose?.needs.petals && seed ? petalsToday(seed, today) : 0);
const light = $derived(place && now > 0 ? lightAt(now, place) : 'day');
async function openRing(): Promise<void> {
ringOpen = !ringOpen;
await tick();
if (ringOpen) ring?.querySelector<HTMLElement>('button')?.focus();
else roseTarget?.focus();
}
async function closeRing(): Promise<void> {
ringOpen = false;
await tick();
roseTarget?.focus();
}
/** A ring button: the gardener does it, and it is the same act as ever. */
function careBy(act: 'shade' | 'weed' | 'petals'): void {
planet?.act(act === 'weed' ? 'weeds' : act === 'shade' ? 'shade' : 'petals');
care(act);
}
// --- What she says: one line, or nothing --------------------------------
const says = $derived.by(() => {
if (!rose) return '';
@@ -185,27 +225,46 @@
{#if rose}
<section class="rose">
<figure>
<div class="picture">
<img src={picture} {alt} width="120" height="320" class:turned={rose.drift > 0} />
<!-- Her picture keeps its description; the touch is its own button over it (thorns.md T5). -->
<button
type="button"
class="touch"
aria-label={en.rose.touch.label}
onclick={touchHer}
onkeydown={(e) => {
// A held key is one touch, not a rush.
if (e.repeat) e.preventDefault();
}}
></button>
</div>
{#if says}
<figcaption class="bubble" aria-live="polite">{says}</figcaption>
{/if}
</figure>
{#if says}
<p class="bubble" aria-live="polite">{says}</p>
{/if}
<!-- Her planet: the gardener, and every care by the player's hand (planet-garden.md). -->
<Planet
bind:this={planet}
bind:roseTarget
{picture}
{alt}
turned={rose.drift > 0}
{light}
{look}
weeds={weedCount}
petals={petalCount}
wind={rose.needs.wind}
{pouring}
{tilt}
{ringOpen}
onrose={openRing}
onstroke={touchHer}
onpourstart={() => startPour(0)}
onpourtilt={(t) => (tilt = t)}
onpourend={stopPour}
onweeds={() => care('weed')}
onpetals={() => care('petals')}
onshade={() => care('shade')}
/>
<div class="care" role="group" aria-label={en.rose.care}>
{#if ringOpen}
<!-- svelte-ignore a11y_no_noninteractive_element_interactions (Escape anywhere in the ring closes it) -->
<div
class="care"
role="group"
aria-label={en.scene.ring}
bind:this={ring}
tabindex="-1"
onkeydown={(e) => {
if (e.key === 'Escape') void closeRing();
}}
>
<button
type="button"
class="water"
@@ -229,16 +288,29 @@
onblur={stopPour}
>{en.rose.water}</button>
{#if rose.needs.wind}
<button type="button" onclick={() => care('shade')}>{en.rose.shade}</button>
<button type="button" onclick={() => careBy('shade')}>{en.rose.shade}</button>
{/if}
{#if rose.needs.weeds}
<button type="button" onclick={() => care('weed')}>{en.rose.weed}</button>
<button type="button" onclick={() => careBy('weed')}>{en.rose.weed}</button>
{/if}
{#if rose.needs.petals}
<button type="button" onclick={() => care('petals')}>{en.rose.petals}</button>
<button type="button" onclick={() => careBy('petals')}>{en.rose.petals}</button>
{/if}
<button
type="button"
onclick={() => {
planet?.act('touch');
touchHer();
}}
onkeydown={(e) => {
// A held key is one touch, not a rush (thorns.md T2).
if (e.repeat) e.preventDefault();
}}
>{en.rose.touch.label}</button>
<button type="button" class="quiet" onclick={() => void closeRing()}>{en.scene.close}</button>
</div>
<p id="rose-water-hint" class="hint">{en.rose.waterHint}</p>
{/if}
{#if pouring && can}
<div class="can">
@@ -256,6 +328,9 @@
<div class="more">
<button type="button" class="quiet" aria-expanded={showNumbers} aria-controls="rose-numbers" onclick={() => (showNumbers = !showNumbers)}>{en.rose.numbers}</button>
<button type="button" class="quiet" aria-expanded={showSafe} onclick={() => (showSafe = !showSafe)}>{en.rose.safe.title}</button>
{#if onchangegardener}
<button type="button" class="quiet" onclick={onchangegardener}>{en.gardener.change}</button>
{/if}
</div>
{#if showNumbers}
<dl id="rose-numbers" class="numbers">
@@ -278,39 +353,9 @@
gap: var(--space-2);
}
figure {
margin: 0;
display: grid;
justify-items: center;
gap: var(--space-2);
}
img {
height: 13rem;
width: auto;
transition: transform 0.6s ease;
}
.picture {
position: relative;
}
.touch {
position: absolute;
inset: 0;
border: none;
border-radius: 1rem;
background: transparent;
cursor: pointer;
}
/* Drift is drawn as waiting: turned a little away, never hurt (CLAUDE.md §8). */
img.turned {
transform: rotate(-4deg) scaleX(-1);
}
.bubble {
max-width: 22rem;
margin: 0;
padding: var(--space-2) var(--space-3);
border-radius: 1rem;
background: color-mix(in srgb, var(--rose) 12%, var(--paper));
+6 -1
View File
@@ -1,4 +1,4 @@
import type { CareEvent, HopeSentence, SentenceOpened } from '@rosea/schema';
import type { CareEvent, Gardener, HopeSentence, SentenceOpened } from '@rosea/schema';
/**
* What the rose needs from the app: her care log, her key, and the clock. The app
@@ -23,6 +23,11 @@ export interface RoseWiring {
/** The rose as a file's contents, and bringing one back. */
readonly exportRose: (currentKey: string) => Promise<unknown>;
readonly importRose: (file: unknown, currentKey: string) => Promise<{ readonly added: number; readonly petals: number }>;
/** The player's gardener (planet-garden.md G6). Absent, the garden asks nothing and shows the first look. */
readonly gardener?: {
readonly load: () => Promise<Gardener | null>;
readonly save: (look: Gardener) => Promise<void>;
};
/** Hears care, a petal or a rose brought back in another tab (two-tabs.md); returns the way to stop. */
readonly changes?: (listener: () => void) => () => void;
/** Hands the player a file to keep. */
+110
View File
@@ -0,0 +1,110 @@
<svelte:options namespace="svg" />
<script lang="ts" module>
/** What the gardener is doing (planet-garden.md G5). */
export type Pose = 'stand' | 'walk' | 'pour' | 'pull' | 'sweep' | 'carry' | 'reach';
</script>
<script lang="ts">
import type { Gardener } from '@rosea/schema';
/**
* The player's gardener: a stand-in drawn in code until the art board's gardener sheets are
* accepted. Feet at (0, 0), about 72 units tall, facing right. A child in a work apron, never
* a scarf, coat, cape or crown (planet-garden.md §0). The pose bends the figure; the scene
* moves it.
*/
let { look, pose = 'stand', tilt = 0 }: { look: Gardener; pose?: Pose; tilt?: number } = $props();
const SKIN: Record<Gardener['skin'], string> = {
'skin-1': '#f6dcc8', 'skin-2': '#e8bf9c', 'skin-3': '#cf9a72', 'skin-4': '#a9714b', 'skin-5': '#7f5236', 'skin-6': '#553422'
};
const HAIR: Record<Gardener['hairColour'], string> = {
black: '#2b2324', 'dark-brown': '#4a2f24', brown: '#7a4b2e', auburn: '#9a4a2a', red: '#b5532c', fair: '#d9b26a'
};
const CLOTHES: Record<Gardener['clothes'], string> = { sage: '#7fa07a', rose: '#c85a6e', honey: '#b98a5a', dusk: '#5b6fa6', plum: '#7a4f6e' };
const INK = '#3a2730';
const APRON = '#efe4d2';
const skin = $derived(SKIN[look.skin]);
const hair = $derived(HAIR[look.hairColour]);
const cloth = $derived(CLOTHES[look.clothes]);
/** How far the body leans forward, by pose. */
const lean = $derived({ stand: 0, walk: 4, pour: 10, pull: 28, sweep: 18, carry: 6, reach: 14 }[pose]);
/** The near arm's angle from hanging down, by pose (degrees, forward is negative). */
const arm = $derived({ stand: 8, walk: -12, pour: -70 - tilt * 25, pull: -150, sweep: -40, carry: -80, reach: -95 }[pose]);
</script>
<g class="gardener {pose}" aria-hidden="true">
<!-- Legs: a skirt-length tunic for a girl, trousers for a boy; both chosen by the player. -->
{#if look.presentation === 'girl'}
<path d="M-7 0 V -18 M7 0 V -18" stroke={skin} stroke-width="5" stroke-linecap="round" />
{:else}
<path d="M-7 0 V -20 M7 0 V -20" stroke={cloth} stroke-width="7" stroke-linecap="round" />
{/if}
<path d="M-10 0 h6 M4 0 h6" stroke={INK} stroke-width="4" stroke-linecap="round" />
<g transform="rotate({lean} 0 -20)">
<!-- Body: shirt or tunic in the chosen colour, a cream work apron over it. -->
{#if look.presentation === 'girl'}
<path d="M-12 -44 Q -16 -24 -15 -16 H 15 Q 16 -24 12 -44 Z" fill={cloth} stroke={INK} stroke-width="2" />
{:else}
<path d="M-11 -44 Q -12 -30 -10 -20 H 10 Q 12 -30 11 -44 Z" fill={cloth} stroke={INK} stroke-width="2" />
{/if}
<path d="M-7 -36 H 7 V -18 Q 0 -15 -7 -18 Z" fill={APRON} stroke={INK} stroke-width="1.5" />
<!-- The far arm hangs; the near arm does the work. -->
<path d="M-10 -42 l -4 16" stroke={skin} stroke-width="4.5" stroke-linecap="round" />
<g transform="rotate({arm} 9 -42)">
<path d="M9 -42 l 2 18" stroke={skin} stroke-width="4.5" stroke-linecap="round" />
{#if pose === 'pour'}
<!-- The watering can, tipped as the player tips it. -->
<g transform="translate(11 -22) rotate({20 + tilt * 40})">
<rect x="-7" y="-6" width="14" height="11" rx="3" fill="#7fa07a" stroke={INK} stroke-width="1.5" />
<path d="M7 -2 l 9 -6" stroke={INK} stroke-width="2.5" stroke-linecap="round" />
</g>
{:else if pose === 'sweep'}
<path d="M11 -24 l 3 16" stroke="#b98a5a" stroke-width="2.5" />
{/if}
</g>
<!-- Head: skin, then the chosen hair, then the chosen hat. A tiny painted face. -->
<circle cx="0" cy="-54" r="10" fill={skin} stroke={INK} stroke-width="2" />
{#if look.hair === 'short'}
<path d="M-10 -56 Q 0 -70 10 -56 Q 4 -61 -10 -56 Z" fill={hair} />
{:else if look.hair === 'curly'}
{#each [-8, -3, 2, 7] as x (x)}<circle cx={x} cy="-62" r="4.5" fill={hair} />{/each}
{:else if look.hair === 'ponytail'}
<path d="M-10 -55 Q 0 -70 10 -55 Q 0 -60 -10 -55 Z" fill={hair} /><path d="M-9 -58 q -8 6 -5 16" stroke={hair} stroke-width="4" fill="none" stroke-linecap="round" />
{:else if look.hair === 'braids'}
<path d="M-10 -55 Q 0 -70 10 -55 Q 0 -60 -10 -55 Z" fill={hair} /><path d="M-9 -54 v 14 M9 -54 v 14" stroke={hair} stroke-width="3.5" stroke-linecap="round" />
{:else if look.hair === 'bob'}
<path d="M-11 -50 Q -12 -68 0 -66 Q 12 -68 11 -50 L 8 -50 Q 0 -60 -8 -50 Z" fill={hair} />
{:else}
<path d="M-10 -55 Q 0 -70 10 -55 Q 0 -60 -10 -55 Z" fill={hair} /><circle cx="0" cy="-66" r="4.5" fill={hair} />
{/if}
{#if look.hat === 'straw-hat'}
<ellipse cx="0" cy="-61" rx="16" ry="3.5" fill="#e6c98a" stroke={INK} stroke-width="1.5" /><path d="M-7 -61 Q 0 -72 7 -61 Z" fill="#e6c98a" stroke={INK} stroke-width="1.5" />
{:else if look.hat === 'cap'}
<path d="M-9 -60 Q 0 -70 9 -60 Z" fill={cloth} stroke={INK} stroke-width="1.5" /><path d="M7 -60 h 8" stroke={INK} stroke-width="2.5" stroke-linecap="round" />
{/if}
<circle cx="3" cy="-55" r="1.2" fill={INK} /><circle cx="7" cy="-55" r="1.2" fill={INK} />
<path d="M3 -50 q 2 1.5 4 0" stroke={INK} stroke-width="1.2" fill="none" stroke-linecap="round" />
</g>
</g>
<style>
.gardener g {
transition: transform 0.35s ease;
}
.walk {
animation: step 0.5s ease-in-out infinite alternate;
}
@keyframes step {
to {
transform: translateY(-2px);
}
}
</style>
+177
View File
@@ -0,0 +1,177 @@
<script lang="ts">
import { GARDENER_FIELDS, GARDENER_OPTIONS, type Gardener as Look } from '@rosea/schema';
import { untrack } from 'svelte';
import { en } from '../copy/en.js';
import Gardener from './Gardener.svelte';
import { FIRST_LOOK } from './look.js';
/**
* *Who tends her?* (planet-garden.md §1): the player chooses and dresses their gardener from
* fixed lists, with a preview that follows every choice. Nothing typed, nothing sent.
*/
let {
current = null,
onchoose,
oncancel
}: { current?: Look | null; onchoose: (look: Look) => void; oncancel?: () => void } = $props();
// A copy of what was given: the choice changes it freely until *This is me*.
let look = $state<Look>({ ...(untrack(() => current) ?? FIRST_LOOK) });
const uid = $props.id();
let heading = $state<HTMLHeadingElement>();
$effect(() => {
if (current) heading?.focus();
});
const label = (field: keyof Look, value: string): string => (en.gardener.values[field] as Record<string, string>)[value] ?? value;
</script>
<section class="choice" aria-labelledby="{uid}-q">
<h2 id="{uid}-q" tabindex="-1" bind:this={heading}>{en.gardener.question}</h2>
<p class="why">{en.gardener.why}</p>
<svg class="preview" viewBox="-40 -90 80 96" role="img" aria-label={en.gardener.preview}>
<ellipse cx="0" cy="2" rx="26" ry="5" fill="#a9c48e" />
<Gardener {look} />
</svg>
<form
onsubmit={(e) => {
e.preventDefault();
onchoose({ ...look });
}}
>
{#each GARDENER_FIELDS as field (field)}
<fieldset>
<legend>{en.gardener.labels[field]}</legend>
<div class="options">
{#each GARDENER_OPTIONS[field] as value (value)}
<label>
<input type="radio" name="{uid}-{field}" {value} checked={look[field] === value} onchange={() => (look = { ...look, [field]: value })} />
<span>{label(field, value)}</span>
</label>
{/each}
</div>
</fieldset>
{/each}
<div class="actions">
<button type="submit" class="primary">{en.gardener.done}</button>
{#if oncancel}<button type="button" class="quiet" onclick={oncancel}>{en.scene.close}</button>{/if}
</div>
</form>
</section>
<style>
.choice {
display: grid;
gap: var(--space-2);
justify-items: center;
max-width: 28rem;
text-align: center;
}
h2 {
margin: 0;
font-family: var(--font-display);
font-weight: 400;
}
h2:focus {
outline: none;
}
.why {
margin: 0;
color: var(--ink-soft);
}
.preview {
width: 7rem;
height: auto;
}
form {
display: grid;
gap: var(--space-2);
width: 100%;
}
fieldset {
border: none;
margin: 0;
padding: 0;
display: grid;
gap: var(--space-1);
}
legend {
font-weight: 600;
padding: 0;
margin-bottom: var(--space-1);
}
.options {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: var(--space-1);
}
label {
display: inline-flex;
}
input {
position: absolute;
opacity: 0;
width: 1px;
height: 1px;
}
label span {
padding: var(--space-1) var(--space-2);
border-radius: 999px;
border: 1px solid color-mix(in srgb, var(--ink-soft) 40%, transparent);
cursor: pointer;
}
input:checked + span {
border-color: var(--rose);
background: color-mix(in srgb, var(--rose) 14%, var(--paper));
}
input:focus-visible + span {
outline: 2px solid var(--rose);
outline-offset: 2px;
}
.actions {
display: flex;
justify-content: center;
gap: var(--space-3);
}
button {
font: inherit;
padding: var(--space-2) var(--space-4);
border-radius: 999px;
border: 1px solid var(--rose);
background: var(--paper);
color: var(--ink);
cursor: pointer;
}
.primary {
background: var(--rose);
color: var(--paper);
}
.quiet {
border: none;
text-decoration: underline;
color: var(--rose);
}
button:focus-visible {
outline: 2px solid var(--rose);
outline-offset: 2px;
}
</style>
+419
View File
@@ -0,0 +1,419 @@
<script lang="ts" module>
/** What the gardener is busy with; `idle` stands beside her. */
export type Activity = 'idle' | 'pour' | 'weeds' | 'petals' | 'shade' | 'touch';
</script>
<script lang="ts">
import type { Light } from '@rosea/engine';
import type { Gardener as Look } from '@rosea/schema';
import { untrack } from 'svelte';
import { en } from '../copy/en.js';
import Gardener, { type Pose } from './Gardener.svelte';
import { inside, isPull, isSweep, strokeOf, tiltOf, type Sample } from './gestures.js';
/**
* Her planet (planet-garden.md): a small round world under the real sky, with her bed, the
* gardener, and the things of her care, each answering the player's hand. It decides nothing:
* every gesture is handed to the rose, whose rules are the engine's.
*/
let {
picture,
alt,
turned = false,
light = 'day',
look,
weeds = 0,
petals = 0,
wind = false,
pouring = false,
tilt = 0,
ringOpen = false,
roseTarget = $bindable(),
onrose,
onstroke,
onpourstart,
onpourtilt,
onpourend,
onweeds,
onpetals,
onshade
}: {
picture: string;
alt: string;
turned?: boolean;
light?: Light;
look: Look;
weeds?: number;
petals?: number;
wind?: boolean;
pouring?: boolean;
tilt?: number;
ringOpen?: boolean;
roseTarget?: SVGElement | undefined;
onrose: () => void;
onstroke: () => void;
onpourstart: () => void;
onpourtilt: (tilt: number) => void;
onpourend: () => void;
onweeds: () => void;
onpetals: () => void;
onshade: () => void;
} = $props();
// --- The world's geometry: a planet of radius R, the rose on its top ---------
const CX = 180;
const CY = 285;
const R = 105;
const TOP = CY - R;
/** A point on the surface at `deg` from the top (positive is to the right). */
const surface = (deg: number, lift = 0): { x: number; y: number } => {
const a = (deg * Math.PI) / 180;
return { x: CX + (R + lift) * Math.sin(a), y: CY - (R + lift) * Math.cos(a) };
};
const WEED_AT = [9, -9, 15, -15];
const PETAL_AT = [22, 26, 30, 34, 38];
const CAN_AT = -42;
const WINDBREAK_AT = 48;
/** Where the windbreak must be dropped: her windward (left) side, the wind's side. */
const DROP: { x0: number; y0: number; x1: number; y1: number } = { x0: 112, y0: 110, x1: 172, y1: 200 };
// --- What the gardener is doing ---------------------------------------------
let activity = $state<Activity>('idle');
let activityTimer: ReturnType<typeof setTimeout> | undefined;
const reduced = typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
/** The gardener walks over and does it, then goes back to stand beside her. */
export function act(kind: Activity, ms = 1600): void {
activity = kind;
clearTimeout(activityTimer);
if (kind !== 'pour') activityTimer = setTimeout(() => (activity = 'idle'), ms);
}
$effect(() => () => clearTimeout(activityTimer));
$effect(() => {
// Only `pouring` drives this; the activity it sets is read without tracking.
if (pouring) act('pour');
else if (untrack(() => activity) === 'pour') activity = 'idle';
});
const STATION: Record<Activity, { at: number; pose: Pose }> = {
idle: { at: -28, pose: 'stand' },
pour: { at: -15, pose: 'pour' },
weeds: { at: 4, pose: 'pull' },
petals: { at: 20, pose: 'sweep' },
shade: { at: -18, pose: 'carry' },
touch: { at: -10, pose: 'reach' }
};
const station = $derived(STATION[activity]);
// --- The player's hand ------------------------------------------------------
type Drag =
| { kind: 'rose'; samples: Sample[] }
| { kind: 'can'; samples: Sample[] }
| { kind: 'weed'; index: number; samples: Sample[] }
| { kind: 'sweep'; samples: Sample[] }
| { kind: 'windbreak'; samples: Sample[] };
let drag: Drag | null = null;
let svg = $state<SVGSVGElement>();
let pulled = $state<ReadonlySet<number>>(new Set());
let windbreakAt = $state<{ x: number; y: number } | null>(null);
let said = $state('');
// A new day's weeds start whole: forget the pulled ones when the count changes.
$effect(() => {
void weeds;
pulled = new Set();
});
/** The pointer in the scene's own units. Without a layout (a test), client units are scene units. */
function point(e: PointerEvent): Sample {
const t = e.timeStamp || performance.now();
const ctm = svg?.getScreenCTM?.();
if (!svg || !ctm) return { x: e.clientX, y: e.clientY, t };
const p = new DOMPoint(e.clientX, e.clientY).matrixTransform(ctm.inverse());
return { x: p.x, y: p.y, t };
}
function start(e: PointerEvent, next: Drag): void {
e.preventDefault();
e.stopPropagation();
try {
svg?.setPointerCapture?.(e.pointerId);
} catch (error) {
// A synthetic pointer (a test) has nothing to capture; the gesture still works.
void error;
}
drag = next;
if (next.kind === 'can') onpourstart();
if (next.kind === 'windbreak') windbreakAt = next.samples[0] ?? null;
}
function move(e: PointerEvent): void {
if (!drag) return;
const p = point(e);
drag.samples.push(p);
if (drag.kind === 'can') onpourtilt(tiltOf(drag.samples[0]!, p));
if (drag.kind === 'windbreak') windbreakAt = p;
}
function end(e: PointerEvent): void {
if (!drag) return;
const d = drag;
drag = null;
d.samples.push(point(e));
switch (d.kind) {
case 'rose': {
const kind = strokeOf(d.samples);
if (kind === 'stroke') {
act('touch');
said = en.scene.did.touch;
onstroke();
} else if (kind === 'tap') onrose();
break;
}
case 'can':
onpourend();
said = en.scene.did.water;
break;
case 'weed':
if (isPull(d.samples) && !pulled.has(d.index)) {
pulled = new Set([...pulled, d.index]);
act('weeds', 900);
said = en.scene.did.weed;
if (pulled.size >= weeds) onweeds();
}
break;
case 'sweep': {
const xs = PETAL_AT.slice(0, petals).map((a) => surface(a).x);
if (petals > 0 && isSweep(d.samples, Math.min(...xs), Math.max(...xs))) {
act('petals');
said = en.scene.did.petals;
onpetals();
}
break;
}
case 'windbreak': {
const at = d.samples[d.samples.length - 1]!;
windbreakAt = null;
if (inside(at, DROP)) {
act('shade');
said = en.scene.did.shade;
onshade();
}
break;
}
}
}
const SKY: Record<Light, [string, string]> = { day: ['#a9cbe0', '#e8f0ec'], golden: ['#f2b860', '#e9846a'], night: ['#2e3561', '#46557a'] };
const sky = $derived(SKY[light]);
const rose = surface(0);
const can = surface(CAN_AT);
const resting = surface(WINDBREAK_AT);
const chair = surface(62);
</script>
<div class="planet" class:reduced>
<svg
bind:this={svg}
viewBox="0 0 360 400"
role="group"
aria-label={en.scene.planet}
onpointerdown={(e) => {
if (petals > 0) start(e, { kind: 'sweep', samples: [point(e)] });
}}
onpointermove={move}
onpointerup={end}
onpointercancel={() => {
if (drag?.kind === 'can') onpourend();
drag = null;
windbreakAt = null;
}}
>
<defs>
<linearGradient id="planet-sky" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stop-color={sky[0]} />
<stop offset="1" stop-color={sky[1]} />
</linearGradient>
<radialGradient id="planet-ground" cx="0.4" cy="0.3" r="0.8">
<stop offset="0" stop-color="#b9d39c" />
<stop offset="1" stop-color="#7fa07a" />
</radialGradient>
</defs>
<!-- The sky follows the real sun (engine lightAt). Stars are never invented here (STYLE.md S5). -->
<rect width="360" height="400" fill="url(#planet-sky)" />
{#if wind}
<g class="gust" aria-hidden="true">
{#each [70, 95, 120] as y (y)}<path d="M10 {y} q 40 -14 80 0 t 70 -6" fill="none" stroke="#fbf6f1" stroke-width="3" stroke-linecap="round" opacity=".7" />{/each}
</g>
{/if}
<!-- Her small round world: meadow over warm earth, a low dry-stone wall, her bed, the chair. -->
<circle cx={CX} cy={CY} r={R} fill="url(#planet-ground)" stroke="#3a2730" stroke-width="3" />
<path d="M{CX - 70} {CY + 40} q 70 50 140 0" fill="none" stroke="#8a6248" stroke-width="10" opacity=".25" />
{#each [-58, -52, -46, 46, 52] as a (a)}
{@const s = surface(a, 3)}
<ellipse cx={s.x} cy={s.y} rx="6" ry="4" fill="#c9bcae" stroke="#3a2730" stroke-width="1.5" transform="rotate({a} {s.x} {s.y})" />
{/each}
<ellipse cx={rose.x} cy={TOP + 2} rx="34" ry="8" fill="#8a6248" stroke="#3a2730" stroke-width="2" />
<g transform="translate({chair.x} {chair.y}) rotate(62)" aria-hidden="true">
<rect x="-9" y="-26" width="18" height="16" rx="2" fill="#b98a5a" stroke="#3a2730" stroke-width="1.5" />
<rect x="-10" y="-12" width="20" height="4" fill="#f2b5be" stroke="#3a2730" stroke-width="1.5" />
<path d="M-8 -8 v 8 M8 -8 v 8" stroke="#b98a5a" stroke-width="2.5" />
</g>
<!-- The rose: her picture stands on top of the world; a tap opens her care, a slow stroke touches her. -->
<image href={picture} x={rose.x - 24} y={TOP - 128} width="48" height="128" role="img" aria-label={alt} class:turned />
<rect
bind:this={roseTarget}
x={rose.x - 28}
y={TOP - 132}
width="56"
height="132"
fill="transparent"
role="button"
tabindex="0"
aria-label={en.rose.care}
aria-expanded={ringOpen}
class="target"
onpointerdown={(e) => start(e, { kind: 'rose', samples: [point(e)] })}
onkeydown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
if (!e.repeat) onrose();
}
}}
/>
<!-- Weeds in her bed: swipe each one up and out. -->
{#each WEED_AT.slice(0, weeds) as a, i (a)}
{#if !pulled.has(i)}
{@const s = surface(a, 1)}
<g
class="weed target"
transform="translate({s.x} {s.y}) rotate({a})"
role="img"
aria-label={en.scene.weed}
onpointerdown={(e) => start(e, { kind: 'weed', index: i, samples: [point(e)] })}
>
<rect x="-10" y="-22" width="20" height="26" fill="transparent" />
<path d="M0 0 l -6 -14 l 5 4 l 1 -10 l 3 8 l 4 -6 l -2 18 z" fill="#7fa07a" stroke="#3a2730" stroke-width="1.5" />
</g>
{/if}
{/each}
<!-- Fallen petals on the grass: sweep across them. -->
{#each PETAL_AT.slice(0, petals) as a (a)}
{@const s = surface(a, 2)}
<ellipse cx={s.x} cy={s.y} rx="5" ry="3" fill="#c85a6e" stroke="#3a2730" stroke-width="1" transform="rotate({a + 30} {s.x} {s.y})" role="img" aria-label={en.scene.petals} />
{/each}
<!-- The windbreak, only on a windy hour: drag it to her windward side. -->
{#if wind}
<rect x={DROP.x0} y={DROP.y0} width={DROP.x1 - DROP.x0} height={DROP.y1 - DROP.y0} rx="10" fill="#fbf6f1" opacity={windbreakAt ? 0.25 : 0} aria-hidden="true" />
{@const at = windbreakAt ?? resting}
<g
class="windbreak target"
transform="translate({at.x} {at.y}) rotate({windbreakAt ? 0 : WINDBREAK_AT})"
role="img"
aria-label={en.scene.windbreak}
onpointerdown={(e) => start(e, { kind: 'windbreak', samples: [point(e)] })}
>
<rect x="-16" y="-24" width="32" height="26" fill="transparent" />
{#each [-12, -6, 0, 6, 12] as x (x)}<path d="M{x} 0 v -20" stroke="#b98a5a" stroke-width="4" stroke-linecap="round" />{/each}
</g>
{/if}
<!-- The watering can by the bed: press it and tilt to pour. -->
{#if !pouring}
<g
class="can target"
transform="translate({can.x} {can.y}) rotate({CAN_AT})"
role="img"
aria-label={en.scene.can}
onpointerdown={(e) => start(e, { kind: 'can', samples: [point(e)] })}
>
<rect x="-14" y="-22" width="28" height="24" fill="transparent" />
<rect x="-9" y="-14" width="18" height="14" rx="4" fill="#7fa07a" stroke="#3a2730" stroke-width="1.5" />
<path d="M-9 -9 l -8 -6" stroke="#3a2730" stroke-width="2.5" stroke-linecap="round" />
</g>
{:else}
{@const p = surface(-6, 40)}
<g aria-hidden="true">
{#each [0, 1, 2] as i (i)}<circle cx={p.x + 4 + i * 3} cy={p.y + 8 + i * 9} r={1.5 + tilt} fill="#9cc3d8" />{/each}
</g>
{/if}
<!-- The gardener: walks round the world to where the work is. -->
<g class="walker" style:transform="rotate({station.at}deg)" style:transform-origin="{CX}px {CY}px">
<g transform="translate({CX} {TOP})">
<Gardener {look} pose={station.pose} {tilt} />
</g>
</g>
</svg>
<p class="sr-only" aria-live="polite">{said}</p>
</div>
<style>
.planet {
width: min(100%, 26rem);
position: relative;
}
svg {
display: block;
width: 100%;
height: auto;
border-radius: 1.25rem;
touch-action: none;
user-select: none;
}
.target {
cursor: grab;
}
.target:focus-visible {
outline: 3px solid var(--rose);
outline-offset: 2px;
}
image.turned {
transform-box: fill-box;
transform-origin: 50% 100%;
transform: rotate(-4deg);
}
.walker {
transition: transform 0.9s ease-in-out;
}
.reduced .walker {
transition: none;
}
.gust path {
animation: gust 2.4s ease-in-out infinite;
}
@keyframes gust {
from {
transform: translateX(-20px);
opacity: 0;
}
50% {
opacity: 0.8;
}
to {
transform: translateX(40px);
opacity: 0;
}
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
</style>
+4
View File
@@ -0,0 +1,4 @@
import type { Gardener } from '@rosea/schema';
/** The gardener the choice starts from, and who tends her if the device could not keep a choice. */
export const FIRST_LOOK: Gardener = { presentation: 'girl', skin: 'skin-3', hair: 'braids', hairColour: 'brown', clothes: 'sage', hat: 'straw-hat' };