1.5 KiB
1.5 KiB
Quickstart: Set Initiative
What This Feature Does
Adds an optional initiative value to combatants. When set, the encounter automatically sorts combatants from highest to lowest initiative. Combatants without initiative appear at the end. The active turn is preserved through reorders.
Key Files to Modify
packages/domain/src/types.ts— Addinitiative?: numbertoCombatantpackages/domain/src/events.ts— AddInitiativeSetevent to the unionpackages/domain/src/set-initiative.ts— New domain function (pure, no I/O)packages/domain/src/index.ts— Export new function and typespackages/application/src/set-initiative-use-case.ts— New use casepackages/application/src/index.ts— Export use caseapps/web/src/hooks/use-encounter.ts— AddsetInitiativecallbackapps/web/src/App.tsx— Add initiative input next to each combatant
Implementation Order
- Domain types + event (foundation)
- Domain function + tests (core logic)
- Application use case (orchestration)
- Web adapter hook + UI (user-facing)
How to Verify
pnpm check # Must pass: format + lint + typecheck + test
Patterns to Follow
- Domain functions return
{ encounter, events } | DomainError— never throw - Use
readonlyeverywhere, create new objects via spread - Tests live in
packages/domain/src/__tests__/ - Use cases follow get → call → check error → save → return events