Add Pathfinder 2e game system mode
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:
@@ -8,9 +8,11 @@
|
||||
|
||||
## Overview
|
||||
|
||||
The Bestiary feature provides creature search across a pre-indexed library of 3,312+ creatures from 102+ D&D sources, stat block display for full creature reference during combat, source data management via on-demand fetch or file upload, and a dual-panel UX with collapse/expand and pin capabilities. Creatures can be added individually or in batch from a search dropdown, with stats pre-filled from the index.
|
||||
The Bestiary feature provides creature search across pre-indexed creature libraries: 3,312+ D&D creatures from 102+ sources and ~2,700+ Pathfinder 2e creatures from 79 Pf2eTools sources. The active game system setting (see `specs/003-combatant-state/spec.md`, FR-096) determines which index the search operates against. Stat block display, source management, and creature pre-fill all adapt to the active game system.
|
||||
|
||||
The architecture uses a two-tier design: a lightweight search index (`data/bestiary/index.json`) shipped with the app containing mechanical facts for all creatures, and full stat block data loaded on-demand at the source level, normalized, and cached in IndexedDB.
|
||||
The feature also includes full creature reference via stat block display during combat, source data management via on-demand fetch or file upload, and a dual-panel UX with collapse/expand and pin capabilities. Creatures can be added individually or in batch from a search dropdown, with stats pre-filled from the index.
|
||||
|
||||
The architecture uses a two-tier design: lightweight search indexes shipped with the app (one per game system) containing mechanical facts for all creatures, and full stat block data loaded on-demand at the source level, normalized, and cached in IndexedDB.
|
||||
|
||||
**Structure**: This spec is organized by topic area. Each topic section contains its own user scenarios, requirements, and edge cases.
|
||||
|
||||
@@ -37,11 +39,11 @@ When the search input has no bestiary matches (or fewer than 2 characters typed)
|
||||
|
||||
### Requirements
|
||||
|
||||
- **FR-001**: The app MUST ship a pre-generated search index (`data/bestiary/index.json`) containing creature name, source code, AC, HP average, DEX score, CR, initiative proficiency multiplier, size code, and creature type for all indexed creatures.
|
||||
- **FR-001**: The app MUST ship pre-generated search indexes for each supported game system. The D&D index (`data/bestiary/index.json`) MUST contain creature name, source code, AC, HP average, DEX score, CR, initiative proficiency multiplier, size code, and creature type. The PF2e index (`data/bestiary/pf2e-index.json`) MUST contain creature name, source code, AC, HP, level, Perception modifier, size, and creature type.
|
||||
- **FR-002**: The app MUST include a source display name map translating source codes to human-readable names (e.g., "XMM" -> "Monster Manual (2025)").
|
||||
- **FR-003**: Search MUST operate against the full shipped index — case-insensitive substring match on creature name, minimum 2 characters, maximum 10 results, sorted alphabetically.
|
||||
- **FR-003**: Search MUST operate against the shipped index corresponding to the active game system — case-insensitive substring match on creature name, minimum 2 characters, maximum 10 results, sorted alphabetically.
|
||||
- **FR-004**: Search results MUST display the source display name alongside the creature name.
|
||||
- **FR-005**: Adding a creature from search MUST populate name, HP, AC, and initiative data directly from the index without any network fetch.
|
||||
- **FR-005**: Adding a creature from search MUST populate name, HP, AC, and initiative data directly from the index without any network fetch. For D&D creatures, initiative data is the DEX-based modifier. For PF2e creatures, initiative data is the Perception modifier.
|
||||
- **FR-006**: The system MUST auto-number duplicate creature names (e.g., "Goblin 1", "Goblin 2") when multiple combatants share the same bestiary creature name. When a second copy is added, the existing combatant is renamed to include the suffix.
|
||||
- **FR-007**: Auto-numbered names MUST remain editable via the existing rename functionality.
|
||||
- **FR-008**: Combatants added from the bestiary MUST retain a link (`creatureId`) to their creature data so the stat block can be re-opened from the tracker.
|
||||
@@ -67,6 +69,8 @@ When the search input has no bestiary matches (or fewer than 2 characters typed)
|
||||
10. **Given** the user types a name with no bestiary match, **When** the dropdown shows no results, **Then** optional input fields for initiative, AC, and max HP appear with visible labels.
|
||||
11. **Given** the optional fields are visible, **When** the user leaves all optional fields empty and submits, **Then** the creature is added with only the name (no stats pre-filled).
|
||||
12. **Given** the search input is open, **When** the user presses Escape, **Then** the search closes without adding a combatant.
|
||||
13. **Given** the game system is Pathfinder 2e, **When** the DM types "abo" in the search field, **Then** results show PF2e creatures (e.g., "Aboleth (Bestiary 1)") from the PF2e index, not D&D creatures.
|
||||
14. **Given** the game system is Pathfinder 2e, **When** the DM selects a PF2e creature, **Then** a combatant is added with name, HP, AC, and Perception as the initiative modifier.
|
||||
|
||||
### Edge Cases
|
||||
|
||||
@@ -97,7 +101,7 @@ As a DM using the app on different devices, I want the layout to adapt between s
|
||||
### Requirements
|
||||
|
||||
- **FR-016**: The system MUST display a stat block panel with full creature information when a creature is selected.
|
||||
- **FR-017**: The stat block MUST include: name, size, type, alignment, AC (with armor source if applicable), HP (average + formula), speed, ability scores with modifiers, saving throws, skills, damage vulnerabilities, damage resistances, damage immunities, condition immunities, senses, languages, challenge rating, proficiency bonus, passive perception, traits, actions, bonus actions, reactions, spellcasting, and legendary actions.
|
||||
- **FR-017**: For D&D creatures, the stat block MUST include: name, size, type, alignment, AC (with armor source if applicable), HP (average + formula), speed, ability scores with modifiers, saving throws, skills, damage vulnerabilities, damage resistances, damage immunities, condition immunities, senses, languages, challenge rating, proficiency bonus, passive perception, traits, actions, bonus actions, reactions, spellcasting, and legendary actions. For PF2e creatures, the stat block MUST include: name, level, traits (as tags), Perception and senses, languages, skills, ability modifiers (Str/Dex/Con/Int/Wis/Cha as modifiers, not scores), items, AC, saving throws (Fort/Ref/Will), HP (with optional immunities/resistances/weaknesses), speed, attacks, top abilities, mid abilities (reactions/auras), bot abilities (active), and spellcasting.
|
||||
- **FR-018**: Optional stat block sections (traits, legendary actions, bonus actions, reactions, etc.) MUST be omitted entirely when the creature has none.
|
||||
- **FR-019**: The system MUST strip bestiary markup tags (spell references, dice notation, attack tags) and render them as plain readable text (e.g., `{@spell fireball|XPHB}` -> "fireball", `{@dice 3d6}` -> "3d6").
|
||||
- **FR-020**: On wide viewports (desktop), the layout MUST be side-by-side with the encounter tracker on the left and stat block on the right.
|
||||
@@ -105,6 +109,12 @@ As a DM using the app on different devices, I want the layout to adapt between s
|
||||
- **FR-022**: The stat block panel MUST scroll independently of the encounter tracker.
|
||||
- **FR-023**: When the user clicks the book icon on a different bestiary-linked combatant row, the stat block panel MUST update to show that creature's data.
|
||||
- **FR-024**: The existing search/view button MUST be repurposed to open the stat block for the currently focused/selected creature in the dropdown.
|
||||
- **FR-063**: The stat block renderer MUST select the appropriate layout (D&D or PF2e) based on the creature's game system. The creature's game system is determined by the index it was added from.
|
||||
- **FR-064**: PF2e stat blocks MUST display level in place of challenge rating. Level MUST appear in the stat block header.
|
||||
- **FR-065**: PF2e stat blocks MUST display three saving throws (Fortitude, Reflex, Will) instead of D&D's six ability-based saves.
|
||||
- **FR-066**: PF2e stat blocks MUST display ability modifiers directly (e.g., "Str +4") rather than ability scores with derived modifiers.
|
||||
- **FR-067**: PF2e stat blocks MUST organize abilities into three sections: top (above defenses), mid (reactions and auras), and bot (active abilities), matching the Pf2eTools source structure.
|
||||
- **FR-068**: PF2e stat blocks MUST strip Pf2eTools markup tags (e.g., `{@damage 1d8+7}`, `{@condition frightened}`) and render them as plain readable text, using the same tag-stripping approach as D&D (FR-019).
|
||||
- **FR-062**: Bestiary-linked combatant rows MUST display a small book icon (Lucide `BookOpen`) as the dedicated stat block trigger. The icon MUST have a tooltip ("View stat block") and an `aria-label="View stat block"` for accessibility. The book icon is the only way to manually open a stat block from the tracker — clicking the combatant name always enters inline rename mode. Non-bestiary combatant rows MUST NOT display the book icon.
|
||||
|
||||
### Acceptance Scenarios
|
||||
@@ -119,6 +129,8 @@ As a DM using the app on different devices, I want the layout to adapt between s
|
||||
8. **Given** a bestiary-linked combatant row is visible, **When** the user looks at the row, **Then** a small book icon is visible as the stat block trigger with a tooltip "View stat block".
|
||||
9. **Given** a custom (non-bestiary) combatant row is visible, **When** the user looks at the row, **Then** no book icon is displayed.
|
||||
10. **Given** a bestiary-linked combatant row is visible, **When** the user clicks the combatant's name, **Then** inline rename mode is entered — the stat block does NOT open.
|
||||
11. **Given** a PF2e creature is selected, **When** the stat block opens, **Then** it displays: name, level, traits as tags, Perception, senses, languages, skills, ability modifiers, AC, Fort/Ref/Will saves, HP, speed, attacks, abilities (top/mid/bot sections), and spellcasting (if applicable). No CR, no ability scores, no legendary actions.
|
||||
12. **Given** a PF2e creature with conditional AC (e.g., "with shield raised"), **When** viewing the stat block, **Then** both the standard AC and conditional AC are shown.
|
||||
|
||||
### Edge Cases
|
||||
|
||||
@@ -164,7 +176,7 @@ A DM wants to see which sources are cached, find a specific source, clear a spec
|
||||
- **FR-034**: An import button (Lucide Import icon) in the top bar MUST open the stat block side panel with the bulk import prompt.
|
||||
- **FR-035**: The bulk import prompt MUST show a descriptive text explaining the operation, including approximate data volume (~12.5 MB) and the dynamic number of sources derived from the bestiary index at runtime.
|
||||
- **FR-036**: The system MUST pre-fill a base URL that the user can edit.
|
||||
- **FR-037**: The system MUST construct individual fetch URLs by appending `bestiary-{sourceCode}.json` to the base URL for each source.
|
||||
- **FR-037**: The system MUST construct individual fetch URLs by appending the appropriate filename pattern to the base URL: `bestiary-{sourceCode}.json` for D&D sources, `creatures-{sourceCode}.json` for PF2e sources (matching the Pf2eTools naming convention).
|
||||
- **FR-038**: All fetch requests during bulk import MUST fire concurrently (browser handles connection pooling).
|
||||
- **FR-039**: Already-cached sources MUST be skipped during bulk import.
|
||||
- **FR-040**: The system MUST show a text counter ("Loading sources... N/T") and progress bar during bulk import.
|
||||
@@ -177,6 +189,10 @@ A DM wants to see which sources are cached, find a specific source, clear a spec
|
||||
- **FR-047**: The app MUST provide a management UI showing cached sources with a filter input for searching by display name and options to clear individual sources or all cached data.
|
||||
- **FR-048**: The normalization adapter and tag-stripping utility MUST remain the canonical pipeline for all fetched and uploaded data.
|
||||
- **FR-049**: The distributed app bundle MUST contain zero copyrighted prose content — only mechanical facts and creature names in the search index.
|
||||
- **FR-069**: The system MUST use a separate normalization pipeline for PF2e source data, mapping the Pf2eTools JSON structure to the PF2e creature type. Both pipelines (D&D and PF2e) MUST use the canonical tag-stripping utility.
|
||||
- **FR-070**: The source cache MUST be scoped by game system. D&D and PF2e sources MUST NOT collide in IndexedDB (e.g., both may have a source code "B1" but they are different sources).
|
||||
- **FR-071**: The bulk import prompt MUST adapt to the active game system: showing the correct source count, base URL (Pf2eTools for PF2e, 5etools for D&D), and approximate data volume for the active system.
|
||||
- **FR-072**: The source management UI MUST show only sources for the active game system.
|
||||
|
||||
### Acceptance Scenarios
|
||||
|
||||
@@ -199,6 +215,8 @@ A DM wants to see which sources are cached, find a specific source, clear a spec
|
||||
17. **Given** the source management UI is open, **When** the DM clears a single source, **Then** that source's data is removed; stat blocks for its creatures require re-fetching, while other cached sources remain.
|
||||
18. **Given** the source management UI is open, **When** the DM clears all cached data, **Then** all source data is removed and all stat blocks require re-fetching.
|
||||
19. **Given** many sources are cached, **When** the DM types a partial name in the filter input, **Then** only sources whose display name matches (case-insensitive) are shown.
|
||||
20. **Given** the game system is Pathfinder 2e, **When** the user clicks the import button, **Then** the bulk import prompt shows the PF2e source count (~79), a Pf2eTools-based URL, and a PF2e-appropriate data volume estimate.
|
||||
21. **Given** the game system is Pathfinder 2e and a PF2e source is cached, **When** the user opens a PF2e creature's stat block from that source, **Then** the PF2e stat block renders correctly from cached data.
|
||||
|
||||
### Edge Cases
|
||||
|
||||
@@ -273,8 +291,9 @@ As a DM with a creature pinned, I want to collapse the right (browse) panel inde
|
||||
|
||||
## Key Entities
|
||||
|
||||
- **Search Index** (`BestiaryIndex`): Pre-shipped lightweight dataset keyed by name + source, containing mechanical facts (name, source code, AC, HP average, DEX score, CR, initiative proficiency multiplier, size, type) for all creatures. Sufficient for adding combatants; insufficient for rendering a full stat block.
|
||||
- **Source** (`BestiarySource`): A D&D publication identified by a code (e.g., "XMM") with a display name (e.g., "Monster Manual (2025)"). Caching and fetching operate at the source level.
|
||||
- **Search Index (D&D)** (`BestiaryIndex`): Pre-shipped lightweight dataset keyed by name + source, containing mechanical facts (name, source code, AC, HP average, DEX score, CR, initiative proficiency multiplier, size, type) for all creatures. Sufficient for adding combatants; insufficient for rendering a full stat block.
|
||||
- **Search Index (PF2e)** (`Pf2eBestiaryIndex`): Pre-shipped lightweight dataset for PF2e creatures, containing name, source code, AC, HP, level, Perception modifier, size, and creature type. Parallel to the D&D search index but with PF2e-specific fields (level instead of CR, Perception instead of DEX/proficiency).
|
||||
- **Source** (`BestiarySource`): A D&D or PF2e publication identified by a code (e.g., "XMM") with a display name (e.g., "Monster Manual (2025)"). Caching and fetching operate at the source level.
|
||||
- **Creature (Full)** (`Creature`): A complete creature record with all stat block data (traits, actions, legendary actions, spellcasting, etc.), available only after source data is fetched/uploaded and cached. Identified by a branded `CreatureId`.
|
||||
- **Cached Source Data**: The full normalized bestiary data for a single source, stored in IndexedDB. Contains complete creature stat blocks.
|
||||
- **Combatant** (extended): Gains an optional `creatureId` reference to a `Creature`, enabling stat block lookup and stat pre-fill on creation.
|
||||
@@ -287,7 +306,7 @@ As a DM with a creature pinned, I want to collapse the right (browse) panel inde
|
||||
|
||||
## Success Criteria *(mandatory)*
|
||||
|
||||
- **SC-001**: All 3,312+ indexed creatures are searchable immediately on app load, with search results appearing within 100ms of typing.
|
||||
- **SC-001**: All indexed creatures for the active game system (3,312+ D&D or ~2,700+ PF2e) are searchable immediately on app load, with search results appearing within 100ms of typing.
|
||||
- **SC-002**: Adding a creature from search to the encounter completes without any network request and within 200ms.
|
||||
- **SC-003**: After a source is cached, stat blocks for any creature from that source display within 200ms with no additional prompt.
|
||||
- **SC-004**: The distributed app bundle contains zero copyrighted prose content — only mechanical facts and creature names in the search index.
|
||||
@@ -304,3 +323,7 @@ As a DM with a creature pinned, I want to collapse the right (browse) panel inde
|
||||
- **SC-015**: Users can pin a creature and browse a different creature's stat block simultaneously, without any additional navigation steps.
|
||||
- **SC-016**: The pinned panel is never visible on screens narrower than the dual-panel breakpoint, ensuring mobile usability is not degraded.
|
||||
- **SC-017**: All collapse/expand and pin/unpin interactions are discoverable through visible button controls without requiring documentation or tooltips.
|
||||
- **SC-018**: All ~2,700+ PF2e indexed creatures are searchable when PF2e is the active game system, with search results appearing within 100ms of typing.
|
||||
- **SC-019**: PF2e stat blocks render the correct layout (level, three saves, ability modifiers, ability sections) for all PF2e creatures — no D&D-specific fields (CR, ability scores, legendary actions) are shown.
|
||||
- **SC-020**: Switching game system immediately changes which creatures appear in search — no page reload required.
|
||||
- **SC-021**: Both D&D and PF2e search indexes ship bundled with the app; no network fetch is required to search creatures in either system.
|
||||
|
||||
Reference in New Issue
Block a user