[ui] PlanetGarden: Her round planet, the player's gardener, the ring of care, and care by gesture
This commit is contained in:
@@ -3,7 +3,7 @@ export {
|
||||
careEvent, careIdentity, judgeCare, newCare, OWN_TRACE, petalsOn, pour, ROSE, roseAt, seeded, stageFor, weedsOn, windOn,
|
||||
type Judged, type Mood, type Needs, type RoseKeys, type RoseNow, type Stage, type Trend
|
||||
} from './rose/rose.js';
|
||||
export { invitation, nextInvitation, nextSunEvent, sunDay, type NamedPlace, type Place, type SunDay } from './sun/sun.js';
|
||||
export { invitation, lightAt, nextInvitation, nextSunEvent, sunDay, type Light, type NamedPlace, type Place, type SunDay } from './sun/sun.js';
|
||||
export {
|
||||
goodMoment, newOpened, openedIdentity, PETAL, petalAt, petalOrder, sentenceOpened, type PetalNow, type PetalSentence
|
||||
} from './petal/petal.js';
|
||||
|
||||
@@ -159,6 +159,27 @@ export function nextInvitation(now: number, place: Place): { readonly sun: SunDa
|
||||
throw new Error(`nextInvitation: no invitation within two days of ${today}`);
|
||||
}
|
||||
|
||||
/** The light over her planet now (planet-garden.md): the scene's sky follows the real sun. */
|
||||
export type Light = 'day' | 'golden' | 'night';
|
||||
|
||||
/**
|
||||
* Golden within 45 minutes before and 30 after the sunset or sunrise (in polar day, around the
|
||||
* lowest light; in polar night, around the brightest twilight at noon); day between, night outside.
|
||||
*/
|
||||
export function lightAt(now: number, place: Place): Light {
|
||||
const sun = sunDay(localDay(now, place.timeZone), place);
|
||||
const near = (at: number, before: number, after: number): boolean => now >= at - before * MINUTE && now <= at + after * MINUTE;
|
||||
switch (sun.kind) {
|
||||
case 'polar-day':
|
||||
return near(sun.lowestLight, 60, 60) ? 'golden' : 'day';
|
||||
case 'polar-night':
|
||||
return near(sun.solarNoon, 90, 90) ? 'golden' : 'night';
|
||||
case 'sun-sets':
|
||||
if (near(sun.sunset, 45, 30) || near(sun.sunrise, 30, 30)) return 'golden';
|
||||
return now > sun.sunrise && now < sun.sunset ? 'day' : 'night';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The next thing to look up for (sunrise.md R1): the sunrise of the next invitation's
|
||||
* day while it is still ahead, otherwise the invitation itself. Built on
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fc from 'fast-check';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { invitation, nextInvitation, nextSunEvent, sunDay, type Place, type SunDay } from '../src/sun/sun.js';
|
||||
import { invitation, lightAt, nextInvitation, nextSunEvent, sunDay, type Place, type SunDay } from '../src/sun/sun.js';
|
||||
import { addDays, localDay } from '../src/time/localDay.js';
|
||||
|
||||
/** Recorded by scripts/fetch-sun-golden.ts from the U.S. Naval Observatory. */
|
||||
@@ -317,3 +317,27 @@ describe('nextSunEvent — the next thing to look up for (sunrise.md)', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('lightAt — the sky over her planet (planet-garden.md)', () => {
|
||||
const brno: Place = { lat: 49.1951, lon: 16.6068, timeZone: 'Europe/Prague' };
|
||||
const day = sunDay('2026-03-02', brno);
|
||||
if (day.kind !== 'sun-sets') throw new Error('Brno has a sunset in March');
|
||||
|
||||
it('night before dawn, golden at sunrise, day at noon, golden at sunset, night after', () => {
|
||||
expect(lightAt(day.sunrise - 2 * HOUR, brno)).toBe('night');
|
||||
expect(lightAt(day.sunrise, brno)).toBe('golden');
|
||||
expect(lightAt(day.solarNoon, brno)).toBe('day');
|
||||
expect(lightAt(day.sunset - 30 * MINUTE, brno)).toBe('golden');
|
||||
expect(lightAt(day.sunset + 2 * HOUR, brno)).toBe('night');
|
||||
});
|
||||
|
||||
it('polar day is day, golden around the lowest light; polar night is night, golden at noon', () => {
|
||||
const tromso: Place = { lat: 69.6492, lon: 18.9553, timeZone: 'Europe/Oslo' };
|
||||
const summer = sunDay('2026-06-21', tromso);
|
||||
const winter = sunDay('2026-12-21', tromso);
|
||||
if (summer.kind !== 'polar-day' || winter.kind !== 'polar-night') throw new Error('Tromsø: polar day and night');
|
||||
expect(lightAt(summer.solarNoon, tromso)).toBe('day');
|
||||
expect(lightAt(winter.solarNoon, tromso)).toBe('golden');
|
||||
expect(lightAt(winter.solarNoon + 4 * HOUR, tromso)).toBe('night');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user