Implement the 017-combat-conditions feature that adds D&D 5e status conditions to combatants with icon tags, color coding, and a compact toggle picker in the encounter tracker

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-06 11:29:39 +01:00
parent 78c6591973
commit febe892e15
22 changed files with 1301 additions and 62 deletions

View File

@@ -0,0 +1,57 @@
# Quickstart: Combat Conditions
## Prerequisites
```bash
pnpm install # install dependencies (no new packages needed)
pnpm --filter web dev # start dev server at localhost:5173
```
## Implementation Order
1. **Domain: Condition types & registry** (`packages/domain/src/conditions.ts`)
- Define `ConditionId` union type and `ConditionDefinition` interface
- Create `CONDITION_DEFINITIONS` static array with all 15 entries
- Export `VALID_CONDITION_IDS` set for validation
2. **Domain: Extend Combatant** (`packages/domain/src/types.ts`)
- Add `readonly conditions?: readonly ConditionId[]` to `Combatant`
3. **Domain: Events** (`packages/domain/src/events.ts`)
- Add `ConditionAdded` and `ConditionRemoved` event types
- Add to `DomainEvent` union
4. **Domain: Operations** (`packages/domain/src/toggle-condition.ts`)
- `toggleCondition(encounter, combatantId, conditionId)` — add if absent, remove if present
- Maintains sorted order and emits `ConditionAdded` or `ConditionRemoved` event
5. **Domain: Tests** (`packages/domain/src/__tests__/`)
- Test toggle on/off, ordering, duplicate prevention, unknown condition rejection, immutability
6. **Application: Use case** (`packages/application/src/`)
- `toggleConditionUseCase` following `setAcUseCase` pattern
7. **Web: Persistence** (`apps/web/src/persistence/encounter-storage.ts`)
- Add conditions rehydration with validation against `VALID_CONDITION_IDS`
8. **Web: Components** (`apps/web/src/components/`)
- `condition-tags.tsx` — renders icon tags + "+" button
- `condition-picker.tsx` — popover with all 15 conditions for toggling
- Update `combatant-row.tsx` to include condition area below name
9. **Web: Hook** (`apps/web/src/hooks/use-encounter.ts`)
- Add `toggleCondition` callback
## Verification
```bash
pnpm check # must pass: knip + format + lint + typecheck + test
```
## Key Patterns to Follow
- **Domain operations**: See `packages/domain/src/set-ac.ts` for the exact pattern
- **Use cases**: See `packages/application/src/set-ac-use-case.ts`
- **UI components**: See `combatant-row.tsx` AcInput for inline editing pattern
- **Persistence**: See `encounter-storage.ts` AC validation for rehydration pattern
- **Hook integration**: See `use-encounter.ts` setAc callback for wiring pattern