[ui] Sunrise: The garden names the real sunrise from sunset until it comes

This commit is contained in:
2026-11-17 18:52:56 +01:00
parent e0a3b66dc8
commit 0c4f5bb556
9 changed files with 137 additions and 16 deletions
+3
View File
@@ -106,6 +106,9 @@ export const en = {
choose: 'Choose a town',
tonight: (time: string, town: string): string => `Tonight the sun sets at ${time} in ${town}.`,
tomorrow: (time: string, town: string): string => `Tomorrow the sun sets at ${time} in ${town}.`,
/** The sunrise, named from sunset until it comes (sunrise.md). Only a time: nothing invites. */
rises: (time: string, town: string): string => `The sun rises at ${time} in ${town}.`,
risesTomorrow: (time: string, town: string): string => `Tomorrow the sun rises at ${time} in ${town}.`,
polarDay: (time: string, town: string): string => `In ${town} the sun stays up tonight. The light is lowest at ${time}.`,
polarNight: (time: string, town: string): string => `In ${town} the sun stays below the horizon today. The twilight is brightest at ${time}.`,
guessed: "A guess from this device's time zone.",
+2 -1
View File
@@ -81,7 +81,8 @@
{#if phase === 'after'}
<div class="after-words">
{#if place}
<SunsetLine {place} {guessed} now={afterAt} />
<!-- 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}
+19 -9
View File
@@ -1,26 +1,36 @@
<script lang="ts">
import { localDay, nextInvitation, type NamedPlace } from '@rosea/engine';
import { localDay, nextInvitation, nextSunEvent, type NamedPlace } from '@rosea/engine';
import { en } from '../copy/en.js';
/**
* The next sunset, or its polar alternative, in one sentence. The engine says
* when; this only reads it on the town's clock, in the device's own time format
* (sunset-place.md P6).
* The next real thing to look up for, in one sentence: the sunrise until it comes,
* then the sunset, or their polar alternatives (sunrise.md). `of="sunset"` names the
* sunset only, for the in-game sunset's closing words. The engine says when; this
* only reads it on the town's clock, in the device's own time format (sunset-place.md P6).
*/
let { place, guessed = false, now }: { place: NamedPlace; guessed?: boolean; now: number } = $props();
let {
place,
guessed = false,
now,
of = 'next'
}: { place: NamedPlace; guessed?: boolean; now: number; of?: 'next' | 'sunset' } = $props();
const line = $derived.by(() => {
const { sun, at } = nextInvitation(now, place);
const event = of === 'sunset' ? { ...nextInvitation(now, place), kind: 'invitation' as const } : nextSunEvent(now, place);
const { sun, at } = event;
const time = new Intl.DateTimeFormat(undefined, { hour: 'numeric', minute: '2-digit', timeZone: place.timeZone }).format(at);
const today = localDay(now, place.timeZone);
// A sunrise is tomorrow's when it falls on a later local day than now.
if (event.kind === 'sunrise') return localDay(at, place.timeZone) > today ? en.sunset.risesTomorrow(time, place.name) : en.sunset.rises(time, place.name);
// "Tomorrow" for a sunset only when it belongs to a later day: tonight's sunset may
// fall after midnight (sun.md D2).
switch (sun.kind) {
case 'polar-day':
return en.sunset.polarDay(time, place.name);
case 'polar-night':
return en.sunset.polarNight(time, place.name);
case 'sun-sets':
// Tonight's sunset may fall after midnight (sun.md D2), so "tomorrow" only
// when it belongs to a later day than today.
return sun.day > localDay(now, place.timeZone) ? en.sunset.tomorrow(time, place.name) : en.sunset.tonight(time, place.name);
return sun.day > today ? en.sunset.tomorrow(time, place.name) : en.sunset.tonight(time, place.name);
}
});
</script>