[ui] PlanetGarden: Her round planet, the player's gardener, the ring of care, and care by gesture
This commit is contained in:
@@ -99,6 +99,8 @@
|
||||
sentences,
|
||||
loadOpened: () => storage.loadOpened(),
|
||||
appendOpened: (event) => storage.appendOpened(event),
|
||||
// The player's gardener, chosen at the first open (planet-garden.md G6).
|
||||
gardener: { load: () => storage.loadGardener(), save: (look) => storage.saveGardener(look) },
|
||||
// Another tab gave care, opened a petal or brought her back (two-tabs.md).
|
||||
changes: (listener) => storage.onChange((what) => what === 'log' && listener()),
|
||||
clientVersion: version,
|
||||
|
||||
@@ -3,7 +3,7 @@ export {
|
||||
careEvent, careIdentity, judgeCare, newCare, OWN_TRACE, petalsOn, pour, ROSE, roseAt, seeded, stageFor, weedsOn, windOn,
|
||||
type Judged, type Mood, type Needs, type RoseKeys, type RoseNow, type Stage, type Trend
|
||||
} from './rose/rose.js';
|
||||
export { invitation, nextInvitation, nextSunEvent, sunDay, type NamedPlace, type Place, type SunDay } from './sun/sun.js';
|
||||
export { invitation, lightAt, nextInvitation, nextSunEvent, sunDay, type Light, type NamedPlace, type Place, type SunDay } from './sun/sun.js';
|
||||
export {
|
||||
goodMoment, newOpened, openedIdentity, PETAL, petalAt, petalOrder, sentenceOpened, type PetalNow, type PetalSentence
|
||||
} from './petal/petal.js';
|
||||
|
||||
@@ -159,6 +159,27 @@ export function nextInvitation(now: number, place: Place): { readonly sun: SunDa
|
||||
throw new Error(`nextInvitation: no invitation within two days of ${today}`);
|
||||
}
|
||||
|
||||
/** The light over her planet now (planet-garden.md): the scene's sky follows the real sun. */
|
||||
export type Light = 'day' | 'golden' | 'night';
|
||||
|
||||
/**
|
||||
* Golden within 45 minutes before and 30 after the sunset or sunrise (in polar day, around the
|
||||
* lowest light; in polar night, around the brightest twilight at noon); day between, night outside.
|
||||
*/
|
||||
export function lightAt(now: number, place: Place): Light {
|
||||
const sun = sunDay(localDay(now, place.timeZone), place);
|
||||
const near = (at: number, before: number, after: number): boolean => now >= at - before * MINUTE && now <= at + after * MINUTE;
|
||||
switch (sun.kind) {
|
||||
case 'polar-day':
|
||||
return near(sun.lowestLight, 60, 60) ? 'golden' : 'day';
|
||||
case 'polar-night':
|
||||
return near(sun.solarNoon, 90, 90) ? 'golden' : 'night';
|
||||
case 'sun-sets':
|
||||
if (near(sun.sunset, 45, 30) || near(sun.sunrise, 30, 30)) return 'golden';
|
||||
return now > sun.sunrise && now < sun.sunset ? 'day' : 'night';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The next thing to look up for (sunrise.md R1): the sunrise of the next invitation's
|
||||
* day while it is still ahead, otherwise the invitation itself. Built on
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fc from 'fast-check';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { invitation, nextInvitation, nextSunEvent, sunDay, type Place, type SunDay } from '../src/sun/sun.js';
|
||||
import { invitation, lightAt, nextInvitation, nextSunEvent, sunDay, type Place, type SunDay } from '../src/sun/sun.js';
|
||||
import { addDays, localDay } from '../src/time/localDay.js';
|
||||
|
||||
/** Recorded by scripts/fetch-sun-golden.ts from the U.S. Naval Observatory. */
|
||||
@@ -317,3 +317,27 @@ describe('nextSunEvent — the next thing to look up for (sunrise.md)', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lightAt — the sky over her planet (planet-garden.md)', () => {
|
||||
const brno: Place = { lat: 49.1951, lon: 16.6068, timeZone: 'Europe/Prague' };
|
||||
const day = sunDay('2026-03-02', brno);
|
||||
if (day.kind !== 'sun-sets') throw new Error('Brno has a sunset in March');
|
||||
|
||||
it('night before dawn, golden at sunrise, day at noon, golden at sunset, night after', () => {
|
||||
expect(lightAt(day.sunrise - 2 * HOUR, brno)).toBe('night');
|
||||
expect(lightAt(day.sunrise, brno)).toBe('golden');
|
||||
expect(lightAt(day.solarNoon, brno)).toBe('day');
|
||||
expect(lightAt(day.sunset - 30 * MINUTE, brno)).toBe('golden');
|
||||
expect(lightAt(day.sunset + 2 * HOUR, brno)).toBe('night');
|
||||
});
|
||||
|
||||
it('polar day is day, golden around the lowest light; polar night is night, golden at noon', () => {
|
||||
const tromso: Place = { lat: 69.6492, lon: 18.9553, timeZone: 'Europe/Oslo' };
|
||||
const summer = sunDay('2026-06-21', tromso);
|
||||
const winter = sunDay('2026-12-21', tromso);
|
||||
if (summer.kind !== 'polar-day' || winter.kind !== 'polar-night') throw new Error('Tromsø: polar day and night');
|
||||
expect(lightAt(summer.solarNoon, tromso)).toBe('day');
|
||||
expect(lightAt(winter.solarNoon, tromso)).toBe('golden');
|
||||
expect(lightAt(winter.solarNoon + 4 * HOUR, tromso)).toBe('night');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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.',
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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' };
|
||||
@@ -0,0 +1,81 @@
|
||||
import type { Gardener } from '@rosea/schema';
|
||||
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/svelte';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import Shell from '../src/Shell.svelte';
|
||||
import { en } from '../src/copy/en.js';
|
||||
import type { RoseWiring } from '../src/rose/types.js';
|
||||
|
||||
const ZONE = 'Europe/Prague';
|
||||
const MORNING = Date.parse('2026-03-01T09:00:00+01:00');
|
||||
const saved: Gardener = { presentation: 'boy', skin: 'skin-5', hair: 'curly', hairColour: 'black', clothes: 'dusk', hat: 'cap' };
|
||||
|
||||
function rose(gardener: RoseWiring['gardener'] | undefined): RoseWiring {
|
||||
return {
|
||||
identity: async () => ({ publicKey: 'M'.repeat(87), kept: true }),
|
||||
loadCare: async () => [],
|
||||
appendCare: async () => undefined,
|
||||
sentences: [],
|
||||
loadOpened: async () => [],
|
||||
appendOpened: async () => undefined,
|
||||
clientVersion: '0.1.0',
|
||||
deviceZone: ZONE,
|
||||
now: () => MORNING,
|
||||
pastKeys: async () => [],
|
||||
exportRose: async () => ({}),
|
||||
importRose: async () => ({ added: 0, petals: 0 }),
|
||||
saveFile: () => undefined,
|
||||
keeping: { persisted: async () => false, persist: async () => true },
|
||||
installHint: false,
|
||||
...(gardener ? { gardener } : {})
|
||||
};
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
cleanup();
|
||||
});
|
||||
|
||||
describe('who tends her (planet-garden.md §1)', () => {
|
||||
it('the first open asks before the garden; the choice is kept and the garden opens', async () => {
|
||||
const saves: Gardener[] = [];
|
||||
render(Shell, { rose: rose({ load: async () => null, save: async (g) => void saves.push(g) }) });
|
||||
expect(await screen.findByRole('heading', { level: 2, name: en.gardener.question })).toBeTruthy();
|
||||
expect(screen.queryByRole('button', { name: en.rose.care })).toBeNull();
|
||||
await fireEvent.click(screen.getByLabelText(en.gardener.values.presentation.boy));
|
||||
await fireEvent.click(screen.getByLabelText(en.gardener.values.hair.curly));
|
||||
await fireEvent.click(screen.getByLabelText(en.gardener.values.hat.cap));
|
||||
await fireEvent.click(screen.getByRole('button', { name: en.gardener.done }));
|
||||
expect(saves).toEqual([{ presentation: 'boy', skin: 'skin-3', hair: 'curly', hairColour: 'brown', clothes: 'sage', hat: 'cap' }]);
|
||||
expect(await screen.findByRole('button', { name: en.rose.care })).toBeTruthy();
|
||||
expect(screen.queryByRole('heading', { name: en.gardener.question })).toBeNull();
|
||||
});
|
||||
|
||||
it('a saved gardener: no question; Change gardener opens it with their choices, and Close keeps them', async () => {
|
||||
const save = vi.fn(async () => undefined);
|
||||
render(Shell, { rose: rose({ load: async () => saved, save }) });
|
||||
await screen.findByRole('button', { name: en.rose.care });
|
||||
expect(screen.queryByRole('heading', { name: en.gardener.question })).toBeNull();
|
||||
await fireEvent.click(screen.getByRole('button', { name: en.gardener.change }));
|
||||
expect((screen.getByLabelText(en.gardener.values.presentation.boy) as HTMLInputElement).checked).toBe(true);
|
||||
expect((screen.getByLabelText(en.gardener.values.skin['skin-5']) as HTMLInputElement).checked).toBe(true);
|
||||
await fireEvent.click(screen.getByRole('button', { name: en.scene.close }));
|
||||
expect(await screen.findByRole('button', { name: en.rose.care })).toBeTruthy();
|
||||
expect(save).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('a device that cannot keep the choice: the garden still opens, and says it will ask again', async () => {
|
||||
const error = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
||||
render(Shell, { rose: rose({ load: async () => null, save: () => Promise.reject(new Error('IndexedDB blocked')) }) });
|
||||
await fireEvent.click(await screen.findByRole('button', { name: en.gardener.done }));
|
||||
expect(await screen.findByRole('button', { name: en.rose.care })).toBeTruthy();
|
||||
await waitFor(() => expect(screen.getByText(en.gardener.notKept)).toBeTruthy());
|
||||
expect(error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('without a place to keep a gardener, the garden asks nothing', async () => {
|
||||
render(Shell, { rose: rose(undefined) });
|
||||
expect(await screen.findByRole('button', { name: en.rose.care })).toBeTruthy();
|
||||
expect(screen.queryByRole('heading', { name: en.gardener.question })).toBeNull();
|
||||
expect(screen.queryByRole('button', { name: en.gardener.change })).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -98,7 +98,7 @@ describe('the folded petal (day-sentence.md)', () => {
|
||||
it('with an empty library: no petal, and she says nothing about one', async () => {
|
||||
const q = quietMoment(MORNING);
|
||||
render(Rose, { wiring: wiring({ log: q.log, at: q.now, sentences: [] }), timeZone: ZONE });
|
||||
await screen.findByRole('button', { name: en.rose.water });
|
||||
await screen.findByRole('button', { name: en.rose.care });
|
||||
expect(screen.queryByRole('button', { name: en.rose.petal.open })).toBeNull();
|
||||
expect(bubble()).not.toContain('petal');
|
||||
});
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
import { careEvent, localDay, petalsOn, petalsToday, weedsOn, weedsToday, windOn } from '@rosea/engine';
|
||||
import type { CareEvent } from '@rosea/schema';
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/svelte';
|
||||
import { tick } from 'svelte';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { en } from '../src/copy/en.js';
|
||||
import Rose from '../src/rose/Rose.svelte';
|
||||
import type { RoseWiring } from '../src/rose/types.js';
|
||||
|
||||
// jsdom has no PointerEvent: without it a test pointer carries no coordinates. Every browser has one.
|
||||
if (typeof window.PointerEvent !== 'function') {
|
||||
class PointerEventPolyfill extends MouseEvent {
|
||||
readonly pointerId: number;
|
||||
readonly pointerType: string;
|
||||
constructor(type: string, init: PointerEventInit = {}) {
|
||||
super(type, init);
|
||||
this.pointerId = init.pointerId ?? 1;
|
||||
this.pointerType = init.pointerType ?? 'touch';
|
||||
}
|
||||
}
|
||||
Object.assign(window, { PointerEvent: PointerEventPolyfill });
|
||||
}
|
||||
|
||||
const ZONE = 'Europe/Prague';
|
||||
const ME = 'M'.repeat(87);
|
||||
const DAY = 86_400_000;
|
||||
const MINUTE = 60_000;
|
||||
/** 1 March 2026, local midnight in Prague (CET, before the clocks change). */
|
||||
const MARCH = Date.parse('2026-03-01T00:00:00+01:00');
|
||||
|
||||
function wiring(at: number, log: CareEvent[] = []): RoseWiring & { appended: CareEvent[] } {
|
||||
const appended: CareEvent[] = [];
|
||||
return {
|
||||
identity: async () => ({ publicKey: ME, kept: true }),
|
||||
loadCare: async () => log,
|
||||
appendCare: async (e) => void appended.push(e),
|
||||
sentences: [],
|
||||
loadOpened: async () => [],
|
||||
appendOpened: async () => undefined,
|
||||
clientVersion: '0.1.0',
|
||||
deviceZone: ZONE,
|
||||
now: () => at,
|
||||
pastKeys: async () => [],
|
||||
exportRose: async () => ({}),
|
||||
importRose: async () => ({ added: 0, petals: 0 }),
|
||||
saveFile: () => undefined,
|
||||
keeping: { persisted: async () => false, persist: async () => true },
|
||||
installHint: false,
|
||||
appended
|
||||
};
|
||||
}
|
||||
|
||||
/** The first morning in March for which `has` holds. */
|
||||
function morningWhen(has: (day: string) => boolean): number {
|
||||
for (let i = 0; i < 27; i++) {
|
||||
const at = MARCH + i * DAY + 9 * 60 * MINUTE;
|
||||
if (has(localDay(at, ZONE))) return at;
|
||||
}
|
||||
throw new Error('no such day in March');
|
||||
}
|
||||
|
||||
/**
|
||||
* A pointer moving from a to b on `target`, then let go on the scene, as a finger does. jsdom stamps
|
||||
* events with the real clock, so `ms` is waited for real when a gesture's speed matters.
|
||||
*/
|
||||
async function gesture(target: Element, a: [number, number], b: [number, number], ms = 0, steps = 6): Promise<void> {
|
||||
const scene = screen.getByRole('group', { name: en.scene.planet });
|
||||
await fireEvent.pointerDown(target, { pointerId: 1, clientX: a[0], clientY: a[1] });
|
||||
for (let i = 1; i <= steps; i++) {
|
||||
if (ms > 0) await new Promise((r) => setTimeout(r, ms / steps));
|
||||
const x = a[0] + ((b[0] - a[0]) * i) / steps, y = a[1] + ((b[1] - a[1]) * i) / steps;
|
||||
await fireEvent.pointerMove(scene, { pointerId: 1, clientX: x, clientY: y });
|
||||
}
|
||||
await fireEvent.pointerUp(scene, { pointerId: 1, clientX: b[0], clientY: b[1] });
|
||||
await tick();
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
vi.unstubAllGlobals();
|
||||
cleanup();
|
||||
});
|
||||
|
||||
describe('her planet (planet-garden.md)', () => {
|
||||
it('tapping her opens the ring of what she needs, with Touch her; Escape closes it and focus comes back to her', async () => {
|
||||
render(Rose, { wiring: wiring(morningWhen((d) => !weedsOn(ME, d) && !petalsOn(ME, d))), timeZone: ZONE });
|
||||
const her = await screen.findByRole('button', { name: en.rose.care });
|
||||
expect(her.getAttribute('aria-expanded')).toBe('false');
|
||||
await fireEvent.keyDown(her, { key: 'Enter' });
|
||||
await tick();
|
||||
const ring = screen.getByRole('group', { name: en.scene.ring });
|
||||
expect(her.getAttribute('aria-expanded')).toBe('true');
|
||||
expect(document.activeElement?.textContent).toBe(en.rose.water);
|
||||
expect(screen.getByRole('button', { name: en.rose.touch.label })).toBeTruthy();
|
||||
expect(screen.queryByRole('button', { name: en.rose.weed })).toBeNull();
|
||||
await fireEvent.keyDown(ring, { key: 'Escape' });
|
||||
await tick();
|
||||
expect(screen.queryByRole('group', { name: en.scene.ring })).toBeNull();
|
||||
expect(document.activeElement).toBe(her);
|
||||
});
|
||||
|
||||
it('weeds: each one swiped up comes out; only when the last is out is it one act of care', async () => {
|
||||
const at = morningWhen((d) => weedsOn(ME, d));
|
||||
const w = wiring(at);
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
await screen.findByRole('button', { name: en.rose.care });
|
||||
const n = weedsToday(ME, localDay(at, ZONE));
|
||||
expect(screen.getAllByRole('img', { name: en.scene.weed })).toHaveLength(n);
|
||||
|
||||
// A sideways swipe does not pull it.
|
||||
await gesture(screen.getAllByRole('img', { name: en.scene.weed })[0]!, [200, 180], [280, 175]);
|
||||
expect(screen.getAllByRole('img', { name: en.scene.weed })).toHaveLength(n);
|
||||
|
||||
for (let pulled = 1; pulled <= n; pulled++) {
|
||||
await gesture(screen.getAllByRole('img', { name: en.scene.weed })[0]!, [200, 180], [202, 110]);
|
||||
expect(w.appended).toHaveLength(pulled === n ? 1 : 0);
|
||||
}
|
||||
expect(w.appended[0]?.act).toBe('weed');
|
||||
});
|
||||
|
||||
it('fallen petals: one sweep across all of them gathers them; a short swipe does not', async () => {
|
||||
const at = morningWhen((d) => petalsOn(ME, d) && !weedsOn(ME, d));
|
||||
// Petals fall only once she has opened: four earlier days of helpful watering.
|
||||
const opened = [4, 3, 2, 1].map((d) => careEvent({ now: at - d * DAY, timeZone: ZONE, from: ME, to: ME, act: 'water', amount: 0.5, clientVersion: '0.1.0' }));
|
||||
const w = wiring(at, opened);
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
await screen.findByRole('button', { name: en.rose.care });
|
||||
expect(screen.getAllByRole('img', { name: en.scene.petals })).toHaveLength(petalsToday(ME, localDay(at, ZONE)));
|
||||
const scene = screen.getByRole('group', { name: en.scene.planet });
|
||||
await gesture(scene, [200, 160], [230, 160]);
|
||||
expect(w.appended).toEqual([]);
|
||||
await gesture(scene, [180, 160], [320, 170]);
|
||||
expect(w.appended.map((e) => e.act)).toEqual(['petals']);
|
||||
});
|
||||
|
||||
it('wind: the windbreak dragged to her windward side is shade; dropped elsewhere it goes back', async () => {
|
||||
let at = 0;
|
||||
for (let i = 0; i < 27 && !at; i++) {
|
||||
const day = localDay(MARCH + i * DAY + 12 * 60 * MINUTE, ZONE);
|
||||
const wind = windOn(ME, day);
|
||||
if (wind && !petalsOn(ME, day)) at = MARCH + i * DAY + (wind[0] + 10) * MINUTE;
|
||||
}
|
||||
expect(at).toBeGreaterThan(0);
|
||||
const w = wiring(at);
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
const windbreak = await screen.findByRole('img', { name: en.scene.windbreak });
|
||||
await gesture(windbreak, [258, 250], [330, 380]);
|
||||
expect(w.appended).toEqual([]);
|
||||
await gesture(screen.getByRole('img', { name: en.scene.windbreak }), [258, 250], [140, 150]);
|
||||
expect(w.appended.map((e) => e.act)).toEqual(['shade']);
|
||||
});
|
||||
|
||||
it('the can: pressed and tilted far, it pours faster than a steady hold', async () => {
|
||||
const at = morningWhen(() => true);
|
||||
const w = wiring(at);
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
const can = await screen.findByRole('img', { name: en.scene.can });
|
||||
vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval'] });
|
||||
const scene = screen.getByRole('group', { name: en.scene.planet });
|
||||
await fireEvent.pointerDown(can, { pointerId: 1, clientX: 100, clientY: 220 });
|
||||
await fireEvent.pointerMove(scene, { pointerId: 1, clientX: 260, clientY: 220 });
|
||||
vi.advanceTimersByTime(1000);
|
||||
await fireEvent.pointerUp(scene, { pointerId: 1, clientX: 260, clientY: 220 });
|
||||
vi.useRealTimers();
|
||||
await tick();
|
||||
expect(w.appended[0]?.act).toBe('water');
|
||||
// A steady hold pours a third of a can in a second; fully tilted pours half again as fast.
|
||||
expect(w.appended[0]?.amount).toBeGreaterThan(0.45);
|
||||
});
|
||||
|
||||
it('a slow stroke across her petals touches her; nothing is written', async () => {
|
||||
const w = wiring(morningWhen(() => true));
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
const her = await screen.findByRole('button', { name: en.rose.care });
|
||||
await gesture(her, [170, 100], [200, 104], 500);
|
||||
expect(document.querySelector('.bubble')?.textContent).toBe(en.rose.touch.fond[0]);
|
||||
expect(w.appended).toEqual([]);
|
||||
expect(screen.queryByRole('group', { name: en.scene.ring })).toBeNull();
|
||||
});
|
||||
|
||||
it('with reduced motion the gardener does not walk', async () => {
|
||||
vi.stubGlobal('matchMedia', (q: string) => ({ matches: q.includes('reduce'), media: q, addEventListener: () => undefined, removeEventListener: () => undefined }));
|
||||
render(Rose, { wiring: wiring(morningWhen(() => true)), timeZone: ZONE });
|
||||
await screen.findByRole('button', { name: en.rose.care });
|
||||
expect(document.querySelector('.planet')?.classList.contains('reduced')).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -44,8 +44,16 @@ function wiring(over: Partial<RoseWiring> & { log?: CareEvent[]; at?: number } =
|
||||
}
|
||||
const water = (now: number, amount: number): CareEvent => careEvent({ now, timeZone: ZONE, from: ME, to: ME, act: 'water', amount, clientVersion: '0.1.0' });
|
||||
|
||||
/** Opens the ring of care, as a tap on her, or Enter on her, does (planet-garden.md G7). */
|
||||
async function openRing(): Promise<void> {
|
||||
if (screen.queryByRole('group', { name: en.scene.ring })) return;
|
||||
await fireEvent.keyDown(await screen.findByRole('button', { name: en.rose.care }), { key: 'Enter' });
|
||||
await tick();
|
||||
}
|
||||
|
||||
/** Holds the Water button for `ms`, with the pour's own timer under control. */
|
||||
async function hold(ms: number, how: 'pointer' | 'keyboard' = 'pointer'): Promise<void> {
|
||||
await openRing();
|
||||
const button = screen.getByRole('button', { name: en.rose.water });
|
||||
vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval'] });
|
||||
try {
|
||||
@@ -79,7 +87,7 @@ describe('the rose', () => {
|
||||
it('hold Water: the leaves lift while pouring; let go and it is one act of care, and she thanks you', async () => {
|
||||
const w = wiring();
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
await screen.findByRole('img');
|
||||
await screen.findByRole('img', { name: /^The rose/ });
|
||||
await hold(1500); // half a can
|
||||
expect(screen.getByRole('status').textContent).toBe(en.rose.leavesLift);
|
||||
await release();
|
||||
@@ -95,7 +103,7 @@ describe('the rose', () => {
|
||||
|
||||
it('pouring too long says that is plenty', async () => {
|
||||
render(Rose, { wiring: wiring({ log: [water(MORNING - 60_000, 0.5)] }), timeZone: ZONE });
|
||||
await screen.findByRole('img');
|
||||
await screen.findByRole('img', { name: /^The rose/ });
|
||||
await hold(3000);
|
||||
expect(screen.getByRole('status').textContent).toBe(en.rose.plenty);
|
||||
});
|
||||
@@ -103,7 +111,7 @@ describe('the rose', () => {
|
||||
it('pours with the keyboard too: hold Space, let go', async () => {
|
||||
const w = wiring();
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
await screen.findByRole('img');
|
||||
await screen.findByRole('img', { name: /^The rose/ });
|
||||
await hold(1200, 'keyboard');
|
||||
await release('keyboard');
|
||||
expect(w.appended[0]).toMatchObject({ act: 'water', amount: 0.4 });
|
||||
@@ -114,6 +122,7 @@ describe('the rose', () => {
|
||||
while (!weedsOn(ME, localDay(day, ZONE))) day += DAY;
|
||||
const w = wiring({ at: day });
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
await openRing();
|
||||
await fireEvent.click(await screen.findByRole('button', { name: en.rose.weed }));
|
||||
expect(w.appended[0]?.act).toBe('weed');
|
||||
await waitFor(() => expect(screen.queryByRole('button', { name: en.rose.weed })).toBeNull());
|
||||
@@ -122,7 +131,8 @@ describe('the rose', () => {
|
||||
while (weedsOn(ME, localDay(clear, ZONE))) clear += DAY;
|
||||
cleanup();
|
||||
render(Rose, { wiring: wiring({ at: clear }), timeZone: ZONE });
|
||||
await screen.findByRole('img');
|
||||
await screen.findByRole('img', { name: /^The rose/ });
|
||||
await openRing();
|
||||
expect(screen.queryByRole('button', { name: en.rose.weed })).toBeNull();
|
||||
});
|
||||
|
||||
@@ -130,7 +140,7 @@ describe('the rose', () => {
|
||||
const log = [water(MORNING - 30 * DAY, 0.5)];
|
||||
render(Rose, { wiring: wiring({ log }), timeZone: ZONE });
|
||||
const img = await screen.findByRole('img', { name: /waiting/ });
|
||||
expect(img.className).toContain('turned');
|
||||
expect(img.getAttribute('class')).toContain('turned');
|
||||
expect(screen.getByText(new RegExp(`^${en.rose.says.back}`))).toBeTruthy();
|
||||
await fireEvent.click(screen.getByRole('button', { name: en.rose.numbers }));
|
||||
expect(document.getElementById('rose-numbers')?.textContent).toContain(en.rose.warmthDays(0));
|
||||
@@ -141,7 +151,7 @@ describe('the rose', () => {
|
||||
const error = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
||||
const w = wiring({ appendCare: () => Promise.reject(new Error('IndexedDB blocked')) });
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
await screen.findByRole('img');
|
||||
await screen.findByRole('img', { name: /^The rose/ });
|
||||
await hold(1500);
|
||||
await release();
|
||||
expect(await screen.findByText(en.rose.says.thanks)).toBeTruthy();
|
||||
@@ -165,7 +175,7 @@ if (typeof File.prototype.text !== 'function') {
|
||||
describe('keep her safe (keep-her-safe.md)', () => {
|
||||
const OLD = 'O'.repeat(87);
|
||||
const open = async (): Promise<void> => {
|
||||
await screen.findByRole('img');
|
||||
await screen.findByRole('img', { name: /^The rose/ });
|
||||
await fireEvent.click(screen.getByRole('button', { name: en.rose.safe.title }));
|
||||
};
|
||||
|
||||
|
||||
@@ -39,9 +39,18 @@ function wiring(log: CareEvent[] = []): RoseWiring & { clock: { now: number }; w
|
||||
|
||||
const bubble = (): string => document.querySelector('.bubble')?.textContent ?? '';
|
||||
|
||||
/** Opens the ring of care, where Touch her lives (planet-garden.md G7). */
|
||||
async function openRing(): Promise<HTMLElement> {
|
||||
if (!screen.queryByRole('group', { name: en.scene.ring })) {
|
||||
await fireEvent.keyDown(await screen.findByRole('button', { name: en.rose.care }), { key: 'Enter' });
|
||||
await tick();
|
||||
}
|
||||
return screen.getByRole('button', { name: en.rose.touch.label });
|
||||
}
|
||||
|
||||
async function touchAt(w: ReturnType<typeof wiring>, at: number): Promise<void> {
|
||||
w.clock.now = at;
|
||||
await fireEvent.click(screen.getByRole('button', { name: en.rose.touch.label }));
|
||||
await fireEvent.click(await openRing());
|
||||
await tick();
|
||||
}
|
||||
|
||||
@@ -54,7 +63,7 @@ describe('touching her (thorns.md)', () => {
|
||||
it('a touch is answered fondly, then her usual line returns; nothing is written', async () => {
|
||||
const w = wiring();
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
await screen.findByRole('button', { name: en.rose.touch.label });
|
||||
await openRing();
|
||||
const usual = bubble();
|
||||
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
|
||||
await touchAt(w, MORNING);
|
||||
@@ -70,7 +79,7 @@ describe('touching her (thorns.md)', () => {
|
||||
it('three quick taps: Gently. I have thorns. Taps while she rests change nothing', async () => {
|
||||
const w = wiring();
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
await screen.findByRole('button', { name: en.rose.touch.label });
|
||||
await openRing();
|
||||
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
|
||||
await touchAt(w, MORNING);
|
||||
await touchAt(w, MORNING + 500);
|
||||
@@ -84,7 +93,7 @@ describe('touching her (thorns.md)', () => {
|
||||
it('a held key is one touch, not a rush', async () => {
|
||||
const w = wiring();
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
const button = await screen.findByRole('button', { name: en.rose.touch.label });
|
||||
const button = await openRing();
|
||||
const repeat = new KeyboardEvent('keydown', { key: 'Enter', repeat: true, cancelable: true, bubbles: true });
|
||||
button.dispatchEvent(repeat);
|
||||
expect(repeat.defaultPrevented).toBe(true);
|
||||
@@ -102,7 +111,7 @@ describe('touching her (thorns.md)', () => {
|
||||
w.clock.now = MORNING + 25 * DAY + 3 * 3_600_000;
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
const img = await screen.findByRole('img', { name: /full bloom/ });
|
||||
expect(img.getAttribute('alt')).not.toMatch(/blushing/);
|
||||
expect(img.getAttribute('aria-label')).not.toMatch(/blushing/);
|
||||
await touchAt(w, w.clock.now);
|
||||
expect(screen.getByRole('img', { name: /full bloom, blushing/ })).toBeTruthy();
|
||||
});
|
||||
|
||||
@@ -69,6 +69,8 @@ describe('two tabs, one garden (two-tabs.md)', () => {
|
||||
it("this tab's own care, still being written, is not lost when another tab's news arrives first", async () => {
|
||||
const w = roseWiring();
|
||||
render(Rose, { wiring: w, timeZone: ZONE });
|
||||
// The ring of care opens on her (planet-garden.md G7); Water is in it.
|
||||
await fireEvent.keyDown(await screen.findByRole('button', { name: en.rose.care }), { key: 'Enter' });
|
||||
const button = await screen.findByRole('button', { name: en.rose.water });
|
||||
vi.useFakeTimers({ toFake: ['setInterval', 'clearInterval'] });
|
||||
await fireEvent.pointerDown(button, { pointerId: 1 });
|
||||
|
||||
Reference in New Issue
Block a user