221 lines
5.5 KiB
Svelte
221 lines
5.5 KiB
Svelte
<script lang="ts">
|
|
import type { NamedPlace } from '@rosea/engine';
|
|
import { en } from '../copy/en.js';
|
|
import SunsetLine from './SunsetLine.svelte';
|
|
// The art board's stand-ins until real art is accepted. The garden layer is
|
|
// transparent above its horizon (40 %): the sky is drawn here, in code (STYLE.md S5).
|
|
import garden from '../../../../art/placeholders/garden-sunset.svg?url';
|
|
import chair from '../../../../art/placeholders/garden-chair.svg?url';
|
|
|
|
/**
|
|
* The in-game sunset (chair-sunset.md): half a minute with nothing to press, then
|
|
* the real sunset's time. A rehearsal: it decides nothing and logs nothing.
|
|
*/
|
|
let {
|
|
place,
|
|
guessed = false,
|
|
now,
|
|
durationMs = SUNSET_MS,
|
|
onclose
|
|
}: { place: NamedPlace | null; guessed?: boolean; now: () => number; durationMs?: number; onclose: () => void } = $props();
|
|
|
|
const uid = $props.id();
|
|
let phase = $state<'watching' | 'after'>('watching');
|
|
/** Bumped by Watch it again, so the animation starts over. */
|
|
let showing = $state(0);
|
|
let dialog = $state<HTMLElement>();
|
|
let afterAt = $state(0);
|
|
|
|
$effect(() => {
|
|
// Read what the effect depends on first: it reruns on Watch it again.
|
|
const run = showing;
|
|
void run;
|
|
phase = 'watching';
|
|
dialog?.focus();
|
|
const timer = setTimeout(() => {
|
|
afterAt = now();
|
|
phase = 'after';
|
|
}, durationMs);
|
|
return () => clearTimeout(timer);
|
|
});
|
|
|
|
function leave(): void {
|
|
onclose();
|
|
}
|
|
</script>
|
|
|
|
<script lang="ts" module>
|
|
/** Half a minute: long enough to breathe, short enough to come back to the rose. */
|
|
export const SUNSET_MS = 30_000;
|
|
</script>
|
|
|
|
<div
|
|
class="scene"
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-labelledby="{uid}-title"
|
|
aria-describedby="{uid}-leave"
|
|
tabindex="-1"
|
|
bind:this={dialog}
|
|
style="--duration: {durationMs}ms"
|
|
onkeydown={(e) => {
|
|
if (e.key === 'Escape') leave();
|
|
}}
|
|
onclick={() => {
|
|
if (phase === 'watching') leave();
|
|
}}
|
|
>
|
|
<h2 id="{uid}-title" class="sr-only">{en.chair.scene}</h2>
|
|
<p id="{uid}-leave" class="sr-only">{en.chair.leave}</p>
|
|
|
|
{#key showing}
|
|
<!-- The sky fills the whole screen; the garden stands on the bottom edge. -->
|
|
<div class="sky" class:after={phase === 'after'}></div>
|
|
<div class="frame" class:after={phase === 'after'}>
|
|
<div class="sun"></div>
|
|
<img class="garden" src={garden} alt="" />
|
|
<img class="chair" src={chair} alt="" />
|
|
</div>
|
|
{/key}
|
|
|
|
{#if phase === 'after'}
|
|
<div class="after-words">
|
|
{#if place}
|
|
<!-- The real sunset, always: this scene tells the player when it is (sunrise.md R4). -->
|
|
<SunsetLine {place} {guessed} now={afterAt} of="sunset" />
|
|
{:else}
|
|
<p>{en.sunset.noTown}</p>
|
|
{/if}
|
|
<div class="choices">
|
|
<button type="button" onclick={(e) => { e.stopPropagation(); showing += 1; }}>{en.chair.again}</button>
|
|
<button type="button" class="quiet" onclick={(e) => { e.stopPropagation(); leave(); }}>{en.chair.back}</button>
|
|
</div>
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
|
|
<style>
|
|
.scene {
|
|
position: fixed;
|
|
inset: 0;
|
|
z-index: 10;
|
|
display: grid;
|
|
place-items: end center;
|
|
overflow: hidden;
|
|
background: #2e3561;
|
|
color: #fbf6f1;
|
|
outline: none;
|
|
}
|
|
|
|
.frame {
|
|
position: relative;
|
|
height: min(100dvh, 150vw);
|
|
aspect-ratio: 2 / 3;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* Day to amber to coral to dusk, drawn in code (STYLE.md §2 palette). */
|
|
.sky {
|
|
position: absolute;
|
|
inset: 0;
|
|
background: linear-gradient(to bottom, #a9cbe0 0%, #f4d58d 30%, #f2b860 45%, #e9846a 62%, #7a4f6e 80%, #2e3561 100%);
|
|
background-size: 100% 300%;
|
|
background-position: 0 0;
|
|
animation: dusk var(--duration) linear forwards;
|
|
}
|
|
|
|
.sun {
|
|
position: absolute;
|
|
left: 22%;
|
|
top: 12%;
|
|
width: 13%;
|
|
aspect-ratio: 1;
|
|
border-radius: 50%;
|
|
background: radial-gradient(circle, #fff4cf 0%, #f4d58d 55%, #f2b860 100%);
|
|
box-shadow: 0 0 2.5rem #f2b86099;
|
|
animation: set var(--duration) ease-in forwards;
|
|
}
|
|
|
|
/* The garden layer: its sky is transparent, so the sun sets behind its horizon. */
|
|
.garden {
|
|
position: absolute;
|
|
inset: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.chair {
|
|
position: absolute;
|
|
left: 10%;
|
|
top: 58%;
|
|
width: 24%;
|
|
}
|
|
|
|
.sky.after,
|
|
.after .sun {
|
|
animation-play-state: paused;
|
|
}
|
|
|
|
@keyframes dusk {
|
|
to {
|
|
background-position: 0 100%;
|
|
}
|
|
}
|
|
|
|
@keyframes set {
|
|
to {
|
|
/* From 12 % down past the horizon at 40 %, where the garden hides it. */
|
|
transform: translateY(380%);
|
|
opacity: 0.85;
|
|
}
|
|
}
|
|
|
|
.after-words {
|
|
position: absolute;
|
|
inset: auto 0 0 0;
|
|
display: grid;
|
|
justify-items: center;
|
|
gap: var(--space-2);
|
|
padding: var(--space-4) var(--space-3) calc(var(--space-4) + env(safe-area-inset-bottom));
|
|
background: linear-gradient(to top, #2e3561ee 60%, transparent);
|
|
text-align: center;
|
|
/* The words below read on dusk, whatever the page's own theme. */
|
|
--ink: #fbf6f1;
|
|
--ink-soft: #e8dccf;
|
|
}
|
|
|
|
.choices {
|
|
display: flex;
|
|
gap: var(--space-3);
|
|
}
|
|
|
|
button {
|
|
font: inherit;
|
|
padding: var(--space-2) var(--space-3);
|
|
border-radius: 999px;
|
|
border: 1px solid #f4d58d;
|
|
background: transparent;
|
|
color: #fbf6f1;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.quiet {
|
|
border: none;
|
|
text-decoration: underline;
|
|
}
|
|
|
|
button:focus-visible {
|
|
outline: 2px solid #f4d58d;
|
|
outline-offset: 2px;
|
|
}
|
|
|
|
.sr-only {
|
|
position: absolute;
|
|
width: 1px;
|
|
height: 1px;
|
|
overflow: hidden;
|
|
clip-path: inset(50%);
|
|
white-space: nowrap;
|
|
}
|
|
</style>
|