[ui] Sunrise: The garden names the real sunrise from sunset until it comes
This commit is contained in:
@@ -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.",
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -91,6 +91,14 @@ describe('the in-game sunset (chair-sunset.md)', () => {
|
||||
expect(screen.queryByRole('dialog')).toBeNull();
|
||||
});
|
||||
|
||||
it('late in the evening its words still name the real sunset, never the sunrise (sunrise.md R4)', async () => {
|
||||
const late = Date.parse('2026-03-29T22:00:00+02:00');
|
||||
const scene = await openScene({ now: () => late });
|
||||
vi.advanceTimersByTime(SUNSET_MS);
|
||||
await tick();
|
||||
expect(within(scene).getByText(/^Tomorrow the sun sets at .* in Brno\.$/)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('with no town and no guess, the words after it ask for a town', async () => {
|
||||
const scene = await openScene({ guess: null, load: async () => ({ kind: 'device-zone' }) });
|
||||
vi.advanceTimersByTime(SUNSET_MS);
|
||||
|
||||
@@ -89,11 +89,23 @@ describe('the garden remembers', () => {
|
||||
expect(screen.queryByRole('searchbox')).toBeNull();
|
||||
});
|
||||
|
||||
it('after the sunset, it speaks of tomorrow\'s', async () => {
|
||||
it("after the sunset, it names tomorrow's sunrise (sunrise.md)", async () => {
|
||||
const after = invitation(sunDay('2026-03-29', brno)) + 60_000;
|
||||
render(Shell, { sunset: wiring({ saved: { kind: 'town', town: brno }, now: () => after }) });
|
||||
const tomorrow = invitation(sunDay('2026-03-30', brno));
|
||||
expect(await screen.findByText(en.sunset.tomorrow(timeOf(brno, tomorrow), 'Brno'))).toBeTruthy();
|
||||
const tomorrow = sunDay('2026-03-30', brno);
|
||||
if (tomorrow.kind !== 'sun-sets') throw new Error('Brno has a sunrise in March');
|
||||
expect(await screen.findByText(en.sunset.risesTomorrow(timeOf(brno, tomorrow.sunrise), 'Brno'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('before sunrise, it names this morning\'s sunrise; after it, tonight\'s sunset', async () => {
|
||||
const early = Date.parse('2026-03-29T04:00:00+02:00');
|
||||
const today = sunDay('2026-03-29', brno);
|
||||
if (today.kind !== 'sun-sets') throw new Error('Brno has a sunrise in March');
|
||||
render(Shell, { sunset: wiring({ saved: { kind: 'town', town: brno }, now: () => early }) });
|
||||
expect(await screen.findByText(en.sunset.rises(timeOf(brno, today.sunrise), 'Brno'))).toBeTruthy();
|
||||
cleanup();
|
||||
render(Shell, { sunset: wiring({ saved: { kind: 'town', town: brno }, now: () => today.sunrise + 60_000 }) });
|
||||
expect(await screen.findByText(en.sunset.tonight(timeOf(brno, today.sunset), 'Brno'))).toBeTruthy();
|
||||
});
|
||||
|
||||
it('in polar night it speaks of the noon twilight; in polar day, of the lowest light', async () => {
|
||||
|
||||
Reference in New Issue
Block a user