ridge: the View is the one owner of the sun's place, with no default; the rebuild key, weather and sky are given it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Nibu 2026-11-14 09:25:49 +00:00
commit 6347148d7d
10 changed files with 247 additions and 74 deletions

View file

@ -8,8 +8,7 @@ import { chooseSky, skyColour, urlSky } from './terrain/terrainSky';
import type { SkyName } from './terrain/terrainSky';
import type { SkyColours, Srgb } from './ridge/skyColour';
import { makePhysicalSky } from './ridge/physicalSky';
import { FALLBACK_VIEW } from './ridge/view';
import type { View } from './ridge/view';
import type { Place, View } from './ridge/view';
import { BUDGET } from './ridge/toneMap';
import { ridgeWeather, setFedWeather } from './ridge/weather';
import { currentWeather, fetchWeatherFile } from './ridge/weatherFeed';
@ -29,21 +28,23 @@ export const DUSK_SUN_ELEVATION = 2;
*/
export const ridgeSkyKey = (
state: SkyState,
view: View,
weather: number = ridgeWeather(),
now: Date = skyNow(),
view: View = FALLBACK_VIEW
now: Date = skyNow()
): string => `ridge:${resolveSkyState(state, now)}:${weather}:${view.place.id}`;
const WEATHER_REFRESH_MS = 10 * 60_000;
let weatherAt = -Infinity;
let weatherPlace = '';
/**
* Read `weather.json` (the page's own, next to config.json) into the weather the ridge sky is drawn for; at most once in ten minutes.
* Never throws: a missing, stale or broken file is a clear sky (`currentWeather`).
*/
export async function loadWeather(url: string, now: Date = skyNow()): Promise<void> {
if (now.getTime() - weatherAt < WEATHER_REFRESH_MS) return;
export async function loadWeather(url: string, place: Place, now: Date = skyNow()): Promise<void> {
if (place.id === weatherPlace && now.getTime() - weatherAt < WEATHER_REFRESH_MS) return;
weatherAt = now.getTime();
setFedWeather(currentWeather(await fetchWeatherFile(url), now));
weatherPlace = place.id;
setFedWeather(currentWeather(await fetchWeatherFile(url), place, now));
}
/**
@ -53,9 +54,9 @@ export async function loadWeather(url: string, now: Date = skyNow()): Promise<vo
*/
export function ridgeSkyFor(
state: SkyState,
view: View,
weather: number = ridgeWeather(),
now: Date = skyNow(),
view: View = FALLBACK_VIEW
now: Date = skyNow()
): SkyColours {
const fixed = resolveSkyState(state, now);
const physical = makePhysicalSky(fixed, now, weather, view);