Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,151 @@
# OpenSpec Change: enterprise-gaming-day-night
- **Change ID**: enterprise-gaming-day-night
- **Package**: `@suaveplan/day-night`
- **Category**: gaming/world
- **Target path**: `gaming/world/day-night`
- **Status**: PROPOSED
- **Date**: 2026-04-24
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/day-night.md`
---
## Summary
Deliver `@suaveplan/day-night` on the genesis branch from scratch at enterprise quality. The package provides a day/night cycle with configurable time scale, sun/moon position math, light schedule interpolation, and gameplay effect modifiers. `DayNightClock` advances in-game time at a configurable multiple of real time; `SkyPositionCalculator` computes sun and moon azimuth/elevation from in-game time using a simplified celestial model; `LightSchedule` keyframes ambient light color and intensity across the day; `GameplayModifiers` maps time-of-day segments to gameplay effect multipliers (spawn rate, visibility, economy). Genesis adds Zod schemas, structured errors, OTel time counter, injectable clock, and 100% coverage.
---
## Current-state audit (genesis)
Package does not exist on genesis yet — fresh build.
---
## Available workspace deps on genesis
| Package | Role |
|---|---|
| `@suaveplan/error` (`workspace:^`) | `DayNightError`; `DAY_NIGHT.*` codes |
| `@suaveplan/types` (`workspace:^`) | `Clock` |
| `@suaveplan/events` (`workspace:^`) | `time:dawn`, `time:noon`, `time:dusk`, `time:midnight` events |
| `zod` (`catalog:forms`) | `LightSchedule`, `GameplayModifiers` schemas |
| `@opentelemetry/api` (`catalog:observability`) | In-game time gauge |
---
## Public API surface
```ts
function createDayNightClock(options: DayNightClockOptions): DayNightClock
interface DayNightClockOptions {
timeScale?: number // real seconds per in-game minute, default 1 min = 1 sec
initialHour?: number // 0–24
clock?: Clock
}
interface DayNightClock {
tick(dt: number): void
readonly hour: number // 0–24 fractional
readonly dayCount: number
setHour(hour: number): void
pause(): void
resume(): void
readonly isPaused: boolean
}
interface SkyPosition {
azimuth: number // degrees
elevation: number // degrees (-90 to 90)
intensity: number // 0–1
}
function computeSunPosition(hour: number): SkyPosition
function computeMoonPosition(hour: number): SkyPosition
// Light schedule
interface LightKeyframe {
hour: number
ambientColor: [r: number, g: number, b: number]
ambientIntensity: number
fogDensity?: number
}
function createLightSchedule(keyframes: LightKeyframe[]): LightSchedule
interface LightSchedule {
evaluate(hour: number): LightKeyframe
}
// Gameplay modifiers
interface TimeModifier {
fromHour: number
toHour: number
spawnRateMultiplier?: number
visibilityMultiplier?: number
economyMultiplier?: number
label?: string
}
function createGameplayModifiers(modifiers: TimeModifier[]): GameplayModifiers
interface GameplayModifiers {
evaluate(hour: number): TimeModifier & Required<Omit<TimeModifier, 'label' | 'fromHour' | 'toHour'>>
}
```
### Error codes
```ts
type DayNightErrorCode =
| 'DAY_NIGHT_INVALID_HOUR'
| 'DAY_NIGHT_SCHEDULE_EMPTY'
| 'DAY_NIGHT_KEYFRAME_GAP'
```
---
## File layout
```text
gaming/world/day-night/
package.json
tsconfig.json
vitest.config.ts
src/
index.ts
error-codes.ts
constants/index.ts
types/common.ts
types/common.md
core/
day-night-clock/
day-night-clock.ts
day-night-clock.md
day-night-clock.types.ts
day-night-clock.test.ts
index.ts
light-schedule/
light-schedule.ts
light-schedule.md
light-schedule.types.ts
light-schedule.test.ts
index.ts
gameplay-modifiers/
gameplay-modifiers.ts
gameplay-modifiers.md
gameplay-modifiers.types.ts
gameplay-modifiers.test.ts
index.ts
utils/
sky-position.ts
sky-position.md
sky-position.test.ts
tests/
integration.test.ts
```
---
## Impact
**Downstream**: `@suaveplan/r3f-environment` uses sun/moon positions for directional light; `@suaveplan/weather` reads time for weather transitions. Prerequisites: `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/events`.

View File

@@ -0,0 +1,51 @@
# Tasks: enterprise-gaming-day-night
## 0. Pre-flight (non-negotiable)
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
## Phase 1 — Scaffold
- [ ] Create `gaming/world/day-night/` (`@suaveplan/day-night`, `0.1.0`, `sideEffects: false`)
- [ ] `tsconfig.json`, `vitest.config.ts`
## Phase 2 — Error codes & constants
- [ ] `src/error-codes.ts` + `src/constants/index.ts` — `DEFAULT_TIME_SCALE`, `HOURS_IN_DAY`
## Phase 3 — Types
- [ ] `src/types/common.ts` + `common.md`
## Phase 4 — Sky position utils
- [ ] `src/utils/sky-position.ts` — simplified celestial math: sun elevation peaks at noon, moon at midnight
- [ ] Tests + docs
## Phase 5 — Day/night clock
- [ ] `src/core/day-night-clock/day-night-clock.ts` — time scale, tick/pause/resume, dawn/dusk events, OTel gauge
- [ ] Tests (time scale, day boundary wrap, events)
- [ ] Docs
## Phase 6 — Light schedule
- [ ] `src/core/light-schedule/light-schedule.ts` — keyframe interpolation (lerp color/intensity between keyframes)
- [ ] Tests + docs
## Phase 7 — Gameplay modifiers
- [ ] `src/core/gameplay-modifiers/gameplay-modifiers.ts` — time-segment lookup + merge defaults
- [ ] Tests + docs
## Phase 8 — Integration tests
- [ ] `tests/integration.test.ts` — advance clock through full day, verify light + modifier evaluations
## Phase 9 — Pre-publish gate
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/day-night` green
- [ ] 100% coverage
- [ ] Publish: `bun scripts/publish.ts --package @suaveplan/day-night`