178 lines
4.0 KiB
Svelte
178 lines
4.0 KiB
Svelte
<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>
|