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>
41 lines
982 B
TypeScript
41 lines
982 B
TypeScript
import { createContext, type ReactNode, useContext } from "react";
|
|
import type {
|
|
BestiaryCachePort,
|
|
BestiaryIndexPort,
|
|
EncounterPersistence,
|
|
Pf2eBestiaryIndexPort,
|
|
PlayerCharacterPersistence,
|
|
UndoRedoPersistence,
|
|
} from "../adapters/ports.js";
|
|
|
|
export interface Adapters {
|
|
encounterPersistence: EncounterPersistence;
|
|
undoRedoPersistence: UndoRedoPersistence;
|
|
playerCharacterPersistence: PlayerCharacterPersistence;
|
|
bestiaryCache: BestiaryCachePort;
|
|
bestiaryIndex: BestiaryIndexPort;
|
|
pf2eBestiaryIndex: Pf2eBestiaryIndexPort;
|
|
}
|
|
|
|
const AdapterContext = createContext<Adapters | null>(null);
|
|
|
|
export function AdapterProvider({
|
|
adapters,
|
|
children,
|
|
}: {
|
|
adapters: Adapters;
|
|
children: ReactNode;
|
|
}) {
|
|
return (
|
|
<AdapterContext.Provider value={adapters}>
|
|
{children}
|
|
</AdapterContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useAdapters(): Adapters {
|
|
const ctx = useContext(AdapterContext);
|
|
if (!ctx) throw new Error("useAdapters requires AdapterProvider");
|
|
return ctx;
|
|
}
|