@dreamboard-games/sdk 0.2.0
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.md +96 -0
- package/README.md +12 -0
- package/dist/HandView-ncJIVLhN.d.ts +193 -0
- package/dist/ResourceCounter-CTREyF73.d.ts +102 -0
- package/dist/ThemeProvider-fy0_QzgO.d.ts +99 -0
- package/dist/bundle-TIZcw8LB.d.ts +281 -0
- package/dist/cards-Sl3b40Mv.d.ts +13 -0
- package/dist/chunk-7YAHLYBR.js +481 -0
- package/dist/chunk-7YAHLYBR.js.map +1 -0
- package/dist/chunk-FDNZTDD6.js +8085 -0
- package/dist/chunk-FDNZTDD6.js.map +1 -0
- package/dist/chunk-GKKBPPSW.js +598 -0
- package/dist/chunk-GKKBPPSW.js.map +1 -0
- package/dist/chunk-I46YJSOD.js +1 -0
- package/dist/chunk-I46YJSOD.js.map +1 -0
- package/dist/chunk-KAELH4KC.js +104 -0
- package/dist/chunk-KAELH4KC.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-T3ZKNUZ7.js +1 -0
- package/dist/chunk-T3ZKNUZ7.js.map +1 -0
- package/dist/chunk-T52J5RMF.js +1 -0
- package/dist/chunk-T52J5RMF.js.map +1 -0
- package/dist/chunk-TDSWKVZ4.js +5401 -0
- package/dist/chunk-TDSWKVZ4.js.map +1 -0
- package/dist/chunk-U5C6BONG.js +34 -0
- package/dist/chunk-U5C6BONG.js.map +1 -0
- package/dist/chunk-VDXOF4FW.js +69 -0
- package/dist/chunk-VDXOF4FW.js.map +1 -0
- package/dist/chunk-VFTAA4WO.js +115 -0
- package/dist/chunk-VFTAA4WO.js.map +1 -0
- package/dist/chunk-WN74KVNY.js +17 -0
- package/dist/chunk-WN74KVNY.js.map +1 -0
- package/dist/chunk-WYPQ3GG5.js +10990 -0
- package/dist/chunk-WYPQ3GG5.js.map +1 -0
- package/dist/components-D5ZRE2Hl.d.ts +1451 -0
- package/dist/generated/runtime/primitives.d.ts +12 -0
- package/dist/generated/runtime/primitives.js +180 -0
- package/dist/generated/runtime/primitives.js.map +1 -0
- package/dist/generated/runtime-api.d.ts +3 -0
- package/dist/generated/runtime-api.js +2 -0
- package/dist/generated/runtime-api.js.map +1 -0
- package/dist/generated/runtime.d.ts +14 -0
- package/dist/generated/runtime.js +18 -0
- package/dist/generated/runtime.js.map +1 -0
- package/dist/generated/workspace-contract.d.ts +14 -0
- package/dist/generated/workspace-contract.js +14 -0
- package/dist/generated/workspace-contract.js.map +1 -0
- package/dist/hex-board-view-D_07hO6O.d.ts +933 -0
- package/dist/hex-color-MhOyuY-o.d.ts +8 -0
- package/dist/index-BwqPQtBu.d.ts +1433 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/reducer-bundle-abi.d.ts +1083 -0
- package/dist/infrastructure/reducer-bundle-abi.js +14 -0
- package/dist/infrastructure/reducer-bundle-abi.js.map +1 -0
- package/dist/infrastructure/workspace-codegen.d.ts +53 -0
- package/dist/infrastructure/workspace-codegen.js +44 -0
- package/dist/infrastructure/workspace-codegen.js.map +1 -0
- package/dist/manifest-contract-BNHVGFtU.d.ts +9 -0
- package/dist/package-set.d.ts +13 -0
- package/dist/package-set.js +12 -0
- package/dist/package-set.js.map +1 -0
- package/dist/primitive-props-DpKs-GCr.d.ts +11 -0
- package/dist/reducer.d.ts +3786 -0
- package/dist/reducer.js +8131 -0
- package/dist/reducer.js.map +1 -0
- package/dist/runtime/primitives.d.ts +226 -0
- package/dist/runtime/primitives.js +180 -0
- package/dist/runtime/primitives.js.map +1 -0
- package/dist/runtime/types/runtime-api.d.ts +1 -0
- package/dist/runtime/types/runtime-api.js +2 -0
- package/dist/runtime/types/runtime-api.js.map +1 -0
- package/dist/runtime/workspace-contract.d.ts +172 -0
- package/dist/runtime/workspace-contract.js +14 -0
- package/dist/runtime/workspace-contract.js.map +1 -0
- package/dist/runtime-api-3dshj6kK.d.ts +101 -0
- package/dist/runtime-api-DWxvTr-O.d.ts +379 -0
- package/dist/runtime.d.ts +58 -0
- package/dist/runtime.js +13 -0
- package/dist/runtime.js.map +1 -0
- package/dist/slots-1GPGihk8.d.ts +8 -0
- package/dist/testing.d.ts +149 -0
- package/dist/testing.js +513 -0
- package/dist/testing.js.map +1 -0
- package/dist/types.d.ts +496 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/components.d.ts +16 -0
- package/dist/ui/components.js +192 -0
- package/dist/ui/components.js.map +1 -0
- package/dist/ui/defaults.d.ts +19 -0
- package/dist/ui/defaults.js +104 -0
- package/dist/ui/defaults.js.map +1 -0
- package/dist/ui/plugin-styles.css +250 -0
- package/dist/ui/types/player-state.d.ts +365 -0
- package/dist/ui/types/player-state.js +1 -0
- package/dist/ui/types/player-state.js.map +1 -0
- package/dist/ui-contract-iQfTtUSL.d.ts +1161 -0
- package/dist/ui.d.ts +320 -0
- package/dist/ui.js +253 -0
- package/dist/ui.js.map +1 -0
- package/package.json +199 -0
- package/src/generated/reducer-contract/builders.ts +90 -0
- package/src/generated/reducer-contract/version.ts +9 -0
- package/src/generated/reducer-contract/wire.ts +100 -0
- package/src/generated/reducer-contract/zod.ts +101 -0
- package/src/generated/runtime/primitives.ts +2 -0
- package/src/generated/runtime-api.ts +5 -0
- package/src/generated/runtime.ts +35 -0
- package/src/generated/workspace-contract.ts +2 -0
- package/src/index.ts +7 -0
- package/src/infrastructure/reducer-bundle-abi.ts +8 -0
- package/src/infrastructure/reducer-contract/bundle.ts +37 -0
- package/src/infrastructure/workspace-codegen/hex-geometry.ts +69 -0
- package/src/infrastructure/workspace-codegen/index.ts +64 -0
- package/src/infrastructure/workspace-codegen/manifest-contract.ts +6632 -0
- package/src/infrastructure/workspace-codegen/manifest-validation.ts +795 -0
- package/src/infrastructure/workspace-codegen/ownership.ts +131 -0
- package/src/infrastructure/workspace-codegen/preset-card-sets.ts +169 -0
- package/src/infrastructure/workspace-codegen/seeds.ts +1705 -0
- package/src/infrastructure/workspace-codegen.ts +1 -0
- package/src/package-set.ts +19 -0
- package/src/reducer/authoring/contract.ts +157 -0
- package/src/reducer/authoring/effect.ts +224 -0
- package/src/reducer/authoring/game.ts +23 -0
- package/src/reducer/authoring/interaction.ts +98 -0
- package/src/reducer/authoring/phase.ts +300 -0
- package/src/reducer/authoring/types.ts +70 -0
- package/src/reducer/authoring/validation.ts +382 -0
- package/src/reducer/authoring/view-stage.ts +68 -0
- package/src/reducer/authoring.ts +29 -0
- package/src/reducer/bundle/ingress-bundle.ts +491 -0
- package/src/reducer/bundle/trusted/engine-instruction-resolver.ts +254 -0
- package/src/reducer/bundle/trusted/flow-instruction-resolver.ts +73 -0
- package/src/reducer/bundle/trusted/instruction-runner.ts +414 -0
- package/src/reducer/bundle/trusted/interaction-authorization.ts +137 -0
- package/src/reducer/bundle/trusted/interaction-collectors.ts +859 -0
- package/src/reducer/bundle/trusted/interaction-decision.ts +747 -0
- package/src/reducer/bundle/trusted/interaction-resolver.ts +95 -0
- package/src/reducer/bundle/trusted/interaction-types.ts +171 -0
- package/src/reducer/bundle/trusted/lifecycle-runner.ts +427 -0
- package/src/reducer/bundle/trusted/projection-builder.ts +356 -0
- package/src/reducer/bundle/trusted/projection-context.ts +39 -0
- package/src/reducer/bundle/trusted/rng-sampler.ts +150 -0
- package/src/reducer/bundle/trusted/runtime-registry.ts +120 -0
- package/src/reducer/bundle/trusted/runtime-scope.ts +336 -0
- package/src/reducer/bundle/trusted/simultaneous-player.ts +97 -0
- package/src/reducer/bundle/trusted/stage-resolver.ts +87 -0
- package/src/reducer/bundle/trusted/static-projection.ts +116 -0
- package/src/reducer/bundle/trusted/trusted-runtime-args.ts +97 -0
- package/src/reducer/bundle/trusted/trusted-runtime-result.ts +39 -0
- package/src/reducer/bundle/trusted/trusted-setup-profiles.ts +43 -0
- package/src/reducer/bundle/trusted/trusted-state-codec.ts +48 -0
- package/src/reducer/bundle/trusted-bundle.ts +97 -0
- package/src/reducer/bundle/types.ts +171 -0
- package/src/reducer/bundle.ts +2 -0
- package/src/reducer/client-param-schemas.ts +57 -0
- package/src/reducer/compose.ts +34 -0
- package/src/reducer/core/runtime-input.ts +30 -0
- package/src/reducer/core/runtime-instruction.ts +59 -0
- package/src/reducer/core/types.ts +62 -0
- package/src/reducer/definition-index.ts +277 -0
- package/src/reducer/derived.ts +106 -0
- package/src/reducer/effects.ts +92 -0
- package/src/reducer/engine/runtime-instruction-engine.ts +155 -0
- package/src/reducer/ingress/decode-runtime-input.ts +7 -0
- package/src/reducer/ingress/decode-session-state.ts +9 -0
- package/src/reducer/ingress/encode-session-state.ts +6 -0
- package/src/reducer/ingress/input-codec.ts +18 -0
- package/src/reducer/ingress/phase-schemas.ts +62 -0
- package/src/reducer/ingress/raw-types.ts +107 -0
- package/src/reducer/ingress/runtime-codec.ts +14 -0
- package/src/reducer/ingress/runtime-payload.ts +13 -0
- package/src/reducer/ingress/session-codec.ts +392 -0
- package/src/reducer/ingress/types.ts +6 -0
- package/src/reducer/inputs/boardInput.ts +217 -0
- package/src/reducer/inputs/boardTarget.ts +190 -0
- package/src/reducer/inputs/cardInput.ts +86 -0
- package/src/reducer/inputs/cardTarget.ts +101 -0
- package/src/reducer/inputs/choiceTarget.ts +104 -0
- package/src/reducer/inputs/defineInputs.ts +71 -0
- package/src/reducer/inputs/formInput.ts +809 -0
- package/src/reducer/inputs/many.ts +120 -0
- package/src/reducer/inputs/promptInput.ts +87 -0
- package/src/reducer/inputs/rngInput.ts +58 -0
- package/src/reducer/inputs/targetRule.ts +123 -0
- package/src/reducer/inputs.ts +41 -0
- package/src/reducer/model/definition.ts +1072 -0
- package/src/reducer/model/extract.ts +745 -0
- package/src/reducer/model/manifest.ts +570 -0
- package/src/reducer/model/queries.ts +641 -0
- package/src/reducer/model/runtime.ts +264 -0
- package/src/reducer/model/spec.ts +1386 -0
- package/src/reducer/model/table.ts +260 -0
- package/src/reducer/model.ts +7 -0
- package/src/reducer/ops.ts +1034 -0
- package/src/reducer/parse-utils.ts +28 -0
- package/src/reducer/per-player.ts +422 -0
- package/src/reducer/rng.ts +69 -0
- package/src/reducer/schema-helpers.ts +185 -0
- package/src/reducer/setup-bootstrap-helpers.ts +171 -0
- package/src/reducer/setup-bootstrap.ts +481 -0
- package/src/reducer/table-ops.ts +2671 -0
- package/src/reducer/table-queries.ts +372 -0
- package/src/reducer/transaction.ts +120 -0
- package/src/reducer.ts +314 -0
- package/src/runtime/primitives.ts +1 -0
- package/src/runtime/types/runtime-api.ts +1 -0
- package/src/runtime/workspace-contract.ts +32 -0
- package/src/runtime-internal/components/InteractionForm.tsx +1309 -0
- package/src/runtime-internal/components/PluginRuntime.tsx +103 -0
- package/src/runtime-internal/components/board/target-layer.ts +70 -0
- package/src/runtime-internal/context/ClientParamSchemaContext.tsx +44 -0
- package/src/runtime-internal/context/InteractionDraftContext.tsx +279 -0
- package/src/runtime-internal/context/PluginSessionContext.tsx +47 -0
- package/src/runtime-internal/context/PluginStateContext.tsx +262 -0
- package/src/runtime-internal/context/RuntimeContext.tsx +96 -0
- package/src/runtime-internal/defaults/components.tsx +409 -0
- package/src/runtime-internal/defaults/index.ts +11 -0
- package/src/runtime-internal/errors/ValidationError.ts +29 -0
- package/src/runtime-internal/hooks/useActivePlayers.ts +33 -0
- package/src/runtime-internal/hooks/useBoardInteractions.ts +665 -0
- package/src/runtime-internal/hooks/useGameSelector.ts +105 -0
- package/src/runtime-internal/hooks/useGameView.ts +9 -0
- package/src/runtime-internal/hooks/useInteractionByKey.ts +354 -0
- package/src/runtime-internal/hooks/useInteractionHandle.ts +438 -0
- package/src/runtime-internal/hooks/useIsMyTurn.ts +20 -0
- package/src/runtime-internal/hooks/useLobby.ts +76 -0
- package/src/runtime-internal/hooks/useMe.ts +48 -0
- package/src/runtime-internal/hooks/usePlayerInfo.ts +28 -0
- package/src/runtime-internal/hooks/usePlayerTurnOrder.ts +23 -0
- package/src/runtime-internal/hooks/usePluginRuntime.ts +147 -0
- package/src/runtime-internal/hooks/useSeatInbox.ts +61 -0
- package/src/runtime-internal/hooks/useSimultaneousPhase.ts +10 -0
- package/src/runtime-internal/index.ts +42 -0
- package/src/runtime-internal/internal.ts +43 -0
- package/src/runtime-internal/plugin-styles.css +250 -0
- package/src/runtime-internal/primitives/board.tsx +459 -0
- package/src/runtime-internal/primitives/dialog-lifecycle.ts +58 -0
- package/src/runtime-internal/primitives/dice.tsx +79 -0
- package/src/runtime-internal/primitives/game-ui-provider.tsx +35 -0
- package/src/runtime-internal/primitives/game.tsx +387 -0
- package/src/runtime-internal/primitives/hand-intent-adapter.ts +147 -0
- package/src/runtime-internal/primitives/hand-surface.tsx +594 -0
- package/src/runtime-internal/primitives/index.ts +196 -0
- package/src/runtime-internal/primitives/interaction-form-binding.tsx +56 -0
- package/src/runtime-internal/primitives/interaction-submit.ts +90 -0
- package/src/runtime-internal/primitives/interaction.tsx +987 -0
- package/src/runtime-internal/primitives/phase.tsx +43 -0
- package/src/runtime-internal/primitives/player-roster.tsx +302 -0
- package/src/runtime-internal/primitives/primitive-props.tsx +101 -0
- package/src/runtime-internal/primitives/prompt.tsx +255 -0
- package/src/runtime-internal/primitives/ui.tsx +60 -0
- package/src/runtime-internal/primitives/zone.tsx +791 -0
- package/src/runtime-internal/reducer.ts +30 -0
- package/src/runtime-internal/runtime/createPluginRuntimeAPI.ts +605 -0
- package/src/runtime-internal/types/plugin-state.ts +508 -0
- package/src/runtime-internal/types/reducer-state.ts +24 -0
- package/src/runtime-internal/types/runtime-api.ts +114 -0
- package/src/runtime-internal/ui-contract.ts +519 -0
- package/src/runtime-internal/utils/card-intent-adapter.ts +546 -0
- package/src/runtime-internal/utils/interaction-inputs.ts +492 -0
- package/src/runtime-internal/utils/interaction-labels.ts +23 -0
- package/src/runtime-internal/utils/interaction-router.ts +273 -0
- package/src/runtime-internal/utils/interaction-status.ts +74 -0
- package/src/runtime-internal/workspace-contract.ts +1170 -0
- package/src/runtime.ts +34 -0
- package/src/testing/create-expect-api.ts +352 -0
- package/src/testing/create-test-runtime.ts +381 -0
- package/src/testing/definitions.ts +127 -0
- package/src/testing/index.ts +3 -0
- package/src/testing.ts +1 -0
- package/src/type-stubs/manifest-contract.d.ts +42 -0
- package/src/type-stubs/manifest-contract.js +72 -0
- package/src/type-stubs/ui-contract.d.ts +5 -0
- package/src/type-stubs/ui-contract.js +1 -0
- package/src/types/authoring-card-properties.type-test.ts +266 -0
- package/src/types/authoring.ts +1282 -0
- package/src/types/cards.ts +19 -0
- package/src/types/contracts.ts +1550 -0
- package/src/types/generated-helpers.ts +35 -0
- package/src/types/index.ts +147 -0
- package/src/types/slots.ts +11 -0
- package/src/types.ts +1 -0
- package/src/ui/components/ActionButton.tsx +97 -0
- package/src/ui/components/ActionPanel.tsx +315 -0
- package/src/ui/components/Card.tsx +378 -0
- package/src/ui/components/CardDragSurface.tsx +1076 -0
- package/src/ui/components/ChromeSuppressionContext.tsx +70 -0
- package/src/ui/components/CostDisplay.tsx +145 -0
- package/src/ui/components/DiceRoller.tsx +581 -0
- package/src/ui/components/Drawer.tsx +180 -0
- package/src/ui/components/ErrorBoundary.tsx +275 -0
- package/src/ui/components/GameEndDisplay.tsx +398 -0
- package/src/ui/components/GameSkeleton.tsx +260 -0
- package/src/ui/components/Hand.tsx +468 -0
- package/src/ui/components/HandDock.tsx +299 -0
- package/src/ui/components/HandView.tsx +441 -0
- package/src/ui/components/MobileHandTray.tsx +381 -0
- package/src/ui/components/MoreActions.tsx +143 -0
- package/src/ui/components/PhaseIndicator.tsx +341 -0
- package/src/ui/components/PlayArea.tsx +146 -0
- package/src/ui/components/PrimaryActionButton.tsx +336 -0
- package/src/ui/components/PrimaryButton.tsx +45 -0
- package/src/ui/components/ResourceCounter.tsx +270 -0
- package/src/ui/components/StagingZone.tsx +134 -0
- package/src/ui/components/ThemedButton.tsx +113 -0
- package/src/ui/components/Toast.tsx +264 -0
- package/src/ui/components/board/HexGrid.tsx +1294 -0
- package/src/ui/components/board/NetworkGraph.tsx +476 -0
- package/src/ui/components/board/SlotSystem.tsx +388 -0
- package/src/ui/components/board/SquareGrid.tsx +1165 -0
- package/src/ui/components/board/TrackBoard.tsx +496 -0
- package/src/ui/components/board/ZoneMap.tsx +448 -0
- package/src/ui/components/board/hex-board-view.ts +123 -0
- package/src/ui/components/board/index.ts +142 -0
- package/src/ui/components/board/interaction-accessibility.ts +21 -0
- package/src/ui/components/board/target-layer.ts +66 -0
- package/src/ui/components/card-render-content.type-test.ts +27 -0
- package/src/ui/components/hand-layout-math.ts +163 -0
- package/src/ui/components/hand-pointer-engine.ts +413 -0
- package/src/ui/components/index.ts +245 -0
- package/src/ui/components.ts +1 -0
- package/src/ui/defaults/components.tsx +106 -0
- package/src/ui/defaults/index.ts +8 -0
- package/src/ui/defaults.ts +1 -0
- package/src/ui/errors/ValidationError.ts +29 -0
- package/src/ui/helpers/cards.ts +19 -0
- package/src/ui/helpers/track-board.ts +211 -0
- package/src/ui/hooks/useBoardTopology.ts +316 -0
- package/src/ui/hooks/useCards.ts +10 -0
- package/src/ui/hooks/useHandCardPointer.ts +381 -0
- package/src/ui/hooks/useHandLayout.ts +378 -0
- package/src/ui/hooks/useHandPresentation.ts +121 -0
- package/src/ui/hooks/useHexBoard.ts +74 -0
- package/src/ui/hooks/useHexGrid.ts +185 -0
- package/src/ui/hooks/useIsMobile.ts +35 -0
- package/src/ui/hooks/usePanZoom.ts +278 -0
- package/src/ui/hooks/useSquareBoard.ts +124 -0
- package/src/ui/hooks/useSquareGrid.ts +328 -0
- package/src/ui/index.ts +98 -0
- package/src/ui/internal/ui/alert.tsx +51 -0
- package/src/ui/internal/ui/button.tsx +58 -0
- package/src/ui/internal/ui/dialog.tsx +134 -0
- package/src/ui/internal/ui/input.tsx +21 -0
- package/src/ui/internal/ui/label.tsx +21 -0
- package/src/ui/internal/ui/select.tsx +129 -0
- package/src/ui/internal/ui/tooltip.tsx +54 -0
- package/src/ui/internal/ui/utils.ts +5 -0
- package/src/ui/plugin-styles.css +250 -0
- package/src/ui/primitives/dialog-lifecycle.ts +58 -0
- package/src/ui/primitives/dice.tsx +79 -0
- package/src/ui/primitives/primitive-props.tsx +101 -0
- package/src/ui/theme/ThemeProvider.tsx +252 -0
- package/src/ui/theme/board.ts +61 -0
- package/src/ui/theme/css-vars.ts +105 -0
- package/src/ui/theme/derive.ts +240 -0
- package/src/ui/theme/index.ts +61 -0
- package/src/ui/theme/presets/arcade.ts +261 -0
- package/src/ui/theme/presets/studio.ts +261 -0
- package/src/ui/theme/presets/tabletop.ts +266 -0
- package/src/ui/theme/tokens.ts +392 -0
- package/src/ui/types/hex-color.ts +20 -0
- package/src/ui/types/player-state.ts +463 -0
- package/src/ui/types/tiled-board.ts +785 -0
- package/src/ui/types/visual-state.ts +137 -0
- package/src/ui.ts +1 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/** Reducer-native UI primitives for building game interfaces. */
|
|
2
|
+
|
|
3
|
+
// Presentational components (no hooks, receive data as props)
|
|
4
|
+
export { CardFace, type CardFaceProps, type ViewCard } from "./Card.js";
|
|
5
|
+
export { Hand, type HandProps } from "./Hand.js";
|
|
6
|
+
export { StagingZone, type StagingZoneProps } from "./StagingZone.js";
|
|
7
|
+
export {
|
|
8
|
+
HandView,
|
|
9
|
+
type HandViewProps,
|
|
10
|
+
type HandLayoutKind,
|
|
11
|
+
type HandLayoutPolicy,
|
|
12
|
+
} from "./HandView.js";
|
|
13
|
+
export {
|
|
14
|
+
CardDragSurface,
|
|
15
|
+
CardDropTargetView,
|
|
16
|
+
useCardDragSurface,
|
|
17
|
+
type CardDragSurfaceProps,
|
|
18
|
+
type CardDragSurfaceController,
|
|
19
|
+
type CardDragSurfaceContextValue,
|
|
20
|
+
type CardDropTargetViewProps,
|
|
21
|
+
type DragPhase,
|
|
22
|
+
} from "./CardDragSurface.js";
|
|
23
|
+
export type { HandInteractionPolicy } from "./hand-pointer-engine.js";
|
|
24
|
+
export {
|
|
25
|
+
HandDock,
|
|
26
|
+
type HandDockMode,
|
|
27
|
+
type HandDockPlacement,
|
|
28
|
+
type HandDockPresentation,
|
|
29
|
+
type HandDockProps,
|
|
30
|
+
type HandDockToggleContext,
|
|
31
|
+
} from "./HandDock.js";
|
|
32
|
+
export {
|
|
33
|
+
MobileHandTrayProvider,
|
|
34
|
+
useRegisterMobileHand,
|
|
35
|
+
useMobileHandTrayActive,
|
|
36
|
+
type HandRole,
|
|
37
|
+
type MobileHandRegistration,
|
|
38
|
+
} from "./MobileHandTray.js";
|
|
39
|
+
export { PlayArea, type PlayAreaProps } from "./PlayArea.js";
|
|
40
|
+
export {
|
|
41
|
+
ChromeSuppressionProvider,
|
|
42
|
+
useChromeSuppression,
|
|
43
|
+
} from "./ChromeSuppressionContext.js";
|
|
44
|
+
|
|
45
|
+
// Other UI components
|
|
46
|
+
export { GameSkeleton, type GameSkeletonProps } from "./GameSkeleton.js";
|
|
47
|
+
export {
|
|
48
|
+
Toast,
|
|
49
|
+
ToastActions,
|
|
50
|
+
ToastProvider,
|
|
51
|
+
type ToastActionsProps,
|
|
52
|
+
type ToastActionsValue,
|
|
53
|
+
type ToastNotification,
|
|
54
|
+
type ToastType,
|
|
55
|
+
} from "./Toast.js";
|
|
56
|
+
export { ErrorBoundary, type ErrorBoundaryProps } from "./ErrorBoundary.js";
|
|
57
|
+
export {
|
|
58
|
+
Drawer,
|
|
59
|
+
DrawerPortal,
|
|
60
|
+
DrawerOverlay,
|
|
61
|
+
DrawerTrigger,
|
|
62
|
+
DrawerClose,
|
|
63
|
+
DrawerContent,
|
|
64
|
+
DrawerHeader,
|
|
65
|
+
DrawerFooter,
|
|
66
|
+
DrawerTitle,
|
|
67
|
+
DrawerDescription,
|
|
68
|
+
} from "./Drawer.js";
|
|
69
|
+
export {
|
|
70
|
+
Dialog,
|
|
71
|
+
DialogPortal,
|
|
72
|
+
DialogOverlay,
|
|
73
|
+
DialogTrigger,
|
|
74
|
+
DialogClose,
|
|
75
|
+
DialogContent,
|
|
76
|
+
DialogHeader,
|
|
77
|
+
DialogFooter,
|
|
78
|
+
DialogTitle,
|
|
79
|
+
DialogDescription,
|
|
80
|
+
} from "../internal/ui/dialog.js";
|
|
81
|
+
export { Input } from "../internal/ui/input.js";
|
|
82
|
+
export { Label } from "../internal/ui/label.js";
|
|
83
|
+
export {
|
|
84
|
+
Select,
|
|
85
|
+
SelectContent,
|
|
86
|
+
SelectItem,
|
|
87
|
+
SelectTrigger,
|
|
88
|
+
} from "../internal/ui/select.js";
|
|
89
|
+
|
|
90
|
+
// Game UI primitives (SDK v0.1.0+)
|
|
91
|
+
export {
|
|
92
|
+
ResourceCounter,
|
|
93
|
+
ResourceCounterCount,
|
|
94
|
+
ResourceCounterIcon,
|
|
95
|
+
ResourceCounterItem,
|
|
96
|
+
ResourceCounterLabel,
|
|
97
|
+
ResourceCounterRoot,
|
|
98
|
+
createResourceCounter,
|
|
99
|
+
type BoundResourceCounterRootProps,
|
|
100
|
+
type ResourceCounterComponents,
|
|
101
|
+
type ResourceCounterItemState,
|
|
102
|
+
type ResourceCounterPartProps,
|
|
103
|
+
type ResourceCounterProps,
|
|
104
|
+
type ResourceCounterRootProps,
|
|
105
|
+
type ResourceDisplayConfig,
|
|
106
|
+
type ResourceIconProps,
|
|
107
|
+
} from "./ResourceCounter.js";
|
|
108
|
+
export {
|
|
109
|
+
CostDisplay,
|
|
110
|
+
type CostDisplayProps,
|
|
111
|
+
type ResourceDefinition,
|
|
112
|
+
} from "./CostDisplay.js";
|
|
113
|
+
export { ActionButton, type ActionButtonProps } from "./ActionButton.js";
|
|
114
|
+
export { PrimaryButton, type PrimaryButtonProps } from "./PrimaryButton.js";
|
|
115
|
+
export { ThemedButton, type ThemedButtonProps } from "./ThemedButton.js";
|
|
116
|
+
export {
|
|
117
|
+
PrimaryActionButton,
|
|
118
|
+
type PrimaryActionButtonProps,
|
|
119
|
+
type PrimaryActionAttention,
|
|
120
|
+
} from "./PrimaryActionButton.js";
|
|
121
|
+
export {
|
|
122
|
+
ActionPanel,
|
|
123
|
+
ActionGroup,
|
|
124
|
+
type ActionPanelProps,
|
|
125
|
+
type ActionGroupProps,
|
|
126
|
+
} from "./ActionPanel.js";
|
|
127
|
+
export { MoreActions, type MoreActionsProps } from "./MoreActions.js";
|
|
128
|
+
export { DiceRoller, type DiceRollerProps } from "./DiceRoller.js";
|
|
129
|
+
export { PhaseIndicator, type PhaseIndicatorProps } from "./PhaseIndicator.js";
|
|
130
|
+
export {
|
|
131
|
+
GameEndDisplay,
|
|
132
|
+
type GameEndDisplayProps,
|
|
133
|
+
type PlayerScore,
|
|
134
|
+
} from "./GameEndDisplay.js";
|
|
135
|
+
|
|
136
|
+
// Board primitives (SDK v0.2.0+)
|
|
137
|
+
export {
|
|
138
|
+
NetworkGraph,
|
|
139
|
+
DefaultNetworkNode,
|
|
140
|
+
DefaultNetworkEdge,
|
|
141
|
+
DefaultNetworkPiece,
|
|
142
|
+
type NetworkGraphProps,
|
|
143
|
+
type NetworkNode,
|
|
144
|
+
type NetworkEdge,
|
|
145
|
+
type NetworkPiece,
|
|
146
|
+
type DefaultNetworkNodeProps,
|
|
147
|
+
type DefaultNetworkEdgeProps,
|
|
148
|
+
type DefaultNetworkPieceProps,
|
|
149
|
+
} from "./board/NetworkGraph.js";
|
|
150
|
+
|
|
151
|
+
export {
|
|
152
|
+
ZoneMap,
|
|
153
|
+
DefaultZone,
|
|
154
|
+
DefaultZonePieces,
|
|
155
|
+
DefaultZonePiece,
|
|
156
|
+
type ZoneMapProps,
|
|
157
|
+
type ZoneDefinition,
|
|
158
|
+
type ZonePiece,
|
|
159
|
+
type ZoneShape,
|
|
160
|
+
type ZoneHighlightType,
|
|
161
|
+
type DefaultZoneProps,
|
|
162
|
+
type DefaultZonePiecesProps,
|
|
163
|
+
type DefaultZonePieceProps,
|
|
164
|
+
} from "./board/ZoneMap.js";
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
TrackBoard,
|
|
168
|
+
DefaultTrackSpace,
|
|
169
|
+
DefaultTrackPiece,
|
|
170
|
+
DefaultTrackConnection,
|
|
171
|
+
DefaultTrackJump,
|
|
172
|
+
type TrackBoardProps,
|
|
173
|
+
type TrackSpace,
|
|
174
|
+
type TrackPiece,
|
|
175
|
+
type DefaultTrackSpaceProps,
|
|
176
|
+
type DefaultTrackPieceProps,
|
|
177
|
+
type DefaultTrackConnectionProps,
|
|
178
|
+
type DefaultTrackJumpProps,
|
|
179
|
+
} from "./board/TrackBoard.js";
|
|
180
|
+
|
|
181
|
+
export {
|
|
182
|
+
SlotSystem,
|
|
183
|
+
DefaultSlotItem,
|
|
184
|
+
DefaultSlotOccupant,
|
|
185
|
+
DefaultEmptySlot,
|
|
186
|
+
type SlotSystemProps,
|
|
187
|
+
type SlotDefinition,
|
|
188
|
+
type SlotOccupant,
|
|
189
|
+
type DefaultSlotItemProps,
|
|
190
|
+
type DefaultSlotOccupantProps,
|
|
191
|
+
type DefaultEmptySlotProps,
|
|
192
|
+
} from "./board/SlotSystem.js";
|
|
193
|
+
|
|
194
|
+
export {
|
|
195
|
+
SquareGrid,
|
|
196
|
+
DefaultGridCell,
|
|
197
|
+
DefaultGridPiece,
|
|
198
|
+
DefaultChessPiece,
|
|
199
|
+
toAlgebraic,
|
|
200
|
+
toNumeric,
|
|
201
|
+
type SquareGridBoardProps,
|
|
202
|
+
type SquareGridProps,
|
|
203
|
+
type InteractiveSquareEdge,
|
|
204
|
+
type InteractiveSquareVertex,
|
|
205
|
+
type SquareEdgePosition,
|
|
206
|
+
type SquareVertexPosition,
|
|
207
|
+
type DefaultGridCellProps,
|
|
208
|
+
type DefaultGridPieceProps,
|
|
209
|
+
type DefaultChessPieceProps,
|
|
210
|
+
} from "./board/SquareGrid.js";
|
|
211
|
+
|
|
212
|
+
export {
|
|
213
|
+
HexGrid,
|
|
214
|
+
hexUtils,
|
|
215
|
+
DefaultHexTile,
|
|
216
|
+
DefaultHexEdge,
|
|
217
|
+
DefaultHexVertex,
|
|
218
|
+
type HexGridBoardProps,
|
|
219
|
+
type HexGridProps,
|
|
220
|
+
type HexOrientation,
|
|
221
|
+
type HexTileGeometry,
|
|
222
|
+
type InteractiveHexEdge,
|
|
223
|
+
type InteractiveHexVertex,
|
|
224
|
+
type InteractiveTargetLayer,
|
|
225
|
+
type InteractiveTargetRenderState,
|
|
226
|
+
type EdgePosition,
|
|
227
|
+
type DefaultHexTileProps,
|
|
228
|
+
type DefaultHexEdgeProps,
|
|
229
|
+
type DefaultHexVertexProps,
|
|
230
|
+
} from "./board/HexGrid.js";
|
|
231
|
+
export {
|
|
232
|
+
createHexBoardView,
|
|
233
|
+
type HexBoardView,
|
|
234
|
+
type HexBoardViewTile,
|
|
235
|
+
} from "./board/hex-board-view.js";
|
|
236
|
+
export type {
|
|
237
|
+
HexTileState,
|
|
238
|
+
HexEdgeState,
|
|
239
|
+
HexVertexState,
|
|
240
|
+
SquareCellState,
|
|
241
|
+
SquareEdgeState,
|
|
242
|
+
SquarePieceState,
|
|
243
|
+
SquareVertexState,
|
|
244
|
+
} from "../types/player-state.js";
|
|
245
|
+
export type { CardCollection, ViewSlotOccupant } from "../../types/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./components/index.js";
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { CSSProperties, HTMLAttributes } from "react";
|
|
2
|
+
import {
|
|
3
|
+
renderPrimitive,
|
|
4
|
+
type PrimitiveCommonProps,
|
|
5
|
+
} from "../primitives/primitive-props.js";
|
|
6
|
+
|
|
7
|
+
type LayoutPrimitiveProps = PrimitiveCommonProps & HTMLAttributes<HTMLElement>;
|
|
8
|
+
|
|
9
|
+
function layoutStyle(
|
|
10
|
+
base: CSSProperties,
|
|
11
|
+
style: CSSProperties | undefined,
|
|
12
|
+
): CSSProperties {
|
|
13
|
+
return style ? { ...base, ...style } : base;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function GameLayoutRoot({
|
|
17
|
+
children,
|
|
18
|
+
style,
|
|
19
|
+
...props
|
|
20
|
+
}: LayoutPrimitiveProps) {
|
|
21
|
+
return renderPrimitive("div", {
|
|
22
|
+
...props,
|
|
23
|
+
"data-dreamboard-game-layout": "",
|
|
24
|
+
style: layoutStyle(
|
|
25
|
+
{
|
|
26
|
+
display: "grid",
|
|
27
|
+
gridTemplateColumns: "minmax(0, 1fr) minmax(18rem, 24rem)",
|
|
28
|
+
gridTemplateRows: "auto minmax(0, 1fr) auto",
|
|
29
|
+
gridTemplateAreas: `"header header" "board sidebar" "bottom sidebar"`,
|
|
30
|
+
minHeight: "100%",
|
|
31
|
+
gap: "1rem",
|
|
32
|
+
},
|
|
33
|
+
style,
|
|
34
|
+
),
|
|
35
|
+
children,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function GameLayoutHeader({
|
|
40
|
+
children,
|
|
41
|
+
style,
|
|
42
|
+
...props
|
|
43
|
+
}: LayoutPrimitiveProps) {
|
|
44
|
+
return renderPrimitive("header", {
|
|
45
|
+
...props,
|
|
46
|
+
"data-dreamboard-game-layout-header": "",
|
|
47
|
+
style: layoutStyle({ gridArea: "header" }, style),
|
|
48
|
+
children,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function GameLayoutBoard({
|
|
53
|
+
children,
|
|
54
|
+
style,
|
|
55
|
+
...props
|
|
56
|
+
}: LayoutPrimitiveProps) {
|
|
57
|
+
return renderPrimitive("section", {
|
|
58
|
+
...props,
|
|
59
|
+
"data-dreamboard-game-layout-board": "",
|
|
60
|
+
style: layoutStyle({ gridArea: "board", minWidth: 0 }, style),
|
|
61
|
+
children,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function GameLayoutSidebar({
|
|
66
|
+
children,
|
|
67
|
+
style,
|
|
68
|
+
...props
|
|
69
|
+
}: LayoutPrimitiveProps) {
|
|
70
|
+
return renderPrimitive("aside", {
|
|
71
|
+
...props,
|
|
72
|
+
"data-dreamboard-game-layout-sidebar": "",
|
|
73
|
+
style: layoutStyle(
|
|
74
|
+
{
|
|
75
|
+
gridArea: "sidebar",
|
|
76
|
+
minWidth: 0,
|
|
77
|
+
display: "flex",
|
|
78
|
+
flexDirection: "column",
|
|
79
|
+
gap: "0.75rem",
|
|
80
|
+
},
|
|
81
|
+
style,
|
|
82
|
+
),
|
|
83
|
+
children,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function GameLayoutBottom({
|
|
88
|
+
children,
|
|
89
|
+
style,
|
|
90
|
+
...props
|
|
91
|
+
}: LayoutPrimitiveProps) {
|
|
92
|
+
return renderPrimitive("section", {
|
|
93
|
+
...props,
|
|
94
|
+
"data-dreamboard-game-layout-bottom": "",
|
|
95
|
+
style: layoutStyle({ gridArea: "bottom", minWidth: 0 }, style),
|
|
96
|
+
children,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const GameLayout = {
|
|
101
|
+
Root: GameLayoutRoot,
|
|
102
|
+
Header: GameLayoutHeader,
|
|
103
|
+
Board: GameLayoutBoard,
|
|
104
|
+
Sidebar: GameLayoutSidebar,
|
|
105
|
+
Bottom: GameLayoutBottom,
|
|
106
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./defaults/index.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when action validation fails.
|
|
3
|
+
* Contains the error code and optional message from the validation result.
|
|
4
|
+
*/
|
|
5
|
+
export class ValidationError extends Error {
|
|
6
|
+
constructor(
|
|
7
|
+
public readonly errorCode?: string,
|
|
8
|
+
message?: string,
|
|
9
|
+
) {
|
|
10
|
+
super(message || errorCode || "Validation failed");
|
|
11
|
+
this.name = "ValidationError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function validationErrorFromUnknown(
|
|
16
|
+
error: unknown,
|
|
17
|
+
fallbackMessage = "Interaction submission failed",
|
|
18
|
+
): ValidationError {
|
|
19
|
+
if (error instanceof ValidationError) return error;
|
|
20
|
+
const errorCode =
|
|
21
|
+
typeof error === "object" &&
|
|
22
|
+
error !== null &&
|
|
23
|
+
"errorCode" in error &&
|
|
24
|
+
typeof error.errorCode === "string"
|
|
25
|
+
? error.errorCode
|
|
26
|
+
: undefined;
|
|
27
|
+
const message = error instanceof Error ? error.message : fallbackMessage;
|
|
28
|
+
return new ValidationError(errorCode, message);
|
|
29
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CardCollection, ViewCard } from "../../types/index.js";
|
|
2
|
+
|
|
3
|
+
export function materializeCards<
|
|
4
|
+
CardIdValue extends string,
|
|
5
|
+
CardValue extends ViewCard<CardIdValue>,
|
|
6
|
+
>(collection: CardCollection<CardIdValue, CardValue>): CardValue[] {
|
|
7
|
+
const items: CardValue[] = [];
|
|
8
|
+
|
|
9
|
+
for (const cardId of collection.cardIds) {
|
|
10
|
+
const card = collection.cardsById[cardId];
|
|
11
|
+
if (!card) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
items.push(card);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return items;
|
|
19
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type { TrackPiece, TrackSpace } from "../components/board/TrackBoard.js";
|
|
2
|
+
|
|
3
|
+
interface GenericBoardSpaceLike<
|
|
4
|
+
SpaceIdValue extends string = string,
|
|
5
|
+
Fields = Record<string, unknown>,
|
|
6
|
+
> {
|
|
7
|
+
id: SpaceIdValue;
|
|
8
|
+
name?: string | null;
|
|
9
|
+
typeId?: string | null;
|
|
10
|
+
fields: Fields;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface GenericBoardRelationLike<SpaceIdValue extends string = string> {
|
|
14
|
+
fromSpaceId: SpaceIdValue;
|
|
15
|
+
toSpaceId: SpaceIdValue;
|
|
16
|
+
directed: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface GenericBoardLike<
|
|
20
|
+
BoardIdValue extends string = string,
|
|
21
|
+
SpaceIdValue extends string = string,
|
|
22
|
+
SpaceFields = Record<string, unknown>,
|
|
23
|
+
> {
|
|
24
|
+
id: BoardIdValue;
|
|
25
|
+
spaces: Readonly<
|
|
26
|
+
Record<SpaceIdValue, GenericBoardSpaceLike<SpaceIdValue, SpaceFields>>
|
|
27
|
+
>;
|
|
28
|
+
relations?: ReadonlyArray<GenericBoardRelationLike<SpaceIdValue>>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface TrackBoardPieceLike<
|
|
32
|
+
PieceIdValue extends string = string,
|
|
33
|
+
SpaceIdValue extends string = string,
|
|
34
|
+
OwnerIdValue extends string = string,
|
|
35
|
+
Fields = unknown,
|
|
36
|
+
> {
|
|
37
|
+
id: PieceIdValue;
|
|
38
|
+
spaceId: SpaceIdValue;
|
|
39
|
+
owner: OwnerIdValue;
|
|
40
|
+
typeId?: string | null;
|
|
41
|
+
fields?: Fields;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
type BoardSpaceOf<TBoard extends GenericBoardLike> =
|
|
45
|
+
TBoard["spaces"][keyof TBoard["spaces"]];
|
|
46
|
+
type SpaceIdOf<TBoard extends GenericBoardLike> =
|
|
47
|
+
BoardSpaceOf<TBoard> extends {
|
|
48
|
+
id: infer Id extends string;
|
|
49
|
+
}
|
|
50
|
+
? Id
|
|
51
|
+
: never;
|
|
52
|
+
type SpaceFieldsOf<TBoard extends GenericBoardLike> =
|
|
53
|
+
BoardSpaceOf<TBoard> extends { fields: infer Fields } ? Fields : never;
|
|
54
|
+
type PieceIdOf<TPiece extends TrackBoardPieceLike> = TPiece extends {
|
|
55
|
+
id: infer Id extends string;
|
|
56
|
+
}
|
|
57
|
+
? Id
|
|
58
|
+
: never;
|
|
59
|
+
type PieceOwnerOf<TPiece extends TrackBoardPieceLike> = TPiece extends {
|
|
60
|
+
owner: infer Owner extends string;
|
|
61
|
+
}
|
|
62
|
+
? Owner
|
|
63
|
+
: never;
|
|
64
|
+
type PieceFieldsOf<TPiece extends TrackBoardPieceLike> = TPiece extends {
|
|
65
|
+
fields?: infer Fields;
|
|
66
|
+
}
|
|
67
|
+
? Fields
|
|
68
|
+
: never;
|
|
69
|
+
|
|
70
|
+
type TrackLayout =
|
|
71
|
+
| {
|
|
72
|
+
type: "linear";
|
|
73
|
+
axis?: "x" | "y";
|
|
74
|
+
spacing?: number;
|
|
75
|
+
origin?: { x: number; y: number };
|
|
76
|
+
}
|
|
77
|
+
| {
|
|
78
|
+
type: "circular";
|
|
79
|
+
center: { x: number; y: number };
|
|
80
|
+
radius: number;
|
|
81
|
+
startAngleDeg?: number;
|
|
82
|
+
clockwise?: boolean;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type PositionOptions<TBoard extends GenericBoardLike> =
|
|
86
|
+
| {
|
|
87
|
+
getPosition: (
|
|
88
|
+
space: BoardSpaceOf<TBoard>,
|
|
89
|
+
index: number,
|
|
90
|
+
spaces: ReadonlyArray<BoardSpaceOf<TBoard>>,
|
|
91
|
+
) => { x: number; y: number };
|
|
92
|
+
layout?: never;
|
|
93
|
+
}
|
|
94
|
+
| {
|
|
95
|
+
getPosition?: never;
|
|
96
|
+
layout: TrackLayout;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type ToTrackBoardDataOptions<
|
|
100
|
+
TBoard extends GenericBoardLike,
|
|
101
|
+
TPiece extends TrackBoardPieceLike<
|
|
102
|
+
string,
|
|
103
|
+
SpaceIdOf<TBoard>,
|
|
104
|
+
string,
|
|
105
|
+
unknown
|
|
106
|
+
>,
|
|
107
|
+
> = PositionOptions<TBoard> & {
|
|
108
|
+
pieces?: readonly TPiece[];
|
|
109
|
+
getNextSpaces?: (
|
|
110
|
+
space: BoardSpaceOf<TBoard>,
|
|
111
|
+
board: TBoard,
|
|
112
|
+
) => ReadonlyArray<SpaceIdOf<TBoard>> | undefined;
|
|
113
|
+
getJumpTo?: (
|
|
114
|
+
space: BoardSpaceOf<TBoard>,
|
|
115
|
+
board: TBoard,
|
|
116
|
+
) => SpaceIdOf<TBoard> | undefined;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
function positionForLayout(
|
|
120
|
+
layout: TrackLayout,
|
|
121
|
+
index: number,
|
|
122
|
+
count: number,
|
|
123
|
+
): { x: number; y: number } {
|
|
124
|
+
if (layout.type === "linear") {
|
|
125
|
+
const spacing = layout.spacing ?? 72;
|
|
126
|
+
const origin = layout.origin ?? { x: 0, y: 0 };
|
|
127
|
+
return layout.axis === "y"
|
|
128
|
+
? { x: origin.x, y: origin.y + index * spacing }
|
|
129
|
+
: { x: origin.x + index * spacing, y: origin.y };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const startAngleDeg = layout.startAngleDeg ?? -90;
|
|
133
|
+
const clockwise = layout.clockwise ?? true;
|
|
134
|
+
const angleStep = count === 0 ? 0 : 360 / count;
|
|
135
|
+
const angleDeg = startAngleDeg + (clockwise ? 1 : -1) * angleStep * index;
|
|
136
|
+
const angle = (angleDeg * Math.PI) / 180;
|
|
137
|
+
return {
|
|
138
|
+
x: layout.center.x + Math.cos(angle) * layout.radius,
|
|
139
|
+
y: layout.center.y + Math.sin(angle) * layout.radius,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function defaultNextSpaces<TBoard extends GenericBoardLike>(
|
|
144
|
+
board: TBoard,
|
|
145
|
+
spaceId: SpaceIdOf<TBoard>,
|
|
146
|
+
): Array<SpaceIdOf<TBoard>> {
|
|
147
|
+
const relations = board.relations ?? [];
|
|
148
|
+
return relations.flatMap((relation) => {
|
|
149
|
+
if (relation.fromSpaceId === spaceId) {
|
|
150
|
+
return [relation.toSpaceId];
|
|
151
|
+
}
|
|
152
|
+
if (!relation.directed && relation.toSpaceId === spaceId) {
|
|
153
|
+
return [relation.fromSpaceId];
|
|
154
|
+
}
|
|
155
|
+
return [];
|
|
156
|
+
}) as Array<SpaceIdOf<TBoard>>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function toTrackBoardData<
|
|
160
|
+
TBoard extends GenericBoardLike,
|
|
161
|
+
TPiece extends TrackBoardPieceLike<
|
|
162
|
+
string,
|
|
163
|
+
SpaceIdOf<TBoard>,
|
|
164
|
+
string,
|
|
165
|
+
unknown
|
|
166
|
+
>,
|
|
167
|
+
>(
|
|
168
|
+
board: TBoard,
|
|
169
|
+
options: ToTrackBoardDataOptions<TBoard, TPiece>,
|
|
170
|
+
): {
|
|
171
|
+
spaces: Array<TrackSpace<SpaceIdOf<TBoard>, SpaceFieldsOf<TBoard>>>;
|
|
172
|
+
pieces: Array<
|
|
173
|
+
TrackPiece<
|
|
174
|
+
PieceIdOf<TPiece>,
|
|
175
|
+
SpaceIdOf<TBoard>,
|
|
176
|
+
PieceOwnerOf<TPiece>,
|
|
177
|
+
PieceFieldsOf<TPiece>
|
|
178
|
+
>
|
|
179
|
+
>;
|
|
180
|
+
} {
|
|
181
|
+
const spaces = Object.values(board.spaces) as Array<BoardSpaceOf<TBoard>>;
|
|
182
|
+
const orderedSpaces = [...spaces].sort((left, right) =>
|
|
183
|
+
left.id.localeCompare(right.id),
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
spaces: orderedSpaces.map((space, index, allSpaces) => ({
|
|
188
|
+
id: space.id as SpaceIdOf<TBoard>,
|
|
189
|
+
index,
|
|
190
|
+
name: space.name ?? undefined,
|
|
191
|
+
type: space.typeId ?? undefined,
|
|
192
|
+
nextSpaces: (options.getNextSpaces?.(space, board) ??
|
|
193
|
+
defaultNextSpaces(board, space.id as SpaceIdOf<TBoard>)) as Array<
|
|
194
|
+
SpaceIdOf<TBoard>
|
|
195
|
+
>,
|
|
196
|
+
jumpTo: options.getJumpTo?.(space, board),
|
|
197
|
+
position:
|
|
198
|
+
"getPosition" in options && options.getPosition
|
|
199
|
+
? options.getPosition(space, index, allSpaces)
|
|
200
|
+
: positionForLayout(options.layout, index, allSpaces.length),
|
|
201
|
+
data: space.fields as SpaceFieldsOf<TBoard>,
|
|
202
|
+
})),
|
|
203
|
+
pieces: (options.pieces ?? []).map((piece) => ({
|
|
204
|
+
id: piece.id as PieceIdOf<TPiece>,
|
|
205
|
+
spaceId: piece.spaceId,
|
|
206
|
+
owner: piece.owner as PieceOwnerOf<TPiece>,
|
|
207
|
+
type: piece.typeId ?? undefined,
|
|
208
|
+
data: piece.fields as PieceFieldsOf<TPiece>,
|
|
209
|
+
})),
|
|
210
|
+
};
|
|
211
|
+
}
|