@bendyline/molen-tooling 0.0.1 → 0.0.3

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 (158) hide show
  1. package/README.md +22 -4
  2. package/dist/capture/harness.js +216 -216
  3. package/dist/capture/worldgen-preview.js +288 -288
  4. package/dist/cli.mjs +134 -12
  5. package/dist/docs-src/guide/3d-art-guidelines.md +2 -2
  6. package/dist/docs-src/guide/3d-model-assets.md +49 -13
  7. package/dist/docs-src/guide/adaptive-performance.md +4 -0
  8. package/dist/docs-src/guide/agent-loop.md +6 -6
  9. package/dist/docs-src/guide/aircraft.md +25 -17
  10. package/dist/docs-src/guide/audio.md +247 -0
  11. package/dist/docs-src/guide/browser-mount.md +17 -1
  12. package/dist/docs-src/guide/building-interiors.md +7 -5
  13. package/dist/docs-src/guide/determinism.md +27 -22
  14. package/dist/docs-src/guide/earth-view.md +444 -0
  15. package/dist/docs-src/guide/entities.md +17 -6
  16. package/dist/docs-src/guide/examples.md +39 -23
  17. package/dist/docs-src/guide/experience-playback.md +2 -3
  18. package/dist/docs-src/guide/game-samples.md +50 -21
  19. package/dist/docs-src/guide/graphics-performance.md +40 -8
  20. package/dist/docs-src/guide/input.md +9 -0
  21. package/dist/docs-src/guide/markers.md +52 -0
  22. package/dist/docs-src/guide/materials.md +10 -3
  23. package/dist/docs-src/guide/navigation.md +144 -0
  24. package/dist/docs-src/guide/project.md +23 -3
  25. package/dist/docs-src/guide/quickstart.md +39 -30
  26. package/dist/docs-src/guide/recognizable-places.md +24 -17
  27. package/dist/docs-src/guide/rendering-backends.md +5 -4
  28. package/dist/docs-src/guide/scripting.md +8 -4
  29. package/dist/docs-src/guide/sky.md +26 -9
  30. package/dist/docs-src/guide/source-bundles.md +0 -1
  31. package/dist/docs-src/guide/structure-library.md +20 -10
  32. package/dist/docs-src/guide/terrain.md +51 -6
  33. package/dist/docs-src/guide/vehicles.md +27 -14
  34. package/dist/docs-src/guide/worldgen.md +34 -24
  35. package/dist/docs-src/llms.txt +35 -18
  36. package/dist/docs-src/schemas/README.md +4 -1
  37. package/dist/docs-src/schemas/archive-set.md +175 -0
  38. package/dist/docs-src/schemas/components.md +1104 -1
  39. package/dist/docs-src/schemas/matgraph.md +6 -0
  40. package/dist/docs-src/schemas/soundbank.md +251 -0
  41. package/dist/docs-src/schemas/structure-placements.md +496 -0
  42. package/dist/docs-src/schemas/terrain-package.md +120 -0
  43. package/dist/index.d.mts +31 -3
  44. package/dist/index.mjs +2 -2
  45. package/dist/{mcp-BFnCWrg0.mjs → mcp-BTVwVKFb.mjs} +78 -4
  46. package/dist/{ops-BGxhSP6w.mjs → ops-BPdHodFR.mjs} +1181 -61
  47. package/dist/templates/city-courier/README.md +66 -0
  48. package/dist/templates/city-courier/checks.json +20 -0
  49. package/dist/templates/city-courier/commands.json +32 -0
  50. package/dist/templates/city-courier/delivery-run.replay.json +214 -0
  51. package/dist/templates/city-courier/gen/molen-types.ts +1016 -0
  52. package/dist/templates/city-courier/index.html +2 -0
  53. package/dist/templates/city-courier/package.json +26 -0
  54. package/dist/templates/city-courier/project.json +8 -0
  55. package/dist/templates/city-courier/scene.json +3474 -0
  56. package/dist/templates/city-courier/scripts/game.ts +131 -0
  57. package/dist/templates/city-courier/scripts/molen-scripts.d.ts +1288 -0
  58. package/dist/templates/city-courier/scripts/tsconfig.json +16 -0
  59. package/dist/templates/city-courier/src/audio.ts +96 -0
  60. package/dist/templates/city-courier/src/game-shell.css +317 -0
  61. package/dist/templates/city-courier/src/main.ts +84 -0
  62. package/dist/templates/city-courier/src/scene.ts +17 -0
  63. package/dist/templates/city-courier/src/vite-env.d.ts +1 -0
  64. package/dist/templates/city-courier/src/worker.ts +5 -0
  65. package/dist/templates/city-courier/test/headless.test.ts +95 -0
  66. package/dist/templates/city-courier/test/playthrough.test.js +52 -0
  67. package/dist/templates/city-courier/test/replay.test.ts +22 -0
  68. package/dist/templates/city-courier/tsconfig.json +17 -0
  69. package/dist/templates/city-courier/vite.config.ts +19 -0
  70. package/dist/templates/cubes/README.md +51 -0
  71. package/dist/templates/cubes/index.html +16 -0
  72. package/dist/templates/cubes/package.json +24 -0
  73. package/dist/templates/cubes/scene.json +15 -0
  74. package/dist/templates/cubes/src/cubes.ts +100 -0
  75. package/dist/templates/cubes/src/main.ts +21 -0
  76. package/dist/templates/cubes/src/worker.ts +15 -0
  77. package/dist/templates/cubes/test/headless.test.ts +98 -0
  78. package/dist/templates/cubes/tsconfig.json +17 -0
  79. package/dist/templates/cubes/vite.config.ts +17 -0
  80. package/dist/templates/data-viz/README.md +47 -0
  81. package/dist/templates/data-viz/camera-track.json +12 -0
  82. package/dist/templates/data-viz/data.json +9 -0
  83. package/dist/templates/data-viz/index.html +16 -0
  84. package/dist/templates/data-viz/package.json +25 -0
  85. package/dist/templates/data-viz/scene.json +7 -0
  86. package/dist/templates/data-viz/src/main.ts +39 -0
  87. package/dist/templates/data-viz/src/viz.ts +91 -0
  88. package/dist/templates/data-viz/src/worker.ts +12 -0
  89. package/dist/templates/data-viz/test/headless.test.ts +75 -0
  90. package/dist/templates/data-viz/tsconfig.json +17 -0
  91. package/dist/templates/data-viz/vite.config.ts +16 -0
  92. package/dist/templates/figures-gallery/README.md +46 -0
  93. package/dist/templates/figures-gallery/index.html +16 -0
  94. package/dist/templates/figures-gallery/package.json +25 -0
  95. package/dist/templates/figures-gallery/scene.json +276 -0
  96. package/dist/templates/figures-gallery/src/main.ts +44 -0
  97. package/dist/templates/figures-gallery/src/worker.ts +17 -0
  98. package/dist/templates/figures-gallery/test/headless.test.ts +90 -0
  99. package/dist/templates/figures-gallery/tsconfig.json +17 -0
  100. package/dist/templates/figures-gallery/vite.config.ts +17 -0
  101. package/dist/templates/index.json +191 -0
  102. package/dist/templates/skybound/README.md +66 -0
  103. package/dist/templates/skybound/checks.json +24 -0
  104. package/dist/templates/skybound/commands.json +32 -0
  105. package/dist/templates/skybound/first-leap.replay.json +224 -0
  106. package/dist/templates/skybound/gen/molen-types.ts +1016 -0
  107. package/dist/templates/skybound/index.html +2 -0
  108. package/dist/templates/skybound/package.json +26 -0
  109. package/dist/templates/skybound/project.json +8 -0
  110. package/dist/templates/skybound/scene.json +1777 -0
  111. package/dist/templates/skybound/scripts/game.ts +122 -0
  112. package/dist/templates/skybound/scripts/molen-scripts.d.ts +1288 -0
  113. package/dist/templates/skybound/scripts/tsconfig.json +16 -0
  114. package/dist/templates/skybound/src/audio.ts +96 -0
  115. package/dist/templates/skybound/src/game-shell.css +317 -0
  116. package/dist/templates/skybound/src/main.ts +63 -0
  117. package/dist/templates/skybound/src/scene.ts +17 -0
  118. package/dist/templates/skybound/src/vite-env.d.ts +1 -0
  119. package/dist/templates/skybound/src/worker.ts +5 -0
  120. package/dist/templates/skybound/test/headless.test.ts +124 -0
  121. package/dist/templates/skybound/test/playthrough.test.js +38 -0
  122. package/dist/templates/skybound/test/replay.test.ts +22 -0
  123. package/dist/templates/skybound/tsconfig.json +17 -0
  124. package/dist/templates/skybound/vite.config.ts +19 -0
  125. package/dist/templates/terrain-flyover/README.md +46 -0
  126. package/dist/templates/terrain-flyover/index.html +16 -0
  127. package/dist/templates/terrain-flyover/package.json +26 -0
  128. package/dist/templates/terrain-flyover/src/flyover.ts +23 -0
  129. package/dist/templates/terrain-flyover/src/main.ts +93 -0
  130. package/dist/templates/terrain-flyover/terrain.json +15 -0
  131. package/dist/templates/terrain-flyover/test/headless.test.ts +72 -0
  132. package/dist/templates/terrain-flyover/tsconfig.json +17 -0
  133. package/dist/templates/terrain-flyover/vite.config.ts +15 -0
  134. package/dist/templates/top-down-arena/README.md +65 -0
  135. package/dist/templates/top-down-arena/arena-skirmish.replay.json +204 -0
  136. package/dist/templates/top-down-arena/index.html +16 -0
  137. package/dist/templates/top-down-arena/package.json +26 -0
  138. package/dist/templates/top-down-arena/project.json +10 -0
  139. package/dist/templates/top-down-arena/scene.json +182 -0
  140. package/dist/templates/top-down-arena/scripts/chase.ts +17 -0
  141. package/dist/templates/top-down-arena/scripts/combat.ts +13 -0
  142. package/dist/templates/top-down-arena/scripts/control.ts +8 -0
  143. package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +1258 -0
  144. package/dist/templates/top-down-arena/scripts/spawner.ts +11 -0
  145. package/dist/templates/top-down-arena/scripts/tsconfig.json +16 -0
  146. package/dist/templates/top-down-arena/src/arena.ts +8 -0
  147. package/dist/templates/top-down-arena/src/audio.ts +96 -0
  148. package/dist/templates/top-down-arena/src/gen/molen-types.ts +1020 -0
  149. package/dist/templates/top-down-arena/src/main.ts +34 -0
  150. package/dist/templates/top-down-arena/src/scene.ts +24 -0
  151. package/dist/templates/top-down-arena/src/vite-env.d.ts +1 -0
  152. package/dist/templates/top-down-arena/src/worker.ts +7 -0
  153. package/dist/templates/top-down-arena/test/headless.test.ts +87 -0
  154. package/dist/templates/top-down-arena/test/replay.test.ts +22 -0
  155. package/dist/templates/top-down-arena/tsconfig.json +17 -0
  156. package/dist/templates/top-down-arena/types/arena.types.json +54 -0
  157. package/dist/templates/top-down-arena/vite.config.ts +21 -0
  158. package/package.json +14 -14
@@ -0,0 +1,16 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowJs": true,
4
+ "checkJs": true,
5
+ "noEmit": true,
6
+ "strict": true,
7
+ "erasableSyntaxOnly": true,
8
+ "target": "ES2023",
9
+ "module": "preserve",
10
+ "moduleResolution": "bundler",
11
+ "lib": ["ES2023"],
12
+ "types": [],
13
+ "skipLibCheck": true
14
+ },
15
+ "include": ["*.ts", "*.js"]
16
+ }
@@ -0,0 +1,96 @@
1
+ import type { MolenClient } from '@bendyline/molen-client';
2
+ import {
3
+ attachAutoplayUnlock,
4
+ createAudioLayer,
5
+ loadPackSoundbanks,
6
+ } from '@bendyline/molen-client/audio';
7
+ import { createPackSet, openPack, type PackIndex } from '@bendyline/molen-pack';
8
+
9
+ // Sound for this sample. The rules live in scene.json (the `audioEnvironment` entity and the
10
+ // `audioSource` components) and in the scripts (`molen.audio.play`); this file only loads the
11
+ // `molen.sounds` content pack and plays what the rules ask for. Without the pack the game is
12
+ // silent: fetch it with `npx molen pack fetch https://molen.dev/packs/index.json molen.sounds
13
+ // --out-dir public/packs`.
14
+
15
+ const SOUND_PACK = 'molen.sounds';
16
+ const MUTED_KEY = 'molen.samples.muted';
17
+
18
+ /** This app's packs/index.json first, then the site-wide one (molen.dev hosts it at /packs/). */
19
+ async function openSoundPack() {
20
+ const candidates = [new URL(`${import.meta.env.BASE_URL}packs/index.json`, location.href)];
21
+ const site = new URL('/packs/index.json', location.href);
22
+ if (site.href !== candidates[0]?.href) candidates.push(site);
23
+ for (const indexUrl of candidates) {
24
+ const response = await fetch(indexUrl).catch(() => undefined);
25
+ if (!response?.ok) continue;
26
+ const index = (await response.json().catch(() => undefined)) as PackIndex | undefined;
27
+ const entry = index?.packs?.[SOUND_PACK];
28
+ if (!entry) continue;
29
+ return openPack(new URL(entry.file, indexUrl).href, {
30
+ sizeHint: entry.size,
31
+ expect: { contentHash: entry.contentHash },
32
+ });
33
+ }
34
+ return undefined;
35
+ }
36
+
37
+ function readMuted(): boolean {
38
+ try {
39
+ return localStorage.getItem(MUTED_KEY) === '1';
40
+ } catch {
41
+ return false;
42
+ }
43
+ }
44
+
45
+ /** Start the sample's audio; resolves to a stop function (a no-op when there is no sound pack). */
46
+ export async function startAudio(client: MolenClient, tickRate: number): Promise<() => void> {
47
+ const pack = await openSoundPack().catch((error: unknown) => {
48
+ console.warn('audio unavailable', error);
49
+ return undefined;
50
+ });
51
+ if (!pack) return () => {};
52
+ const packs = createPackSet([pack]);
53
+ const layer = createAudioLayer({
54
+ banks: await loadPackSoundbanks(packs),
55
+ provider: packs.assetProvider(),
56
+ renderer: client.renderer,
57
+ muted: readMuted(),
58
+ onWarning: (message) => console.warn(`audio: ${message}`),
59
+ });
60
+ const detachClient = layer.attachClient(client, { tickRate });
61
+ const detachUnlock = attachAutoplayUnlock(layer);
62
+
63
+ const toggle = document.createElement('button');
64
+ toggle.type = 'button';
65
+ toggle.className = 'sound-toggle';
66
+ toggle.textContent = 'Sound';
67
+ toggle.setAttribute('aria-pressed', String(!layer.muted));
68
+ toggle.addEventListener('click', () => {
69
+ layer.setMuted(!layer.muted);
70
+ toggle.setAttribute('aria-pressed', String(!layer.muted));
71
+ try {
72
+ localStorage.setItem(MUTED_KEY, layer.muted ? '1' : '0');
73
+ } catch {
74
+ // Storage can be unavailable (private windows); the choice just is not remembered.
75
+ }
76
+ });
77
+ const shell = document.getElementById('interface');
78
+ if (shell) shell.append(toggle);
79
+ else {
80
+ // Pages without the shared game shell get a plain corner button.
81
+ toggle.style.cssText = 'position:fixed;right:12px;bottom:10px;font:13px system-ui';
82
+ document.body.append(toggle);
83
+ }
84
+
85
+ let frame = requestAnimationFrame(function loop(now) {
86
+ layer.update(now);
87
+ frame = requestAnimationFrame(loop);
88
+ });
89
+ return () => {
90
+ cancelAnimationFrame(frame);
91
+ toggle.remove();
92
+ detachUnlock();
93
+ detachClient();
94
+ layer.dispose();
95
+ };
96
+ }
@@ -0,0 +1,317 @@
1
+ * {
2
+ box-sizing: border-box;
3
+ }
4
+ html,
5
+ body {
6
+ margin: 0;
7
+ height: 100%;
8
+ overflow: hidden;
9
+ }
10
+ body {
11
+ --ink: #ecf1e8;
12
+ --muted: #aab9bf;
13
+ --accent: #f9bc60;
14
+ --panel: rgba(18, 32, 43, 0.91);
15
+ font-family: Inter, "Segoe UI", sans-serif;
16
+ color: var(--ink);
17
+ background: #182733;
18
+ }
19
+ canvas#view {
20
+ display: block;
21
+ width: 100%;
22
+ height: 100%;
23
+ outline: none;
24
+ }
25
+ #interface {
26
+ position: fixed;
27
+ inset: 0;
28
+ pointer-events: none;
29
+ }
30
+ .topbar {
31
+ position: absolute;
32
+ inset: 0 0 auto;
33
+ display: flex;
34
+ justify-content: space-between;
35
+ align-items: flex-start;
36
+ padding: 28px 34px;
37
+ background: linear-gradient(#132331d9, transparent);
38
+ gap: 24px;
39
+ }
40
+ .eyebrow {
41
+ font-size: 10px;
42
+ text-transform: uppercase;
43
+ letter-spacing: 3px;
44
+ font-weight: 700;
45
+ color: var(--accent);
46
+ margin-bottom: 9px;
47
+ }
48
+ h1 {
49
+ font-size: 32px;
50
+ line-height: 1;
51
+ letter-spacing: -1.3px;
52
+ margin: 0 0 9px;
53
+ font-weight: 750;
54
+ }
55
+ .subtitle {
56
+ font-size: 12px;
57
+ color: var(--muted);
58
+ }
59
+ .stats {
60
+ display: flex;
61
+ gap: 24px;
62
+ padding: 15px 24px;
63
+ border: 1px solid #ffffff20;
64
+ border-radius: 14px;
65
+ background: var(--panel);
66
+ backdrop-filter: blur(12px);
67
+ }
68
+ .stat {
69
+ min-width: 65px;
70
+ }
71
+ .stat label {
72
+ display: block;
73
+ text-transform: uppercase;
74
+ font-size: 9px;
75
+ letter-spacing: 1.7px;
76
+ color: var(--muted);
77
+ margin-bottom: 4px;
78
+ }
79
+ .stat strong {
80
+ font-size: 23px;
81
+ font-variant-numeric: tabular-nums;
82
+ font-weight: 650;
83
+ }
84
+ .stat small {
85
+ font-size: 11px;
86
+ color: var(--muted);
87
+ margin-left: 4px;
88
+ }
89
+ .bottom {
90
+ position: absolute;
91
+ bottom: 26px;
92
+ left: 34px;
93
+ right: 34px;
94
+ display: flex;
95
+ justify-content: space-between;
96
+ align-items: flex-end;
97
+ gap: 20px;
98
+ }
99
+ .brief {
100
+ max-width: 445px;
101
+ border-left: 3px solid var(--accent);
102
+ padding: 16px 20px;
103
+ background: var(--panel);
104
+ border-radius: 0 12px 12px 0;
105
+ }
106
+ .brief .label {
107
+ font-size: 10px;
108
+ letter-spacing: 2px;
109
+ text-transform: uppercase;
110
+ color: var(--accent);
111
+ }
112
+ #message {
113
+ font-size: 14px;
114
+ line-height: 1.5;
115
+ margin: 8px 0 12px;
116
+ min-height: 21px;
117
+ }
118
+ .controls {
119
+ font-size: 11px;
120
+ color: var(--muted);
121
+ line-height: 2;
122
+ }
123
+ kbd {
124
+ font-family: inherit;
125
+ font-size: 10px;
126
+ background: #ffffff13;
127
+ border: 1px solid #ffffff28;
128
+ border-bottom-width: 2px;
129
+ border-radius: 4px;
130
+ padding: 2px 5px;
131
+ color: var(--ink);
132
+ white-space: nowrap;
133
+ }
134
+ button {
135
+ pointer-events: auto;
136
+ border: 1px solid #ffffff30;
137
+ border-radius: 8px;
138
+ padding: 9px 13px;
139
+ background: #ffffff09;
140
+ color: var(--ink);
141
+ font: inherit;
142
+ font-size: 11px;
143
+ cursor: pointer;
144
+ }
145
+ button:hover {
146
+ background: #ffffff20;
147
+ }
148
+ button:focus-visible {
149
+ outline: 2px solid var(--accent);
150
+ }
151
+ .map {
152
+ width: 152px;
153
+ height: 152px;
154
+ padding: 12px;
155
+ background: var(--panel);
156
+ border: 1px solid #ffffff20;
157
+ border-radius: 14px;
158
+ }
159
+ .map svg {
160
+ width: 100%;
161
+ height: 100%;
162
+ }
163
+ .map-caption {
164
+ position: absolute;
165
+ right: 0;
166
+ bottom: 164px;
167
+ text-transform: uppercase;
168
+ letter-spacing: 2px;
169
+ font-size: 9px;
170
+ color: var(--muted);
171
+ }
172
+ #outcome {
173
+ position: absolute;
174
+ left: 50%;
175
+ top: 40%;
176
+ transform: translate(-50%, -50%);
177
+ background: var(--panel);
178
+ border: 1px solid var(--accent);
179
+ padding: 26px 40px;
180
+ border-radius: 16px;
181
+ text-align: center;
182
+ min-width: 290px;
183
+ box-shadow: 0 20px 80px #0005;
184
+ }
185
+ #outcome[hidden] {
186
+ display: none;
187
+ }
188
+ #outcome h2 {
189
+ font-size: 28px;
190
+ margin: 0 0 10px;
191
+ }
192
+ #outcome p {
193
+ font-size: 13px;
194
+ color: var(--muted);
195
+ }
196
+ .crosshair {
197
+ position: absolute;
198
+ left: 50%;
199
+ top: 50%;
200
+ width: 5px;
201
+ height: 5px;
202
+ border: 1px solid #f5d59b;
203
+ transform: translate(-50%, -50%);
204
+ border-radius: 50%;
205
+ box-shadow: 0 0 15px #ffdaac;
206
+ }
207
+ .sword {
208
+ position: absolute;
209
+ bottom: -90px;
210
+ right: 23%;
211
+ width: 34px;
212
+ height: 320px;
213
+ background: linear-gradient(90deg, #718897 0%, #e5ebdf 45%, #8a9eac 50%, #456276 100%);
214
+ clip-path: polygon(50% 0, 100% 15%, 100% 73%, 85% 76%, 85% 100%, 15% 100%, 15% 76%, 0 73%, 0 15%);
215
+ transform: rotate(22deg);
216
+ transform-origin: bottom;
217
+ transition: transform 0.11s;
218
+ filter: drop-shadow(0 0 12px #000);
219
+ }
220
+ .sword.swing {
221
+ transform: rotate(-40deg) translate(-120px, -35px);
222
+ }
223
+ body[data-game="lantern-dungeon"] {
224
+ --accent: #e8bb75;
225
+ --panel: rgba(15, 23, 34, 0.93);
226
+ }
227
+ body[data-game="lantern-dungeon"] h1 {
228
+ font-family: Georgia, serif;
229
+ font-weight: 400;
230
+ letter-spacing: 0.3px;
231
+ }
232
+ body[data-game="skybound"] {
233
+ --accent: #ffd68e;
234
+ --panel: rgba(28, 70, 77, 0.92);
235
+ }
236
+ body[data-game="skybound"] h1 {
237
+ font-size: 39px;
238
+ font-weight: 850;
239
+ letter-spacing: -2px;
240
+ }
241
+ .progress {
242
+ width: 150px;
243
+ height: 7px;
244
+ background: #ffffff25;
245
+ border-radius: 6px;
246
+ margin: 8px 0;
247
+ }
248
+ .progress span {
249
+ display: block;
250
+ height: 100%;
251
+ background: var(--accent);
252
+ border-radius: 6px;
253
+ width: 0;
254
+ }
255
+ #diagnostic {
256
+ position: absolute;
257
+ top: 105px;
258
+ left: 34px;
259
+ color: #ffb7a5;
260
+ font-size: 12px;
261
+ max-width: 600px;
262
+ white-space: pre-wrap;
263
+ }
264
+ @media (max-width: 720px) {
265
+ .topbar {
266
+ padding: 18px;
267
+ }
268
+ .stats {
269
+ gap: 12px;
270
+ padding: 12px;
271
+ }
272
+ .stat {
273
+ min-width: 38px;
274
+ }
275
+ .stat strong {
276
+ font-size: 19px;
277
+ }
278
+ h1 {
279
+ font-size: 25px;
280
+ }
281
+ .subtitle {
282
+ display: none;
283
+ }
284
+ .bottom {
285
+ left: 18px;
286
+ right: 18px;
287
+ bottom: 18px;
288
+ }
289
+ .brief {
290
+ padding: 12px;
291
+ max-width: 70vw;
292
+ }
293
+ .map {
294
+ width: 105px;
295
+ height: 105px;
296
+ }
297
+ .map-caption {
298
+ bottom: 116px;
299
+ }
300
+ .controls {
301
+ font-size: 10px;
302
+ }
303
+ .sword {
304
+ right: 13%;
305
+ }
306
+ body[data-game="skybound"] h1 {
307
+ font-size: 29px;
308
+ }
309
+ }
310
+ .sound-toggle {
311
+ position: absolute;
312
+ right: 34px;
313
+ bottom: 28px;
314
+ }
315
+ .sound-toggle[aria-pressed="false"] {
316
+ opacity: 0.6;
317
+ }
@@ -0,0 +1,84 @@
1
+ import { mountExperience } from '@bendyline/molen-client';
2
+ import { startAudio } from './audio';
3
+ import { scene } from './scene';
4
+ import './game-shell.css';
5
+
6
+ // Presentation only: all rules and durable state live in scene.json + scripts/game.js.
7
+ document.body.dataset.game = 'city-courier';
8
+ element('interface').innerHTML =
9
+ `<header class="topbar"><div><div class="eyebrow">MOLEN / 01 / ARCADE DRIVING</div><h1>City Courier</h1><div class="subtitle">A SMALL CITY. FIVE DELIVERIES.</div></div><div class="stats"><div class="stat"><label>DELIVERIES</label><strong id="stat0">0 / 5</strong></div><div class="stat"><label>TIME LEFT</label><strong id="stat1">120 s</strong></div><div class="stat"><label>CONDITION</label><strong id="stat2">100%</strong></div></div></header><div class="bottom"><div class="brief"><div class="label">WASD / arrows steer & accelerate.</div><p id="message">Loading the experience...</p><div class="controls"><kbd>W S</kbd> accelerate / reverse &nbsp; <kbd>A D</kbd> steer<br/><kbd>Space</kbd> handbrake &nbsp; <kbd>R</kbd> new route</div></div><div><div class="map-caption">DELIVERY GRID</div><div class="map"><svg viewBox="-38 -38 76 76" aria-label="City route map"><path d="M-24 -35V35 M0 -35V35 M24 -35V35 M-35 -24H35 M-35 0H35 M-35 24H35" stroke="#526775" stroke-width="5"/><circle id="destination" r="3" fill="#7cffd9"/><path id="map-player" d="M0 -2.7L1.7 2L0 1L-1.7 2Z" fill="#ffc46b"/></svg></div></div></div><div id="outcome" hidden><h2 id="outcome-title"></h2><p id="outcome-detail"></p><button id="restart" type="button">Play again &rarr;</button></div><div id="diagnostic" role="alert"></div>`;
10
+ const canvas = document.getElementById('view') as HTMLCanvasElement;
11
+ const worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' });
12
+ const mounted = await mountExperience({ link: worker, scene: scene(), canvas, antialias: true });
13
+ const { client } = mounted;
14
+ const stopAudio = startAudio(client, scene().tickRate ?? 30);
15
+ function element(id: string): HTMLElement {
16
+ const node = document.getElementById(id);
17
+ if (node === null) throw new Error(`Missing UI element: ${id}`);
18
+ return node;
19
+ }
20
+ const diagnostic = (message: string): void => {
21
+ element('diagnostic').textContent = message;
22
+ };
23
+ worker.addEventListener('error', (event) => diagnostic(event.message));
24
+ client.onDiag((d) => {
25
+ if (d.code !== 'tick-overrun') diagnostic(`${d.code}: ${JSON.stringify(d.detail)}`);
26
+ });
27
+ client.onEvent('script-error', (e) => diagnostic(JSON.stringify(e.payload)));
28
+ element('restart').addEventListener('click', () => {
29
+ client.command('restart');
30
+ canvas.focus();
31
+ });
32
+ const timer = setInterval(() => {
33
+ const g = client.get('game', 'courierGame');
34
+ if (!g) return;
35
+ const p = client.get('player', 'transform');
36
+ const pos = p?.pos as number[] | undefined;
37
+ element('message').textContent = String(g.message);
38
+ const outcome = element('outcome');
39
+ outcome.hidden = g.status === 'playing';
40
+ element('outcome-title').textContent = g.status === 'won' ? 'Route complete!' : 'Try again';
41
+ element('outcome-detail').textContent =
42
+ g.status === 'won'
43
+ ? 'A complete adventure, powered by Molen.'
44
+ : 'A fresh start is one key away.';
45
+ // Read-only browser telemetry: useful to both automation and human inspectors.
46
+ canvas.dataset.tick = String(client.tick);
47
+ canvas.dataset.status = String(g.status);
48
+ canvas.dataset.x = String(pos?.[0] ?? 0);
49
+ canvas.dataset.y = String(pos?.[1] ?? 0);
50
+ canvas.dataset.z = String(pos?.[2] ?? 0);
51
+ element('stat0').textContent = `${g.delivered} / ${g.total}`;
52
+ element('stat1').textContent = `${g.seconds} s`;
53
+ element('stat2').textContent = `${g.health}%`;
54
+ const route = [
55
+ [0, -20],
56
+ [24, -20],
57
+ [24, 20],
58
+ [0, 20],
59
+ [0, 0],
60
+ ];
61
+ const destination = route[Number(g.delivered)];
62
+ document
63
+ .getElementById('destination')
64
+ ?.setAttribute('transform', `translate(${destination?.[0] ?? 0} ${destination?.[1] ?? 0})`);
65
+ if (pos) {
66
+ const rot = p?.rot as [number, number, number, number];
67
+ const yaw = 2 * Math.atan2(rot[1] ?? 0, rot[3] ?? 1);
68
+ canvas.dataset.yaw = String(yaw);
69
+ document
70
+ .getElementById('map-player')
71
+ ?.setAttribute(
72
+ 'transform',
73
+ `translate(${pos[0]} ${pos[2]}) rotate(${(-yaw * 180) / Math.PI})`,
74
+ );
75
+ }
76
+ }, 80);
77
+ function dispose(): void {
78
+ clearInterval(timer);
79
+ void stopAudio.then((stop) => stop());
80
+ mounted.dispose();
81
+ worker.terminate();
82
+ }
83
+ window.addEventListener('pagehide', dispose, { once: true });
84
+ if (import.meta.hot) import.meta.hot.dispose(dispose);
@@ -0,0 +1,17 @@
1
+ import { loadProject } from '@bendyline/molen-kernel';
2
+ import type { SceneManifest } from '@bendyline/molen-schema';
3
+ import document from '../scene.json';
4
+
5
+ // loadProject validates the document and inlines each script's source, matching the sources a
6
+ // bundler hands over to the `path` the scene declares — the browser and the tests end up with
7
+ // the identical manifest the CLI builds by reading those files from disk.
8
+ const scripts = import.meta.glob('../scripts/*.ts', {
9
+ query: '?raw',
10
+ import: 'default',
11
+ eager: true,
12
+ }) as Record<string, string>;
13
+
14
+ /** Browser and tests load the same scene + scripts that the CLI reads from disk. */
15
+ export function scene(): SceneManifest {
16
+ return loadProject({ scene: document, scripts }).scene;
17
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,5 @@
1
+ /// <reference lib="webworker" />
2
+ import { startKernelWorker } from '@bendyline/molen-kernel';
3
+ import { scene } from './scene';
4
+
5
+ startKernelWorker({ scene: scene() });
@@ -0,0 +1,95 @@
1
+ import {
2
+ applyKeyframeTo,
3
+ buildWorld,
4
+ componentHandle,
5
+ stateHash,
6
+ takeKeyframe,
7
+ type World,
8
+ } from '@bendyline/molen-kernel';
9
+ import type { JsonObject } from '@bendyline/molen-schema';
10
+ import { describe, expect, it } from 'vitest';
11
+ import { scene } from '../src/scene';
12
+
13
+ const build = (): World => buildWorld(scene());
14
+ function command(w: World, type: string, payload: JsonObject = {}): void {
15
+ const result = w.submitCommand({
16
+ kind: 'command',
17
+ source: type,
18
+ seq: w.tick * 10 + w.commandTypes().indexOf(type),
19
+ tick: w.tick,
20
+ type,
21
+ payload,
22
+ });
23
+ expect(result.accepted, result.reason).toBe(true);
24
+ }
25
+ function data(w: World, id: string, name: string): JsonObject {
26
+ const value = w.get(id, componentHandle(name));
27
+ if (value === undefined) throw new Error(`Missing ${id}.${name}`);
28
+ return value;
29
+ }
30
+
31
+ describe('city-courier: authored scene + scripts', () => {
32
+ // A pinned hash, not just run-to-run equality: two runs of the same build always agree, so
33
+ // that check cannot see a refactor that moved the whole simulation. This literal can only be
34
+ // updated on purpose, which is the point — it is the courier run's behaviour, frozen.
35
+ it('matches the pinned state hash across engine versions', () => {
36
+ const w = build();
37
+ command(w, 'drive', { dir: [0, -1] });
38
+ w.stepN(90);
39
+ expect(stateHash(w)).toBe(
40
+ 'sha256:d82352ff8a1969ea1f702d38a963b09efe7b9c6d00a2f067fed247b239451fdb',
41
+ );
42
+ });
43
+
44
+ it('runs the same world twice and continues from a checkpoint', () => {
45
+ const a = build();
46
+ const b = build();
47
+ command(a, 'drive', { dir: [0, -1] });
48
+ command(b, 'drive', { dir: [0, -1] });
49
+ a.stepN(20);
50
+ b.stepN(20);
51
+ expect(stateHash(a)).toBe(stateHash(b));
52
+ const c = build();
53
+ applyKeyframeTo(c, takeKeyframe(a));
54
+ a.stepN(30);
55
+ c.stepN(30);
56
+ expect(stateHash(a)).toBe(stateHash(c));
57
+ });
58
+ it('rejects malformed input and restarts through the declared command', () => {
59
+ const w = build();
60
+ expect(
61
+ w.submitCommand({
62
+ kind: 'command',
63
+ source: 'bad',
64
+ seq: 0,
65
+ tick: 0,
66
+ type: 'drive',
67
+ payload: { dir: [20, 0] },
68
+ }).accepted,
69
+ ).toBe(false);
70
+ w.stepN(30);
71
+ command(w, 'restart');
72
+ w.stepN(2);
73
+ expect(data(w, 'game', 'courierGame').status).toBe('playing');
74
+ });
75
+ it('accelerates, brakes, and delivers the first beacon by driving', () => {
76
+ const w = build();
77
+ command(w, 'drive', { dir: [0, -1] });
78
+ w.stepN(140);
79
+ expect(data(w, 'game', 'courierGame').delivered).toBeGreaterThanOrEqual(1);
80
+ const speed = Number(data(w, 'game', 'courierGame').speed);
81
+ command(w, 'brake', { held: true });
82
+ command(w, 'drive', { dir: [0, 0] });
83
+ w.stepN(20);
84
+ expect(Number(data(w, 'game', 'courierGame').speed)).toBeLessThan(speed * 0.3);
85
+ });
86
+ it('ends the run when the clock expires', () => {
87
+ const manifest = scene();
88
+ const script = manifest.scripts[0];
89
+ if (script === undefined) throw new Error('Missing game script');
90
+ script.config.duration = 1;
91
+ const w = buildWorld(manifest);
92
+ w.stepN(32);
93
+ expect(data(w, 'game', 'courierGame').status).toBe('lost');
94
+ });
95
+ });
@@ -0,0 +1,52 @@
1
+ import { buildWorld, componentHandle, Transform } from '@bendyline/molen-kernel';
2
+ import { expect, it } from 'vitest';
3
+ import { scene } from '../src/scene';
4
+
5
+ const get = (w, id, c) => w.get(id, componentHandle(c));
6
+ const p = (w) => w.get('player', Transform).pos;
7
+ it('completes city-courier using only player commands, then restarts', () => {
8
+ let seq = 0;
9
+ function send(w, type, payload = {}) {
10
+ const result = w.submitCommand({
11
+ kind: 'command',
12
+ source: 'proof',
13
+ seq: seq++,
14
+ tick: w.tick,
15
+ type,
16
+ payload,
17
+ });
18
+ expect(result.accepted, result.reason).toBe(true);
19
+ }
20
+ const w = buildWorld(scene());
21
+ let i = 0;
22
+ const route = [
23
+ [0, -24],
24
+ [24, -24],
25
+ [24, 24],
26
+ [0, 24],
27
+ [0, 0],
28
+ ];
29
+ for (let n = 0; n < 3400 && get(w, 'game', 'courierGame').status === 'playing'; n++) {
30
+ const point = route[i];
31
+ if (!point) break;
32
+ const [x, , z] = p(w);
33
+ const dx = point[0] - x,
34
+ dz = point[1] - z,
35
+ d = Math.hypot(dx, dz);
36
+ if (d < 1.7 && i < route.length - 1) i++;
37
+ const q = get(w, 'player', 'transform').rot,
38
+ yaw = 2 * Math.atan2(q[1], q[3]);
39
+ const desired = Math.atan2(-dx, -dz),
40
+ error = Math.atan2(Math.sin(desired - yaw), Math.cos(desired - yaw));
41
+ const speed = get(w, 'game', 'courierGame').speed;
42
+ const target = Math.abs(error) > 0.5 ? 3.8 : 7;
43
+ send(w, 'drive', { dir: [Math.max(-1, Math.min(1, -error * 2)), speed < target ? -1 : 0] });
44
+ send(w, 'brake', { held: speed > target + 1 });
45
+ w.step();
46
+ }
47
+ expect(get(w, 'game', 'courierGame').status).toBe('won');
48
+ send(w, 'restart');
49
+ w.stepN(2);
50
+ expect(get(w, 'game', 'courierGame').status).toBe('playing');
51
+ expect(get(w, 'game', 'courierGame').delivered).toBe(0);
52
+ });