From b542987d422017193eed163ec77f0254c63377ce Mon Sep 17 00:00:00 2001 From: Claude Code Date: Wed, 1 Apr 2026 06:23:51 -0700 Subject: [PATCH] =?UTF-8?q?refactor(guide-contexts):=20=E2=99=BB=EF=B8=8F?= =?UTF-8?q?=20Implement=20cleaner=20context=20provider=20and=20state=20man?= =?UTF-8?q?agement=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Lilith Autocommit --- .../guide/src/contexts/GuideDataContext.tsx | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/packages/guide/src/contexts/GuideDataContext.tsx diff --git a/src/packages/guide/src/contexts/GuideDataContext.tsx b/src/packages/guide/src/contexts/GuideDataContext.tsx new file mode 100644 index 00000000..801a4f9a --- /dev/null +++ b/src/packages/guide/src/contexts/GuideDataContext.tsx @@ -0,0 +1,107 @@ +import { createContext, useContext, type ReactNode } from 'react' +import type { + Keyword, Race, EncyclopediaEntry, + Unit, Building, Spell, Tech, Terrain, Resource, + Improvement, Government, Era, Victory, MapType, Item, + PromotionsData, DisciplinesData, + EcologicalEventCategory, CrossTriggers, + WeatherEvent, LeyChanneling, TerrainModifier, + InfusionTree, InfusionConfig, + EncyclopediaCategoryMeta, +} from '../types/game-data' + +// --------------------------------------------------------------------------- +// Context value — comprehensive data surface for all shared pages/components +// --------------------------------------------------------------------------- + +/** Wind band definition from climate_params. */ +export interface WindBandData { + name: string + dir: 'east' | 'west' | 'calm' + dirLabel: string + speed: number +} + +/** Merged weather event with effects/thresholds for the events page. */ +export interface MergedWeatherEvent extends WeatherEvent { + effects: Record + thresholds: Record +} + +export interface GuideDataContextValue { + // Game identity + packId: string + packName: string + + // Core game-pack data + races: Race[] + units: Unit[] + buildings: Building[] + spells: Spell[] + techs: Tech[] + keywords: Keyword[] + terrains: Terrain[] + resources: Resource[] + improvements: Improvement[] + governments: Government[] + eras: Era[] + victories: Victory[] + mapTypes: MapType[] + items: Item[] + encyclopediaEntries: EncyclopediaEntry[] + encyclopediaCategories: EncyclopediaCategoryMeta[] + promotionsData: PromotionsData + disciplinesData: DisciplinesData + infusionConfig: InfusionConfig + infusionTrees: InfusionTree[] + + // Derived building splits + playerWonders: Building[] + playerBuildings: Building[] + npcBuildings: Building[] + + // Climate / engine data (per-pack subscriptions to shared resources) + climateSpec: Record + climateParams: Record + hydrologyParams: Record + weatherEvents: MergedWeatherEvent[] + windBands: WindBandData[] + qualityUpThreshold: number + qualityDownThreshold: number + mountainRainShadowBlock: number + allEventCategories: Record + crossTriggers: CrossTriggers + leyChanneling: LeyChanneling + terrainModifiers: Record + + // Derived / computed + techTierMap: ReadonlyMap +} + +// --------------------------------------------------------------------------- +// Context + provider +// --------------------------------------------------------------------------- + +const GuideDataContext = createContext(null) + +export function GuideDataProvider({ + data, + children, +}: { + data: GuideDataContextValue + children: ReactNode +}) { + return ( + + {children} + + ) +} + +export function useGuideData(): GuideDataContextValue { + const ctx = useContext(GuideDataContext) + if (!ctx) { + throw new Error('useGuideData must be used within a ') + } + return ctx +}