Add Pathfinder 2e game system mode
All checks were successful
CI / check (push) Successful in 2m21s
CI / build-image (push) Successful in 24s

Implements PF2e as an alternative game system alongside D&D 5e/5.5e.
Settings modal "Game System" selector switches conditions, bestiary,
stat block layout, and initiative calculation between systems.

- Valued conditions with increment/decrement UX (Clumsy 2, Frightened 3)
- 2,502 PF2e creatures from bundled search index (77 sources)
- PF2e stat block: level, traits, Perception, Fort/Ref/Will, ability mods
- Perception-based initiative rolling
- System-scoped source cache (D&D and PF2e sources don't collide)
- Backwards-compatible condition rehydration (ConditionId[] → ConditionEntry[])
- Difficulty indicator hidden in PF2e mode (excluded from MVP)

Closes dostulata/initiative#19

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-04-07 01:26:22 +02:00
parent 8f6eebc43b
commit e62c49434c
67 changed files with 27758 additions and 527 deletions

View File

@@ -23,10 +23,15 @@ interface Combatant {
readonly currentHp?: number; // 0..maxHp
readonly tempHp?: number; // positive integer, damage buffer
readonly ac?: number; // non-negative integer
readonly conditions?: readonly ConditionId[];
readonly conditions?: readonly ConditionEntry[];
readonly isConcentrating?: boolean;
readonly creatureId?: CreatureId; // link to bestiary entry
}
interface ConditionEntry {
readonly id: ConditionId;
readonly value?: number; // PF2e valued conditions (e.g., Clumsy 2); undefined for D&D
}
```
---
@@ -273,21 +278,41 @@ Acceptance scenarios:
3. **Given** a combatant is NOT concentrating, **When** damage is taken, **Then** no pulse/flash occurs.
4. **Given** a concentrating combatant takes damage, **When** the animation completes, **Then** the row returns to its normal concentration-active appearance.
**Story CC-8 — Rules Edition Setting (P2)**
As a DM who plays in both 5e (2014) and 5.5e (2024) groups, I want to choose which edition's condition descriptions appear in tooltips so I reference the correct rules for the game I am running.
**Story CC-8 — Game System Setting (P2)**
As a DM who runs games across D&D 5e, 5.5e, and Pathfinder 2e, I want to choose which game system the tracker uses so that conditions, bestiary search, stat block layout, and initiative calculation all match the game I am running.
Acceptance scenarios:
1. **Given** the user opens the kebab menu, **When** they click "Settings", **Then** a settings modal opens.
2. **Given** the settings modal is open, **When** viewing the Conditions section, **Then** a rules edition selector shows 5e (2014) and 5.5e (2024) with 5.5e selected by default.
3. **Given** the user selects 5e (2014), **When** hovering a condition icon (e.g., Exhaustion), **Then** the tooltip shows the 2014 description.
4. **Given** the user selects 5.5e (2024), **When** hovering the same condition, **Then** the tooltip shows the 2024 description.
5. **Given** the user changes the edition and reloads the page, **Then** the selected edition is preserved.
6. **Given** a condition with identical rules across editions (e.g., Deafened), **Then** the tooltip text is the same regardless of setting.
7. **Given** the settings modal is open, **When** viewing the Theme section, **Then** a System / Light / Dark selector is available, replacing the inline cycle button in the kebab menu.
2. **Given** the settings modal is open, **When** viewing the Game System section, **Then** a selector shows three options: D&D 5e (2014), D&D 5.5e (2024), and Pathfinder 2e, with D&D 5.5e selected by default.
3. **Given** the user selects Pathfinder 2e, **When** viewing condition icons/tooltips, **Then** the PF2e condition set is used (Clumsy, Drained, Enfeebled, etc.) instead of D&D conditions.
4. **Given** the user selects Pathfinder 2e, **When** searching creatures in the bestiary, **Then** results come from the PF2e index (~2,700+ creatures) instead of the D&D index.
5. **Given** the user selects Pathfinder 2e, **When** viewing a creature stat block, **Then** the PF2e layout is shown (level, Fort/Ref/Will, ability modifiers, top/mid/bot ability sections).
6. **Given** the user selects Pathfinder 2e, **When** rolling initiative for a bestiary creature, **Then** Perception is used as the initiative modifier instead of DEX + proficiency.
7. **Given** the user selects D&D 5e (2014), **When** hovering a condition icon (e.g., Exhaustion), **Then** the tooltip shows the 2014 description. **When** 5.5e (2024) is selected, **Then** the tooltip shows the 2024 description.
8. **Given** the user changes the game system and reloads the page, **Then** the selected game system is preserved.
9. **Given** a condition with identical rules across D&D editions (e.g., Deafened), **Then** the tooltip text is the same regardless of D&D edition.
10. **Given** the settings modal is open, **When** viewing the Theme section, **Then** a System / Light / Dark selector is available, replacing the inline cycle button in the kebab menu.
**Story CC-9 — Value-Based Conditions (P2)**
As a DM running a PF2e encounter, I want conditions like Clumsy, Frightened, and Drained to carry an integer value so I can track escalating severity levels as defined by the PF2e rules.
The condition picker uses the same counter pattern as the bestiary batch-add (see `specs/004-bestiary/spec.md`, US-S2): clicking a valued condition shows `[-] N [+] [✓]` controls inline; the user adjusts the value and confirms. Clicking a condition tag on the combatant row decrements the value by 1.
Acceptance scenarios:
1. **Given** the game system is Pathfinder 2e and the condition picker is open, **When** the user clicks an inactive valued condition (e.g., Frightened), **Then** the row shows a counter at value 1 with `[-]`, `[+]`, and `[✓]` (confirm) buttons — the condition is not yet applied.
2. **Given** the counter is showing value 1, **When** the user clicks `[+]` twice, **Then** the counter shows value 3.
3. **Given** the counter is showing a value, **When** the user clicks `[✓]` (confirm), **Then** the condition is applied at that value and its icon appears inline with the value as a badge.
4. **Given** a combatant already has Frightened 2 and the picker is open, **When** the user clicks Frightened in the picker, **Then** the counter shows pre-filled at value 2 for adjustment.
5. **Given** a combatant has Frightened 2, **When** the user clicks the Frightened icon tag on the row, **Then** the value decrements to 1.
6. **Given** a combatant has Frightened 1, **When** the user clicks the Frightened icon tag on the row, **Then** the condition is removed entirely.
7. **Given** a PF2e condition that is not valued (e.g., Prone, Off-Guard), **When** the user clicks it in the picker, **Then** it toggles on/off with no counter or value badge — identical to D&D condition behavior.
8. **Given** the game system is D&D (5e or 5.5e), **When** interacting with conditions, **Then** no value counters or badges are shown and conditions toggle on/off as before.
9. **Given** a combatant has Clumsy 3, **When** the user hovers over the condition icon, **Then** the tooltip shows the condition name, the current value, and the PF2e rules description.
10. **Given** a valued condition counter is showing, **When** the user clicks a different valued condition, **Then** the previous counter is replaced (only one counter at a time).
### Requirements
- **FR-032**: The MVP MUST support the following 15 standard D&D 5e/5.5e conditions: blinded, charmed, deafened, exhaustion, frightened, grappled, incapacitated, invisible, paralyzed, petrified, poisoned, prone, restrained, stunned, unconscious.
- **FR-032**: When a D&D game system is active, the system MUST support the following 15 standard D&D 5e/5.5e conditions: blinded, charmed, deafened, exhaustion, frightened, grappled, incapacitated, invisible, paralyzed, petrified, poisoned, prone, restrained, stunned, unconscious. When Pathfinder 2e is active, the system MUST support the PF2e condition set (see FR-103).
- **FR-033**: Each condition MUST have a fixed icon and color mapping (Lucide icons; no emoji):
| Condition | Icon | Color |
@@ -312,9 +337,9 @@ Acceptance scenarios:
- **FR-035**: Conditions MUST be displayed in the fixed definition order (blinded -> unconscious), regardless of application order.
- **FR-036**: The "+" condition button MUST be hidden by default and appear only on row hover (or touch/focus on touch devices).
- **FR-037**: Clicking "+" MUST open the compact condition picker showing all conditions as icon + label pairs.
- **FR-038**: Clicking a condition in the picker MUST toggle it on or off.
- **FR-039**: Clicking an active condition icon tag in the row MUST remove that condition.
- **FR-040**: Hovering an active condition icon MUST show a tooltip with the condition name and its rules description for the selected edition.
- **FR-038**: Clicking a condition in the picker MUST toggle it on or off. For PF2e valued conditions, clicking MUST open an inline counter (same pattern as the bestiary batch-add count badge: `[-] N [+] [✓]`) instead of toggling immediately. The user adjusts the value and confirms with the `[✓]` button. Only one valued condition counter may be open at a time.
- **FR-039**: For D&D conditions, clicking an active condition icon tag in the row MUST remove that condition. For PF2e valued conditions, clicking MUST decrement the value by 1; the condition is removed when the value reaches 0. For PF2e non-valued conditions, clicking removes the condition.
- **FR-040**: Hovering an active condition icon MUST show a tooltip with the condition name and its rules description for the active game system. For PF2e valued conditions, the tooltip MUST also display the current value (e.g., "Frightened 2").
- **FR-041**: Condition icons MUST NOT increase the row's width; row height MAY increase to accommodate wrapping.
- **FR-042**: The condition picker MUST close when the user clicks outside of it.
- **FR-043**: Conditions MUST persist as part of combatant state (surviving page reload).
@@ -330,6 +355,11 @@ Acceptance scenarios:
- **FR-053**: When a concentrating combatant takes damage, the Brain icon and row accent MUST briefly pulse/flash for 700 ms.
- **FR-054**: The pulse animation MUST NOT trigger on healing or when concentration is inactive.
- **FR-055**: Concentration MUST persist across page reloads via existing storage.
- **FR-103**: When Pathfinder 2e is active, the system MUST support the following PF2e conditions: blinded, clumsy (valued), concealed, confused, controlled, dazzled, deafened, doomed (valued), drained (valued), dying (valued), enfeebled (valued), fascinated, fatigued, fleeing, frightened (valued), grabbed, hidden, immobilized, off-guard, paralyzed, petrified, prone, quickened, restrained, sickened (valued), slowed (valued), stunned (valued), stupefied (valued), unconscious, undetected, wounded (valued).
- **FR-104**: Each PF2e condition MUST have a fixed icon and color mapping (Lucide icons; no emoji). The icon/color table for PF2e conditions is defined separately from the D&D table (FR-033).
- **FR-105**: For PF2e valued conditions, the condition icon tag MUST display the current value as a small numeric badge (e.g., "2" next to the Frightened icon). Non-valued PF2e conditions display without a badge.
- **FR-106**: The condition data model MUST use `ConditionEntry` objects (`{ id: ConditionId, value?: number }`) instead of bare `ConditionId` values. D&D conditions MUST be stored without a `value` field (backwards-compatible).
- **FR-107**: Switching the game system MUST NOT clear existing combatant conditions. Conditions from the previous game system that are not valid in the new system remain stored but are hidden from display until the user switches back.
### Edge Cases
@@ -340,9 +370,13 @@ Acceptance scenarios:
- When concentration is toggled during an active pulse animation, the animation cancels and the new state applies immediately.
- Multiple combatants may concentrate simultaneously; concentration is independent per combatant.
- Conditions have no mechanical effects in the MVP baseline (no auto-disadvantage, no automation).
- When the rules edition preference is missing from localStorage, the system defaults to 5.5e (2024).
- Changing the edition while a condition tooltip is visible updates the tooltip on next hover (no live update required).
- When the game system preference is missing from localStorage, the system defaults to D&D 5.5e (2024).
- Changing the game system while a condition tooltip is visible updates the tooltip on next hover (no live update required).
- The settings modal is app-level UI; it does not interact with encounter state.
- When the game system is switched from D&D to PF2e, existing D&D conditions on combatants are hidden (not deleted). Switching back to D&D restores them.
- PF2e valued condition at value 0 is treated as removed — it MUST NOT appear on the row.
- Dying 4 in PF2e has special mechanical significance (death), but the system does not enforce this automatically — it displays the value only.
- Persistent damage is excluded from the PF2e MVP condition set. It can be added as a follow-up feature.
---
@@ -410,12 +444,12 @@ Acceptance scenarios:
- **FR-066**: System MUST display a d20 icon button in the initiative slot for every combatant that has a linked bestiary creature and does not yet have an initiative value.
- **FR-067**: System MUST NOT display the d20 button for combatants without a linked bestiary creature; they see a "--" placeholder that is clickable to type a value.
- **FR-068**: When the d20 button is clicked, the system MUST generate a uniform random integer in [1, 20], add the creature's initiative modifier, and set the result as the initiative value.
- **FR-069**: The initiative modifier MUST be calculated as: DEX modifier + (proficiency multiplier x proficiency bonus), where DEX modifier = floor((DEX - 10) / 2) and proficiency bonus is derived from challenge rating.
- **FR-069**: For D&D creatures, the initiative modifier MUST be calculated as: DEX modifier + (proficiency multiplier x proficiency bonus), where DEX modifier = floor((DEX - 10) / 2) and proficiency bonus is derived from challenge rating. For PF2e creatures, the initiative modifier MUST be the creature's Perception value from the index.
- **FR-070**: The initiative proficiency multiplier MUST be read from `initiative.proficiency` in bestiary data (0 if absent, 1 for proficiency, 2 for expertise).
- **FR-071**: System MUST provide a "Roll All Initiative" button in the top bar. Clicking it MUST roll for every bestiary-linked combatant that does not already have an initiative value; all others MUST be left unchanged.
- **FR-072**: After any initiative roll (single or batch), the encounter list MUST re-sort descending per existing behavior.
- **FR-073**: Once a combatant has an initiative value, the d20 button is replaced by the value as plain text using a click-to-edit pattern (consistent with AC and name editing).
- **FR-074**: The stat block header MUST display initiative in the format "Initiative +X (Y)" where X is the modifier (with + or - sign) and Y = 10 + X.
- **FR-074**: For D&D creatures, the stat block header MUST display initiative in the format "Initiative +X (Y)" where X is the modifier (with + or - sign) and Y = 10 + X. For PF2e creatures, the stat block MUST display "Perception +X" where X is the Perception modifier.
- **FR-075**: The initiative display in the stat block MUST be positioned adjacent to the AC value, matching Monster Manual 2024 layout.
- **FR-076**: No initiative line MUST be shown in the stat block for combatants without bestiary data.
- **FR-077**: The initiative display in the stat block is display-only. It MUST NOT modify encounter turn order or trigger rolling automatically.
@@ -489,11 +523,11 @@ Acceptance scenarios:
- **FR-093**: All interactive elements in the row MUST remain keyboard-accessible (focusable and operable via keyboard).
- **FR-094**: On touch devices, hover-only controls ("+" button, "x" button) MUST remain accessible via tap or focus.
- **FR-095**: The system MUST provide a settings modal accessible via a "Settings" item in the kebab overflow menu.
- **FR-096**: The settings modal MUST include a Conditions section with a rules edition selector offering two options: 5e (2014) and 5.5e (2024).
- **FR-097**: The default rules edition MUST be 5.5e (2024).
- **FR-098**: Each condition definition MUST carry a description for both editions. Conditions with identical rules across editions MAY share a single description value.
- **FR-099**: Condition tooltips MUST display the description corresponding to the active rules edition preference.
- **FR-100**: The rules edition preference MUST persist across sessions via localStorage (key `"initiative:rules-edition"`).
- **FR-096**: The settings modal MUST include a Game System section with a selector offering three options: D&D 5e (2014), D&D 5.5e (2024), and Pathfinder 2e. The label MUST read "Game System" (not "Conditions" or "Rules Edition").
- **FR-097**: The default game system MUST be D&D 5.5e (2024).
- **FR-098**: Each D&D condition definition MUST carry a description for both D&D editions. Each PF2e condition definition MUST carry a PF2e rules description. Conditions with identical rules across D&D editions MAY share a single description value.
- **FR-099**: Condition tooltips MUST display the description corresponding to the active game system. For D&D game systems, the tooltip uses the edition-specific description. For PF2e, the tooltip uses the PF2e description.
- **FR-100**: The game system preference MUST persist across sessions via localStorage (key `"initiative:game-system"`).
- **FR-101**: The settings modal MUST include a Theme section with System / Light / Dark options, replacing the inline theme cycle button in the kebab menu.
- **FR-102**: The settings modal MUST close on Escape, click-outside, or the close button.
@@ -539,6 +573,10 @@ Acceptance scenarios:
- **SC-028**: The AC number is visually identifiable as armor class through the shield shape alone.
- **SC-029**: No layout shift occurs when hovering/unhovering rows.
- **SC-030**: All HP, AC, initiative, condition, and concentration interactions remain fully operable using only a keyboard.
- **SC-031**: The user can switch rules edition in 2 interactions (open settings → select edition).
- **SC-032**: Condition tooltips accurately reflect the selected edition's rules text for all conditions that differ between editions.
- **SC-033**: The rules edition preference survives a full page reload.
- **SC-031**: The user can switch game system in 2 interactions (open settings → select system).
- **SC-032**: Condition tooltips accurately reflect the active game system's rules text for all conditions.
- **SC-033**: The game system preference survives a full page reload.
- **SC-034**: All PF2e conditions are available and visually distinguishable by icon and color when PF2e is the active game system.
- **SC-035**: PF2e valued conditions display their current value and can be incremented/decremented within 1 click each.
- **SC-036**: Switching game system immediately changes the available conditions, bestiary search results, stat block layout, and initiative calculation — no page reload required.
- **SC-037**: The game system preference survives a full page reload.