@dreamboard-games/sdk 0.5.0-alpha.3 → 0.5.0-alpha.4
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/README.md +52 -2
- package/dist/board-target-B0QG6OYx.d.ts +8 -0
- package/dist/chunk-3JXUL4VN.js +139 -0
- package/dist/chunk-3JXUL4VN.js.map +1 -0
- package/dist/{chunk-LRILEVKC.js → chunk-C77SYIVT.js} +82 -109
- package/dist/chunk-C77SYIVT.js.map +1 -0
- package/dist/{chunk-SP234IY4.js → chunk-OOFMBCFF.js} +178 -203
- package/dist/chunk-OOFMBCFF.js.map +1 -0
- package/dist/{chunk-ZPRKWPEP.js → chunk-UG2Q4NLG.js} +108 -29
- package/dist/chunk-UG2Q4NLG.js.map +1 -0
- package/dist/{chunk-FMM5LVJW.js → chunk-XU6WJW6K.js} +26 -12
- package/dist/chunk-XU6WJW6K.js.map +1 -0
- package/dist/{diagnostics-B0lgnuZ6.d.ts → diagnostics-B8d5aLad.d.ts} +2 -2
- package/dist/{definition-BaHNPZol.d.ts → extract-gVKcB8Og.d.ts} +484 -387
- package/dist/index.d.ts +404 -175
- package/dist/index.js +266 -215
- package/dist/index.js.map +1 -1
- package/dist/model-vdpLHrxh.d.ts +432 -0
- package/dist/react.d.ts +35 -7
- package/dist/react.js +136 -8
- package/dist/react.js.map +1 -1
- package/dist/reducer.d.ts +169 -118
- package/dist/reducer.js +206 -328
- package/dist/reducer.js.map +1 -1
- package/dist/testing.d.ts +5 -3
- package/dist/testing.js +9 -6
- package/dist/testing.js.map +1 -1
- package/dist/{types-DimqnJBq.d.ts → types-Bj5ZLTUV.d.ts} +38 -10
- package/package.json +19 -16
- package/dist/chunk-FMM5LVJW.js.map +0 -1
- package/dist/chunk-LRILEVKC.js.map +0 -1
- package/dist/chunk-SP234IY4.js.map +0 -1
- package/dist/chunk-VUWNJXLJ.js +0 -52
- package/dist/chunk-VUWNJXLJ.js.map +0 -1
- package/dist/chunk-ZPRKWPEP.js.map +0 -1
- package/dist/model-BHro6yXu.d.ts +0 -288
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react/create-game-hook.tsx"],"sourcesContent":["import {\n createContext,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { useSelector } from \"@tanstack/react-store\";\nimport { createGameInstance } from \"../headless/instance.js\";\nimport type {\n CoreInstance,\n FeatureContext,\n Features,\n GameInstance,\n GameSnapshot,\n GameSource,\n InstanceOptions,\n} from \"../headless/model.js\";\n\nexport interface SelectionOptions<Value> {\n readonly compare?: (previous: Value, next: Value) => boolean;\n}\n\n/** Bind erased game types and features; each provider owns its source lifetime. */\nexport function createGameHook<Game, Source extends GameSource = GameSource>() {\n return function <const Enabled extends Features = Record<never, never>>(\n defaults: Omit<InstanceOptions<Game, Source>, \"source\"> & {\n features?: (\n core: CoreInstance<Game>,\n context: FeatureContext<Game>,\n ) => Enabled;\n },\n ) {\n type Instance = GameInstance<Game, Enabled, Source>;\n type Snapshot = GameSnapshot<Game, Enabled>;\n type ProviderProps = Partial<\n Omit<InstanceOptions<Game, Source>, \"source\">\n > & {\n source: Source;\n children?: ReactNode;\n };\n const Context = createContext<Instance | null>(null);\n\n /** Owns the source. Do not share it between independently mounted providers. */\n function GameProvider({ children, ...overrides }: ProviderProps) {\n const [instance, setInstance] = useState<Instance | null>(null);\n const lifetime = useRef<{\n instance: Instance;\n generation: number;\n } | null>(null);\n const options = {\n ...defaults,\n ...overrides,\n };\n useLayoutEffect(() => {\n let current = lifetime.current;\n if (!current) {\n current = {\n instance: createGameInstance<Game>()(options),\n generation: 0,\n };\n lifetime.current = current;\n setInstance(current.instance);\n }\n const owned = current;\n ++owned.generation;\n return () => {\n const generation = ++owned.generation;\n queueMicrotask(() => {\n if (owned.generation !== generation) return;\n owned.instance.dispose();\n if (lifetime.current === owned) lifetime.current = null;\n });\n };\n // Construction belongs to this committed provider lifetime. Current\n // options are installed separately without recreating features.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n useLayoutEffect(() => {\n lifetime.current?.instance.setOptions(options);\n });\n return instance ? (\n <Context.Provider value={instance}>{children}</Context.Provider>\n ) : null;\n }\n\n function useInstance(): Instance {\n const instance = useContext(Context);\n if (!instance) throw new Error(\"useGame requires its GameProvider.\");\n return instance;\n }\n\n function useGame(): Instance;\n function useGame<Value>(\n selector: (snapshot: Snapshot) => Value,\n options?: SelectionOptions<Value>,\n ): Value;\n function useGame<Value>(\n selector?: (snapshot: Snapshot) => Value,\n options?: SelectionOptions<Value>,\n ): Instance | Value {\n const instance = useInstance();\n const selected = useSelector(\n instance.store,\n selector ?? ((snapshot) => snapshot as unknown as Value),\n options,\n );\n return selector ? selected : instance;\n }\n\n function Subscribe<Value>({\n selector,\n compare,\n children,\n }: {\n selector: (snapshot: Snapshot) => Value;\n compare?: SelectionOptions<Value>[\"compare\"];\n children: (value: Value) => ReactNode;\n }) {\n return children(useGame(selector, { compare }));\n }\n\n return { GameProvider, useGame, Subscribe };\n };\n}\n"],"mappings":";;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,mBAAmB;AA2EpB;AA1DD,SAAS,iBAA+D;AAC7E,SAAO,SACL,UAMA;AASA,UAAM,UAAU,cAA+B,IAAI;AAGnD,aAAS,aAAa,EAAE,UAAU,GAAG,UAAU,GAAkB;AAC/D,YAAM,CAAC,UAAU,WAAW,IAAI,SAA0B,IAAI;AAC9D,YAAM,WAAW,OAGP,IAAI;AACd,YAAM,UAAU;AAAA,QACd,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AACA,sBAAgB,MAAM;AACpB,YAAI,UAAU,SAAS;AACvB,YAAI,CAAC,SAAS;AACZ,oBAAU;AAAA,YACR,UAAU,mBAAyB,EAAE,OAAO;AAAA,YAC5C,YAAY;AAAA,UACd;AACA,mBAAS,UAAU;AACnB,sBAAY,QAAQ,QAAQ;AAAA,QAC9B;AACA,cAAM,QAAQ;AACd,UAAE,MAAM;AACR,eAAO,MAAM;AACX,gBAAM,aAAa,EAAE,MAAM;AAC3B,yBAAe,MAAM;AACnB,gBAAI,MAAM,eAAe,WAAY;AACrC,kBAAM,SAAS,QAAQ;AACvB,gBAAI,SAAS,YAAY,MAAO,UAAS,UAAU;AAAA,UACrD,CAAC;AAAA,QACH;AAAA,MAIF,GAAG,CAAC,CAAC;AACL,sBAAgB,MAAM;AACpB,iBAAS,SAAS,SAAS,WAAW,OAAO;AAAA,MAC/C,CAAC;AACD,aAAO,WACL,oBAAC,QAAQ,UAAR,EAAiB,OAAO,UAAW,UAAS,IAC3C;AAAA,IACN;AAEA,aAAS,cAAwB;AAC/B,YAAM,WAAW,WAAW,OAAO;AACnC,UAAI,CAAC,SAAU,OAAM,IAAI,MAAM,oCAAoC;AACnE,aAAO;AAAA,IACT;AAOA,aAAS,QACP,UACA,SACkB;AAClB,YAAM,WAAW,YAAY;AAC7B,YAAM,WAAW;AAAA,QACf,SAAS;AAAA,QACT,aAAa,CAAC,aAAa;AAAA,QAC3B;AAAA,MACF;AACA,aAAO,WAAW,WAAW;AAAA,IAC/B;AAEA,aAAS,UAAiB;AAAA,MACxB;AAAA,MACA;AAAA,MACA;AAAA,IACF,GAIG;AACD,aAAO,SAAS,QAAQ,UAAU,EAAE,QAAQ,CAAC,CAAC;AAAA,IAChD;AAEA,WAAO,EAAE,cAAc,SAAS,UAAU;AAAA,EAC5C;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/react/drag.tsx","../src/react/create-game-hook.tsx"],"sourcesContent":["import { useId, useLayoutEffect, type ReactNode } from \"react\";\nimport {\n DragDropProvider,\n KeyboardSensor,\n PointerSensor,\n useDragDropManager,\n useDraggable,\n useDroppable,\n type UseDroppableInput,\n type DragOverEvent,\n type DragEndEvent,\n} from \"@dnd-kit/react\";\nimport {\n Accessibility,\n defaultPreset,\n PointerActivationConstraints,\n} from \"@dnd-kit/dom\";\nimport { pointerIntersection } from \"@dnd-kit/collision\";\nimport type { CoreInstance } from \"../headless/model.js\";\nimport type { DragController } from \"../headless/features/drag.js\";\nimport type { DropTarget, TargetOptions } from \"../headless/targets.js\";\n\n/** Browser-only hit testing receives client pixels; SVG renderers invert their screen CTM. */\nexport interface BoardDropOptions {\n containsPoint?(point: { x: number; y: number }): boolean;\n}\nexport type DragGame = CoreInstance<unknown> & {\n readonly drag?: DragController<unknown>;\n};\ntype DragData = { begin?: () => boolean; target?: DropTarget<unknown> | null };\nconst sensors = [\n PointerSensor.configure({\n activationConstraints: [\n new PointerActivationConstraints.Distance({ value: 5 }),\n ],\n }),\n KeyboardSensor,\n];\n\nconst plugins = defaultPreset.plugins.map((plugin) =>\n plugin === Accessibility\n ? Accessibility.configure({\n announcements: {\n dragstart: () =>\n \"Card picked up. Use arrow keys to move and Space or Enter to drop. Escape cancels.\",\n dragover: ({ operation }: DragOverEvent) => {\n const element = operation.target?.element;\n if (!element) return \"No drop destination.\";\n const label =\n element.getAttribute(\"aria-label\") ?? \"board destination\";\n const board = element.getAttribute(\"data-board\");\n return `Over ${label}${board ? ` on ${board}` : \"\"}.`;\n },\n dragend: ({ canceled, operation }: DragEndEvent) =>\n canceled\n ? \"Drag cancelled.\"\n : operation.target\n ? \"Card placement selected.\"\n : \"No placement selected.\",\n },\n })\n : plugin,\n);\n\nfunction DragLifetime({ game }: { game: DragGame }) {\n const manager = useDragDropManager();\n useLayoutEffect(\n () =>\n game.subscribe(() => {\n if (\n !game.drag?.active &&\n manager &&\n !manager.dragOperation.status.idle &&\n !manager.dragOperation.status.dropped\n )\n manager.actions.stop({ canceled: true });\n }),\n [game, manager],\n );\n return null;\n}\n/** Installed by GameProvider when dragFeature is enabled. */\nexport function GameDragProvider({\n game,\n children,\n}: {\n game: DragGame;\n children?: ReactNode;\n}) {\n return (\n <DragDropProvider<DragData>\n sensors={sensors}\n plugins={plugins}\n onBeforeDragStart={(event) => {\n if (!event.operation.source?.data.begin?.()) event.preventDefault();\n }}\n onDragOver={({ operation }) =>\n game.drag?.setDropTarget(operation.target?.data.target ?? null)\n }\n onDragEnd={({ canceled, operation }) => {\n if (canceled) game.drag?.cancel();\n else {\n game.drag?.setDropTarget(operation.target?.data.target ?? null);\n game.drag?.drop();\n }\n }}\n >\n <DragLifetime game={game} />\n {children}\n </DragDropProvider>\n );\n}\n\n/** Bound by createGameHook so card and interaction IDs use the authored game. */\nexport function useCardDraggable(\n game: DragGame,\n cardId: string,\n options?: TargetOptions<unknown>,\n) {\n const id = useId();\n const canDrag = game.drag?.getCanDrag(cardId, options) ?? false;\n const { ref, handleRef, isDragging } = useDraggable<DragData>({\n id,\n disabled: !canDrag,\n data: { begin: () => game.drag?.begin(cardId, options) ?? false },\n });\n return {\n // Disabled draggables must not mark ordinary nested card controls aria-disabled.\n ref: canDrag ? ref : undefined,\n handleRef,\n isDragging,\n canDrag,\n handleProps: {\n type: \"button\" as const,\n disabled: !canDrag,\n \"aria-label\": `Drag ${cardId}`,\n \"data-drag-card\": cardId,\n style: { touchAction: \"none\" as const },\n },\n };\n}\n\n/** Targets retain the exact interaction, card-input and destination-input route. */\nexport function useBoardDroppable(\n target: DropTarget<unknown> | null,\n options?: BoardDropOptions,\n) {\n const id = useId();\n const collisionDetector: UseDroppableInput[\"collisionDetector\"] = (input) => {\n const collision = pointerIntersection(input);\n if (!collision) return null;\n return !options?.containsPoint ||\n options.containsPoint(input.dragOperation.position.current)\n ? collision\n : null;\n };\n const { ref, isDropTarget } = useDroppable<DragData>({\n id,\n disabled: target === null,\n data: { target },\n collisionDetector,\n });\n return { ref, isDropTarget };\n}\n","import {\n GameDragProvider,\n useCardDraggable,\n useBoardDroppable,\n type BoardDropOptions,\n type DragGame,\n} from \"./drag.js\";\nimport type { IdOf } from \"../headless/model.js\";\nimport type { DropTarget, TargetOptions } from \"../headless/targets.js\";\nimport {\n createContext,\n useContext,\n useLayoutEffect,\n useRef,\n useState,\n type ReactNode,\n} from \"react\";\nimport { useSelector } from \"@tanstack/react-store\";\nimport { createGameInstance } from \"../headless/instance.js\";\nimport type {\n CoreInstance,\n FeatureContext,\n Features,\n GameInstance,\n GameSnapshot,\n GameSource,\n InstanceOptions,\n} from \"../headless/model.js\";\n\nexport interface SelectionOptions<Value> {\n readonly compare?: (previous: Value, next: Value) => boolean;\n}\n\n/** Bind erased game types and features; each provider owns its source lifetime. */\nexport function createGameHook<Game, Source extends GameSource = GameSource>() {\n return function <const Enabled extends Features = Record<never, never>>(\n defaults: Omit<InstanceOptions<Game, Source>, \"source\"> & {\n features?: (\n core: CoreInstance<Game>,\n context: FeatureContext<Game>,\n ) => Enabled;\n },\n ) {\n type Instance = GameInstance<Game, Enabled, Source>;\n type Snapshot = GameSnapshot<Game, Enabled>;\n type ProviderProps = Partial<\n Omit<InstanceOptions<Game, Source>, \"source\">\n > & {\n source: Source;\n children?: ReactNode;\n };\n const Context = createContext<Instance | null>(null);\n\n /** Owns the source. Do not share it between independently mounted providers. */\n function GameProvider({ children, ...overrides }: ProviderProps) {\n const [instance, setInstance] = useState<Instance | null>(null);\n const lifetime = useRef<{\n instance: Instance;\n generation: number;\n } | null>(null);\n const options = {\n ...defaults,\n ...overrides,\n };\n useLayoutEffect(() => {\n let current = lifetime.current;\n if (!current) {\n current = {\n instance: createGameInstance<Game>()(options),\n generation: 0,\n };\n lifetime.current = current;\n setInstance(current.instance);\n }\n const owned = current;\n ++owned.generation;\n return () => {\n const generation = ++owned.generation;\n queueMicrotask(() => {\n if (owned.generation !== generation) return;\n owned.instance.dispose();\n if (lifetime.current === owned) lifetime.current = null;\n });\n };\n // Construction belongs to this committed provider lifetime. Current\n // options are installed separately without recreating features.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n useLayoutEffect(() => {\n lifetime.current?.instance.setOptions(options);\n });\n return instance ? (\n <Context.Provider value={instance}>\n {\"drag\" in instance ? (\n <GameDragProvider game={instance as unknown as DragGame}>\n {children}\n </GameDragProvider>\n ) : (\n children\n )}\n </Context.Provider>\n ) : null;\n }\n\n function useInstance(): Instance {\n const instance = useContext(Context);\n if (!instance) throw new Error(\"useGame requires its GameProvider.\");\n return instance;\n }\n\n function useGame(): Instance;\n function useGame<Value>(\n selector: (snapshot: Snapshot) => Value,\n options?: SelectionOptions<Value>,\n ): Value;\n function useGame<Value>(\n selector?: (snapshot: Snapshot) => Value,\n options?: SelectionOptions<Value>,\n ): Instance | Value {\n const instance = useInstance();\n const selected = useSelector(\n instance.store,\n selector ?? ((snapshot) => snapshot as unknown as Value),\n options,\n );\n return selector ? selected : instance;\n }\n\n function Subscribe<Value>({\n selector,\n compare,\n children,\n }: {\n selector: (snapshot: Snapshot) => Value;\n compare?: SelectionOptions<Value>[\"compare\"];\n children: (value: Value) => ReactNode;\n }) {\n return children(useGame(selector, { compare }));\n }\n\n function useCardDrag(\n cardId: IdOf<Game, \"cardId\">,\n options?: TargetOptions<Game>,\n ) {\n const game = useGame();\n return useCardDraggable(\n game as unknown as DragGame,\n cardId,\n options as TargetOptions<unknown> | undefined,\n );\n }\n function useBoardDrop(\n target: DropTarget<Game> | null,\n options?: BoardDropOptions,\n ) {\n return useBoardDroppable(target as DropTarget<unknown> | null, options);\n }\n return { GameProvider, useGame, Subscribe, useCardDrag, useBoardDrop };\n };\n}\n"],"mappings":";;;;;;;AAAA,SAAS,OAAO,uBAAuC;AACvD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AAyEhC,SAiBE,KAjBF;AA5DJ,IAAM,UAAU;AAAA,EACd,cAAc,UAAU;AAAA,IACtB,uBAAuB;AAAA,MACrB,IAAI,6BAA6B,SAAS,EAAE,OAAO,EAAE,CAAC;AAAA,IACxD;AAAA,EACF,CAAC;AAAA,EACD;AACF;AAEA,IAAM,UAAU,cAAc,QAAQ;AAAA,E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A,aAAO,WAAW,WAAW;AAAA,IAC/B;AAEA,aAAS,UAAiB;AAAA,MACxB;AAAA,MACA;AAAA,MACA;AAAA,IACF,GAIG;AACD,aAAO,SAAS,QAAQ,UAAU,EAAE,QAAQ,CAAC,CAAC;AAAA,IAChD;AAEA,aAAS,YACP,QACA,SACA;AACA,YAAM,OAAO,QAAQ;AACrB,aAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AACA,aAAS,aACP,QACA,SACA;AACA,aAAO,kBAAkB,QAAsC,OAAO;AAAA,IACxE;AACA,WAAO,EAAE,cAAc,SAAS,WAAW,aAAa,aAAa;AAAA,EACvE;AACF;","names":["useLayoutEffect","jsx","useLayoutEffect"]}
|
package/dist/reducer.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { F as FrameworkErrorCodes, G as GameEvent,
|
|
1
|
+
import { a1 as ManifestIdSchema, aL as SchemaLike, j as CollectorState, x as InputCollector, ad as PlayerIdOfState, aV as TableQueriesOfState, h as ChoiceListDomainDescriptor, K as InputSelectionDescriptor, ao as ReducerManifestContractLike, aI as RuntimeTableRecord, aG as RuntimeRecord$1, aR as StateDefinition, a0 as ManifestContractOf, B as BaseGameStateOfContract, E as ErrorCodeOfContract, aW as TiledBoardIdOfTable, aT as TableOfManifest, aZ as TiledVertexIdOfTable, aX as TiledEdgeIdOfTable, aY as TiledSpaceIdOfTable, c as BoardIdOfTable, aP as SpaceIdOfTable, d as BoardStateOfTable, D as DeckIdOfTable, H as HandIdOfTable, C as CardIdOfManifest, a3 as OptionsOfContract, as as ReducerTransaction, b0 as ViewData, b1 as ViewDefinition, a9 as PhaseMapOf, b2 as ViewOfContract, am as ReducerGameDefinitionInput, al as ReducerGameDefinition, aa as PhaseNameOfContract, _ as InteractionSteps, aM as ScopedPhaseState, Y as InteractionSpec, X as InteractionRule, W as InteractionMap, a8 as PhaseDefinition, ac as PhaseSchemasOfContract, s as GameTopologyManifest$2, k as DieTypeSpec$2, g as Brand, an as ReducerManifestContract, aB as RuntimeHexBoardState, a2 as ObjectSchema, ag as PropertySchema, aE as RuntimePayload, t as HexEdgeId, v as HexVertexId, u as HexSpaceId, aH as RuntimeSquareBoardState, aA as RuntimeGenericBoardState, aw as RuntimeBoardState, ax as RuntimeCardData, aF as RuntimePieceData, az as RuntimeDieData, ay as RuntimeComponentLocation, aj as ReducerGameContract, aS as SystemActionEvent, aU as TableQueries, ak as ReducerGameContractLike, a as BoardContainerIdOfTable, b as BoardEdgeRef, f as BoardVertexRef, $ as JsonValue } from './extract-gVKcB8Og.js';
|
|
2
|
+
export { F as FrameworkErrorCodes, G as GameEvent, n as GameEventDetail, p as GameOutcome, a4 as OutcomeResult, a5 as OutcomeScoreComponent, a6 as OutcomeStanding, a7 as OutcomeTieBreak, ah as ReducerAccept, ap as ReducerReject, aq as ReducerResult, at as ReducerTransactionOutcome, au as ReducerValidationResult, b9 as ReducerWire, b8 as ReducerWireZod, av as RotatePlayerZoneArgs, aQ as SquareBoardSpec, a_ as ValidationIssue, b4 as fromCoordinates, b5 as hexagon, b6 as rectangle, b7 as ring, ba as spiral } from './extract-gVKcB8Og.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { P as PlayerBoardSpaceTarget } from './board-target-B0QG6OYx.js';
|
|
5
|
+
import { a as ReducerBundleContract, c as ReducerDiagnosticsSink } from './diagnostics-B8d5aLad.js';
|
|
6
|
+
export { D as DispatchTraceSummaryEntry, M as MaybePromise, R as REDUCER_CONTRACT_VERSION, b as ReducerDiagnosticEvent, d as assertReducerBundleContract, n as noopDiagnosticsSink } from './diagnostics-B8d5aLad.js';
|
|
6
7
|
import 'honeycomb-grid';
|
|
7
8
|
|
|
8
9
|
type DomainContext<State extends CollectorState> = {
|
|
@@ -88,12 +89,15 @@ declare function choiceInput<Value extends ChoiceValue, State extends CollectorS
|
|
|
88
89
|
choices: DomainChoices<Value, State>;
|
|
89
90
|
defaultValue: ChoiceDefaultResolver<Value, State>;
|
|
90
91
|
}): InputCollector<SchemaLike<Value>, State, "form">;
|
|
92
|
+
type ChoiceListCollector<Value extends string, State extends CollectorState> = InputCollector<SchemaLike<Value[]>, State, "form"> & {
|
|
93
|
+
readonly domain: (state: CollectorState, playerId: string, q: unknown) => ChoiceListDomainDescriptor;
|
|
94
|
+
};
|
|
91
95
|
declare function choiceListInput<Value extends string, State extends CollectorState = CollectorState>(options: {
|
|
92
96
|
choices: DomainChoices<Value, State>;
|
|
93
97
|
min?: DomainNumber<State>;
|
|
94
98
|
max?: DomainNumber<State>;
|
|
95
99
|
defaultValue: Value[];
|
|
96
|
-
}):
|
|
100
|
+
}): ChoiceListCollector<Value, State> & {
|
|
97
101
|
readonly defaultValue: Value[];
|
|
98
102
|
};
|
|
99
103
|
declare function choiceListInput<Value extends string, State extends CollectorState = CollectorState>(options: {
|
|
@@ -101,7 +105,7 @@ declare function choiceListInput<Value extends string, State extends CollectorSt
|
|
|
101
105
|
min?: DomainNumber<State>;
|
|
102
106
|
max?: DomainNumber<State>;
|
|
103
107
|
defaultValue?: ChoiceListDefaultValue<Value, State>;
|
|
104
|
-
}):
|
|
108
|
+
}): ChoiceListCollector<Value, State>;
|
|
105
109
|
type FormInputForState<State extends CollectorState> = {
|
|
106
110
|
<Schema extends ManifestFormInputSchema & SchemaLike<unknown>>(schema: Schema): InputCollector<Schema, State, "form">;
|
|
107
111
|
<Schema extends ManifestFormInputSchema & SchemaLike<unknown>>(schema: Schema, options: {
|
|
@@ -134,7 +138,7 @@ type FormInputForState<State extends CollectorState> = {
|
|
|
134
138
|
min?: DomainNumber<State>;
|
|
135
139
|
max?: DomainNumber<State>;
|
|
136
140
|
defaultValue: Value[];
|
|
137
|
-
}):
|
|
141
|
+
}): ChoiceListCollector<Value, State> & {
|
|
138
142
|
readonly defaultValue: Value[];
|
|
139
143
|
};
|
|
140
144
|
choiceList<Value extends string>(options: {
|
|
@@ -142,7 +146,7 @@ type FormInputForState<State extends CollectorState> = {
|
|
|
142
146
|
min?: DomainNumber<State>;
|
|
143
147
|
max?: DomainNumber<State>;
|
|
144
148
|
defaultValue?: ChoiceListDefaultValue<Value, State>;
|
|
145
|
-
}):
|
|
149
|
+
}): ChoiceListCollector<Value, State>;
|
|
146
150
|
};
|
|
147
151
|
declare function formInputForState<State extends CollectorState>(): FormInputForState<State>;
|
|
148
152
|
/**
|
|
@@ -179,11 +183,6 @@ type TargetPredicate<State extends CollectorState, Target> = {
|
|
|
179
183
|
};
|
|
180
184
|
|
|
181
185
|
type BoardTargetPredicate<State extends CollectorState, Target> = TargetPredicate<State, Target>;
|
|
182
|
-
type PlayerBoardSpaceTarget<BoardId extends string, SpaceId extends string, PlayerId extends string> = {
|
|
183
|
-
readonly boardId: BoardId;
|
|
184
|
-
readonly playerId: PlayerId;
|
|
185
|
-
readonly spaceId: SpaceId;
|
|
186
|
-
};
|
|
187
186
|
|
|
188
187
|
type PlayerSpaceInputSchema<BoardId extends string, SpaceId extends string, PlayerId extends string> = z.ZodObject<{
|
|
189
188
|
boardId: z.ZodLiteral<BoardId>;
|
|
@@ -279,20 +278,27 @@ type BoundManifest<Contract extends ContractWithPhases> = ContractManifest<Contr
|
|
|
279
278
|
type BoundTable<Contract extends ContractWithPhases> = TableOfManifest<BoundManifest<Contract>>;
|
|
280
279
|
type BoundPhaseState<Contract extends ContractWithPhases, PhaseStateSchema extends SchemaLike<object>> = ScopedPhaseState<BoundState<Contract>, z.infer<PhaseStateSchema>>;
|
|
281
280
|
type BoundFormInputs<Contract extends ContractWithPhases> = ReturnType<typeof formInput.forState<BoundState<Contract>>>;
|
|
282
|
-
/**
|
|
283
|
-
type BoundBoardInputOptions<Contract extends ContractWithPhases, Id> = {
|
|
284
|
-
boardId:
|
|
281
|
+
/** The selected board owns the element namespace, including generic spaces. */
|
|
282
|
+
type BoundBoardInputOptions<Contract extends ContractWithPhases, BoardId, Id> = {
|
|
283
|
+
boardId: BoardId;
|
|
285
284
|
where?: BoundWhere<Contract, Id>;
|
|
286
285
|
};
|
|
286
|
+
type PlayerBoardBaseId<Table> = {
|
|
287
|
+
[B in BoardIdOfTable<Table>]: BoardStateOfTable<Table, B> extends {
|
|
288
|
+
scope: "perPlayer";
|
|
289
|
+
baseId: infer Base extends string;
|
|
290
|
+
} ? Base : never;
|
|
291
|
+
}[BoardIdOfTable<Table>];
|
|
292
|
+
type PlayerBoardRuntimeId<Table, Base extends string> = Extract<BoardIdOfTable<Table>, `${Base}:${string}`>;
|
|
287
293
|
type BoundBoardInputs<Contract extends ContractWithPhases> = {
|
|
288
|
-
vertex<
|
|
289
|
-
edge<
|
|
290
|
-
tile<
|
|
291
|
-
space<
|
|
292
|
-
playerSpace<
|
|
293
|
-
boardId:
|
|
294
|
-
where?: BoundWhere<Contract, PlayerBoardSpaceTarget<
|
|
295
|
-
}): InputCollector<PlayerSpaceInputSchema<
|
|
294
|
+
vertex<B extends TiledBoardIdOfTable<BoundTable<Contract>>>(options: BoundBoardInputOptions<Contract, B, TiledVertexIdOfTable<BoundTable<Contract>, NoInfer<B>>>): InputCollector<z.ZodType<TiledVertexIdOfTable<BoundTable<Contract>, B>>, BoundState<Contract>, "board-vertex">;
|
|
295
|
+
edge<B extends TiledBoardIdOfTable<BoundTable<Contract>>>(options: BoundBoardInputOptions<Contract, B, TiledEdgeIdOfTable<BoundTable<Contract>, NoInfer<B>>>): InputCollector<z.ZodType<TiledEdgeIdOfTable<BoundTable<Contract>, B>>, BoundState<Contract>, "board-edge">;
|
|
296
|
+
tile<B extends TiledBoardIdOfTable<BoundTable<Contract>>>(options: BoundBoardInputOptions<Contract, B, TiledSpaceIdOfTable<BoundTable<Contract>, NoInfer<B>>>): InputCollector<z.ZodType<TiledSpaceIdOfTable<BoundTable<Contract>, B>>, BoundState<Contract>, "board-tile">;
|
|
297
|
+
space<B extends BoardIdOfTable<BoundTable<Contract>>>(options: BoundBoardInputOptions<Contract, B, SpaceIdOfTable<BoundTable<Contract>, NoInfer<B>>>): InputCollector<z.ZodType<SpaceIdOfTable<BoundTable<Contract>, B>>, BoundState<Contract>, "board-space">;
|
|
298
|
+
playerSpace<B extends PlayerBoardBaseId<BoundTable<Contract>>>(options: {
|
|
299
|
+
boardId: B;
|
|
300
|
+
where?: BoundWhere<Contract, PlayerBoardSpaceTarget<NoInfer<B>, SpaceIdOfTable<BoundTable<Contract>, PlayerBoardRuntimeId<BoundTable<Contract>, NoInfer<B>>>, PlayerIdOfState<BoundState<Contract>>>>;
|
|
301
|
+
}): InputCollector<PlayerSpaceInputSchema<B, SpaceIdOfTable<BoundTable<Contract>, PlayerBoardRuntimeId<BoundTable<Contract>, B>>, PlayerIdOfState<BoundState<Contract>>>, BoundState<Contract>, "board-space">;
|
|
296
302
|
};
|
|
297
303
|
/**
|
|
298
304
|
* An eligibility predicate whose `errorCode` is checked against the model's
|
|
@@ -313,10 +319,10 @@ type BoundCardCollector<Contract extends ContractWithPhases, Id extends string,
|
|
|
313
319
|
* Card collector: the zones to draw candidates from and the predicates that
|
|
314
320
|
* filter them. The target rule is built internally.
|
|
315
321
|
*/
|
|
316
|
-
type BoundCardInput<Contract extends ContractWithPhases> = <
|
|
322
|
+
type BoundCardInput<Contract extends ContractWithPhases> = <const ZoneIds extends readonly (DeckIdOfTable<BoundTable<Contract>> | HandIdOfTable<BoundTable<Contract>>)[]>(options: {
|
|
317
323
|
from: ZoneIds;
|
|
318
|
-
where?: BoundWhere<Contract,
|
|
319
|
-
}) => BoundCardCollector<Contract,
|
|
324
|
+
where?: BoundWhere<Contract, CardIdOfManifest<BoundManifest<Contract>>>;
|
|
325
|
+
}) => BoundCardCollector<Contract, CardIdOfManifest<BoundManifest<Contract>>, ZoneIds>;
|
|
320
326
|
type BoundRngInputs<Contract extends ContractWithPhases> = {
|
|
321
327
|
d6(count?: number): ReturnType<typeof rngInput.d6<BoundState<Contract>>>;
|
|
322
328
|
coin(): ReturnType<typeof rngInput.coin<BoundState<Contract>>>;
|
|
@@ -373,26 +379,40 @@ type ContractTypes<Contract extends ContractWithPhases> = {
|
|
|
373
379
|
readonly Queries: TableQueriesOfState<BoundState<Contract>>;
|
|
374
380
|
readonly Tx: ReducerTransaction<BoundState<Contract>, ContractErrorCode<Contract>>;
|
|
375
381
|
};
|
|
376
|
-
/**
|
|
377
|
-
* Rejects phase keys the model did not declare. `PhaseMapOf<Contract>` already
|
|
378
|
-
* requires every declared phase; this closes the other direction so an extra
|
|
379
|
-
* key fails at `assemble` instead of at runtime.
|
|
380
|
-
*/
|
|
381
|
-
type NoUndeclaredPhases<Contract, Definitions> = {
|
|
382
|
-
[Name in Exclude<keyof Definitions, PhaseNameOfContract<Contract>>]: `Phase '${Name & string}' is not declared in model.phases`;
|
|
383
|
-
};
|
|
384
382
|
type GameAuthoring<Contract extends ContractWithPhases> = {
|
|
385
383
|
readonly contract: Contract;
|
|
386
384
|
view<Projection extends ViewData>(view: ViewDefinition<BoundState<Contract>, BoundManifest<Contract>, Projection>): ViewDefinition<BoundState<Contract>, BoundManifest<Contract>, Projection>;
|
|
387
385
|
/** Compile-time only. Reading any member at runtime throws. */
|
|
388
386
|
readonly types: ContractTypes<Contract>;
|
|
389
387
|
/** Assemble the final game definition from phases and the seat view. */
|
|
390
|
-
assemble<Definitions extends PhaseMapOf<Contract>, View extends ViewOfContract<Contract>>(definition:
|
|
391
|
-
phases: NoUndeclaredPhases<Contract, Definitions>;
|
|
392
|
-
}): ReducerGameDefinition<Contract, Definitions, View>;
|
|
388
|
+
assemble<Definitions extends PhaseMapOf<Contract>, View extends ViewOfContract<Contract>>(definition: ReducerGameDefinitionInput<Contract, Definitions, View>): ReducerGameDefinition<Contract, Definitions, View>;
|
|
393
389
|
phase<Name extends PhaseNameOfContract<Contract>>(name: Name): PhaseAuthoring<Contract, PhaseSchemasOfContract<Contract>[Name]>;
|
|
394
390
|
};
|
|
395
391
|
|
|
392
|
+
/** Literal counts can be checked statically; dynamic numbers are checked at runtime. */
|
|
393
|
+
type ValidCount<N> = N extends number ? number extends N ? N : `${N}` extends `${bigint}` ? `${N}` extends `-${string}` | "0" ? never : N : never : N;
|
|
394
|
+
type ValidateCounts<Entries> = Entries extends readonly unknown[] ? {
|
|
395
|
+
[K in keyof Entries]: Entries[K] extends {
|
|
396
|
+
count: infer N;
|
|
397
|
+
} ? Entries[K] & {
|
|
398
|
+
count: ValidCount<N>;
|
|
399
|
+
} : Entries[K];
|
|
400
|
+
} : Entries;
|
|
401
|
+
type ManifestCountValidation<M> = {
|
|
402
|
+
[K in keyof M]: K extends "pieceSeeds" | "dieSeeds" ? ValidateCounts<M[K]> : K extends "cardSets" ? {
|
|
403
|
+
[I in keyof M[K]]: M[K][I] extends {
|
|
404
|
+
cards: infer Cards;
|
|
405
|
+
} ? M[K][I] & {
|
|
406
|
+
cards: ValidateCounts<Cards>;
|
|
407
|
+
} : M[K][I];
|
|
408
|
+
} : M[K];
|
|
409
|
+
};
|
|
410
|
+
type NumberRange<N extends number, A extends number[] = []> = number extends N ? number : A["length"] extends 64 ? number : A["length"] extends N ? A[number] | N : NumberRange<N, [...A, A["length"]]>;
|
|
411
|
+
/** Validated counts use the base id for one copy; omitted seed counts default to one. */
|
|
412
|
+
type RuntimeIdsFromCount<Base extends string, Count> = [Count] extends [
|
|
413
|
+
never
|
|
414
|
+
] ? Base : Count extends number ? number extends Count ? Base | `${Base}-${number}` : ValidCount<Count> extends never ? never : Count extends 1 ? Base : `${Base}-${Exclude<NumberRange<Count>, 0>}` : Base;
|
|
415
|
+
|
|
396
416
|
type DieTypeSpec$1 = Omit<DieTypeSpec$2, "sides"> & {
|
|
397
417
|
sides?: DieTypeSpec$2["sides"];
|
|
398
418
|
};
|
|
@@ -486,6 +506,12 @@ declare function isPerPlayerBoardRef<BaseId extends string, Id extends PlayerId$
|
|
|
486
506
|
type ReadonlyValue<T> = T extends readonly (infer V)[] ? readonly ReadonlyValue<V>[] : T extends object ? {
|
|
487
507
|
readonly [K in keyof T]: ReadonlyValue<T[K]>;
|
|
488
508
|
} : T;
|
|
509
|
+
declare const validatedManifest: unique symbol;
|
|
510
|
+
/** Authored topology that passed the SDK's semantic validation. */
|
|
511
|
+
type ValidatedManifest<M extends AuthoredManifest = AuthoredManifest> = ReadonlyValue<M> & {
|
|
512
|
+
readonly [validatedManifest]: true;
|
|
513
|
+
};
|
|
514
|
+
declare const compiledManifest: unique symbol;
|
|
489
515
|
type AuthoredManifest = ReadonlyValue<GameTopologyManifest$1>;
|
|
490
516
|
type Entry<T> = T extends readonly (infer V)[] ? V : never;
|
|
491
517
|
type Get<T, K extends PropertyKey> = T extends unknown ? K extends keyof T ? T[K] : never : never;
|
|
@@ -493,40 +519,15 @@ type Entries<M, K extends PropertyKey> = Entry<Get<M, K>>;
|
|
|
493
519
|
type Id<T> = T extends {
|
|
494
520
|
id: infer I extends string;
|
|
495
521
|
} ? I : never;
|
|
496
|
-
type NumberRange<N extends number, A extends number[] = []> = number extends N ? number : A["length"] extends 64 ? number : A["length"] extends N ? A[number] | N : NumberRange<N, [...A, A["length"]]>;
|
|
497
|
-
type InstanceIds<Base extends string, Count> = [Count] extends [never] ? Base : Count extends number ? number extends Count ? Base | `${Base}-${number}` : Count extends 0 | 1 ? Base : `${Base}-${Exclude<NumberRange<Count>, 0>}` : Base;
|
|
498
522
|
type SeedIds<S> = S extends {
|
|
499
523
|
typeId: infer T extends string;
|
|
500
|
-
} ?
|
|
524
|
+
} ? RuntimeIdsFromCount<S extends {
|
|
501
525
|
id: infer I extends string;
|
|
502
526
|
} ? I : T, Get<S, "count">> : never;
|
|
503
527
|
type CardIds<C> = C extends {
|
|
504
|
-
|
|
505
|
-
} ?
|
|
506
|
-
type
|
|
507
|
-
type StandardRank = "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "J" | "Q" | "K" | "A";
|
|
508
|
-
type ResolvedCardSet<S> = S extends {
|
|
509
|
-
type: "preset";
|
|
510
|
-
presetId: "standard_52_deck";
|
|
511
|
-
} ? Omit<S, "type"> & {
|
|
512
|
-
type: "manual";
|
|
513
|
-
cards: readonly {
|
|
514
|
-
type: `${StandardSuit}_${StandardRank}`;
|
|
515
|
-
count: 1;
|
|
516
|
-
}[];
|
|
517
|
-
cardSchema: {
|
|
518
|
-
properties: {
|
|
519
|
-
suit: {
|
|
520
|
-
type: "enum";
|
|
521
|
-
enums: readonly StandardSuit[];
|
|
522
|
-
};
|
|
523
|
-
rank: {
|
|
524
|
-
type: "string";
|
|
525
|
-
};
|
|
526
|
-
};
|
|
527
|
-
};
|
|
528
|
-
} : S;
|
|
529
|
-
type CardSets<M> = ResolvedCardSet<Entries<M, "cardSets">>;
|
|
528
|
+
id: infer I extends string;
|
|
529
|
+
} ? RuntimeIdsFromCount<I, Get<C, "count">> : never;
|
|
530
|
+
type CardSets<M> = Entries<M, "cardSets">;
|
|
530
531
|
type Cards<M> = CardSets<M> extends infer S ? S extends {
|
|
531
532
|
cards: infer C;
|
|
532
533
|
} ? Entry<C> : never : never;
|
|
@@ -541,7 +542,7 @@ type RuntimeBoardId<B> = B extends {
|
|
|
541
542
|
} ? `${I}:${string}` : I : never;
|
|
542
543
|
type CardTypeOf<C> = C extends {
|
|
543
544
|
cardType: infer T extends string;
|
|
544
|
-
} ? T :
|
|
545
|
+
} ? T : never;
|
|
545
546
|
type ManifestIdsOf<M> = {
|
|
546
547
|
playerId: PlayerId$1;
|
|
547
548
|
phaseName: string;
|
|
@@ -600,18 +601,50 @@ type ObjectProperties<P, M> = {
|
|
|
600
601
|
type ObjectFields<S, M> = [S] extends [never] ? RuntimeRecord$1 : ObjectSchema extends S ? RuntimeRecord$1 : S extends {
|
|
601
602
|
properties: infer P;
|
|
602
603
|
} ? ObjectProperties<P, M> : RuntimeRecord$1;
|
|
603
|
-
type CardFields<S, M> = S extends {
|
|
604
|
-
variants: infer
|
|
605
|
-
} ?
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
cardType:
|
|
613
|
-
|
|
614
|
-
}
|
|
604
|
+
type CardFields<S, Category extends string, M> = S extends {
|
|
605
|
+
variants: infer Variants;
|
|
606
|
+
} ? Category extends keyof Variants ? ObjectFields<{
|
|
607
|
+
properties: Omit<S extends {
|
|
608
|
+
shared: infer Shared;
|
|
609
|
+
} ? Shared : Record<never, never>, keyof Get<Variants[Category], "properties">> & Get<Variants[Category], "properties">;
|
|
610
|
+
}, M> : never : ObjectFields<S, M>;
|
|
611
|
+
type CardStateFor<M, Set, Card> = Card extends {
|
|
612
|
+
id: infer BaseId extends string;
|
|
613
|
+
cardType: infer Category extends string;
|
|
614
|
+
count: infer Count extends number;
|
|
615
|
+
} ? RuntimeIdsFromCount<BaseId, Count> extends infer RuntimeId ? RuntimeId extends string ? Omit<RuntimeCardData, "id" | "cardSetId" | "cardType" | "properties"> & {
|
|
616
|
+
id: RuntimeId;
|
|
617
|
+
cardSetId: Id<Set>;
|
|
618
|
+
cardType: Category;
|
|
619
|
+
properties: CardFields<Get<Set, "cardSchema">, Category, M>;
|
|
620
|
+
} : never : never : never;
|
|
621
|
+
type CardState<M> = CardSets<M> extends infer Set ? Set extends {
|
|
622
|
+
cards: infer Cards;
|
|
623
|
+
} ? Entry<Cards> extends infer Card ? Card extends unknown ? CardStateFor<M, Set, Card> : never : never : never : never;
|
|
624
|
+
type InferredCards<M> = {
|
|
625
|
+
[Card in CardState<M> as Card["id"]]: Card;
|
|
626
|
+
};
|
|
627
|
+
type SeedState<M, Seed, Definition, Data, TypeKey extends string> = Seed extends {
|
|
628
|
+
typeId: infer TypeId extends string;
|
|
629
|
+
} ? SeedIds<Seed> extends infer RuntimeId ? RuntimeId extends string ? Omit<Data, "id" | TypeKey | "properties"> & {
|
|
630
|
+
id: RuntimeId;
|
|
631
|
+
properties: ObjectFields<Get<Extract<Definition, {
|
|
632
|
+
id: TypeId;
|
|
633
|
+
}>, "fieldsSchema">, M>;
|
|
634
|
+
} & Record<TypeKey, TypeId> : never : never : never;
|
|
635
|
+
type PieceState<M> = SeedState<M, Entries<M, "pieceSeeds">, Entries<M, "pieceTypes">, RuntimePieceData, "pieceTypeId">;
|
|
636
|
+
type DieState<M> = SeedState<M, Entries<M, "dieSeeds">, Entries<M, "dieTypes">, RuntimeDieData, "dieTypeId">;
|
|
637
|
+
type EntityAtId<Entity, Id extends string> = Entity extends {
|
|
638
|
+
id: infer Key;
|
|
639
|
+
} ? Id extends Key ? Entity & {
|
|
640
|
+
id: Id;
|
|
641
|
+
} : Key extends Id ? Entity : never : never;
|
|
642
|
+
type InferredPieces<M> = {
|
|
643
|
+
[Id in SeedIds<Entries<M, "pieceSeeds">>]: EntityAtId<PieceState<M>, Id>;
|
|
644
|
+
};
|
|
645
|
+
type InferredDice<M> = {
|
|
646
|
+
[Id in SeedIds<Entries<M, "dieSeeds">>]: EntityAtId<DieState<M>, Id>;
|
|
647
|
+
};
|
|
615
648
|
type BoardField<B, K extends PropertyKey, M> = ObjectFields<Get<B, K>, M>;
|
|
616
649
|
type BoardSpaceEntry<B> = B extends {
|
|
617
650
|
layout: "hex";
|
|
@@ -623,29 +656,34 @@ type BoardSpaceId<B> = B extends {
|
|
|
623
656
|
type BoardParts<M, B> = {
|
|
624
657
|
id: RuntimeBoardId<B>;
|
|
625
658
|
baseId: Id<B>;
|
|
659
|
+
scope: B extends {
|
|
660
|
+
scope: infer Scope;
|
|
661
|
+
} ? Scope : never;
|
|
626
662
|
fields: BoardField<B, "boardFieldsSchema", M>;
|
|
627
663
|
relations: (Omit<RuntimeHexBoardState["relations"][number], "typeId"> & {
|
|
628
664
|
typeId: Extract<Get<Entry<Get<B, "relations">>, "typeId">, string> | (B extends {
|
|
629
665
|
layout: "hex" | "square";
|
|
630
666
|
} ? "adjacent" : never);
|
|
631
667
|
})[];
|
|
632
|
-
spaces:
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
668
|
+
spaces: {
|
|
669
|
+
[SpaceId in BoardSpaceId<B>]: (B extends {
|
|
670
|
+
layout: "hex";
|
|
671
|
+
} ? {
|
|
672
|
+
q: number;
|
|
673
|
+
r: number;
|
|
674
|
+
} : B extends {
|
|
675
|
+
layout: "square";
|
|
676
|
+
} ? {
|
|
677
|
+
row: number;
|
|
678
|
+
col: number;
|
|
679
|
+
} : unknown) & {
|
|
680
|
+
id: SpaceId;
|
|
681
|
+
name?: string | null;
|
|
682
|
+
typeId?: Extract<Get<BoardSpaceEntry<B>, "typeId">, string> | null;
|
|
683
|
+
fields: BoardField<B, "spaceFieldsSchema", M>;
|
|
684
|
+
zoneId?: string | null;
|
|
685
|
+
};
|
|
686
|
+
};
|
|
649
687
|
};
|
|
650
688
|
type BoardState<M, B> = B extends {
|
|
651
689
|
layout: "hex";
|
|
@@ -679,17 +717,35 @@ type InferredBoards<M> = {
|
|
|
679
717
|
network: Record<string, RuntimeRecord$1>;
|
|
680
718
|
track: Record<string, RuntimeRecord$1>;
|
|
681
719
|
};
|
|
682
|
-
type
|
|
720
|
+
type SeedSlotLocation<Seed, Definition, Kind extends "piece" | "die"> = Seed extends {
|
|
721
|
+
typeId: infer TypeId extends string;
|
|
722
|
+
} ? Id<Entries<Extract<Definition, {
|
|
723
|
+
id: TypeId;
|
|
724
|
+
}>, "slots">> extends infer SlotId extends string ? [SlotId] extends [never] ? never : {
|
|
725
|
+
type: "InSlot";
|
|
726
|
+
host: {
|
|
727
|
+
kind: Kind;
|
|
728
|
+
id: SeedIds<Seed>;
|
|
729
|
+
};
|
|
730
|
+
slotId: SlotId;
|
|
731
|
+
position?: number | null;
|
|
732
|
+
} : never : never;
|
|
733
|
+
type ManifestComponentLocation<M> = Exclude<RuntimeComponentLocation, {
|
|
734
|
+
type: "InSlot";
|
|
735
|
+
}> | SeedSlotLocation<Entries<M, "pieceSeeds">, Entries<M, "pieceTypes">, "piece"> | SeedSlotLocation<Entries<M, "dieSeeds">, Entries<M, "dieTypes">, "die">;
|
|
736
|
+
type ManifestTable<M> = AuthoredManifest extends M ? RuntimeTableRecord : Omit<RuntimeTableRecord, "playerOrder" | "decks" | "hands" | "cards" | "pieces" | "dice" | "boards" | "resources" | "componentLocations"> & {
|
|
683
737
|
boards: InferredBoards<M>;
|
|
684
738
|
playerOrder: PlayerId$1[];
|
|
685
739
|
decks: Record<ManifestIdsOf<M>["deckId"], ManifestIdsOf<M>["cardId"][]>;
|
|
686
740
|
hands: Record<ManifestIdsOf<M>["handId"], Record<PlayerId$1, ManifestIdsOf<M>["cardId"][]>>;
|
|
687
|
-
cards:
|
|
688
|
-
pieces:
|
|
689
|
-
dice:
|
|
741
|
+
cards: InferredCards<M>;
|
|
742
|
+
pieces: InferredPieces<M>;
|
|
743
|
+
dice: InferredDice<M>;
|
|
744
|
+
componentLocations: Record<ManifestIdsOf<M>["cardId" | "pieceId" | "dieId"], ManifestComponentLocation<M>>;
|
|
690
745
|
resources: Record<PlayerId$1, Record<ManifestIdsOf<M>["resourceId"], number>>;
|
|
691
746
|
};
|
|
692
747
|
type CompiledManifest<M extends AuthoredManifest> = Omit<ReducerManifestContract<ManifestTable<M>, string, PlayerId$1, ManifestIdsOf<M>["deckId"], ManifestIdsOf<M>["handId"], ManifestIdsOf<M>["cardId"]>, "ids" | "literals" | "records" | "staticBoards"> & {
|
|
748
|
+
readonly [compiledManifest]: true;
|
|
693
749
|
staticBoards: Pick<InferredBoards<M>, "byId" | "hex" | "square">;
|
|
694
750
|
literals: Omit<ReducerManifestContract<RuntimeTableRecord, string, string, string, string, string>["literals"], `${keyof ManifestIdsOf<M>}s`> & {
|
|
695
751
|
[K in keyof ManifestIdsOf<M> as `${K}s`]: readonly ManifestIdsOf<M>[K][];
|
|
@@ -761,7 +817,7 @@ type DefinedGameContract<Table extends RuntimeTableRecord, Manifest extends Redu
|
|
|
761
817
|
* parameter types are needed.
|
|
762
818
|
*/
|
|
763
819
|
declare function createGame<const Manifest extends AuthoredManifest, PublicSchema extends SchemaLike<object>, PrivateSchema extends SchemaLike<object>, HiddenSchema extends SchemaLike<object>, const Phases extends Record<string, SchemaLike<object>>, const Errors extends Record<string, string> | undefined = undefined, OptionsSchema extends SchemaLike<RuntimeRecord$1> = SchemaLike<Record<string, never>>>(model: {
|
|
764
|
-
manifest: Manifest
|
|
820
|
+
manifest: Manifest & ManifestCountValidation<NoInfer<Manifest>>;
|
|
765
821
|
state: {
|
|
766
822
|
public: PublicSchema;
|
|
767
823
|
private: PrivateSchema;
|
|
@@ -805,7 +861,7 @@ declare function memoize<A extends object, R>(fn: (a: A) => R): (a: A) => R;
|
|
|
805
861
|
declare function assertCardAllowedInContainer<Table extends RuntimeTableRecord, BoardId extends BoardIdOfTable<NoInfer<Table>>, ContainerId extends BoardContainerIdOfTable<NoInfer<Table>, BoardId>>(table: Table, boardId: BoardId, containerId: ContainerId, componentId: string): void;
|
|
806
862
|
|
|
807
863
|
/** Compile authored topology once, in memory, with the same validation used by initialization. */
|
|
808
|
-
declare function compileManifest<const M extends AuthoredManifest>(manifest: M): CompiledManifest<M>;
|
|
864
|
+
declare function compileManifest<const M extends AuthoredManifest>(manifest: M & ManifestCountValidation<NoInfer<M>>): CompiledManifest<M>;
|
|
809
865
|
|
|
810
866
|
declare function materializeManifestTable(options: {
|
|
811
867
|
manifest: GameTopologyManifest$1;
|
|
@@ -844,10 +900,8 @@ type PieceTypeId<Manifest extends GameTopologyManifest> = IdsOf<Manifest["pieceT
|
|
|
844
900
|
type DieTypeId<Manifest extends GameTopologyManifest> = IdsOf<Manifest["dieTypes"]>;
|
|
845
901
|
type PieceSeedOf<Manifest extends GameTopologyManifest> = ArrayItem<NonNullable<Manifest["pieceSeeds"]>>;
|
|
846
902
|
type DieSeedOf<Manifest extends GameTopologyManifest> = ArrayItem<NonNullable<Manifest["dieSeeds"]>>;
|
|
847
|
-
type
|
|
848
|
-
|
|
849
|
-
}>;
|
|
850
|
-
type CardOf<Manifest extends GameTopologyManifest> = ManualCardSetOf<Manifest> extends infer CardSet ? CardSet extends {
|
|
903
|
+
type CardSetOf<Manifest extends GameTopologyManifest> = ArrayItem<NonNullable<Manifest["cardSets"]>>;
|
|
904
|
+
type CardOf<Manifest extends GameTopologyManifest> = CardSetOf<Manifest> extends infer CardSet ? CardSet extends {
|
|
851
905
|
cards: infer Cards extends readonly unknown[];
|
|
852
906
|
} ? ArrayItem<Cards> : never : never;
|
|
853
907
|
type BoardOf<Manifest extends GameTopologyManifest, CurrentBoardId extends BoardId<Manifest>> = Extract<ArrayItem<NonNullable<Manifest["boards"]>>, {
|
|
@@ -870,10 +924,9 @@ type SquareSpaceOf<BoardLike> = Extract<SpaceOf<BoardLike>, {
|
|
|
870
924
|
}>;
|
|
871
925
|
type SpaceIdForBoard<Manifest extends GameTopologyManifest, CurrentBoardId extends BoardId<Manifest>> = SpaceIdOf<BoardOf<Manifest, CurrentBoardId>>;
|
|
872
926
|
type ContainerIdForBoard<Manifest extends GameTopologyManifest, CurrentBoardId extends BoardId<Manifest>> = ContainerIdOf<BoardOf<Manifest, CurrentBoardId>>;
|
|
873
|
-
type RuntimeIdsFromCount<BaseId extends string, Count> = Count extends number ? number extends Count ? BaseId | `${BaseId}-${number}` : Count extends 1 ? BaseId : `${BaseId}-${OneTo<Count>}` : BaseId;
|
|
874
927
|
type CardRuntimeId<Card> = Card extends {
|
|
875
|
-
|
|
876
|
-
} ? RuntimeIdsFromCount<
|
|
928
|
+
id: infer Id extends string;
|
|
929
|
+
} ? RuntimeIdsFromCount<Id, Card extends {
|
|
877
930
|
count: infer Count extends number;
|
|
878
931
|
} ? Count : never> : never;
|
|
879
932
|
type SeedRuntimeId<Seed> = Seed extends {
|
|
@@ -1204,11 +1257,10 @@ type TypedBoardLikeEntry<Entry, Manifest extends GameTopologyManifest> = Entry e
|
|
|
1204
1257
|
} ? TypedSquareBoardLike<Entry, Manifest, Entry> : Entry;
|
|
1205
1258
|
type AuthoredCardType<Card> = Card extends {
|
|
1206
1259
|
cardType: infer Category extends string;
|
|
1207
|
-
} ? Category :
|
|
1208
|
-
type: infer Type extends string;
|
|
1209
|
-
} ? Type : never;
|
|
1260
|
+
} ? Category : never;
|
|
1210
1261
|
type TypedCard<Card, Manifest extends GameTopologyManifest, CardSchema> = Card extends {
|
|
1211
|
-
|
|
1262
|
+
id: string;
|
|
1263
|
+
cardType: string;
|
|
1212
1264
|
} ? Omit<TypedVisibility<Card, Manifest>, "home" | "properties"> & {
|
|
1213
1265
|
home?: TypedComponentHomeSpec<Manifest>;
|
|
1214
1266
|
properties: CardSchema extends {
|
|
@@ -1217,7 +1269,6 @@ type TypedCard<Card, Manifest extends GameTopologyManifest, CardSchema> = Card e
|
|
|
1217
1269
|
} ? AuthoredCardType<Card> extends keyof Variants ? SchemaValueForObjectSchema<MergeSharedProperties<Variants[AuthoredCardType<Card>], Shared>, Manifest> : never : SchemaValueForObjectSchema<CardSchema, Manifest>;
|
|
1218
1270
|
} : Card;
|
|
1219
1271
|
type TypedCardSet<CardSet, Manifest extends GameTopologyManifest> = CardSet extends {
|
|
1220
|
-
type: "manual";
|
|
1221
1272
|
cardSchema: infer CardSchema;
|
|
1222
1273
|
cards: infer Cards extends readonly unknown[];
|
|
1223
1274
|
} ? Omit<CardSet, "cards" | "defaultHome"> & {
|
|
@@ -1256,7 +1307,7 @@ type TypedTopologyManifest<Manifest extends GameTopologyManifest> = Omit<Manifes
|
|
|
1256
1307
|
dieSeeds?: Manifest["dieSeeds"] extends readonly unknown[] ? ReadonlyArray<TypedDieSeed<ArrayItem<Manifest["dieSeeds"]>, Manifest>> : Manifest["dieSeeds"];
|
|
1257
1308
|
};
|
|
1258
1309
|
type TopologyManifestValidation<Manifest> = Manifest extends GameTopologyManifest ? TypedTopologyManifest<Manifest> : GameTopologyManifest;
|
|
1259
|
-
type DefinedTopologyManifest<Manifest> = Manifest extends GameTopologyManifest ? Manifest : GameTopologyManifest
|
|
1260
|
-
declare function defineTopologyManifest<const Manifest>(manifest: Manifest & TopologyManifestValidation<NoInfer<Manifest>>): DefinedTopologyManifest<Manifest>;
|
|
1310
|
+
type DefinedTopologyManifest<Manifest> = Manifest extends GameTopologyManifest ? ValidatedManifest<Manifest> : ValidatedManifest<GameTopologyManifest>;
|
|
1311
|
+
declare function defineTopologyManifest<const Manifest>(manifest: Manifest & TopologyManifestValidation<NoInfer<Manifest>> & ManifestCountValidation<NoInfer<Manifest>>): DefinedTopologyManifest<Manifest>;
|
|
1261
1312
|
|
|
1262
|
-
export { type AuthoredManifest, type BoardRef, type BoardTargetPredicate, type BoundInputBuilders, type BoundTargetPredicate, type CardTargetPredicate, type ChoiceOptionsFactory, type ChoiceTargetOption, type ChoiceTargetPredicate, type CompiledManifest, type ContractTypes, type GameAuthoring, type GameTopologyManifest$1 as GameTopologyManifest, InteractionRule, type ManifestIdsOf, type ManifestTable, type ManyOptions, type PerPlayerBoardRef, type PhaseAuthoring, type PhaseTypes,
|
|
1313
|
+
export { type AuthoredManifest, type BoardRef, type BoardTargetPredicate, type BoundInputBuilders, type BoundTargetPredicate, type CardTargetPredicate, type ChoiceOptionsFactory, type ChoiceTargetOption, type ChoiceTargetPredicate, type CompiledManifest, type ContractTypes, type GameAuthoring, type GameTopologyManifest$1 as GameTopologyManifest, InteractionRule, type ManifestIdsOf, type ManifestTable, type ManyOptions, type PerPlayerBoardRef, type PhaseAuthoring, type PhaseTypes, PlayerBoardSpaceTarget, type PlayerId$1 as PlayerId, type ReducerBundle, ReducerBundleContract, type ReducerBundleOptions, ReducerDiagnosticsSink, ReducerGameDefinition, ReducerGameDefinitionInput, ReducerTransaction, type SharedBoardRef, type SparseCounts, type SparseMap, SystemActionEvent, TableQueries, TableQueriesOfState, type TargetContext, type TargetPredicate, type TargetPredicateArgs, type TypedTopologyManifest, type ValidatedManifest, asPlayerId, assertCardAllowedInContainer, boardRef, boardRefKey, boardRefSchema, compileManifest, createGame, createReducerBundle, createStateQueries, createTableQueries, defineTopologyManifest, gameEvent, isPerPlayerBoardRef, isPlayerId, isSharedBoardRef, many, materializeManifestTable, memoize, normalizeCommandParams, parseBoardRefKey, perPlayerBoardRef, sharedBoardRef, sparseCounts, sparseMap };
|