[ui] DaySentence: Her folded petal, the words and their source; the library bundled after validation
This commit is contained in:
@@ -129,7 +129,7 @@
|
||||
<h1 bind:this={heading} tabindex="-1">{PRODUCT_NAME}</h1>
|
||||
<p>{en.shell.preparing}</p>
|
||||
{#if rose}
|
||||
<Rose wiring={rose} timeZone={roseZone} />
|
||||
<Rose wiring={rose} timeZone={roseZone} {place} />
|
||||
{/if}
|
||||
{#if sunset && (status === 'asking' || changing)}
|
||||
<SunsetPlace
|
||||
|
||||
@@ -50,6 +50,24 @@ 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.',
|
||||
/**
|
||||
* The day's sentence (day-sentence.md). She offers; she never counts, and never
|
||||
* mentions a day the petal was not opened.
|
||||
*/
|
||||
petal: {
|
||||
/** Said when she needs nothing else. */
|
||||
waiting: 'I am keeping a folded petal for you.',
|
||||
/** Around the real sunset (P4); in polar day and night the same words still hold. */
|
||||
goodMoment: 'The sun is low now. Would you open my petal?',
|
||||
/** After opening it at the good moment: the best moments send the player outside. */
|
||||
lookUp: 'Go and look at the sky. I will be here.',
|
||||
open: 'Open her petal',
|
||||
folded: 'A folded petal.',
|
||||
today: 'Today’s petal',
|
||||
remember: 'Do you remember this one?',
|
||||
source: (work: string, author: string | null, translation: string | null): string =>
|
||||
`${author ? `${author}, ` : ''}${work}${translation ? ` (${translation})` : ''}`
|
||||
},
|
||||
/** Keeping her (keep-her-safe.md). True and calm: a browser can clear a site's data. */
|
||||
safe: {
|
||||
title: 'Keep her safe',
|
||||
@@ -62,7 +80,8 @@ export const en = {
|
||||
save: 'Save her to a file',
|
||||
fileNote: 'The file holds her care and when it was given. It never holds your town.',
|
||||
bringBack: 'Bring her back from a file',
|
||||
broughtBack: (n: number): string => (n === 1 ? 'She is back, with 1 act of care.' : `She is back, with ${n} acts of care.`),
|
||||
broughtBack: (n: number): string =>
|
||||
n === 0 ? 'She is back.' : n === 1 ? 'She is back, with 1 act of care.' : `She is back, with ${n} acts of care.`,
|
||||
alreadyHere: 'Everything in that file is already here.',
|
||||
notARose: 'That file does not hold a rose.'
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
const file = input.files?.[0];
|
||||
if (!file) return;
|
||||
try {
|
||||
const { added } = await wiring.importRose(JSON.parse(await file.text()), currentKey);
|
||||
said = added === 0 ? en.rose.safe.alreadyHere : en.rose.safe.broughtBack(added);
|
||||
const { added, petals } = await wiring.importRose(JSON.parse(await file.text()), currentKey);
|
||||
said = added === 0 && petals === 0 ? en.rose.safe.alreadyHere : en.rose.safe.broughtBack(added);
|
||||
onrestored();
|
||||
} catch (error) {
|
||||
// A wrong file is an ordinary thing to choose; the player is told calmly, the console fully.
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<script lang="ts">
|
||||
import type { PetalNow } from '@rosea/engine';
|
||||
import type { HopeSentence } from '@rosea/schema';
|
||||
import { tick } from 'svelte';
|
||||
import { en } from '../copy/en.js';
|
||||
// The art board's stand-in until real art is accepted (docs/ART.md).
|
||||
import folded from '../../../../art/placeholders/petal-folded.svg?url';
|
||||
|
||||
/**
|
||||
* The rose's folded petal (day-sentence.md). The engine decides which sentence and
|
||||
* whether it is open; this shows it and hands the player's tap back.
|
||||
*/
|
||||
let { petal, sentences, onopen }: { petal: PetalNow; sentences: readonly HopeSentence[]; onopen: () => void } = $props();
|
||||
|
||||
const uid = $props.id();
|
||||
/** Today's open petal is shown; the player can fold it away and back for the rest of the day. */
|
||||
let showing = $state(true);
|
||||
let words = $state<HTMLElement>();
|
||||
|
||||
const find = (id: string | null): HopeSentence | undefined => (id === null ? undefined : sentences.find((s) => s.id === id));
|
||||
const today = $derived(petal.kind === 'open' ? find(petal.id) : undefined);
|
||||
const remembered = $derived(petal.kind === 'open' ? find(petal.remembered) : undefined);
|
||||
const source = (s: HopeSentence): string => en.rose.petal.source(s.source.work, s.source.author, s.source.translation);
|
||||
|
||||
async function open(): Promise<void> {
|
||||
onopen();
|
||||
showing = true;
|
||||
// The player acted, so focus follows them to the words.
|
||||
await tick();
|
||||
words?.focus();
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if petal.kind === 'folded'}
|
||||
<div class="petal">
|
||||
<img src={folded} alt={en.rose.petal.folded} width="56" height="56" />
|
||||
<button type="button" onclick={open}>{en.rose.petal.open}</button>
|
||||
</div>
|
||||
{:else if petal.kind === 'open' && today}
|
||||
<div class="petal">
|
||||
<button type="button" class="quiet" aria-expanded={showing} aria-controls="{uid}-words" onclick={() => (showing = !showing)}>{en.rose.petal.today}</button>
|
||||
{#if showing}
|
||||
<div id="{uid}-words" class="words" tabindex="-1" bind:this={words}>
|
||||
<figure>
|
||||
<blockquote>{today.text.en}</blockquote>
|
||||
<figcaption>{source(today)}</figcaption>
|
||||
</figure>
|
||||
{#if remembered}
|
||||
<p class="remember">{en.rose.petal.remember}</p>
|
||||
<figure>
|
||||
<blockquote>{remembered.text.en}</blockquote>
|
||||
<figcaption>{source(remembered)}</figcaption>
|
||||
</figure>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.petal {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
img {
|
||||
width: 3.5rem;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.words {
|
||||
display: grid;
|
||||
gap: var(--space-3);
|
||||
max-width: 24rem;
|
||||
padding: var(--space-3);
|
||||
border-radius: 1.25rem;
|
||||
background: color-mix(in srgb, var(--rose) 10%, var(--paper));
|
||||
}
|
||||
|
||||
.words:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
figure {
|
||||
margin: 0;
|
||||
display: grid;
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 0;
|
||||
font-family: var(--font-display);
|
||||
font-size: 1.15rem;
|
||||
line-height: 1.45;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
figcaption,
|
||||
.remember {
|
||||
margin: 0;
|
||||
font-size: 0.85rem;
|
||||
color: var(--ink-soft);
|
||||
}
|
||||
|
||||
button {
|
||||
font: inherit;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
border-radius: 999px;
|
||||
border: 1px solid var(--rose);
|
||||
background: var(--paper);
|
||||
color: var(--ink);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.quiet {
|
||||
border: none;
|
||||
background: none;
|
||||
padding: var(--space-1) 0;
|
||||
color: var(--rose);
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
button:focus-visible {
|
||||
outline: 2px solid var(--rose);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,8 +1,12 @@
|
||||
<script lang="ts">
|
||||
import { careEvent, localDay, pour, roseAt, ROSE, type Mood, type RoseNow, type Stage } from '@rosea/engine';
|
||||
import type { CareEvent } from '@rosea/schema';
|
||||
import {
|
||||
careEvent, goodMoment, localDay, petalAt, pour, roseAt, ROSE, sentenceOpened,
|
||||
type Mood, type PetalNow, type Place, type RoseNow, type Stage
|
||||
} from '@rosea/engine';
|
||||
import type { CareEvent, SentenceOpened } from '@rosea/schema';
|
||||
import { en } from '../copy/en.js';
|
||||
import KeepSafe from './KeepSafe.svelte';
|
||||
import Petal from './Petal.svelte';
|
||||
import type { RoseWiring } from './types.js';
|
||||
// The art board's stand-ins until real art is accepted (rose.md R10, docs/ART.md).
|
||||
import bud from '../../../../art/placeholders/rose-bud.svg?url';
|
||||
@@ -19,7 +23,7 @@
|
||||
* 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 }: { wiring: RoseWiring; timeZone: string } = $props();
|
||||
let { wiring, timeZone, place = null }: { wiring: RoseWiring; timeZone: string; place?: Place | null } = $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 };
|
||||
@@ -29,18 +33,23 @@
|
||||
let pastKeys = $state.raw<readonly string[]>([]);
|
||||
let showSafe = $state(false);
|
||||
let events = $state.raw<readonly CareEvent[]>([]);
|
||||
/** Her opened petals (day-sentence.md). */
|
||||
let opened = $state.raw<readonly SentenceOpened[]>([]);
|
||||
let now = $state(0);
|
||||
let kept = $state(true);
|
||||
let showNumbers = $state(false);
|
||||
/** The petal was opened at the good moment in this visit: she sends the player out to the sky. */
|
||||
let lookUp = $state(false);
|
||||
|
||||
$effect(() => {
|
||||
const w = wiring;
|
||||
now = w.now();
|
||||
Promise.all([w.identity(), w.loadCare(), w.pastKeys()]).then(
|
||||
([id, log, past]) => {
|
||||
Promise.all([w.identity(), w.loadCare(), w.pastKeys(), w.loadOpened()]).then(
|
||||
([id, log, past, petals]) => {
|
||||
seed = id.publicKey;
|
||||
events = log;
|
||||
pastKeys = past;
|
||||
opened = petals;
|
||||
if (!id.kept) kept = false;
|
||||
},
|
||||
(error: unknown) => {
|
||||
@@ -54,13 +63,28 @@
|
||||
});
|
||||
|
||||
const rose = $derived<RoseNow | null>(seed === null ? null : roseAt(events, [seed, ...pastKeys], now, timeZone));
|
||||
const petal = $derived<PetalNow>(seed === null ? { kind: 'none' } : petalAt(wiring.sentences, opened, [seed, ...pastKeys], now, timeZone));
|
||||
const sunIsLow = $derived(place !== null && now > 0 && goodMoment(now, place));
|
||||
|
||||
function openPetal(): void {
|
||||
if (seed === null || petal.kind !== 'folded') return;
|
||||
now = wiring.now();
|
||||
const event = sentenceOpened({ now, timeZone, from: seed, messageId: petal.id, clientVersion: wiring.clientVersion });
|
||||
lookUp = place !== null && goodMoment(now, place);
|
||||
opened = [...opened, event];
|
||||
wiring.appendOpened(event).catch((error: unknown) => {
|
||||
console.error('rose: the device could not keep the opened petal', error);
|
||||
kept = false;
|
||||
});
|
||||
}
|
||||
|
||||
/** After she is brought back from a file: read her log and keys again. */
|
||||
function restored(): void {
|
||||
Promise.all([wiring.loadCare(), wiring.pastKeys()]).then(
|
||||
([log, past]) => {
|
||||
Promise.all([wiring.loadCare(), wiring.pastKeys(), wiring.loadOpened()]).then(
|
||||
([log, past, petals]) => {
|
||||
events = log;
|
||||
pastKeys = past;
|
||||
opened = petals;
|
||||
now = wiring.now();
|
||||
},
|
||||
(error: unknown) => console.error('rose: could not read her back after restoring', error)
|
||||
@@ -116,7 +140,10 @@
|
||||
: rose.needs.weeds ? s.weeds
|
||||
: rose.needs.petals ? s.petals
|
||||
: '';
|
||||
return [rose.drift > 0 ? s.back : '', need].filter(Boolean).join(' ');
|
||||
// The petal only when she needs nothing else: one line at a time (day-sentence.md §1).
|
||||
const p = en.rose.petal;
|
||||
const offer = need !== '' ? '' : petal.kind === 'folded' ? (sunIsLow ? p.goodMoment : p.waiting) : petal.kind === 'open' && lookUp ? p.lookUp : '';
|
||||
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);
|
||||
@@ -175,6 +202,8 @@
|
||||
{/if}
|
||||
<p class="said" role="status" aria-live="assertive">{pouring && can ? (can.tooFull ? en.rose.plenty : can.leavesLift ? en.rose.leavesLift : '') : ''}</p>
|
||||
|
||||
<Petal {petal} sentences={wiring.sentences} onopen={openPetal} />
|
||||
|
||||
{#if !kept}
|
||||
<p class="hint">{en.rose.notKept}</p>
|
||||
{/if}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { CareEvent } from '@rosea/schema';
|
||||
import type { CareEvent, HopeSentence, SentenceOpened } from '@rosea/schema';
|
||||
|
||||
/**
|
||||
* What the rose needs from the app: her care log, her key, and the clock. The app
|
||||
@@ -9,6 +9,10 @@ export interface RoseWiring {
|
||||
readonly identity: () => Promise<{ readonly publicKey: string; readonly kept: boolean }>;
|
||||
readonly loadCare: () => Promise<CareEvent[]>;
|
||||
readonly appendCare: (event: CareEvent) => Promise<void>;
|
||||
/** The verified library, as bundled. Empty: she holds no petal (day-sentence.md). */
|
||||
readonly sentences: readonly HopeSentence[];
|
||||
readonly loadOpened: () => Promise<SentenceOpened[]>;
|
||||
readonly appendOpened: (event: SentenceOpened) => Promise<void>;
|
||||
readonly clientVersion: string;
|
||||
/** The device's own zone: the rose's day when no sunset town is chosen (rose.md R8). */
|
||||
readonly deviceZone: string;
|
||||
@@ -18,7 +22,7 @@ export interface RoseWiring {
|
||||
readonly pastKeys: () => Promise<string[]>;
|
||||
/** 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 importRose: (file: unknown, currentKey: string) => Promise<{ readonly added: number; readonly petals: number }>;
|
||||
/** Hands the player a file to keep. */
|
||||
readonly saveFile: (name: string, text: string) => void;
|
||||
/** The browser's promise to keep the garden: true, false, or null when it cannot say. */
|
||||
|
||||
Reference in New Issue
Block a user