[ui] Thorns: Merge touching her gently
This commit is contained in:
@@ -8,6 +8,7 @@ One row per feature, with its analysis document (CLAUDE.md §5.1). Gaps live in
|
||||
| Workspace, contracts, gates, PWA shell | 0 | Merged to `main` 2026-11-01 (`d11d242`); built, not deployed. Phase 0 gate still open | [phase0-workspace.md](features/phase0-workspace.md) | [feature-phase0-workspace.md](reviews/feature-phase0-workspace.md) |
|
||||
| Roadmap and gameplay docs, read against the code | 0 | Merged 2026-11-01; Q1–Q7 answered by the author | — | [docs-roadmap-gameplay.md](reviews/docs-roadmap-gameplay.md) |
|
||||
| The Letter slot: page at `#letter`, empty `docs/LETTER.md` | 0 | Merged to `main`; built, not deployed. Invisible until the author writes | [letter-slot.md](features/letter-slot.md) | [feature-letter-slot.md](reviews/feature-letter-slot.md) |
|
||||
| Thorns: touch her; a rush of taps, and she says she has thorns | 1 | Merged to `main`; built, not deployed | [thorns.md](features/thorns.md) | [feature-thorns.md](reviews/feature-thorns.md) |
|
||||
| The day's sentence: her folded petal, one a day, never lost, best at sunset; candidates and `library:verify` | 1 | Merged to `main`; built, not deployed. Invisible until the author verifies sentences | [day-sentence.md](features/day-sentence.md) | [feature-day-sentence.md](reviews/feature-day-sentence.md) |
|
||||
| The in-game sunset: move the chair, half a minute of silence, then the real sunset's time | 1 | Merged to `main`; built, not deployed | [chair-sunset.md](features/chair-sunset.md) | [feature-chair-sunset.md](reviews/feature-chair-sunset.md) |
|
||||
| A calm refresh: a waiting new version is offered in one line, never swapped in by itself | 0 | Merged to `main`; built, not deployed | [calm-refresh.md](features/calm-refresh.md) | [feature-calm-refresh.md](reviews/feature-calm-refresh.md) |
|
||||
|
||||
@@ -58,6 +58,7 @@ sentences). Nothing in Phase 1 is visible to the player yet.
|
||||
| ~~G1.4~~ | ~~No rose~~ | Closed 2026-11-02 on `feature/rose-care`: care with a touch of skill (water by holding, shade, weeds, petals), growth from days of care, drift, moods, her numbers; the care log in IndexedDB, replayed by the engine. Tuning R2/R4/R5/R6 is the author's. 7 of 7 put-back bugs caught after two test holes were closed. |
|
||||
| ~~G1.5~~ | ~~The day's sentence and the folded petal~~ | Closed 2026-11-02 on `feature/day-sentence`, for the code: `engine/petal` (5 properties: never lost, verified-later never swaps it, one a day, no repeat until all opened), the `sentence-opened` event, the rose file v2, the petal in the garden; e2e opens one in a fixture build and reloads. 9 of 9 put-back bugs caught. **The shipped app shows no petal until the author verifies sentences (G0.18).** |
|
||||
| ~~G1.6~~ | ~~The in-game sunset: move the chair, watch it again~~ | Closed 2026-11-02 on `feature/chair-sunset`: half a minute with nothing to press, then the real sunset's time; Escape and a tap leave; the offline suite watches one with the server gone. 4 of 4 put-back bugs caught. |
|
||||
| ~~G1.7~~ | ~~Thorns were on the roadmap but undesigned~~ | Closed 2026-11-02 on `feature/thorns`, as the author chose: thorns teach gentleness. `engine/touch` (2 properties: spaced taps are never a rush; one blush a visit); a tremor is one touch; nothing recorded. 6 of 6 put-back bugs caught. |
|
||||
| G1.3 | Towns have no Czech names (*Vídeň*) | Open. Natural Earth has none; arrives with Czech copy. |
|
||||
|
||||
## Design questions — answered
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
# Thorns — touching her gently
|
||||
|
||||
Status: built on `feature/thorns`. ROADMAP Phase 1: *one rose with her face: … moods, thorns …*.
|
||||
CLAUDE.md §1: *alive and a little vain, with thorns that are part of her.* STYLE.md: *the thorns are
|
||||
part of her and never look threatening.* Decided by the author 2026-11-02: **thorns teach gentleness.**
|
||||
Review: [`feature-thorns.md`](../reviews/feature-thorns.md).
|
||||
|
||||
## 1. Why and what, in the player's terms
|
||||
|
||||
The player can touch her: tap her picture (or Tab to it and press Enter).
|
||||
|
||||
- **A touch** — she answers fondly: *Oh. Hello.*, then *That tickles.* The first touch of a visit makes
|
||||
her blush (seen in full bloom, where her face shows moods).
|
||||
- **A rush of touches** — three quick taps within two seconds — she says *Gently. I have thorns.* and
|
||||
rests for a few seconds; taps meanwhile do nothing. Then she is as before.
|
||||
- **Nothing is recorded.** No event, no number, no penalty, nothing she remembers. A touch is not care:
|
||||
it does not water her, does not count as a day of care, does not move anything she has earned.
|
||||
|
||||
Why: the fox (Phase 2) is tamed by touch, and taming needs patience. The rose rehearses it first, kindly,
|
||||
in the one place where getting it wrong costs nothing.
|
||||
|
||||
## 2. Technical architecture
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
ui["packages/ui<br/>Rose.svelte: a Touch her button over her picture"] -->|"now, state"| engine["packages/engine<br/>touch/touch.ts: touch()"]
|
||||
engine -->|"fond | thorns | resting, next state"| ui
|
||||
```
|
||||
|
||||
| # | Decision | Why |
|
||||
|:--|:--|:--|
|
||||
| T1 | The rule lives in `engine/touch` as a pure function of the visit's recent touches and the clock. | Components decide nothing (CLAUDE.md §7); the fox reuses it. |
|
||||
| T2 | **A rush** is `TOUCH.rushCount` (3) touches within `TOUCH.rushMs` (2 s). Touches closer than `TOUCH.sameMs` (250 ms) to the one before count as one. | A tremor, a bounce or a double tap must never be told *gently*. Three separate, deliberate taps in two seconds is fussing. |
|
||||
| T3 | After the thorns line she **rests** `TOUCH.restMs` (4 s): touches change nothing, then all is as before. | A boundary, kept briefly and then let go; no grudge. |
|
||||
| T4 | **Nothing is stored**, so the blush comes on the first touch of a *visit* (the author's option said *once a day*; a day would need a record, and the option also said nothing is recorded — the second wins). | *Progress never disappears* has nothing to act on; no number can grow from touching. |
|
||||
| T5 | Her picture stays an image with its description; the touch is a separate button laid over it, labelled *Touch her*. | The picture keeps its meaning for a screen reader; the touch is keyboard-operable. |
|
||||
| T6 | Her touch words take the speech bubble for the rest time, then her usual line returns. | One line at a time. |
|
||||
|
||||
## 3. Risk analysis
|
||||
|
||||
| Risk | Answer |
|
||||
|:--|:--|
|
||||
| **Being scolded**: *Gently* read as a reproach, for someone already fragile. | It needs three deliberate taps (T2), is said once, never repeated while she rests, never mentioned again, never recorded. It is her voice about herself (*I have thorns*), not about the player. |
|
||||
| A player with a tremor or a motor difficulty. | T2: taps within 250 ms are one touch. Keyboard repeat (holding Enter) is ignored too. |
|
||||
| **Dependence**: touching as a fidget loop. | It gives nothing: no blush after the first, no number, no reward for more. |
|
||||
| Privacy, reachability, offline | Nothing stored or sent; works offline as everything else. |
|
||||
|
||||
## 4. Gap analysis
|
||||
|
||||
Closes the last Phase 1 roadmap item without a design (*thorns*). Tuning in `TOUCH` is the author's.
|
||||
|
||||
## 5. Verification matrix
|
||||
|
||||
| Case | Kind | Where |
|
||||
|:--|:--|:--|
|
||||
| One touch: fond; second: fond; first of a visit: blush | unit | `engine/test/touch.test.ts`, `ui/test/touch.test.ts` |
|
||||
| Three taps within 2 s: thorns; then resting for 4 s; then fond again | unit | same |
|
||||
| Taps within 250 ms count as one; three such bursts spaced out are not a rush | unit | engine |
|
||||
| **Property:** taps a second or more apart are never a rush (three span at least 2 s) | property | engine |
|
||||
| **Property:** the state never grows past `rushCount` touches | property | engine |
|
||||
| Keyboard: the button is reachable; held Enter (repeat) is one touch | unit | ui |
|
||||
| A touch appends no event | unit | ui |
|
||||
| Built app: touch, rush, axe | e2e | `e2e/shell.spec.ts` |
|
||||
@@ -0,0 +1,43 @@
|
||||
# Review — `feature/thorns`
|
||||
|
||||
Adversarial self-review (CLAUDE.md §5.3). Analysis: [`features/thorns.md`](../features/thorns.md).
|
||||
Reviewed 2026-11-02 on Node 22.11.0, Windows 10. There is no PR: the only remote is Gitea.
|
||||
|
||||
## Gates
|
||||
|
||||
Counts are on the merge; HANDOVER repeats them. New: engine +7 (2 properties), ui +4, e2e +1
|
||||
(touch, rush, axe with the touch focused).
|
||||
|
||||
**The app changed** (CLAUDE.md §5.4): a *Touch her* button over her picture. Rebuilt by the e2e and
|
||||
offline runs; **not deployed** (G0.13). Seen in the built app at phone width: a touch answered
|
||||
*That tickles.*, three taps 400 ms apart gave *Gently. I have thorns.*, and the keyboard focus ring
|
||||
is a rounded frame round her picture.
|
||||
|
||||
## Bug drills
|
||||
|
||||
| Put back | Result |
|
||||
|:--|:--|
|
||||
| A tremor counts as fussing | CAUGHT |
|
||||
| A rush never brings the thorns | CAUGHT: 3 |
|
||||
| She never rests | CAUGHT |
|
||||
| Every touch makes her blush | CAUGHT: 2 |
|
||||
| A touch is written as care | CAUGHT: 2 |
|
||||
| A held key is a rush | CAUGHT |
|
||||
|
||||
## Findings
|
||||
|
||||
| # | Area | Finding | Resolution |
|
||||
|:--|:--|:--|:--|
|
||||
| 1 | Soul | *Gently* can be read as a reproach by someone already fragile. | Three separate, deliberate taps in two seconds; said once; she rests and then it is gone; nothing remembers it. Her words are about herself. Accepted for the author's play test; the line is in `copy/en.ts`. |
|
||||
| 2 | Accessibility / soul | A tremor or a bouncing finger could be told *gently*. | Taps within 250 ms are one touch (T2), and a held key is one; both drilled. Not tried with a real tremor or switch access. |
|
||||
| 3 | Design | The author's option said *a blush once a day*, and also *nothing is recorded*. Those cannot both hold. | Nothing is recorded; the blush is once per visit (T4). Said plainly in the analysis. |
|
||||
| 4 | Design | The blush shows on her face only in full bloom, as every mood does; before that only her words answer. | Accepted: the stand-ins draw moods for the full bloom only (STYLE.md). |
|
||||
| 5 | Correctness | The clock moved back while she rests. | She never rests longer than `restMs` (tested). |
|
||||
| 6 | Correctness | Two tabs: each has its own touches. | Nothing is shared or stored; harmless. |
|
||||
| 7 | Test honesty | A frozen e2e clock (`setFixedTime`) would make three clicks one touch, and the rush test would fail for the wrong reason. | The e2e drives the clock with `clock.install` and `runFor`. |
|
||||
| 8 | Dependence | Touching as a fidget. | It gives nothing after the first blush; no number grows. |
|
||||
| — | Privacy, reachability, offline | Looked; nothing is stored, sent or shared. | — |
|
||||
|
||||
## What was not verified
|
||||
|
||||
- A screen reader announcing the bubble change; switch access; a real phone's touch timing.
|
||||
+9
-2
@@ -12,8 +12,8 @@ Rewritten at the end of each session (CLAUDE.md §5.1).
|
||||
Gitea hashes match. Analysis: [`.agents/features/phase0-workspace.md`](.agents/features/phase0-workspace.md).
|
||||
Review, with counts and the mutation results:
|
||||
[`.agents/reviews/feature-phase0-workspace.md`](.agents/reviews/feature-phase0-workspace.md).
|
||||
- **Gates:** all pass on this machine. Unit tests: 447 (cpu-guard 13, identity 5, schema 19,
|
||||
content 80, storage 58, art-prep 56, engine 161, ui 55). E2E: 18. Offline: 1. `lint:copy`: 21 files, 0 problems.
|
||||
- **Gates:** all pass on this machine. Unit tests: 458 (cpu-guard 13, identity 5, schema 19,
|
||||
content 80, storage 58, art-prep 56, engine 168, ui 59). E2E: 19. Offline: 1. `lint:copy`: 21 files, 0 problems.
|
||||
`validate:library`: 13 of 13 fixtures rejected; 78 candidates pass.
|
||||
- **Built, not deployed:** there is no host yet.
|
||||
- **Roadmap and gameplay docs:** `docs/ROADMAP.md` and `docs/GAMEPLAY.md` are on
|
||||
@@ -88,6 +88,13 @@ Rewritten at the end of each session (CLAUDE.md §5.1).
|
||||
`pnpm library:verify <id…> --by Mark`. Analysis:
|
||||
[`.agents/features/day-sentence.md`](.agents/features/day-sentence.md). Review:
|
||||
[`.agents/reviews/feature-day-sentence.md`](.agents/reviews/feature-day-sentence.md).
|
||||
- **Thorns (Phase 1):** merged to `main`, as the author chose (thorns teach gentleness). *Touch her*
|
||||
over her picture: a fond answer, a blush on the first touch of a visit; three quick taps and she
|
||||
says *Gently. I have thorns.* and rests four seconds. A tremor's taps count as one. Nothing is
|
||||
recorded. Tuning in `TOUCH` (`packages/engine/src/touch/touch.ts`). Review:
|
||||
[`.agents/reviews/feature-thorns.md`](.agents/reviews/feature-thorns.md).
|
||||
- **Phase 1 is built in code.** What remains of it is the author's: verified sentences (the petal
|
||||
appears with them), hosting (G0.13), and the gate itself — two weeks of daily play on a phone.
|
||||
|
||||
**Phase 0 is not finished.** The roadmap's Phase 0 is more than the workspace. Its
|
||||
gate needs 60 verified sentences (G0.18) and one illustration through the art
|
||||
|
||||
@@ -214,6 +214,24 @@ test.describe('the rose, in Prague at 08:00 on 1 March 2026', () => {
|
||||
expect(requests.filter((url) => !url.startsWith(server.origin + '/'))).toEqual([]);
|
||||
});
|
||||
|
||||
test('touch her: a fond answer; three quick taps, and she says she has thorns (thorns.md)', async ({ page }) => {
|
||||
// The clock is driven, not frozen: taps at one frozen instant would be one touch.
|
||||
await page.clock.install({ time: MORNING });
|
||||
await open(page);
|
||||
const touch = page.getByRole('button', { name: en.rose.touch.label });
|
||||
await touch.click();
|
||||
await expect(page.locator('.bubble')).toHaveText(en.rose.touch.fond[0]!);
|
||||
await page.clock.runFor(5_000);
|
||||
for (let i = 0; i < 3; i++) {
|
||||
await touch.click();
|
||||
await page.clock.runFor(400);
|
||||
}
|
||||
await expect(page.locator('.bubble')).toHaveText(en.rose.touch.thorns);
|
||||
await expect(page.getByRole('img', { name: 'The rose, a bud.' })).toBeVisible();
|
||||
await touch.focus();
|
||||
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
||||
});
|
||||
|
||||
test('the rose and her care have no accessibility violations', async ({ page }) => {
|
||||
await page.clock.setFixedTime(MORNING);
|
||||
await open(page);
|
||||
|
||||
@@ -7,3 +7,4 @@ export { invitation, nextInvitation, sunDay, type NamedPlace, type Place, type S
|
||||
export {
|
||||
goodMoment, newOpened, openedIdentity, PETAL, petalAt, petalOrder, sentenceOpened, type PetalNow, type PetalSentence
|
||||
} from './petal/petal.js';
|
||||
export { touch, TOUCH, UNTOUCHED, type TouchReply, type TouchState } from './touch/touch.js';
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Touching her (.agents/features/thorns.md). Pure: the visit's recent touches and the
|
||||
* clock are parameters. Nothing here is recorded: a touch is not care, and no number
|
||||
* grows from it.
|
||||
*/
|
||||
|
||||
/** The author's to tune (thorns.md T2, T3). */
|
||||
export const TOUCH = {
|
||||
/** This many touches… */
|
||||
rushCount: 3,
|
||||
/** …within this long is a rush: she says she has thorns. */
|
||||
rushMs: 2000,
|
||||
/** Touches closer than this to the one before are one touch: a tremor or a bounce is never fussing. */
|
||||
sameMs: 250,
|
||||
/** After the thorns line she rests this long; touches meanwhile change nothing. */
|
||||
restMs: 4000
|
||||
} as const;
|
||||
|
||||
export interface TouchState {
|
||||
/** The touches that still count towards a rush, oldest first. */
|
||||
readonly recent: readonly number[];
|
||||
/** Until when she rests after a rush; 0 when she is not resting. */
|
||||
readonly restUntil: number;
|
||||
/** Whether a touch has already made her blush in this visit (T4). */
|
||||
readonly blushed: boolean;
|
||||
}
|
||||
|
||||
export const UNTOUCHED: TouchState = { recent: [], restUntil: 0, blushed: false };
|
||||
|
||||
export type TouchReply =
|
||||
/** A fond answer. `blush` only on the first of a visit. */
|
||||
| { readonly kind: 'fond'; readonly blush: boolean }
|
||||
| { readonly kind: 'thorns' }
|
||||
/** Resting after a rush, or the same touch again: nothing changes. */
|
||||
| { readonly kind: 'nothing' };
|
||||
|
||||
/** What a touch at `now` does, and the state after it. */
|
||||
export function touch(state: TouchState, now: number): { readonly reply: TouchReply; readonly state: TouchState } {
|
||||
// Resting; a clock that moved back never makes her rest longer than restMs.
|
||||
if (now < state.restUntil && state.restUntil - now <= TOUCH.restMs) return { reply: { kind: 'nothing' }, state };
|
||||
const last = state.recent.at(-1);
|
||||
if (last !== undefined && now - last >= 0 && now - last < TOUCH.sameMs) return { reply: { kind: 'nothing' }, state };
|
||||
|
||||
const recent = [...state.recent.filter((t) => now - t >= 0 && now - t < TOUCH.rushMs), now].slice(-TOUCH.rushCount);
|
||||
if (recent.length >= TOUCH.rushCount) {
|
||||
return { reply: { kind: 'thorns' }, state: { recent: [], restUntil: now + TOUCH.restMs, blushed: state.blushed } };
|
||||
}
|
||||
return { reply: { kind: 'fond', blush: !state.blushed }, state: { recent, restUntil: 0, blushed: true } };
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { touch, TOUCH, UNTOUCHED, type TouchReply, type TouchState } from '../src/touch/touch.js';
|
||||
|
||||
/** Touches at these moments, from no touch at all; the replies in order. */
|
||||
function replies(times: readonly number[], from: TouchState = UNTOUCHED): { replies: TouchReply['kind'][]; state: TouchState; all: TouchReply[] } {
|
||||
let state = from;
|
||||
const all: TouchReply[] = [];
|
||||
for (const t of times) {
|
||||
const next = touch(state, t);
|
||||
all.push(next.reply);
|
||||
state = next.state;
|
||||
}
|
||||
return { replies: all.map((r) => r.kind), state, all };
|
||||
}
|
||||
|
||||
const T0 = 1_000_000;
|
||||
|
||||
describe('a touch (thorns.md)', () => {
|
||||
it('is answered fondly, and only the first of a visit makes her blush', () => {
|
||||
const r = replies([T0, T0 + 5000, T0 + 10_000]);
|
||||
expect(r.all).toEqual([{ kind: 'fond', blush: true }, { kind: 'fond', blush: false }, { kind: 'fond', blush: false }]);
|
||||
});
|
||||
|
||||
it('three within two seconds: thorns, then she rests, then all is as before', () => {
|
||||
const r = replies([T0, T0 + 600, T0 + 1200, T0 + 1500, T0 + 1200 + TOUCH.restMs - 1, T0 + 1200 + TOUCH.restMs]);
|
||||
expect(r.replies).toEqual(['fond', 'fond', 'thorns', 'nothing', 'nothing', 'fond']);
|
||||
});
|
||||
|
||||
it('three touches spanning exactly two seconds are not a rush', () => {
|
||||
expect(replies([T0, T0 + 1000, T0 + 2000]).replies).toEqual(['fond', 'fond', 'fond']);
|
||||
});
|
||||
|
||||
it('touches closer than 250 ms to the one before are one touch: a tremor is never fussing', () => {
|
||||
const burst = (at: number): number[] => [at, at + 60, at + 120, at + 180];
|
||||
expect(replies([...burst(T0), ...burst(T0 + 1100)]).replies).toEqual(['fond', 'nothing', 'nothing', 'nothing', 'fond', 'nothing', 'nothing', 'nothing']);
|
||||
});
|
||||
|
||||
it('a clock moved back never makes her rest longer than the rest time', () => {
|
||||
const rushed = replies([T0, T0 + 500, T0 + 1000]);
|
||||
expect(rushed.replies.at(-1)).toBe('thorns');
|
||||
expect(touch(rushed.state, T0 - 3_600_000).reply.kind).toBe('fond');
|
||||
});
|
||||
|
||||
it('property: touches a second or more apart are never a rush', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.array(fc.integer({ min: 1000, max: 60_000 }), { minLength: 1, maxLength: 40 }), (gaps) => {
|
||||
let t = T0;
|
||||
const times = gaps.map((g) => (t += g));
|
||||
expect(replies(times).replies.every((k) => k === 'fond')).toBe(true);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it('property: whatever the taps, she keeps no more than a rush of them, and blushes at most once', () => {
|
||||
fc.assert(
|
||||
fc.property(fc.array(fc.integer({ min: 0, max: 3000 }), { maxLength: 60 }), (gaps) => {
|
||||
let t = T0;
|
||||
let state = UNTOUCHED;
|
||||
let blushes = 0;
|
||||
for (const g of gaps) {
|
||||
const next = touch(state, (t += g));
|
||||
if (next.reply.kind === 'fond' && next.reply.blush) blushes++;
|
||||
state = next.state;
|
||||
expect(state.recent.length).toBeLessThan(TOUCH.rushCount);
|
||||
}
|
||||
expect(blushes).toBeLessThanOrEqual(1);
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -50,6 +50,12 @@ export const en = {
|
||||
tooFull: 'That was a lot of water. I will be fine by tomorrow.'
|
||||
},
|
||||
notKept: 'This device could not keep today’s care, so it lasts only until the garden closes.',
|
||||
/** Touching her (thorns.md). Her thorns are about herself, never about the player. */
|
||||
touch: {
|
||||
label: 'Touch her',
|
||||
fond: ['Oh. Hello.', 'That tickles.'],
|
||||
thorns: 'Gently. I have thorns.'
|
||||
},
|
||||
/**
|
||||
* The day's sentence (day-sentence.md). She offers; she never counts, and never
|
||||
* mentions a day the petal was not opened.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
careEvent, goodMoment, localDay, petalAt, pour, roseAt, ROSE, sentenceOpened,
|
||||
type Mood, type PetalNow, type Place, type RoseNow, type Stage
|
||||
careEvent, goodMoment, localDay, petalAt, pour, roseAt, ROSE, sentenceOpened, touch, TOUCH, UNTOUCHED,
|
||||
type Mood, type PetalNow, type Place, type RoseNow, type Stage, type TouchState
|
||||
} from '@rosea/engine';
|
||||
import type { CareEvent, SentenceOpened } from '@rosea/schema';
|
||||
import { en } from '../copy/en.js';
|
||||
@@ -126,11 +126,35 @@
|
||||
}
|
||||
$effect(() => () => clearInterval(pourTimer));
|
||||
|
||||
// --- Touching her (thorns.md): nothing is recorded ----------------------
|
||||
let touchState = $state.raw<TouchState>(UNTOUCHED);
|
||||
let touchLine = $state('');
|
||||
let touchBlush = $state(false);
|
||||
let fondSaid = 0;
|
||||
let touchTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
function touchHer(): void {
|
||||
const { reply, state } = touch(touchState, wiring.now());
|
||||
touchState = state;
|
||||
if (reply.kind === 'nothing') return;
|
||||
const fond = en.rose.touch.fond;
|
||||
touchLine = reply.kind === 'thorns' ? en.rose.touch.thorns : (fond[fondSaid++ % fond.length] ?? '');
|
||||
if (reply.kind === 'fond' && reply.blush) touchBlush = true;
|
||||
clearTimeout(touchTimer);
|
||||
// Her words hold the bubble while she would rest, then her usual line returns (T6).
|
||||
touchTimer = setTimeout(() => {
|
||||
touchLine = '';
|
||||
touchBlush = false;
|
||||
}, TOUCH.restMs);
|
||||
}
|
||||
$effect(() => () => clearTimeout(touchTimer));
|
||||
|
||||
const isPourKey = (e: KeyboardEvent): boolean => e.key === ' ' || e.key === 'Enter';
|
||||
|
||||
// --- What she says: one line, or nothing --------------------------------
|
||||
const says = $derived.by(() => {
|
||||
if (!rose) return '';
|
||||
if (touchLine) return touchLine;
|
||||
const s = en.rose.says;
|
||||
if (rose.mood === 'blushing') return s.thanks;
|
||||
if (rose.mood === 'too-full') return s.tooFull;
|
||||
@@ -146,15 +170,30 @@
|
||||
return [rose.drift > 0 ? s.back : '', need || offer].filter(Boolean).join(' ');
|
||||
});
|
||||
|
||||
const picture = $derived(rose ? (rose.stage === 'full-bloom' ? MOOD_PICTURE[rose.mood] : STAGE_PICTURE[rose.stage]) : bud);
|
||||
const alt = $derived(rose ? en.rose.picture(en.rose.stageWords[rose.stage], en.rose.moodWords[rose.mood]) : '');
|
||||
// A touch's blush shows as her mood does: on her face in full bloom (thorns.md T4).
|
||||
const mood = $derived<Mood | null>(rose ? (touchBlush ? 'blushing' : rose.mood) : null);
|
||||
const picture = $derived(rose && mood ? (rose.stage === 'full-bloom' ? MOOD_PICTURE[mood] : STAGE_PICTURE[rose.stage]) : bud);
|
||||
const alt = $derived(rose && mood ? en.rose.picture(en.rose.stageWords[rose.stage], en.rose.moodWords[mood]) : '');
|
||||
const percent = (x: number): string => `${Math.round(Math.max(0, Math.min(1, x)) * 100)} %`;
|
||||
</script>
|
||||
|
||||
{#if rose}
|
||||
<section class="rose">
|
||||
<figure>
|
||||
<img src={picture} {alt} width="120" height="320" class:turned={rose.drift > 0} />
|
||||
<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}
|
||||
@@ -246,6 +285,19 @@
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import { careEvent, TOUCH } 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';
|
||||
|
||||
const ZONE = 'Europe/Prague';
|
||||
const ME = 'M'.repeat(87);
|
||||
const MORNING = Date.parse('2026-03-01T08:00:00+01:00');
|
||||
const DAY = 86_400_000;
|
||||
|
||||
/** A clock the test moves, and every write the rose tries. */
|
||||
function wiring(log: CareEvent[] = []): RoseWiring & { clock: { now: number }; writes: unknown[] } {
|
||||
const clock = { now: MORNING };
|
||||
const writes: unknown[] = [];
|
||||
return {
|
||||
identity: async () => ({ publicKey: ME, kept: true }),
|
||||
loadCare: async () => log,
|
||||
appendCare: async (e) => void writes.push(e),
|
||||
sentences: [],
|
||||
loadOpened: async () => [],
|
||||
appendOpened: async (e) => void writes.push(e),
|
||||
clientVersion: '0.1.0',
|
||||
deviceZone: ZONE,
|
||||
now: () => clock.now,
|
||||
pastKeys: async () => [],
|
||||
exportRose: async () => ({}),
|
||||
importRose: async () => ({ added: 0, petals: 0 }),
|
||||
saveFile: () => undefined,
|
||||
keeping: { persisted: async () => false, persist: async () => true },
|
||||
installHint: false,
|
||||
clock,
|
||||
writes
|
||||
};
|
||||
}
|
||||
|
||||
const bubble = (): string => document.querySelector('.bubble')?.textContent ?? '';
|
||||
|
||||
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 tick();
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
cleanup();
|
||||
});
|
||||
|
||||
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 });
|
||||
const usual = bubble();
|
||||
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
|
||||
await touchAt(w, MORNING);
|
||||
expect(bubble()).toBe(en.rose.touch.fond[0]);
|
||||
await touchAt(w, MORNING + 5000);
|
||||
expect(bubble()).toBe(en.rose.touch.fond[1]);
|
||||
vi.advanceTimersByTime(TOUCH.restMs);
|
||||
await tick();
|
||||
expect(bubble()).toBe(usual);
|
||||
expect(w.writes).toEqual([]);
|
||||
});
|
||||
|
||||
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 });
|
||||
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
|
||||
await touchAt(w, MORNING);
|
||||
await touchAt(w, MORNING + 500);
|
||||
await touchAt(w, MORNING + 1000);
|
||||
expect(bubble()).toBe(en.rose.touch.thorns);
|
||||
await touchAt(w, MORNING + 2000);
|
||||
expect(bubble()).toBe(en.rose.touch.thorns);
|
||||
expect(w.writes).toEqual([]);
|
||||
});
|
||||
|
||||
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 repeat = new KeyboardEvent('keydown', { key: 'Enter', repeat: true, cancelable: true, bubbles: true });
|
||||
button.dispatchEvent(repeat);
|
||||
expect(repeat.defaultPrevented).toBe(true);
|
||||
const first = new KeyboardEvent('keydown', { key: 'Enter', cancelable: true, bubbles: true });
|
||||
button.dispatchEvent(first);
|
||||
expect(first.defaultPrevented).toBe(false);
|
||||
});
|
||||
|
||||
it('in full bloom the first touch of a visit makes her blush; her picture keeps its description', async () => {
|
||||
// 25 days of helpful morning watering: full bloom.
|
||||
const log = Array.from({ length: 25 }, (_, i) =>
|
||||
careEvent({ now: MORNING + i * DAY, timeZone: ZONE, from: ME, to: ME, act: 'water', amount: 0.5, clientVersion: '0.1.0' })
|
||||
);
|
||||
const w = wiring(log);
|
||||
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/);
|
||||
await touchAt(w, w.clock.now);
|
||||
expect(screen.getByRole('img', { name: /full bloom, blushing/ })).toBeTruthy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user