@dreamboard-games/ui-sdk 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +89 -0
- package/NOTICE +1 -0
- package/README.md +154 -0
- package/dist/components/ActionButton.d.ts +13 -0
- package/dist/components/ActionButton.d.ts.map +1 -0
- package/dist/components/ActionButton.js +14 -0
- package/dist/components/ActionPanel.d.ts +33 -0
- package/dist/components/ActionPanel.d.ts.map +1 -0
- package/dist/components/ActionPanel.js +148 -0
- package/dist/components/Card.d.ts +29 -0
- package/dist/components/Card.d.ts.map +1 -0
- package/dist/components/Card.js +220 -0
- package/dist/components/ChromeSuppressionContext.d.ts +7 -0
- package/dist/components/ChromeSuppressionContext.d.ts.map +1 -0
- package/dist/components/ChromeSuppressionContext.js +34 -0
- package/dist/components/CostDisplay.d.ts +22 -0
- package/dist/components/CostDisplay.d.ts.map +1 -0
- package/dist/components/CostDisplay.js +41 -0
- package/dist/components/DiceRoller.d.ts +30 -0
- package/dist/components/DiceRoller.d.ts.map +1 -0
- package/dist/components/DiceRoller.js +319 -0
- package/dist/components/Drawer.d.ts +19 -0
- package/dist/components/Drawer.d.ts.map +1 -0
- package/dist/components/Drawer.js +55 -0
- package/dist/components/ErrorBoundary.d.ts +24 -0
- package/dist/components/ErrorBoundary.d.ts.map +1 -0
- package/dist/components/ErrorBoundary.js +37 -0
- package/dist/components/GameEndDisplay.d.ts +27 -0
- package/dist/components/GameEndDisplay.d.ts.map +1 -0
- package/dist/components/GameEndDisplay.js +185 -0
- package/dist/components/GameSkeleton.d.ts +12 -0
- package/dist/components/GameSkeleton.d.ts.map +1 -0
- package/dist/components/GameSkeleton.js +54 -0
- package/dist/components/Hand.d.ts +99 -0
- package/dist/components/Hand.d.ts.map +1 -0
- package/dist/components/Hand.js +162 -0
- package/dist/components/HandDock.d.ts +35 -0
- package/dist/components/HandDock.d.ts.map +1 -0
- package/dist/components/HandDock.js +124 -0
- package/dist/components/InteractionForm.d.ts +50 -0
- package/dist/components/InteractionForm.d.ts.map +1 -0
- package/dist/components/InteractionForm.js +402 -0
- package/dist/components/MoreActions.d.ts +49 -0
- package/dist/components/MoreActions.d.ts.map +1 -0
- package/dist/components/MoreActions.js +64 -0
- package/dist/components/PhaseIndicator.d.ts +35 -0
- package/dist/components/PhaseIndicator.d.ts.map +1 -0
- package/dist/components/PhaseIndicator.js +212 -0
- package/dist/components/PlayArea.d.ts +28 -0
- package/dist/components/PlayArea.d.ts.map +1 -0
- package/dist/components/PlayArea.js +48 -0
- package/dist/components/PluginRuntime.d.ts +37 -0
- package/dist/components/PluginRuntime.d.ts.map +1 -0
- package/dist/components/PluginRuntime.js +47 -0
- package/dist/components/PrimaryActionButton.d.ts +98 -0
- package/dist/components/PrimaryActionButton.d.ts.map +1 -0
- package/dist/components/PrimaryActionButton.js +183 -0
- package/dist/components/PrimaryButton.d.ts +20 -0
- package/dist/components/PrimaryButton.d.ts.map +1 -0
- package/dist/components/PrimaryButton.js +5 -0
- package/dist/components/PromptDialogHost.d.ts +15 -0
- package/dist/components/PromptDialogHost.d.ts.map +1 -0
- package/dist/components/PromptDialogHost.js +22 -0
- package/dist/components/ResourceCounter.d.ts +38 -0
- package/dist/components/ResourceCounter.d.ts.map +1 -0
- package/dist/components/ResourceCounter.js +118 -0
- package/dist/components/ThemedButton.d.ts +12 -0
- package/dist/components/ThemedButton.d.ts.map +1 -0
- package/dist/components/ThemedButton.js +38 -0
- package/dist/components/Toast.d.ts +35 -0
- package/dist/components/Toast.d.ts.map +1 -0
- package/dist/components/Toast.js +116 -0
- package/dist/components/board/HexGrid.d.ts +344 -0
- package/dist/components/board/HexGrid.d.ts.map +1 -0
- package/dist/components/board/HexGrid.js +340 -0
- package/dist/components/board/NetworkGraph.d.ts +100 -0
- package/dist/components/board/NetworkGraph.d.ts.map +1 -0
- package/dist/components/board/NetworkGraph.js +123 -0
- package/dist/components/board/SlotSystem.d.ts +71 -0
- package/dist/components/board/SlotSystem.d.ts.map +1 -0
- package/dist/components/board/SlotSystem.js +87 -0
- package/dist/components/board/SquareGrid.d.ts +188 -0
- package/dist/components/board/SquareGrid.d.ts.map +1 -0
- package/dist/components/board/SquareGrid.js +328 -0
- package/dist/components/board/TrackBoard.d.ts +113 -0
- package/dist/components/board/TrackBoard.d.ts.map +1 -0
- package/dist/components/board/TrackBoard.js +135 -0
- package/dist/components/board/ZoneMap.d.ts +88 -0
- package/dist/components/board/ZoneMap.d.ts.map +1 -0
- package/dist/components/board/ZoneMap.js +133 -0
- package/dist/components/board/hex-board-view.d.ts +69 -0
- package/dist/components/board/hex-board-view.d.ts.map +1 -0
- package/dist/components/board/hex-board-view.js +60 -0
- package/dist/components/board/index.d.ts +23 -0
- package/dist/components/board/index.d.ts.map +1 -0
- package/dist/components/board/index.js +40 -0
- package/dist/components/board/interaction-accessibility.d.ts +5 -0
- package/dist/components/board/interaction-accessibility.d.ts.map +1 -0
- package/dist/components/board/interaction-accessibility.js +13 -0
- package/dist/components/board/target-layer.d.ts +13 -0
- package/dist/components/board/target-layer.d.ts.map +1 -0
- package/dist/components/board/target-layer.js +10 -0
- package/dist/components/card-render-content.type-test.d.ts +2 -0
- package/dist/components/card-render-content.type-test.d.ts.map +1 -0
- package/dist/components/card-render-content.type-test.js +1 -0
- package/dist/components/index.d.ts +34 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +35 -0
- package/dist/components/interaction-dialog-behavior.d.ts +15 -0
- package/dist/components/interaction-dialog-behavior.d.ts.map +1 -0
- package/dist/components/interaction-dialog-behavior.js +9 -0
- package/dist/components/surfaces/BlockerSurface.d.ts +27 -0
- package/dist/components/surfaces/BlockerSurface.d.ts.map +1 -0
- package/dist/components/surfaces/BlockerSurface.js +38 -0
- package/dist/components/surfaces/BoardSurface.d.ts +77 -0
- package/dist/components/surfaces/BoardSurface.d.ts.map +1 -0
- package/dist/components/surfaces/BoardSurface.js +180 -0
- package/dist/components/surfaces/ChromeSurface.d.ts +29 -0
- package/dist/components/surfaces/ChromeSurface.d.ts.map +1 -0
- package/dist/components/surfaces/ChromeSurface.js +34 -0
- package/dist/components/surfaces/ExhaustivenessAudit.d.ts +32 -0
- package/dist/components/surfaces/ExhaustivenessAudit.d.ts.map +1 -0
- package/dist/components/surfaces/ExhaustivenessAudit.js +65 -0
- package/dist/components/surfaces/InboxSurface.d.ts +40 -0
- package/dist/components/surfaces/InboxSurface.d.ts.map +1 -0
- package/dist/components/surfaces/InboxSurface.js +99 -0
- package/dist/components/surfaces/MarketSurface.d.ts +62 -0
- package/dist/components/surfaces/MarketSurface.d.ts.map +1 -0
- package/dist/components/surfaces/MarketSurface.js +242 -0
- package/dist/components/surfaces/PanelSurface.d.ts +111 -0
- package/dist/components/surfaces/PanelSurface.d.ts.map +1 -0
- package/dist/components/surfaces/PanelSurface.js +180 -0
- package/dist/components/surfaces/PlayerCardsSurface.d.ts +104 -0
- package/dist/components/surfaces/PlayerCardsSurface.d.ts.map +1 -0
- package/dist/components/surfaces/PlayerCardsSurface.js +178 -0
- package/dist/components/surfaces/internal/CardZoneFollowUpForm.d.ts +7 -0
- package/dist/components/surfaces/internal/CardZoneFollowUpForm.d.ts.map +1 -0
- package/dist/components/surfaces/internal/CardZoneFollowUpForm.js +9 -0
- package/dist/components/surfaces/internal/DefaultInteractionButton.d.ts +71 -0
- package/dist/components/surfaces/internal/DefaultInteractionButton.d.ts.map +1 -0
- package/dist/components/surfaces/internal/DefaultInteractionButton.js +82 -0
- package/dist/components/surfaces/internal/useCardZoneInteractions.d.ts +21 -0
- package/dist/components/surfaces/internal/useCardZoneInteractions.d.ts.map +1 -0
- package/dist/components/surfaces/internal/useCardZoneInteractions.js +202 -0
- package/dist/components/surfaces/types.d.ts +59 -0
- package/dist/components/surfaces/types.d.ts.map +1 -0
- package/dist/components/surfaces/types.js +1 -0
- package/dist/context/ClientParamSchemaContext.d.ts +21 -0
- package/dist/context/ClientParamSchemaContext.d.ts.map +1 -0
- package/dist/context/ClientParamSchemaContext.js +12 -0
- package/dist/context/InteractionDraftContext.d.ts +69 -0
- package/dist/context/InteractionDraftContext.d.ts.map +1 -0
- package/dist/context/InteractionDraftContext.js +145 -0
- package/dist/context/PluginSessionContext.d.ts +33 -0
- package/dist/context/PluginSessionContext.d.ts.map +1 -0
- package/dist/context/PluginSessionContext.js +38 -0
- package/dist/context/PluginStateContext.d.ts +116 -0
- package/dist/context/PluginStateContext.d.ts.map +1 -0
- package/dist/context/PluginStateContext.js +186 -0
- package/dist/context/RuntimeContext.d.ts +49 -0
- package/dist/context/RuntimeContext.d.ts.map +1 -0
- package/dist/context/RuntimeContext.js +67 -0
- package/dist/defaults/components.d.ts +52 -0
- package/dist/defaults/components.d.ts.map +1 -0
- package/dist/defaults/components.js +159 -0
- package/dist/defaults/index.d.ts +2 -0
- package/dist/defaults/index.d.ts.map +1 -0
- package/dist/defaults/index.js +1 -0
- package/dist/errors/ValidationError.d.ts +10 -0
- package/dist/errors/ValidationError.d.ts.map +1 -0
- package/dist/errors/ValidationError.js +23 -0
- package/dist/helpers/cards.d.ts +3 -0
- package/dist/helpers/cards.d.ts.map +1 -0
- package/dist/helpers/cards.js +11 -0
- package/dist/helpers/track-board.d.ts +79 -0
- package/dist/helpers/track-board.d.ts.map +1 -0
- package/dist/helpers/track-board.js +56 -0
- package/dist/hooks/useActivePlayers.d.ts +16 -0
- package/dist/hooks/useActivePlayers.d.ts.map +1 -0
- package/dist/hooks/useActivePlayers.js +17 -0
- package/dist/hooks/useBoardInteractions.d.ts +110 -0
- package/dist/hooks/useBoardInteractions.d.ts.map +1 -0
- package/dist/hooks/useBoardInteractions.js +248 -0
- package/dist/hooks/useBoardTopology.d.ts +23 -0
- package/dist/hooks/useBoardTopology.d.ts.map +1 -0
- package/dist/hooks/useBoardTopology.js +128 -0
- package/dist/hooks/useCards.d.ts +3 -0
- package/dist/hooks/useCards.d.ts.map +1 -0
- package/dist/hooks/useCards.js +5 -0
- package/dist/hooks/useGameSelector.d.ts +13 -0
- package/dist/hooks/useGameSelector.d.ts.map +1 -0
- package/dist/hooks/useGameSelector.js +67 -0
- package/dist/hooks/useGameView.d.ts +6 -0
- package/dist/hooks/useGameView.d.ts.map +1 -0
- package/dist/hooks/useGameView.js +7 -0
- package/dist/hooks/useHandLayout.d.ts +120 -0
- package/dist/hooks/useHandLayout.d.ts.map +1 -0
- package/dist/hooks/useHandLayout.js +235 -0
- package/dist/hooks/useHexBoard.d.ts +19 -0
- package/dist/hooks/useHexBoard.d.ts.map +1 -0
- package/dist/hooks/useHexBoard.js +28 -0
- package/dist/hooks/useHexGrid.d.ts +56 -0
- package/dist/hooks/useHexGrid.d.ts.map +1 -0
- package/dist/hooks/useHexGrid.js +112 -0
- package/dist/hooks/useInteractionByKey.d.ts +29 -0
- package/dist/hooks/useInteractionByKey.d.ts.map +1 -0
- package/dist/hooks/useInteractionByKey.js +263 -0
- package/dist/hooks/useInteractionHandle.d.ts +103 -0
- package/dist/hooks/useInteractionHandle.d.ts.map +1 -0
- package/dist/hooks/useInteractionHandle.js +254 -0
- package/dist/hooks/useIsMobile.d.ts +7 -0
- package/dist/hooks/useIsMobile.d.ts.map +1 -0
- package/dist/hooks/useIsMobile.js +29 -0
- package/dist/hooks/useIsMyTurn.d.ts +6 -0
- package/dist/hooks/useIsMyTurn.d.ts.map +1 -0
- package/dist/hooks/useIsMyTurn.js +11 -0
- package/dist/hooks/useLobby.d.ts +28 -0
- package/dist/hooks/useLobby.d.ts.map +1 -0
- package/dist/hooks/useLobby.js +60 -0
- package/dist/hooks/useMe.d.ts +11 -0
- package/dist/hooks/useMe.d.ts.map +1 -0
- package/dist/hooks/useMe.js +32 -0
- package/dist/hooks/usePanZoom.d.ts +113 -0
- package/dist/hooks/usePanZoom.d.ts.map +1 -0
- package/dist/hooks/usePanZoom.js +165 -0
- package/dist/hooks/usePlayerInfo.d.ts +4 -0
- package/dist/hooks/usePlayerInfo.d.ts.map +1 -0
- package/dist/hooks/usePlayerInfo.js +21 -0
- package/dist/hooks/usePlayerTurnOrder.d.ts +15 -0
- package/dist/hooks/usePlayerTurnOrder.d.ts.map +1 -0
- package/dist/hooks/usePlayerTurnOrder.js +22 -0
- package/dist/hooks/usePluginRuntime.d.ts +45 -0
- package/dist/hooks/usePluginRuntime.d.ts.map +1 -0
- package/dist/hooks/usePluginRuntime.js +92 -0
- package/dist/hooks/useSeatInbox.d.ts +22 -0
- package/dist/hooks/useSeatInbox.d.ts.map +1 -0
- package/dist/hooks/useSeatInbox.js +43 -0
- package/dist/hooks/useSimultaneousPhase.d.ts +7 -0
- package/dist/hooks/useSimultaneousPhase.d.ts.map +1 -0
- package/dist/hooks/useSimultaneousPhase.js +8 -0
- package/dist/hooks/useSquareBoard.d.ts +21 -0
- package/dist/hooks/useSquareBoard.d.ts.map +1 -0
- package/dist/hooks/useSquareBoard.js +67 -0
- package/dist/hooks/useSquareGrid.d.ts +96 -0
- package/dist/hooks/useSquareGrid.d.ts.map +1 -0
- package/dist/hooks/useSquareGrid.js +152 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/internal/ui/alert.d.ts +8 -0
- package/dist/internal/ui/alert.d.ts.map +1 -0
- package/dist/internal/ui/alert.js +11 -0
- package/dist/internal/ui/button.d.ts +10 -0
- package/dist/internal/ui/button.d.ts.map +1 -0
- package/dist/internal/ui/button.js +21 -0
- package/dist/internal/ui/dialog.d.ts +16 -0
- package/dist/internal/ui/dialog.d.ts.map +1 -0
- package/dist/internal/ui/dialog.js +35 -0
- package/dist/internal/ui/input.d.ts +3 -0
- package/dist/internal/ui/input.d.ts.map +1 -0
- package/dist/internal/ui/input.js +5 -0
- package/dist/internal/ui/label.d.ts +4 -0
- package/dist/internal/ui/label.d.ts.map +1 -0
- package/dist/internal/ui/label.js +7 -0
- package/dist/internal/ui/select.d.ts +9 -0
- package/dist/internal/ui/select.d.ts.map +1 -0
- package/dist/internal/ui/select.js +23 -0
- package/dist/internal/ui/tooltip.d.ts +7 -0
- package/dist/internal/ui/tooltip.d.ts.map +1 -0
- package/dist/internal/ui/tooltip.js +16 -0
- package/dist/internal/ui/utils.d.ts +3 -0
- package/dist/internal/ui/utils.d.ts.map +1 -0
- package/dist/internal/ui/utils.js +4 -0
- package/dist/internal.d.ts +7 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +4 -0
- package/dist/plugin-styles.css +246 -0
- package/dist/primitives/board.d.ts +29 -0
- package/dist/primitives/board.d.ts.map +1 -0
- package/dist/primitives/board.js +163 -0
- package/dist/primitives/game-ui-provider.d.ts +12 -0
- package/dist/primitives/game-ui-provider.d.ts.map +1 -0
- package/dist/primitives/game-ui-provider.js +7 -0
- package/dist/primitives/index.d.ts +8 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +7 -0
- package/dist/primitives/interaction.d.ts +52 -0
- package/dist/primitives/interaction.d.ts.map +1 -0
- package/dist/primitives/interaction.js +250 -0
- package/dist/primitives/phase.d.ts +15 -0
- package/dist/primitives/phase.d.ts.map +1 -0
- package/dist/primitives/phase.js +18 -0
- package/dist/primitives/player-roster.d.ts +64 -0
- package/dist/primitives/player-roster.d.ts.map +1 -0
- package/dist/primitives/player-roster.js +149 -0
- package/dist/primitives/primitive-props.d.ts +15 -0
- package/dist/primitives/primitive-props.d.ts.map +1 -0
- package/dist/primitives/primitive-props.js +39 -0
- package/dist/primitives/prompt.d.ts +44 -0
- package/dist/primitives/prompt.d.ts.map +1 -0
- package/dist/primitives/prompt.js +101 -0
- package/dist/primitives/zone.d.ts +31 -0
- package/dist/primitives/zone.d.ts.map +1 -0
- package/dist/primitives/zone.js +58 -0
- package/dist/reducer.d.ts +21 -0
- package/dist/reducer.d.ts.map +1 -0
- package/dist/reducer.js +14 -0
- package/dist/runtime/createPluginRuntimeAPI.d.ts +67 -0
- package/dist/runtime/createPluginRuntimeAPI.d.ts.map +1 -0
- package/dist/runtime/createPluginRuntimeAPI.js +419 -0
- package/dist/theme/ThemeProvider.d.ts +98 -0
- package/dist/theme/ThemeProvider.d.ts.map +1 -0
- package/dist/theme/ThemeProvider.js +148 -0
- package/dist/theme/board.d.ts +42 -0
- package/dist/theme/board.d.ts.map +1 -0
- package/dist/theme/board.js +34 -0
- package/dist/theme/css-vars.d.ts +31 -0
- package/dist/theme/css-vars.d.ts.map +1 -0
- package/dist/theme/css-vars.js +88 -0
- package/dist/theme/derive.d.ts +66 -0
- package/dist/theme/derive.d.ts.map +1 -0
- package/dist/theme/derive.js +161 -0
- package/dist/theme/index.d.ts +22 -0
- package/dist/theme/index.d.ts.map +1 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/presets/arcade.d.ts +10 -0
- package/dist/theme/presets/arcade.d.ts.map +1 -0
- package/dist/theme/presets/arcade.js +257 -0
- package/dist/theme/presets/studio.d.ts +10 -0
- package/dist/theme/presets/studio.d.ts.map +1 -0
- package/dist/theme/presets/studio.js +257 -0
- package/dist/theme/presets/tabletop.d.ts +15 -0
- package/dist/theme/presets/tabletop.d.ts.map +1 -0
- package/dist/theme/presets/tabletop.js +262 -0
- package/dist/theme/tokens.d.ts +345 -0
- package/dist/theme/tokens.d.ts.map +1 -0
- package/dist/theme/tokens.js +57 -0
- package/dist/types/player-state.d.ts +337 -0
- package/dist/types/player-state.d.ts.map +1 -0
- package/dist/types/player-state.js +1 -0
- package/dist/types/plugin-state.d.ts +324 -0
- package/dist/types/plugin-state.d.ts.map +1 -0
- package/dist/types/plugin-state.js +1 -0
- package/dist/types/reducer-state.d.ts +10 -0
- package/dist/types/reducer-state.d.ts.map +1 -0
- package/dist/types/reducer-state.js +1 -0
- package/dist/types/runtime-api.d.ts +99 -0
- package/dist/types/runtime-api.d.ts.map +1 -0
- package/dist/types/runtime-api.js +1 -0
- package/dist/types/tiled-board.d.ts +187 -0
- package/dist/types/tiled-board.d.ts.map +1 -0
- package/dist/types/tiled-board.js +226 -0
- package/dist/ui-contract.d.ts +78 -0
- package/dist/ui-contract.d.ts.map +1 -0
- package/dist/ui-contract.js +15 -0
- package/dist/ui-sdk.d.ts +3409 -0
- package/dist/utils/interaction-inputs.d.ts +22 -0
- package/dist/utils/interaction-inputs.d.ts.map +1 -0
- package/dist/utils/interaction-inputs.js +219 -0
- package/dist/utils/interaction-labels.d.ts +4 -0
- package/dist/utils/interaction-labels.d.ts.map +1 -0
- package/dist/utils/interaction-labels.js +18 -0
- package/dist/utils/interaction-status.d.ts +15 -0
- package/dist/utils/interaction-status.d.ts.map +1 -0
- package/dist/utils/interaction-status.js +31 -0
- package/package.json +101 -0
- package/src/components/ActionButton.tsx +48 -0
- package/src/components/ActionPanel.tsx +310 -0
- package/src/components/Card.tsx +385 -0
- package/src/components/ChromeSuppressionContext.tsx +70 -0
- package/src/components/CostDisplay.test.tsx +23 -0
- package/src/components/CostDisplay.tsx +145 -0
- package/src/components/DiceRoller.tsx +601 -0
- package/src/components/Drawer.tsx +179 -0
- package/src/components/ErrorBoundary.tsx +119 -0
- package/src/components/GameEndDisplay.test.tsx +19 -0
- package/src/components/GameEndDisplay.tsx +398 -0
- package/src/components/GameSkeleton.tsx +260 -0
- package/src/components/Hand.tsx +387 -0
- package/src/components/HandDock.tsx +257 -0
- package/src/components/InteractionForm.test.tsx +303 -0
- package/src/components/InteractionForm.tsx +1029 -0
- package/src/components/MoreActions.test.tsx +93 -0
- package/src/components/MoreActions.tsx +143 -0
- package/src/components/PhaseIndicator.tsx +341 -0
- package/src/components/PlayArea.tsx +125 -0
- package/src/components/PluginRuntime.tsx +92 -0
- package/src/components/PrimaryActionButton.test.tsx +138 -0
- package/src/components/PrimaryActionButton.tsx +351 -0
- package/src/components/PrimaryButton.tsx +44 -0
- package/src/components/PromptDialogHost.tsx +92 -0
- package/src/components/ResourceCounter.test.tsx +29 -0
- package/src/components/ResourceCounter.tsx +275 -0
- package/src/components/ThemedButton.tsx +78 -0
- package/src/components/Toast.tsx +251 -0
- package/src/components/__fixtures__/ActionButton.fixture.tsx +234 -0
- package/src/components/__fixtures__/ActionPanel.fixture.tsx +298 -0
- package/src/components/__fixtures__/Card.fixture.tsx +185 -0
- package/src/components/__fixtures__/CostDisplay.fixture.tsx +156 -0
- package/src/components/__fixtures__/DiceRoller.fixture.tsx +435 -0
- package/src/components/__fixtures__/Drawer.fixture.tsx +113 -0
- package/src/components/__fixtures__/ErrorBoundary.fixture.tsx +82 -0
- package/src/components/__fixtures__/GameEndDisplay.fixture.tsx +188 -0
- package/src/components/__fixtures__/GameSkeleton.fixture.tsx +46 -0
- package/src/components/__fixtures__/Hand.fixture.tsx +522 -0
- package/src/components/__fixtures__/HexGrid.fixture.tsx +1181 -0
- package/src/components/__fixtures__/NetworkGraph.fixture.tsx +599 -0
- package/src/components/__fixtures__/PhaseIndicator.fixture.tsx +181 -0
- package/src/components/__fixtures__/PlayArea.fixture.tsx +221 -0
- package/src/components/__fixtures__/ResourceCounter.fixture.tsx +227 -0
- package/src/components/__fixtures__/SlotSystem.fixture.tsx +824 -0
- package/src/components/__fixtures__/SquareGrid.fixture.tsx +764 -0
- package/src/components/__fixtures__/Toast.fixture.tsx +97 -0
- package/src/components/__fixtures__/TrackBoard.fixture.tsx +685 -0
- package/src/components/__fixtures__/ZoneMap.fixture.tsx +754 -0
- package/src/components/board/HexGrid.tsx +1294 -0
- package/src/components/board/NetworkGraph.tsx +476 -0
- package/src/components/board/SlotSystem.tsx +339 -0
- package/src/components/board/SquareGrid.tsx +1165 -0
- package/src/components/board/TrackBoard.tsx +496 -0
- package/src/components/board/ZoneMap.tsx +448 -0
- package/src/components/board/hex-board-view.test.tsx +114 -0
- package/src/components/board/hex-board-view.ts +123 -0
- package/src/components/board/index.ts +142 -0
- package/src/components/board/interaction-accessibility.ts +21 -0
- package/src/components/board/target-layer-grids.test.tsx +420 -0
- package/src/components/board/target-layer.ts +30 -0
- package/src/components/card-render-content.type-test.ts +27 -0
- package/src/components/index.ts +208 -0
- package/src/components/interaction-dialog-behavior.test.ts +23 -0
- package/src/components/interaction-dialog-behavior.ts +22 -0
- package/src/components/surfaces/BlockerSurface.test.tsx +158 -0
- package/src/components/surfaces/BlockerSurface.tsx +127 -0
- package/src/components/surfaces/BoardSurface.tsx +340 -0
- package/src/components/surfaces/ChromeSurface.tsx +123 -0
- package/src/components/surfaces/ExhaustivenessAudit.tsx +91 -0
- package/src/components/surfaces/InboxSurface.test.tsx +149 -0
- package/src/components/surfaces/InboxSurface.tsx +245 -0
- package/src/components/surfaces/MarketSurface.tsx +544 -0
- package/src/components/surfaces/PanelSurface.test.tsx +496 -0
- package/src/components/surfaces/PanelSurface.tsx +458 -0
- package/src/components/surfaces/PlayerCardsSurface.tsx +525 -0
- package/src/components/surfaces/internal/CardZoneFollowUpForm.tsx +35 -0
- package/src/components/surfaces/internal/DefaultInteractionButton.tsx +219 -0
- package/src/components/surfaces/internal/useCardZoneInteractions.ts +311 -0
- package/src/components/surfaces/types.ts +100 -0
- package/src/context/ClientParamSchemaContext.tsx +44 -0
- package/src/context/InteractionDraftContext.tsx +204 -0
- package/src/context/PluginSessionContext.tsx +47 -0
- package/src/context/PluginStateContext.tsx +254 -0
- package/src/context/RuntimeContext.tsx +96 -0
- package/src/defaults/components.tsx +442 -0
- package/src/defaults/defaults.test.tsx +230 -0
- package/src/defaults/index.ts +1 -0
- package/src/errors/ValidationError.ts +29 -0
- package/src/helpers/cards.ts +19 -0
- package/src/helpers/track-board.ts +211 -0
- package/src/hooks/useActivePlayers.ts +19 -0
- package/src/hooks/useBoardInteractions.test.tsx +622 -0
- package/src/hooks/useBoardInteractions.ts +434 -0
- package/src/hooks/useBoardTopology.ts +316 -0
- package/src/hooks/useCards.test.tsx +129 -0
- package/src/hooks/useCards.ts +10 -0
- package/src/hooks/useGameSelector.ts +105 -0
- package/src/hooks/useGameView.ts +9 -0
- package/src/hooks/useHandLayout.ts +349 -0
- package/src/hooks/useHexBoard.ts +74 -0
- package/src/hooks/useHexGrid.ts +185 -0
- package/src/hooks/useInteractionByKey.ts +349 -0
- package/src/hooks/useInteractionHandle.ts +437 -0
- package/src/hooks/useIsMobile.ts +35 -0
- package/src/hooks/useIsMyTurn.test.tsx +99 -0
- package/src/hooks/useIsMyTurn.ts +15 -0
- package/src/hooks/useLobby.ts +76 -0
- package/src/hooks/useMe.ts +48 -0
- package/src/hooks/usePanZoom.ts +278 -0
- package/src/hooks/usePlayerInfo.ts +28 -0
- package/src/hooks/usePlayerTurnOrder.ts +23 -0
- package/src/hooks/usePluginRuntime.test.tsx +102 -0
- package/src/hooks/usePluginRuntime.ts +130 -0
- package/src/hooks/useSeatInbox.ts +61 -0
- package/src/hooks/useSimultaneousPhase.ts +10 -0
- package/src/hooks/useSquareBoard.ts +124 -0
- package/src/hooks/useSquareGrid.ts +328 -0
- package/src/index.test.ts +474 -0
- package/src/index.ts +148 -0
- package/src/internal/ui/alert.tsx +51 -0
- package/src/internal/ui/button.tsx +58 -0
- package/src/internal/ui/dialog.tsx +134 -0
- package/src/internal/ui/input.tsx +21 -0
- package/src/internal/ui/label.tsx +21 -0
- package/src/internal/ui/select.tsx +129 -0
- package/src/internal/ui/tooltip.tsx +54 -0
- package/src/internal/ui/utils.ts +5 -0
- package/src/internal.ts +18 -0
- package/src/plugin-styles.css +246 -0
- package/src/primitives/board.test.tsx +139 -0
- package/src/primitives/board.tsx +267 -0
- package/src/primitives/game-ui-provider.tsx +35 -0
- package/src/primitives/index.ts +83 -0
- package/src/primitives/interaction.test.tsx +420 -0
- package/src/primitives/interaction.tsx +405 -0
- package/src/primitives/phase.test.tsx +82 -0
- package/src/primitives/phase.tsx +43 -0
- package/src/primitives/player-roster.test.tsx +168 -0
- package/src/primitives/player-roster.tsx +301 -0
- package/src/primitives/primitive-props.tsx +82 -0
- package/src/primitives/prompt.test.tsx +159 -0
- package/src/primitives/prompt.tsx +203 -0
- package/src/primitives/zone.tsx +113 -0
- package/src/reducer.ts +42 -0
- package/src/runtime/createPluginRuntimeAPI.ts +605 -0
- package/src/theme/ThemeProvider.test.tsx +36 -0
- package/src/theme/ThemeProvider.tsx +252 -0
- package/src/theme/board.ts +61 -0
- package/src/theme/css-vars.ts +105 -0
- package/src/theme/derive.ts +240 -0
- package/src/theme/index.ts +61 -0
- package/src/theme/presets/arcade.ts +261 -0
- package/src/theme/presets/studio.ts +261 -0
- package/src/theme/presets/tabletop.ts +266 -0
- package/src/theme/theme.test.ts +258 -0
- package/src/theme/tokens.ts +392 -0
- package/src/types/player-state.ts +445 -0
- package/src/types/plugin-state.ts +407 -0
- package/src/types/reducer-state.ts +24 -0
- package/src/types/runtime-api.ts +114 -0
- package/src/types/tiled-board.ts +785 -0
- package/src/ui-contract.ts +168 -0
- package/src/utils/interaction-inputs.test.ts +109 -0
- package/src/utils/interaction-inputs.ts +331 -0
- package/src/utils/interaction-labels.ts +23 -0
- package/src/utils/interaction-status.ts +59 -0
|
@@ -0,0 +1,785 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BoardId,
|
|
3
|
+
EdgeTypeId,
|
|
4
|
+
PlayerId,
|
|
5
|
+
SpaceTypeId,
|
|
6
|
+
VertexTypeId,
|
|
7
|
+
} from "@dreamboard/manifest-contract";
|
|
8
|
+
import type {
|
|
9
|
+
HexBoardState,
|
|
10
|
+
HexEdgeState,
|
|
11
|
+
HexTileState,
|
|
12
|
+
HexVertexState,
|
|
13
|
+
SquareBoardState,
|
|
14
|
+
SquareCellState,
|
|
15
|
+
SquareEdgeState,
|
|
16
|
+
SquarePieceState,
|
|
17
|
+
SquareVertexState,
|
|
18
|
+
} from "./player-state.js";
|
|
19
|
+
|
|
20
|
+
type RuntimeFields = Record<string, unknown>;
|
|
21
|
+
|
|
22
|
+
type NormalizeOptional<T> = Exclude<T, null | undefined> | undefined;
|
|
23
|
+
|
|
24
|
+
export interface GeneratedTiledEdgeStateLike<
|
|
25
|
+
SpaceIdValue extends string = string,
|
|
26
|
+
EdgeIdValue extends string = string,
|
|
27
|
+
Fields = RuntimeFields,
|
|
28
|
+
> {
|
|
29
|
+
id: EdgeIdValue;
|
|
30
|
+
spaceIds: readonly SpaceIdValue[];
|
|
31
|
+
typeId?: EdgeTypeId | null;
|
|
32
|
+
label?: string | null;
|
|
33
|
+
ownerId?: PlayerId | null;
|
|
34
|
+
fields?: Fields;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface GeneratedTiledVertexStateLike<
|
|
38
|
+
SpaceIdValue extends string = string,
|
|
39
|
+
VertexIdValue extends string = string,
|
|
40
|
+
Fields = RuntimeFields,
|
|
41
|
+
> {
|
|
42
|
+
id: VertexIdValue;
|
|
43
|
+
spaceIds: readonly SpaceIdValue[];
|
|
44
|
+
typeId?: VertexTypeId | null;
|
|
45
|
+
label?: string | null;
|
|
46
|
+
ownerId?: PlayerId | null;
|
|
47
|
+
fields?: Fields;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface GeneratedHexSpaceStateLike<
|
|
51
|
+
SpaceIdValue extends string = string,
|
|
52
|
+
Fields = RuntimeFields,
|
|
53
|
+
> {
|
|
54
|
+
id: SpaceIdValue;
|
|
55
|
+
q: number;
|
|
56
|
+
r: number;
|
|
57
|
+
typeId?: SpaceTypeId | null;
|
|
58
|
+
label?: string | null;
|
|
59
|
+
ownerId?: PlayerId | null;
|
|
60
|
+
fields?: Fields;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface GeneratedSquareSpaceStateLike<
|
|
64
|
+
SpaceIdValue extends string = string,
|
|
65
|
+
Fields = RuntimeFields,
|
|
66
|
+
> {
|
|
67
|
+
id: SpaceIdValue;
|
|
68
|
+
row: number;
|
|
69
|
+
col: number;
|
|
70
|
+
typeId?: SpaceTypeId | null;
|
|
71
|
+
label?: string | null;
|
|
72
|
+
ownerId?: PlayerId | null;
|
|
73
|
+
fields?: Fields;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface GeneratedHexBoardInput<
|
|
77
|
+
BoardIdValue extends string = BoardId,
|
|
78
|
+
SpaceIdValue extends string = string,
|
|
79
|
+
EdgeIdValue extends string = string,
|
|
80
|
+
VertexIdValue extends string = string,
|
|
81
|
+
SpaceFields = RuntimeFields,
|
|
82
|
+
EdgeFields = RuntimeFields,
|
|
83
|
+
VertexFields = RuntimeFields,
|
|
84
|
+
> {
|
|
85
|
+
id: BoardIdValue;
|
|
86
|
+
layout?: "hex";
|
|
87
|
+
orientation?: "pointy-top" | "flat-top";
|
|
88
|
+
spaces: Readonly<
|
|
89
|
+
Record<SpaceIdValue, GeneratedHexSpaceStateLike<SpaceIdValue, SpaceFields>>
|
|
90
|
+
>;
|
|
91
|
+
edges: ReadonlyArray<
|
|
92
|
+
| HexEdgeState<BoardIdValue, SpaceIdValue, EdgeIdValue, EdgeFields>
|
|
93
|
+
| GeneratedTiledEdgeStateLike<SpaceIdValue, EdgeIdValue, EdgeFields>
|
|
94
|
+
>;
|
|
95
|
+
vertices: ReadonlyArray<
|
|
96
|
+
| HexVertexState<BoardIdValue, SpaceIdValue, VertexIdValue, VertexFields>
|
|
97
|
+
| GeneratedTiledVertexStateLike<SpaceIdValue, VertexIdValue, VertexFields>
|
|
98
|
+
>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface AuthoredHexBoardInput<
|
|
102
|
+
BoardIdValue extends string = BoardId,
|
|
103
|
+
SpaceIdValue extends string = string,
|
|
104
|
+
EdgeIdValue extends string = string,
|
|
105
|
+
VertexIdValue extends string = string,
|
|
106
|
+
SpaceFields = RuntimeFields,
|
|
107
|
+
EdgeFields = RuntimeFields,
|
|
108
|
+
VertexFields = RuntimeFields,
|
|
109
|
+
SpaceView = unknown,
|
|
110
|
+
> {
|
|
111
|
+
id: BoardIdValue;
|
|
112
|
+
layout?: "hex";
|
|
113
|
+
orientation?: "pointy-top" | "flat-top";
|
|
114
|
+
tiles: ReadonlyArray<
|
|
115
|
+
HexTileState<BoardIdValue, SpaceIdValue, SpaceFields, SpaceView>
|
|
116
|
+
>;
|
|
117
|
+
edges: ReadonlyArray<
|
|
118
|
+
| HexEdgeState<BoardIdValue, SpaceIdValue, EdgeIdValue, EdgeFields>
|
|
119
|
+
| GeneratedTiledEdgeStateLike<SpaceIdValue, EdgeIdValue, EdgeFields>
|
|
120
|
+
>;
|
|
121
|
+
vertices: ReadonlyArray<
|
|
122
|
+
| HexVertexState<BoardIdValue, SpaceIdValue, VertexIdValue, VertexFields>
|
|
123
|
+
| GeneratedTiledVertexStateLike<SpaceIdValue, VertexIdValue, VertexFields>
|
|
124
|
+
>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export type HexBoardInput<
|
|
128
|
+
BoardIdValue extends string = BoardId,
|
|
129
|
+
SpaceIdValue extends string = string,
|
|
130
|
+
EdgeIdValue extends string = string,
|
|
131
|
+
VertexIdValue extends string = string,
|
|
132
|
+
SpaceFields = RuntimeFields,
|
|
133
|
+
EdgeFields = RuntimeFields,
|
|
134
|
+
VertexFields = RuntimeFields,
|
|
135
|
+
> =
|
|
136
|
+
| AuthoredHexBoardInput<
|
|
137
|
+
BoardIdValue,
|
|
138
|
+
SpaceIdValue,
|
|
139
|
+
EdgeIdValue,
|
|
140
|
+
VertexIdValue,
|
|
141
|
+
SpaceFields,
|
|
142
|
+
EdgeFields,
|
|
143
|
+
VertexFields
|
|
144
|
+
>
|
|
145
|
+
| GeneratedHexBoardInput<
|
|
146
|
+
BoardIdValue,
|
|
147
|
+
SpaceIdValue,
|
|
148
|
+
EdgeIdValue,
|
|
149
|
+
VertexIdValue,
|
|
150
|
+
SpaceFields,
|
|
151
|
+
EdgeFields,
|
|
152
|
+
VertexFields
|
|
153
|
+
>;
|
|
154
|
+
|
|
155
|
+
export interface GeneratedSquareBoardInput<
|
|
156
|
+
BoardIdValue extends string = BoardId,
|
|
157
|
+
SpaceIdValue extends string = string,
|
|
158
|
+
EdgeIdValue extends string = string,
|
|
159
|
+
VertexIdValue extends string = string,
|
|
160
|
+
PieceIdValue extends string = string,
|
|
161
|
+
SpaceFields = RuntimeFields,
|
|
162
|
+
EdgeFields = RuntimeFields,
|
|
163
|
+
VertexFields = RuntimeFields,
|
|
164
|
+
PieceFields = RuntimeFields,
|
|
165
|
+
> {
|
|
166
|
+
id: BoardIdValue;
|
|
167
|
+
layout?: "square";
|
|
168
|
+
spaces: Readonly<
|
|
169
|
+
Record<
|
|
170
|
+
SpaceIdValue,
|
|
171
|
+
GeneratedSquareSpaceStateLike<SpaceIdValue, SpaceFields>
|
|
172
|
+
>
|
|
173
|
+
>;
|
|
174
|
+
edges: ReadonlyArray<
|
|
175
|
+
| SquareEdgeState<SpaceIdValue, EdgeIdValue, EdgeFields>
|
|
176
|
+
| GeneratedTiledEdgeStateLike<SpaceIdValue, EdgeIdValue, EdgeFields>
|
|
177
|
+
>;
|
|
178
|
+
vertices: ReadonlyArray<
|
|
179
|
+
| SquareVertexState<SpaceIdValue, VertexIdValue, VertexFields>
|
|
180
|
+
| GeneratedTiledVertexStateLike<SpaceIdValue, VertexIdValue, VertexFields>
|
|
181
|
+
>;
|
|
182
|
+
pieces?: ReadonlyArray<SquarePieceState<PieceIdValue, PieceFields>>;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface AuthoredSquareBoardInput<
|
|
186
|
+
BoardIdValue extends string = BoardId,
|
|
187
|
+
SpaceIdValue extends string = string,
|
|
188
|
+
EdgeIdValue extends string = string,
|
|
189
|
+
VertexIdValue extends string = string,
|
|
190
|
+
PieceIdValue extends string = string,
|
|
191
|
+
SpaceFields = RuntimeFields,
|
|
192
|
+
EdgeFields = RuntimeFields,
|
|
193
|
+
VertexFields = RuntimeFields,
|
|
194
|
+
PieceFields = RuntimeFields,
|
|
195
|
+
> {
|
|
196
|
+
id: BoardIdValue;
|
|
197
|
+
layout?: "square";
|
|
198
|
+
rows: number;
|
|
199
|
+
cols: number;
|
|
200
|
+
cells: ReadonlyArray<SquareCellState<SpaceIdValue, SpaceFields>>;
|
|
201
|
+
edges: ReadonlyArray<
|
|
202
|
+
| SquareEdgeState<SpaceIdValue, EdgeIdValue, EdgeFields>
|
|
203
|
+
| GeneratedTiledEdgeStateLike<SpaceIdValue, EdgeIdValue, EdgeFields>
|
|
204
|
+
>;
|
|
205
|
+
vertices: ReadonlyArray<
|
|
206
|
+
| SquareVertexState<SpaceIdValue, VertexIdValue, VertexFields>
|
|
207
|
+
| GeneratedTiledVertexStateLike<SpaceIdValue, VertexIdValue, VertexFields>
|
|
208
|
+
>;
|
|
209
|
+
pieces: ReadonlyArray<SquarePieceState<PieceIdValue, PieceFields>>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export type SquareBoardInput<
|
|
213
|
+
BoardIdValue extends string = BoardId,
|
|
214
|
+
SpaceIdValue extends string = string,
|
|
215
|
+
EdgeIdValue extends string = string,
|
|
216
|
+
VertexIdValue extends string = string,
|
|
217
|
+
PieceIdValue extends string = string,
|
|
218
|
+
SpaceFields = RuntimeFields,
|
|
219
|
+
EdgeFields = RuntimeFields,
|
|
220
|
+
VertexFields = RuntimeFields,
|
|
221
|
+
PieceFields = RuntimeFields,
|
|
222
|
+
> =
|
|
223
|
+
| AuthoredSquareBoardInput<
|
|
224
|
+
BoardIdValue,
|
|
225
|
+
SpaceIdValue,
|
|
226
|
+
EdgeIdValue,
|
|
227
|
+
VertexIdValue,
|
|
228
|
+
PieceIdValue,
|
|
229
|
+
SpaceFields,
|
|
230
|
+
EdgeFields,
|
|
231
|
+
VertexFields,
|
|
232
|
+
PieceFields
|
|
233
|
+
>
|
|
234
|
+
| GeneratedSquareBoardInput<
|
|
235
|
+
BoardIdValue,
|
|
236
|
+
SpaceIdValue,
|
|
237
|
+
EdgeIdValue,
|
|
238
|
+
VertexIdValue,
|
|
239
|
+
PieceIdValue,
|
|
240
|
+
SpaceFields,
|
|
241
|
+
EdgeFields,
|
|
242
|
+
VertexFields,
|
|
243
|
+
PieceFields
|
|
244
|
+
>;
|
|
245
|
+
|
|
246
|
+
export type AnyHexBoardInput = HexBoardInput<
|
|
247
|
+
string,
|
|
248
|
+
string,
|
|
249
|
+
string,
|
|
250
|
+
string,
|
|
251
|
+
RuntimeFields,
|
|
252
|
+
RuntimeFields,
|
|
253
|
+
RuntimeFields
|
|
254
|
+
>;
|
|
255
|
+
export type AnySquareBoardInput = SquareBoardInput<
|
|
256
|
+
string,
|
|
257
|
+
string,
|
|
258
|
+
string,
|
|
259
|
+
string,
|
|
260
|
+
string,
|
|
261
|
+
RuntimeFields,
|
|
262
|
+
RuntimeFields,
|
|
263
|
+
RuntimeFields,
|
|
264
|
+
RuntimeFields
|
|
265
|
+
>;
|
|
266
|
+
|
|
267
|
+
export type BoardIdOf<TBoard> = TBoard extends { id: infer Id extends string }
|
|
268
|
+
? Id
|
|
269
|
+
: string;
|
|
270
|
+
|
|
271
|
+
type SpaceRecordValueOf<TBoard> = TBoard extends {
|
|
272
|
+
spaces: Readonly<Record<string, infer Space>>;
|
|
273
|
+
}
|
|
274
|
+
? Space
|
|
275
|
+
: never;
|
|
276
|
+
type TileValueOf<TBoard> = TBoard extends { tiles: ReadonlyArray<infer Tile> }
|
|
277
|
+
? Tile
|
|
278
|
+
: never;
|
|
279
|
+
type CellValueOf<TBoard> = TBoard extends { cells: ReadonlyArray<infer Cell> }
|
|
280
|
+
? Cell
|
|
281
|
+
: never;
|
|
282
|
+
type EdgeValueOf<TBoard> = TBoard extends { edges: ReadonlyArray<infer Edge> }
|
|
283
|
+
? Edge
|
|
284
|
+
: never;
|
|
285
|
+
type VertexValueOf<TBoard> = TBoard extends {
|
|
286
|
+
vertices: ReadonlyArray<infer Vertex>;
|
|
287
|
+
}
|
|
288
|
+
? Vertex
|
|
289
|
+
: never;
|
|
290
|
+
type PieceValueOf<TBoard> = TBoard extends {
|
|
291
|
+
pieces?: ReadonlyArray<infer Piece>;
|
|
292
|
+
}
|
|
293
|
+
? Piece
|
|
294
|
+
: never;
|
|
295
|
+
|
|
296
|
+
export type BoardSpaceIdOf<TBoard> =
|
|
297
|
+
SpaceRecordValueOf<TBoard> extends { id: infer Id extends string }
|
|
298
|
+
? Id
|
|
299
|
+
: TileValueOf<TBoard> extends { id: infer Id extends string }
|
|
300
|
+
? Id
|
|
301
|
+
: CellValueOf<TBoard> extends { id: infer Id extends string }
|
|
302
|
+
? Id
|
|
303
|
+
: never;
|
|
304
|
+
|
|
305
|
+
export type BoardEdgeIdOf<TBoard> =
|
|
306
|
+
EdgeValueOf<TBoard> extends {
|
|
307
|
+
id: infer Id extends string;
|
|
308
|
+
}
|
|
309
|
+
? Id
|
|
310
|
+
: never;
|
|
311
|
+
|
|
312
|
+
export type BoardVertexIdOf<TBoard> =
|
|
313
|
+
VertexValueOf<TBoard> extends {
|
|
314
|
+
id: infer Id extends string;
|
|
315
|
+
}
|
|
316
|
+
? Id
|
|
317
|
+
: never;
|
|
318
|
+
|
|
319
|
+
type HexTilePropertiesOf<TBoard> =
|
|
320
|
+
SpaceRecordValueOf<TBoard> extends { fields?: infer Fields }
|
|
321
|
+
? Fields
|
|
322
|
+
: TileValueOf<TBoard> extends { properties?: infer Properties }
|
|
323
|
+
? Properties
|
|
324
|
+
: RuntimeFields;
|
|
325
|
+
|
|
326
|
+
type HexTileViewOf<TBoard> =
|
|
327
|
+
TileValueOf<TBoard> extends { view: infer View }
|
|
328
|
+
? View
|
|
329
|
+
: TileValueOf<TBoard> extends { view?: infer View }
|
|
330
|
+
? View | undefined
|
|
331
|
+
: unknown;
|
|
332
|
+
|
|
333
|
+
type HexEdgePropertiesOf<TBoard> =
|
|
334
|
+
EdgeValueOf<TBoard> extends { fields?: infer Fields }
|
|
335
|
+
? Fields
|
|
336
|
+
: EdgeValueOf<TBoard> extends { properties?: infer Properties }
|
|
337
|
+
? Properties
|
|
338
|
+
: RuntimeFields;
|
|
339
|
+
|
|
340
|
+
type HexVertexPropertiesOf<TBoard> =
|
|
341
|
+
VertexValueOf<TBoard> extends { fields?: infer Fields }
|
|
342
|
+
? Fields
|
|
343
|
+
: VertexValueOf<TBoard> extends { properties?: infer Properties }
|
|
344
|
+
? Properties
|
|
345
|
+
: RuntimeFields;
|
|
346
|
+
|
|
347
|
+
type SquareCellPropertiesOf<TBoard> =
|
|
348
|
+
SpaceRecordValueOf<TBoard> extends { fields?: infer Fields }
|
|
349
|
+
? Fields
|
|
350
|
+
: CellValueOf<TBoard> extends { properties?: infer Properties }
|
|
351
|
+
? Properties
|
|
352
|
+
: RuntimeFields;
|
|
353
|
+
|
|
354
|
+
type SquareEdgePropertiesOf<TBoard> =
|
|
355
|
+
EdgeValueOf<TBoard> extends { fields?: infer Fields }
|
|
356
|
+
? Fields
|
|
357
|
+
: EdgeValueOf<TBoard> extends { properties?: infer Properties }
|
|
358
|
+
? Properties
|
|
359
|
+
: RuntimeFields;
|
|
360
|
+
|
|
361
|
+
type SquareVertexPropertiesOf<TBoard> =
|
|
362
|
+
VertexValueOf<TBoard> extends { fields?: infer Fields }
|
|
363
|
+
? Fields
|
|
364
|
+
: VertexValueOf<TBoard> extends { properties?: infer Properties }
|
|
365
|
+
? Properties
|
|
366
|
+
: RuntimeFields;
|
|
367
|
+
|
|
368
|
+
type SquarePiecePropertiesOf<TBoard> =
|
|
369
|
+
PieceValueOf<TBoard> extends {
|
|
370
|
+
properties?: infer Properties;
|
|
371
|
+
}
|
|
372
|
+
? Properties
|
|
373
|
+
: RuntimeFields;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Normalized hex tile shape for a given board input.
|
|
377
|
+
*
|
|
378
|
+
* `view` is always present (required) on the result so consumers can
|
|
379
|
+
* read overlay fields without a null-check. For boards that do not
|
|
380
|
+
* statically declare a `view` shape (the generic case), `view` falls
|
|
381
|
+
* back to `unknown`, which still admits any value.
|
|
382
|
+
*
|
|
383
|
+
* The runtime normalizer injects `view: undefined` for inputs that
|
|
384
|
+
* do not author a `view` field, keeping the runtime contract aligned
|
|
385
|
+
* with this static shape.
|
|
386
|
+
*/
|
|
387
|
+
export type NormalizedHexTileOf<TBoard extends AnyHexBoardInput> = Omit<
|
|
388
|
+
HexTileState<
|
|
389
|
+
BoardIdOf<TBoard>,
|
|
390
|
+
BoardSpaceIdOf<TBoard>,
|
|
391
|
+
HexTilePropertiesOf<TBoard>,
|
|
392
|
+
HexTileViewOf<TBoard>
|
|
393
|
+
>,
|
|
394
|
+
"view"
|
|
395
|
+
> & { view: HexTileViewOf<TBoard> };
|
|
396
|
+
|
|
397
|
+
export type NormalizedHexEdgeOf<TBoard extends AnyHexBoardInput> = HexEdgeState<
|
|
398
|
+
BoardIdOf<TBoard>,
|
|
399
|
+
BoardSpaceIdOf<TBoard>,
|
|
400
|
+
BoardEdgeIdOf<TBoard>,
|
|
401
|
+
HexEdgePropertiesOf<TBoard>
|
|
402
|
+
>;
|
|
403
|
+
|
|
404
|
+
export type NormalizedHexVertexOf<TBoard extends AnyHexBoardInput> =
|
|
405
|
+
HexVertexState<
|
|
406
|
+
BoardIdOf<TBoard>,
|
|
407
|
+
BoardSpaceIdOf<TBoard>,
|
|
408
|
+
BoardVertexIdOf<TBoard>,
|
|
409
|
+
HexVertexPropertiesOf<TBoard>
|
|
410
|
+
>;
|
|
411
|
+
|
|
412
|
+
export type NormalizedSquareCellOf<TBoard extends AnySquareBoardInput> =
|
|
413
|
+
SquareCellState<BoardSpaceIdOf<TBoard>, SquareCellPropertiesOf<TBoard>>;
|
|
414
|
+
|
|
415
|
+
export type NormalizedSquareEdgeOf<TBoard extends AnySquareBoardInput> =
|
|
416
|
+
SquareEdgeState<
|
|
417
|
+
BoardSpaceIdOf<TBoard>,
|
|
418
|
+
BoardEdgeIdOf<TBoard>,
|
|
419
|
+
SquareEdgePropertiesOf<TBoard>
|
|
420
|
+
>;
|
|
421
|
+
|
|
422
|
+
export type NormalizedSquareVertexOf<TBoard extends AnySquareBoardInput> =
|
|
423
|
+
SquareVertexState<
|
|
424
|
+
BoardSpaceIdOf<TBoard>,
|
|
425
|
+
BoardVertexIdOf<TBoard>,
|
|
426
|
+
SquareVertexPropertiesOf<TBoard>
|
|
427
|
+
>;
|
|
428
|
+
|
|
429
|
+
export type NormalizedSquarePieceOf<TBoard extends AnySquareBoardInput> =
|
|
430
|
+
SquarePieceState<
|
|
431
|
+
PieceValueOf<TBoard> extends { id: infer PieceIdValue extends string }
|
|
432
|
+
? PieceIdValue
|
|
433
|
+
: string,
|
|
434
|
+
SquarePiecePropertiesOf<TBoard>
|
|
435
|
+
>;
|
|
436
|
+
|
|
437
|
+
export type NormalizedHexBoard<TBoard extends AnyHexBoardInput> = Omit<
|
|
438
|
+
Pick<
|
|
439
|
+
HexBoardState<
|
|
440
|
+
BoardIdOf<TBoard>,
|
|
441
|
+
BoardSpaceIdOf<TBoard>,
|
|
442
|
+
BoardEdgeIdOf<TBoard>,
|
|
443
|
+
BoardVertexIdOf<TBoard>,
|
|
444
|
+
HexTilePropertiesOf<TBoard>,
|
|
445
|
+
HexEdgePropertiesOf<TBoard>,
|
|
446
|
+
HexVertexPropertiesOf<TBoard>
|
|
447
|
+
>,
|
|
448
|
+
"id" | "tiles" | "edges" | "vertices"
|
|
449
|
+
>,
|
|
450
|
+
"tiles"
|
|
451
|
+
> & {
|
|
452
|
+
tiles: ReadonlyArray<NormalizedHexTileOf<TBoard>>;
|
|
453
|
+
orientation?: "pointy-top" | "flat-top";
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
export type NormalizedSquareBoard<TBoard extends AnySquareBoardInput> = Pick<
|
|
457
|
+
SquareBoardState<
|
|
458
|
+
BoardIdOf<TBoard>,
|
|
459
|
+
BoardSpaceIdOf<TBoard>,
|
|
460
|
+
BoardEdgeIdOf<TBoard>,
|
|
461
|
+
BoardVertexIdOf<TBoard>,
|
|
462
|
+
PieceValueOf<TBoard> extends { id: infer PieceIdValue extends string }
|
|
463
|
+
? PieceIdValue
|
|
464
|
+
: string,
|
|
465
|
+
SquareCellPropertiesOf<TBoard>,
|
|
466
|
+
SquareEdgePropertiesOf<TBoard>,
|
|
467
|
+
SquareVertexPropertiesOf<TBoard>,
|
|
468
|
+
SquarePiecePropertiesOf<TBoard>
|
|
469
|
+
>,
|
|
470
|
+
"id" | "rows" | "cols" | "cells" | "edges" | "vertices" | "pieces"
|
|
471
|
+
>;
|
|
472
|
+
|
|
473
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
474
|
+
return typeof value === "object" && value !== null;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function firstValue(record: Readonly<Record<string, unknown>>): unknown {
|
|
478
|
+
const [first] = Object.values(record);
|
|
479
|
+
return first;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function normalizeOptional<T>(
|
|
483
|
+
value: T | null | undefined,
|
|
484
|
+
): NormalizeOptional<T> {
|
|
485
|
+
return (value ?? undefined) as NormalizeOptional<T>;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
export function isGeneratedHexBoardInput<
|
|
489
|
+
TBoard extends AnyHexBoardInput | AnySquareBoardInput,
|
|
490
|
+
>(
|
|
491
|
+
board: TBoard,
|
|
492
|
+
): board is Extract<TBoard, { spaces: Readonly<Record<string, unknown>> }> {
|
|
493
|
+
if (!isRecord(board) || !("spaces" in board) || !isRecord(board.spaces)) {
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
if ("tiles" in board || "cells" in board) {
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
if (board.layout === "hex") {
|
|
500
|
+
return true;
|
|
501
|
+
}
|
|
502
|
+
const firstSpace = firstValue(
|
|
503
|
+
board.spaces as Readonly<Record<string, unknown>>,
|
|
504
|
+
);
|
|
505
|
+
return (
|
|
506
|
+
isRecord(firstSpace) &&
|
|
507
|
+
typeof firstSpace.q === "number" &&
|
|
508
|
+
typeof firstSpace.r === "number"
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
export function isGeneratedSquareBoardInput<
|
|
513
|
+
TBoard extends AnyHexBoardInput | AnySquareBoardInput,
|
|
514
|
+
>(
|
|
515
|
+
board: TBoard,
|
|
516
|
+
): board is Extract<TBoard, { spaces: Readonly<Record<string, unknown>> }> {
|
|
517
|
+
if (!isRecord(board) || !("spaces" in board) || !isRecord(board.spaces)) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
if ("tiles" in board || "cells" in board) {
|
|
521
|
+
return false;
|
|
522
|
+
}
|
|
523
|
+
if (board.layout === "square") {
|
|
524
|
+
return true;
|
|
525
|
+
}
|
|
526
|
+
const firstSpace = firstValue(
|
|
527
|
+
board.spaces as Readonly<Record<string, unknown>>,
|
|
528
|
+
);
|
|
529
|
+
return (
|
|
530
|
+
isRecord(firstSpace) &&
|
|
531
|
+
typeof firstSpace.row === "number" &&
|
|
532
|
+
typeof firstSpace.col === "number"
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
function normalizeHexTile<TBoard extends AnyHexBoardInput>(
|
|
537
|
+
tile: SpaceRecordValueOf<TBoard>,
|
|
538
|
+
): NormalizedHexTileOf<TBoard> {
|
|
539
|
+
return {
|
|
540
|
+
id: tile.id as BoardSpaceIdOf<TBoard>,
|
|
541
|
+
q: tile.q as number,
|
|
542
|
+
r: tile.r as number,
|
|
543
|
+
typeId: normalizeOptional(tile.typeId as SpaceTypeId | null | undefined),
|
|
544
|
+
label: normalizeOptional(tile.label as string | null | undefined),
|
|
545
|
+
owner: normalizeOptional(tile.ownerId as PlayerId | null | undefined),
|
|
546
|
+
properties: (tile.fields ?? undefined) as HexTilePropertiesOf<TBoard>,
|
|
547
|
+
view: undefined,
|
|
548
|
+
} as unknown as NormalizedHexTileOf<TBoard>;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function normalizeHexEdge<TBoard extends AnyHexBoardInput>(
|
|
552
|
+
edge: EdgeValueOf<TBoard>,
|
|
553
|
+
): NormalizedHexEdgeOf<TBoard> {
|
|
554
|
+
if ("hex1" in edge && "hex2" in edge) {
|
|
555
|
+
return {
|
|
556
|
+
...edge,
|
|
557
|
+
label: normalizeOptional(edge.label),
|
|
558
|
+
owner: normalizeOptional(edge.owner),
|
|
559
|
+
typeId: normalizeOptional(edge.typeId),
|
|
560
|
+
properties: edge.properties,
|
|
561
|
+
} as NormalizedHexEdgeOf<TBoard>;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
const [hex1 = "", hex2 = ""] = edge.spaceIds;
|
|
565
|
+
return {
|
|
566
|
+
id: edge.id as BoardEdgeIdOf<TBoard>,
|
|
567
|
+
hex1: hex1 as BoardSpaceIdOf<TBoard>,
|
|
568
|
+
hex2: hex2 as BoardSpaceIdOf<TBoard>,
|
|
569
|
+
typeId: normalizeOptional(edge.typeId),
|
|
570
|
+
label: normalizeOptional(edge.label),
|
|
571
|
+
owner: normalizeOptional(edge.ownerId),
|
|
572
|
+
properties: (edge.fields ?? undefined) as HexEdgePropertiesOf<TBoard>,
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function normalizeHexVertex<TBoard extends AnyHexBoardInput>(
|
|
577
|
+
vertex: VertexValueOf<TBoard>,
|
|
578
|
+
): NormalizedHexVertexOf<TBoard> {
|
|
579
|
+
if ("hexes" in vertex) {
|
|
580
|
+
return {
|
|
581
|
+
...vertex,
|
|
582
|
+
label: normalizeOptional(vertex.label),
|
|
583
|
+
owner: normalizeOptional(vertex.owner),
|
|
584
|
+
typeId: normalizeOptional(vertex.typeId),
|
|
585
|
+
properties: vertex.properties,
|
|
586
|
+
} as NormalizedHexVertexOf<TBoard>;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return {
|
|
590
|
+
id: vertex.id as BoardVertexIdOf<TBoard>,
|
|
591
|
+
hexes: vertex.spaceIds as ReadonlyArray<BoardSpaceIdOf<TBoard>>,
|
|
592
|
+
typeId: normalizeOptional(vertex.typeId),
|
|
593
|
+
label: normalizeOptional(vertex.label),
|
|
594
|
+
owner: normalizeOptional(vertex.ownerId),
|
|
595
|
+
properties: (vertex.fields ?? undefined) as HexVertexPropertiesOf<TBoard>,
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function normalizeSquareCell<TBoard extends AnySquareBoardInput>(
|
|
600
|
+
cell: SpaceRecordValueOf<TBoard>,
|
|
601
|
+
): NormalizedSquareCellOf<TBoard> {
|
|
602
|
+
return {
|
|
603
|
+
id: cell.id as BoardSpaceIdOf<TBoard>,
|
|
604
|
+
row: cell.row as number,
|
|
605
|
+
col: cell.col as number,
|
|
606
|
+
typeId: normalizeOptional(cell.typeId as SpaceTypeId | null | undefined),
|
|
607
|
+
label: normalizeOptional(cell.label as string | null | undefined),
|
|
608
|
+
owner: normalizeOptional(cell.ownerId as PlayerId | null | undefined),
|
|
609
|
+
properties: (cell.fields ?? undefined) as SquareCellPropertiesOf<TBoard>,
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function normalizeSquareEdge<TBoard extends AnySquareBoardInput>(
|
|
614
|
+
edge: EdgeValueOf<TBoard>,
|
|
615
|
+
): NormalizedSquareEdgeOf<TBoard> {
|
|
616
|
+
if ("ownerId" in edge || "fields" in edge) {
|
|
617
|
+
return {
|
|
618
|
+
id: edge.id as BoardEdgeIdOf<TBoard>,
|
|
619
|
+
spaceIds: edge.spaceIds as ReadonlyArray<BoardSpaceIdOf<TBoard>>,
|
|
620
|
+
typeId: normalizeOptional(edge.typeId),
|
|
621
|
+
label: normalizeOptional(edge.label),
|
|
622
|
+
owner: normalizeOptional(edge.ownerId),
|
|
623
|
+
properties: (edge.fields ?? undefined) as SquareEdgePropertiesOf<TBoard>,
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
return {
|
|
628
|
+
id: edge.id as BoardEdgeIdOf<TBoard>,
|
|
629
|
+
spaceIds: edge.spaceIds as ReadonlyArray<BoardSpaceIdOf<TBoard>>,
|
|
630
|
+
typeId: normalizeOptional(edge.typeId),
|
|
631
|
+
label: normalizeOptional(edge.label),
|
|
632
|
+
owner: normalizeOptional(
|
|
633
|
+
(edge as SquareEdgeState<string, string, RuntimeFields>).owner,
|
|
634
|
+
),
|
|
635
|
+
properties: (edge as SquareEdgeState<string, string, RuntimeFields>)
|
|
636
|
+
.properties as SquareEdgePropertiesOf<TBoard>,
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function normalizeSquareVertex<TBoard extends AnySquareBoardInput>(
|
|
641
|
+
vertex: VertexValueOf<TBoard>,
|
|
642
|
+
): NormalizedSquareVertexOf<TBoard> {
|
|
643
|
+
if ("ownerId" in vertex || "fields" in vertex) {
|
|
644
|
+
return {
|
|
645
|
+
id: vertex.id as BoardVertexIdOf<TBoard>,
|
|
646
|
+
spaceIds: vertex.spaceIds as ReadonlyArray<BoardSpaceIdOf<TBoard>>,
|
|
647
|
+
typeId: normalizeOptional(vertex.typeId),
|
|
648
|
+
label: normalizeOptional(vertex.label),
|
|
649
|
+
owner: normalizeOptional(vertex.ownerId),
|
|
650
|
+
properties: (vertex.fields ??
|
|
651
|
+
undefined) as SquareVertexPropertiesOf<TBoard>,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
return {
|
|
656
|
+
id: vertex.id as BoardVertexIdOf<TBoard>,
|
|
657
|
+
spaceIds: vertex.spaceIds as ReadonlyArray<BoardSpaceIdOf<TBoard>>,
|
|
658
|
+
typeId: normalizeOptional(vertex.typeId),
|
|
659
|
+
label: normalizeOptional(vertex.label),
|
|
660
|
+
owner: normalizeOptional(
|
|
661
|
+
(vertex as SquareVertexState<string, string, RuntimeFields>).owner,
|
|
662
|
+
),
|
|
663
|
+
properties: (vertex as SquareVertexState<string, string, RuntimeFields>)
|
|
664
|
+
.properties as SquareVertexPropertiesOf<TBoard>,
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function isAuthoredHexBoardInput(
|
|
669
|
+
board: AnyHexBoardInput,
|
|
670
|
+
): board is Extract<AnyHexBoardInput, { tiles: readonly unknown[] }> {
|
|
671
|
+
return "tiles" in board;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function isAuthoredSquareBoardInput(
|
|
675
|
+
board: AnySquareBoardInput,
|
|
676
|
+
): board is Extract<AnySquareBoardInput, { cells: readonly unknown[] }> {
|
|
677
|
+
return "cells" in board;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
export function normalizeHexBoardInput<TBoard extends AnyHexBoardInput>(
|
|
681
|
+
board: TBoard,
|
|
682
|
+
): NormalizedHexBoard<TBoard> {
|
|
683
|
+
if (isGeneratedHexBoardInput(board)) {
|
|
684
|
+
return {
|
|
685
|
+
id: board.id,
|
|
686
|
+
orientation: board.orientation,
|
|
687
|
+
tiles: Object.values(board.spaces).map((tile) =>
|
|
688
|
+
normalizeHexTile<TBoard>(tile as SpaceRecordValueOf<TBoard>),
|
|
689
|
+
),
|
|
690
|
+
edges: board.edges.map((edge) =>
|
|
691
|
+
normalizeHexEdge<TBoard>(edge as EdgeValueOf<TBoard>),
|
|
692
|
+
),
|
|
693
|
+
vertices: board.vertices.map((vertex) =>
|
|
694
|
+
normalizeHexVertex<TBoard>(vertex as VertexValueOf<TBoard>),
|
|
695
|
+
),
|
|
696
|
+
} as unknown as NormalizedHexBoard<TBoard>;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
if (!isAuthoredHexBoardInput(board)) {
|
|
700
|
+
throw new Error("Expected authored hex board input.");
|
|
701
|
+
}
|
|
702
|
+
const authoredBoard = board as Extract<TBoard, { tiles: readonly unknown[] }>;
|
|
703
|
+
return {
|
|
704
|
+
id: authoredBoard.id,
|
|
705
|
+
orientation: authoredBoard.orientation,
|
|
706
|
+
tiles: authoredBoard.tiles.map((tile) => ({
|
|
707
|
+
...tile,
|
|
708
|
+
label: normalizeOptional(tile.label),
|
|
709
|
+
owner: normalizeOptional(tile.owner),
|
|
710
|
+
typeId: normalizeOptional(tile.typeId),
|
|
711
|
+
properties: tile.properties,
|
|
712
|
+
view: tile.view,
|
|
713
|
+
})),
|
|
714
|
+
edges: authoredBoard.edges.map((edge) =>
|
|
715
|
+
normalizeHexEdge<TBoard>(edge as EdgeValueOf<TBoard>),
|
|
716
|
+
),
|
|
717
|
+
vertices: authoredBoard.vertices.map((vertex) =>
|
|
718
|
+
normalizeHexVertex<TBoard>(vertex as VertexValueOf<TBoard>),
|
|
719
|
+
),
|
|
720
|
+
} as unknown as NormalizedHexBoard<TBoard>;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
export function normalizeSquareBoardInput<TBoard extends AnySquareBoardInput>(
|
|
724
|
+
board: TBoard,
|
|
725
|
+
): NormalizedSquareBoard<TBoard> {
|
|
726
|
+
if (isGeneratedSquareBoardInput(board)) {
|
|
727
|
+
const cells = Object.values(board.spaces).map((cell) =>
|
|
728
|
+
normalizeSquareCell<TBoard>(cell as SpaceRecordValueOf<TBoard>),
|
|
729
|
+
);
|
|
730
|
+
const rows =
|
|
731
|
+
cells.length === 0 ? 0 : Math.max(...cells.map((cell) => cell.row)) + 1;
|
|
732
|
+
const cols =
|
|
733
|
+
cells.length === 0 ? 0 : Math.max(...cells.map((cell) => cell.col)) + 1;
|
|
734
|
+
|
|
735
|
+
return {
|
|
736
|
+
id: board.id,
|
|
737
|
+
rows,
|
|
738
|
+
cols,
|
|
739
|
+
cells,
|
|
740
|
+
edges: board.edges.map((edge) =>
|
|
741
|
+
normalizeSquareEdge<TBoard>(edge as EdgeValueOf<TBoard>),
|
|
742
|
+
),
|
|
743
|
+
vertices: board.vertices.map((vertex) =>
|
|
744
|
+
normalizeSquareVertex<TBoard>(vertex as VertexValueOf<TBoard>),
|
|
745
|
+
),
|
|
746
|
+
pieces: (
|
|
747
|
+
(board.pieces ?? []) as ReadonlyArray<NormalizedSquarePieceOf<TBoard>>
|
|
748
|
+
).map((piece) => ({
|
|
749
|
+
...piece,
|
|
750
|
+
owner: normalizeOptional(piece.owner),
|
|
751
|
+
typeId: piece.typeId,
|
|
752
|
+
properties: piece.properties,
|
|
753
|
+
})),
|
|
754
|
+
} as unknown as NormalizedSquareBoard<TBoard>;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
if (!isAuthoredSquareBoardInput(board)) {
|
|
758
|
+
throw new Error("Expected authored square board input.");
|
|
759
|
+
}
|
|
760
|
+
const authoredBoard = board as Extract<TBoard, { cells: readonly unknown[] }>;
|
|
761
|
+
return {
|
|
762
|
+
id: authoredBoard.id,
|
|
763
|
+
rows: authoredBoard.rows,
|
|
764
|
+
cols: authoredBoard.cols,
|
|
765
|
+
cells: authoredBoard.cells.map((cell) => ({
|
|
766
|
+
...cell,
|
|
767
|
+
label: normalizeOptional(cell.label),
|
|
768
|
+
owner: normalizeOptional(cell.owner),
|
|
769
|
+
typeId: normalizeOptional(cell.typeId),
|
|
770
|
+
properties: cell.properties,
|
|
771
|
+
})),
|
|
772
|
+
edges: authoredBoard.edges.map((edge) =>
|
|
773
|
+
normalizeSquareEdge<TBoard>(edge as EdgeValueOf<TBoard>),
|
|
774
|
+
),
|
|
775
|
+
vertices: authoredBoard.vertices.map((vertex) =>
|
|
776
|
+
normalizeSquareVertex<TBoard>(vertex as VertexValueOf<TBoard>),
|
|
777
|
+
),
|
|
778
|
+
pieces: (authoredBoard.pieces ?? []).map((piece) => ({
|
|
779
|
+
...piece,
|
|
780
|
+
owner: normalizeOptional(piece.owner),
|
|
781
|
+
typeId: piece.typeId,
|
|
782
|
+
properties: piece.properties,
|
|
783
|
+
})),
|
|
784
|
+
} as unknown as NormalizedSquareBoard<TBoard>;
|
|
785
|
+
}
|