@dreamboard-games/sdk 0.5.0-alpha.0 → 0.5.0-alpha.1

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.
Files changed (98) hide show
  1. package/README.md +122 -0
  2. package/dist/authoring/index.js +3 -3
  3. package/dist/authoring-compiler.js +4 -4
  4. package/dist/{authoring-materialize-cli.js → authoring-generate-cli.js} +6 -6
  5. package/dist/authoring-generate-cli.js.map +1 -0
  6. package/dist/{chunk-HUK4234C.js → chunk-2WJSQQT7.js} +3 -3
  7. package/dist/{chunk-VRRR6QZT.js → chunk-32PFKDV7.js} +170 -406
  8. package/dist/chunk-32PFKDV7.js.map +1 -0
  9. package/dist/{chunk-N33CGX2F.js → chunk-3BAD4VC2.js} +3 -3
  10. package/dist/{chunk-LMHCGCA6.js → chunk-3SKDNDPG.js} +2 -2
  11. package/dist/{chunk-6LMESVGT.js → chunk-4ZKTGZZK.js} +3 -3
  12. package/dist/{chunk-533O7C4L.js → chunk-7M3N5DFJ.js} +500 -430
  13. package/dist/chunk-7M3N5DFJ.js.map +1 -0
  14. package/dist/{chunk-FL67RDID.js → chunk-EHPEMPRZ.js} +128 -128
  15. package/dist/chunk-EHPEMPRZ.js.map +1 -0
  16. package/dist/chunk-EY2LL5WD.js +9 -0
  17. package/dist/{chunk-DQS2EG5E.js → chunk-GDPKTBUR.js} +2 -2
  18. package/dist/{chunk-HIH6Y4FA.js → chunk-JUGQ6F3N.js} +88 -352
  19. package/dist/{chunk-HIH6Y4FA.js.map → chunk-JUGQ6F3N.js.map} +1 -1
  20. package/dist/{chunk-VWTKGIYF.js → chunk-K2JGSRMD.js} +1 -1
  21. package/dist/{chunk-ZSTCUJKZ.js → chunk-M2S3QC32.js} +2 -2
  22. package/dist/{chunk-KRJPRYEA.js → chunk-MIKC4Y67.js} +5 -5
  23. package/dist/{chunk-KRJPRYEA.js.map → chunk-MIKC4Y67.js.map} +1 -1
  24. package/dist/chunk-MYKS6MTR.js +1347 -0
  25. package/dist/chunk-MYKS6MTR.js.map +1 -0
  26. package/dist/{chunk-KGV2EUNN.js → chunk-QLSK3DYO.js} +3 -3
  27. package/dist/{chunk-2GQIALJL.js → chunk-UGH54WZ2.js} +6 -2
  28. package/dist/chunk-UGH54WZ2.js.map +1 -0
  29. package/dist/chunk-VCDWP5VL.js +746 -0
  30. package/dist/chunk-VCDWP5VL.js.map +1 -0
  31. package/dist/{chunk-TXELBVTG.js → chunk-VZ7N6WAQ.js} +2 -2
  32. package/dist/{chunk-EOEA3I64.js → chunk-XRS4AZFK.js} +5 -5
  33. package/dist/codegen.d.ts +1 -3
  34. package/dist/codegen.js +1 -5
  35. package/dist/{components-CNAt5J1p.d.ts → components-CuBO6rev.d.ts} +2 -18
  36. package/dist/{definitions-bZSBaPjj.d.ts → definitions-1Hj-pQU8.d.ts} +2 -2
  37. package/dist/digest.d.ts +2 -2
  38. package/dist/game-g9dDFYyU.d.ts +546 -0
  39. package/dist/{index-CR69MyWr.d.ts → index-Bxbv3c9W.d.ts} +1 -1
  40. package/dist/{index.d-Bw8AOcgp.d.ts → index.d-DjzoK7zn.d.ts} +67 -2
  41. package/dist/index.js +2 -2
  42. package/dist/package-set.js +2 -2
  43. package/dist/plugin-runtime-contract.d.ts +4 -4
  44. package/dist/plugin-runtime-contract.js +13 -15
  45. package/dist/{protocol-CVaSqPgX.d.ts → protocol-dYgafTYY.d.ts} +1 -7
  46. package/dist/reducer/advanced.d.ts +6 -5
  47. package/dist/reducer/advanced.js +8 -4
  48. package/dist/reducer-contract.d.ts +1 -1
  49. package/dist/reducer-contract.js +2 -2
  50. package/dist/reducer.d.ts +9 -689
  51. package/dist/reducer.js +15 -1293
  52. package/dist/reducer.js.map +1 -1
  53. package/dist/runtime/primitives.d.ts +3 -4
  54. package/dist/runtime/primitives.js +5 -5
  55. package/dist/runtime/runtime-api.d.ts +1 -2
  56. package/dist/runtime/workspace-contract.d.ts +19 -15
  57. package/dist/runtime/workspace-contract.js +11 -10
  58. package/dist/{runtime-C7Z2acNU.d.ts → runtime-DksMTWtC.d.ts} +2 -2
  59. package/dist/{plugin-state-BRH3UiUp.d.ts → runtime-api-C9bDgp63.d.ts} +83 -4
  60. package/dist/runtime.d.ts +8 -8
  61. package/dist/runtime.js +14 -13
  62. package/dist/runtime.js.map +1 -1
  63. package/dist/schema.d.ts +2 -28
  64. package/dist/testing-compiler.d.ts +4 -4
  65. package/dist/testing-runtime.d.ts +7 -7
  66. package/dist/testing-runtime.js +6 -6
  67. package/dist/testing.d.ts +9 -9
  68. package/dist/testing.js +8 -8
  69. package/dist/{types-q1Guidm5.d.ts → types-DR7DoB1x.d.ts} +1 -1
  70. package/dist/{types-DN4O7kH_.d.ts → types-Dlh4GsNp.d.ts} +2 -2
  71. package/dist/ui/components.d.ts +3 -4
  72. package/dist/ui/components.js +1 -5
  73. package/dist/{ui-contract-BC4JpysE.d.ts → ui-contract-Mgx_k9gm.d.ts} +1 -2
  74. package/dist/ui.d.ts +4 -5
  75. package/dist/ui.js +2 -6
  76. package/dist/{views-D2Cfzr3h.d.ts → views-B4lD4fT0.d.ts} +100 -47
  77. package/package.json +4 -4
  78. package/dist/authoring-materialize-cli.js.map +0 -1
  79. package/dist/chunk-2GQIALJL.js.map +0 -1
  80. package/dist/chunk-533O7C4L.js.map +0 -1
  81. package/dist/chunk-FL67RDID.js.map +0 -1
  82. package/dist/chunk-KWHOFBDM.js +0 -9
  83. package/dist/chunk-VRRR6QZT.js.map +0 -1
  84. package/dist/chunk-XFMSLL3P.js +0 -637
  85. package/dist/chunk-XFMSLL3P.js.map +0 -1
  86. package/dist/runtime-api-CgPuEVeF.d.ts +0 -86
  87. /package/dist/{authoring-materialize-cli.d.ts → authoring-generate-cli.d.ts} +0 -0
  88. /package/dist/{chunk-HUK4234C.js.map → chunk-2WJSQQT7.js.map} +0 -0
  89. /package/dist/{chunk-N33CGX2F.js.map → chunk-3BAD4VC2.js.map} +0 -0
  90. /package/dist/{chunk-LMHCGCA6.js.map → chunk-3SKDNDPG.js.map} +0 -0
  91. /package/dist/{chunk-6LMESVGT.js.map → chunk-4ZKTGZZK.js.map} +0 -0
  92. /package/dist/{chunk-KWHOFBDM.js.map → chunk-EY2LL5WD.js.map} +0 -0
  93. /package/dist/{chunk-DQS2EG5E.js.map → chunk-GDPKTBUR.js.map} +0 -0
  94. /package/dist/{chunk-VWTKGIYF.js.map → chunk-K2JGSRMD.js.map} +0 -0
  95. /package/dist/{chunk-ZSTCUJKZ.js.map → chunk-M2S3QC32.js.map} +0 -0
  96. /package/dist/{chunk-KGV2EUNN.js.map → chunk-QLSK3DYO.js.map} +0 -0
  97. /package/dist/{chunk-TXELBVTG.js.map → chunk-VZ7N6WAQ.js.map} +0 -0
  98. /package/dist/{chunk-EOEA3I64.js.map → chunk-XRS4AZFK.js.map} +0 -0
package/README.md CHANGED
@@ -36,6 +36,128 @@ Include the packaged stylesheet when using SDK UI components:
36
36
  import "@dreamboard-games/sdk/ui/plugin-styles.css";
37
37
  ```
38
38
 
39
+ ## Game authoring
40
+
41
+ `createGame(model)` is the single authoring entry point. The **model** is a
42
+ plain object: manifest ids, state schemas, one Zod schema per phase, and error
43
+ codes. The returned value is three things at once:
44
+
45
+ - the **type leaf**: `typeof game.types.State`, `.ErrorCode`, `.PlayerId`,
46
+ `.Queries`, `.Tx` (phantom carriers; reading them at runtime throws),
47
+ - the **factory namespace**: `game.phase(name)`, `phase.define`,
48
+ `phase.interaction`, `phase.inputs.*`, `game.views.*`,
49
+ - the **assembler**: `game.assemble({ initial, initialPhase, phases, views })`.
50
+
51
+ Mutation callbacks (`enter`, `reduce`, `resolve`) receive an open transaction
52
+ `tx`. Mutate through it and finish with a bare `return` (accept), or with
53
+ `tx.transition(name)`, `tx.endGame(outcome)`, or `tx.reject(code)`. Events go
54
+ through `tx.emit(...)`. `state` is the read-only snapshot the callback started
55
+ from; `tx.state` is the current draft.
56
+
57
+ ```ts
58
+ // app/game-model.ts — the model, bound once
59
+ import { z } from "zod";
60
+ import { createGame } from "@dreamboard-games/sdk/reducer";
61
+ import { ids, manifestContract } from "../shared/manifest-contract";
62
+
63
+ export const game = createGame({
64
+ manifest: manifestContract,
65
+ state: {
66
+ public: z.object({ currentPlayerId: ids.playerId.nullable() }),
67
+ private: z.object({}),
68
+ hidden: z.object({}),
69
+ },
70
+ phases: {
71
+ setup: z.object({}),
72
+ play: z.object({ leadCardId: ids.cardId.nullable() }),
73
+ },
74
+ errors: { NOT_YOUR_CARD: "Play a card from your own hand." },
75
+ });
76
+
77
+ export type GameState = typeof game.types.State;
78
+ ```
79
+
80
+ ```ts
81
+ // app/phases/play.ts — one phase, one file
82
+ import { game } from "../game-model";
83
+
84
+ const play = game.phase("play");
85
+
86
+ // Inputs name their candidate domain and eligibility predicates directly.
87
+ // `where.errorCode` is checked against `model.errors`.
88
+ const ownCard = play.inputs.card({
89
+ from: ["hand"],
90
+ where: {
91
+ id: "own-card",
92
+ errorCode: "NOT_YOUR_CARD",
93
+ test: ({ q, playerId, targetId }) =>
94
+ q.zone.playerCards(playerId, "hand").includes(targetId),
95
+ },
96
+ });
97
+
98
+ export default play.define({
99
+ kind: "player",
100
+ initialState: () => ({ leadCardId: null }),
101
+ actor: ({ state }) => state.publicState.currentPlayerId,
102
+ interactions: {
103
+ playCard: play.interaction({
104
+ inputs: { cardId: ownCard },
105
+ reduce({ tx, input, q }) {
106
+ // tx.state.phase.leadCardId and input.params.cardId are inferred.
107
+ tx.moveCardFromPlayerZoneToSharedZone({
108
+ playerId: input.playerId,
109
+ fromZoneId: "hand",
110
+ toZoneId: "trick",
111
+ cardId: input.params.cardId,
112
+ });
113
+ tx.patchPhaseState({ leadCardId: input.params.cardId });
114
+ const next = q.player.nextInOrder(input.playerId);
115
+ if (next) tx.setActivePlayers([next]);
116
+ if (q.zone.playerCards(input.playerId, "hand").length === 0) {
117
+ return tx.transition("setup");
118
+ }
119
+ },
120
+ }),
121
+ },
122
+ });
123
+ ```
124
+
125
+ ```ts
126
+ // app/game.ts — assembly
127
+ import { game } from "./game-model";
128
+ import play from "./phases/play";
129
+ import setup from "./phases/setup";
130
+
131
+ export default game.assemble({
132
+ initial: {
133
+ public: ({ playerIds }) => ({ currentPlayerId: playerIds[0] ?? null }),
134
+ private: () => ({}),
135
+ hidden: () => ({}),
136
+ },
137
+ initialPhase: "setup",
138
+ phases: { setup, play },
139
+ views: {
140
+ shared: game.views.empty(),
141
+ player: game.views.player({
142
+ project: ({ state, playerId, q }) => ({
143
+ me: playerId,
144
+ hand: q.zone.playerCards(playerId, "hand"),
145
+ current: state.publicState.currentPlayerId,
146
+ }),
147
+ }),
148
+ },
149
+ });
150
+ ```
151
+
152
+ A missing, extra, or misspelled phase key fails to typecheck at `assemble`
153
+ or at `game.phase(name)`. Rules, views, and tests import `GameState` and
154
+ `typeof game.types.Tx` from the model module; nothing but the test harness
155
+ imports the assembled game, so there is no import cycle.
156
+
157
+ New workspaces keep authored starter code in `app/game.ts` and `ui/App.tsx`.
158
+ Run the package-local `pnpm generate` command to refresh framework-owned
159
+ manifest and UI contracts; generated files are not authoring surfaces.
160
+
39
161
  ## Reducer runner contract
40
162
 
41
163
  `createReducerBundle(game)` returns exactly the contract version and four
@@ -7,9 +7,9 @@ import {
7
7
  materializeManifest,
8
8
  projectAuthoringAdapter,
9
9
  validateManifest
10
- } from "../chunk-KGV2EUNN.js";
11
- import "../chunk-KWHOFBDM.js";
12
- import "../chunk-HIH6Y4FA.js";
10
+ } from "../chunk-QLSK3DYO.js";
11
+ import "../chunk-EY2LL5WD.js";
12
+ import "../chunk-JUGQ6F3N.js";
13
13
  import "../chunk-PZ5AY32C.js";
14
14
  export {
15
15
  GENERATED_WORKSPACE_PATHS,
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  materializeWorkspace
3
- } from "./chunk-HUK4234C.js";
4
- import "./chunk-KGV2EUNN.js";
5
- import "./chunk-KWHOFBDM.js";
6
- import "./chunk-HIH6Y4FA.js";
3
+ } from "./chunk-2WJSQQT7.js";
4
+ import "./chunk-QLSK3DYO.js";
5
+ import "./chunk-EY2LL5WD.js";
6
+ import "./chunk-JUGQ6F3N.js";
7
7
  import "./chunk-PZ5AY32C.js";
8
8
  export {
9
9
  materializeWorkspace
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  materializeWorkspace
4
- } from "./chunk-HUK4234C.js";
5
- import "./chunk-KGV2EUNN.js";
6
- import "./chunk-KWHOFBDM.js";
7
- import "./chunk-HIH6Y4FA.js";
4
+ } from "./chunk-2WJSQQT7.js";
5
+ import "./chunk-QLSK3DYO.js";
6
+ import "./chunk-EY2LL5WD.js";
7
+ import "./chunk-JUGQ6F3N.js";
8
8
  import "./chunk-PZ5AY32C.js";
9
9
 
10
- // src/authoring-materialize-cli.ts
10
+ // src/authoring-generate-cli.ts
11
11
  var options = parseArgs(process.argv.slice(2));
12
12
  var result = await materializeWorkspace(options);
13
13
  console.log(JSON.stringify(result, null, 2));
@@ -42,4 +42,4 @@ function parseArgs(argv) {
42
42
  ...writeMissingSeeds ? { writeMissingSeeds: true } : {}
43
43
  };
44
44
  }
45
- //# sourceMappingURL=authoring-materialize-cli.js.map
45
+ //# sourceMappingURL=authoring-generate-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/authoring-generate-cli.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { materializeWorkspace } from \"./authoring/materialize-workspace.js\";\n\nconst options = parseArgs(process.argv.slice(2));\nconst result = await materializeWorkspace(options);\nconsole.log(JSON.stringify(result, null, 2));\n\nfunction parseArgs(argv: readonly string[]): {\n readonly manifestPath: string;\n readonly projectRoot?: string;\n readonly writeMissingSeeds?: boolean;\n} {\n let manifestPath: string | undefined;\n let projectRoot: string | undefined;\n let writeMissingSeeds = false;\n for (let index = 0; index < argv.length; index += 1) {\n const arg = argv[index];\n if (arg === \"--manifest\") {\n manifestPath = argv[index + 1];\n index += 1;\n continue;\n }\n if (arg === \"--project-root\") {\n projectRoot = argv[index + 1];\n index += 1;\n continue;\n }\n if (arg === \"--write-missing-seeds\") {\n writeMissingSeeds = true;\n continue;\n }\n throw new Error(`Unknown argument '${arg}'.`);\n }\n if (!manifestPath) {\n throw new Error(\"--manifest is required.\");\n }\n return {\n manifestPath,\n ...(projectRoot === undefined ? {} : { projectRoot }),\n ...(writeMissingSeeds ? { writeMissingSeeds: true } : {}),\n };\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAM,UAAU,UAAU,QAAQ,KAAK,MAAM,CAAC,CAAC;AAC/C,IAAM,SAAS,MAAM,qBAAqB,OAAO;AACjD,QAAQ,IAAI,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC;AAE3C,SAAS,UAAU,MAIjB;AACA,MAAI;AACJ,MAAI;AACJ,MAAI,oBAAoB;AACxB,WAAS,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAAG;AACnD,UAAM,MAAM,KAAK,KAAK;AACtB,QAAI,QAAQ,cAAc;AACxB,qBAAe,KAAK,QAAQ,CAAC;AAC7B,eAAS;AACT;AAAA,IACF;AACA,QAAI,QAAQ,kBAAkB;AAC5B,oBAAc,KAAK,QAAQ,CAAC;AAC5B,eAAS;AACT;AAAA,IACF;AACA,QAAI,QAAQ,yBAAyB;AACnC,0BAAoB;AACpB;AAAA,IACF;AACA,UAAM,IAAI,MAAM,qBAAqB,GAAG,IAAI;AAAA,EAC9C;AACA,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AACA,SAAO;AAAA,IACL;AAAA,IACA,GAAI,gBAAgB,SAAY,CAAC,IAAI,EAAE,YAAY;AAAA,IACnD,GAAI,oBAAoB,EAAE,mBAAmB,KAAK,IAAI,CAAC;AAAA,EACzD;AACF;","names":[]}
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  generateWorkspaceArtifacts
3
- } from "./chunk-KGV2EUNN.js";
3
+ } from "./chunk-QLSK3DYO.js";
4
4
  import {
5
5
  WORKSPACE_CODEGEN_OWNERSHIP
6
- } from "./chunk-HIH6Y4FA.js";
6
+ } from "./chunk-JUGQ6F3N.js";
7
7
 
8
8
  // src/authoring/materialize-workspace.ts
9
9
  import { createHash, randomUUID } from "crypto";
@@ -163,4 +163,4 @@ async function isFile(filePath) {
163
163
  export {
164
164
  materializeWorkspace
165
165
  };
166
- //# sourceMappingURL=chunk-HUK4234C.js.map
166
+ //# sourceMappingURL=chunk-2WJSQQT7.js.map