@bendyline/molen-tooling 0.0.1 → 0.0.2
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 +22 -4
- package/dist/cli.mjs +26 -4
- package/dist/docs-src/guide/3d-art-guidelines.md +2 -2
- package/dist/docs-src/guide/3d-model-assets.md +15 -11
- package/dist/docs-src/guide/aircraft.md +9 -10
- package/dist/docs-src/guide/browser-mount.md +14 -0
- package/dist/docs-src/guide/building-interiors.md +2 -1
- package/dist/docs-src/guide/determinism.md +16 -11
- package/dist/docs-src/guide/entities.md +16 -5
- package/dist/docs-src/guide/examples.md +38 -23
- package/dist/docs-src/guide/experience-playback.md +2 -3
- package/dist/docs-src/guide/game-samples.md +30 -18
- package/dist/docs-src/guide/project.md +22 -2
- package/dist/docs-src/guide/quickstart.md +37 -28
- package/dist/docs-src/guide/recognizable-places.md +21 -15
- package/dist/docs-src/guide/rendering-backends.md +5 -4
- package/dist/docs-src/guide/scripting.md +4 -2
- package/dist/docs-src/guide/sky.md +10 -9
- package/dist/docs-src/guide/structure-library.md +18 -8
- package/dist/docs-src/guide/terrain.md +6 -4
- package/dist/docs-src/guide/vehicles.md +9 -5
- package/dist/docs-src/guide/worldgen.md +31 -21
- package/dist/docs-src/llms.txt +26 -15
- package/dist/docs-src/schemas/README.md +1 -1
- package/dist/index.d.mts +26 -2
- package/dist/index.mjs +2 -2
- package/dist/{mcp-BFnCWrg0.mjs → mcp-AOfIp89b.mjs} +12 -2
- package/dist/{ops-BGxhSP6w.mjs → ops-C4BvDgP-.mjs} +267 -33
- package/dist/templates/city-courier/README.md +53 -0
- package/dist/templates/city-courier/checks.json +20 -0
- package/dist/templates/city-courier/commands.json +32 -0
- package/dist/templates/city-courier/delivery-run.replay.json +214 -0
- package/dist/templates/city-courier/gen/molen-types.ts +878 -0
- package/dist/templates/city-courier/index.html +2 -0
- package/dist/templates/city-courier/package.json +25 -0
- package/dist/templates/city-courier/project.json +8 -0
- package/dist/templates/city-courier/scene.json +3395 -0
- package/dist/templates/city-courier/scripts/game.ts +127 -0
- package/dist/templates/city-courier/scripts/molen-scripts.d.ts +1125 -0
- package/dist/templates/city-courier/scripts/tsconfig.json +16 -0
- package/dist/templates/city-courier/src/game-shell.css +309 -0
- package/dist/templates/city-courier/src/main.ts +81 -0
- package/dist/templates/city-courier/src/scene.ts +17 -0
- package/dist/templates/city-courier/src/vite-env.d.ts +1 -0
- package/dist/templates/city-courier/src/worker.ts +5 -0
- package/dist/templates/city-courier/test/headless.test.ts +95 -0
- package/dist/templates/city-courier/test/playthrough.test.js +52 -0
- package/dist/templates/city-courier/test/replay.test.ts +22 -0
- package/dist/templates/city-courier/tsconfig.json +17 -0
- package/dist/templates/city-courier/vite.config.ts +19 -0
- package/dist/templates/cubes/README.md +51 -0
- package/dist/templates/cubes/index.html +16 -0
- package/dist/templates/cubes/package.json +24 -0
- package/dist/templates/cubes/scene.json +15 -0
- package/dist/templates/cubes/src/cubes.ts +100 -0
- package/dist/templates/cubes/src/main.ts +21 -0
- package/dist/templates/cubes/src/worker.ts +15 -0
- package/dist/templates/cubes/test/headless.test.ts +98 -0
- package/dist/templates/cubes/tsconfig.json +17 -0
- package/dist/templates/cubes/vite.config.ts +17 -0
- package/dist/templates/data-viz/README.md +47 -0
- package/dist/templates/data-viz/camera-track.json +12 -0
- package/dist/templates/data-viz/data.json +9 -0
- package/dist/templates/data-viz/index.html +16 -0
- package/dist/templates/data-viz/package.json +25 -0
- package/dist/templates/data-viz/scene.json +7 -0
- package/dist/templates/data-viz/src/main.ts +39 -0
- package/dist/templates/data-viz/src/viz.ts +91 -0
- package/dist/templates/data-viz/src/worker.ts +12 -0
- package/dist/templates/data-viz/test/headless.test.ts +75 -0
- package/dist/templates/data-viz/tsconfig.json +17 -0
- package/dist/templates/data-viz/vite.config.ts +16 -0
- package/dist/templates/figures-gallery/README.md +46 -0
- package/dist/templates/figures-gallery/index.html +16 -0
- package/dist/templates/figures-gallery/package.json +25 -0
- package/dist/templates/figures-gallery/scene.json +276 -0
- package/dist/templates/figures-gallery/src/main.ts +44 -0
- package/dist/templates/figures-gallery/src/worker.ts +17 -0
- package/dist/templates/figures-gallery/test/headless.test.ts +90 -0
- package/dist/templates/figures-gallery/tsconfig.json +17 -0
- package/dist/templates/figures-gallery/vite.config.ts +17 -0
- package/dist/templates/index.json +188 -0
- package/dist/templates/skybound/README.md +53 -0
- package/dist/templates/skybound/checks.json +24 -0
- package/dist/templates/skybound/commands.json +32 -0
- package/dist/templates/skybound/first-leap.replay.json +224 -0
- package/dist/templates/skybound/gen/molen-types.ts +878 -0
- package/dist/templates/skybound/index.html +2 -0
- package/dist/templates/skybound/package.json +25 -0
- package/dist/templates/skybound/project.json +8 -0
- package/dist/templates/skybound/scene.json +1737 -0
- package/dist/templates/skybound/scripts/game.ts +119 -0
- package/dist/templates/skybound/scripts/molen-scripts.d.ts +1125 -0
- package/dist/templates/skybound/scripts/tsconfig.json +16 -0
- package/dist/templates/skybound/src/game-shell.css +309 -0
- package/dist/templates/skybound/src/main.ts +60 -0
- package/dist/templates/skybound/src/scene.ts +17 -0
- package/dist/templates/skybound/src/vite-env.d.ts +1 -0
- package/dist/templates/skybound/src/worker.ts +5 -0
- package/dist/templates/skybound/test/headless.test.ts +124 -0
- package/dist/templates/skybound/test/playthrough.test.js +38 -0
- package/dist/templates/skybound/test/replay.test.ts +22 -0
- package/dist/templates/skybound/tsconfig.json +17 -0
- package/dist/templates/skybound/vite.config.ts +19 -0
- package/dist/templates/terrain-flyover/README.md +46 -0
- package/dist/templates/terrain-flyover/index.html +16 -0
- package/dist/templates/terrain-flyover/package.json +26 -0
- package/dist/templates/terrain-flyover/src/flyover.ts +23 -0
- package/dist/templates/terrain-flyover/src/main.ts +93 -0
- package/dist/templates/terrain-flyover/terrain.json +15 -0
- package/dist/templates/terrain-flyover/test/headless.test.ts +72 -0
- package/dist/templates/terrain-flyover/tsconfig.json +17 -0
- package/dist/templates/terrain-flyover/vite.config.ts +15 -0
- package/dist/templates/top-down-arena/README.md +52 -0
- package/dist/templates/top-down-arena/arena-skirmish.replay.json +204 -0
- package/dist/templates/top-down-arena/index.html +16 -0
- package/dist/templates/top-down-arena/package.json +25 -0
- package/dist/templates/top-down-arena/project.json +10 -0
- package/dist/templates/top-down-arena/scene.json +162 -0
- package/dist/templates/top-down-arena/scripts/chase.ts +17 -0
- package/dist/templates/top-down-arena/scripts/combat.ts +12 -0
- package/dist/templates/top-down-arena/scripts/control.ts +8 -0
- package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +1095 -0
- package/dist/templates/top-down-arena/scripts/spawner.ts +11 -0
- package/dist/templates/top-down-arena/scripts/tsconfig.json +16 -0
- package/dist/templates/top-down-arena/src/arena.ts +8 -0
- package/dist/templates/top-down-arena/src/gen/molen-types.ts +882 -0
- package/dist/templates/top-down-arena/src/main.ts +31 -0
- package/dist/templates/top-down-arena/src/scene.ts +24 -0
- package/dist/templates/top-down-arena/src/vite-env.d.ts +1 -0
- package/dist/templates/top-down-arena/src/worker.ts +7 -0
- package/dist/templates/top-down-arena/test/headless.test.ts +87 -0
- package/dist/templates/top-down-arena/test/replay.test.ts +22 -0
- package/dist/templates/top-down-arena/tsconfig.json +17 -0
- package/dist/templates/top-down-arena/types/arena.types.json +54 -0
- package/dist/templates/top-down-arena/vite.config.ts +21 -0
- 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,309 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { mountExperience } from '@bendyline/molen-client';
|
|
2
|
+
import { scene } from './scene';
|
|
3
|
+
import './game-shell.css';
|
|
4
|
+
|
|
5
|
+
// Presentation only: all rules and durable state live in scene.json + scripts/game.js.
|
|
6
|
+
document.body.dataset.game = 'city-courier';
|
|
7
|
+
element('interface').innerHTML =
|
|
8
|
+
`<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 <kbd>A D</kbd> steer<br/><kbd>Space</kbd> handbrake <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 →</button></div><div id="diagnostic" role="alert"></div>`;
|
|
9
|
+
const canvas = document.getElementById('view') as HTMLCanvasElement;
|
|
10
|
+
const worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'module' });
|
|
11
|
+
const mounted = await mountExperience({ link: worker, scene: scene(), canvas, antialias: true });
|
|
12
|
+
const { client } = mounted;
|
|
13
|
+
function element(id: string): HTMLElement {
|
|
14
|
+
const node = document.getElementById(id);
|
|
15
|
+
if (node === null) throw new Error(`Missing UI element: ${id}`);
|
|
16
|
+
return node;
|
|
17
|
+
}
|
|
18
|
+
const diagnostic = (message: string): void => {
|
|
19
|
+
element('diagnostic').textContent = message;
|
|
20
|
+
};
|
|
21
|
+
worker.addEventListener('error', (event) => diagnostic(event.message));
|
|
22
|
+
client.onDiag((d) => {
|
|
23
|
+
if (d.code !== 'tick-overrun') diagnostic(`${d.code}: ${JSON.stringify(d.detail)}`);
|
|
24
|
+
});
|
|
25
|
+
client.onEvent('script-error', (e) => diagnostic(JSON.stringify(e.payload)));
|
|
26
|
+
element('restart').addEventListener('click', () => {
|
|
27
|
+
client.command('restart');
|
|
28
|
+
canvas.focus();
|
|
29
|
+
});
|
|
30
|
+
const timer = setInterval(() => {
|
|
31
|
+
const g = client.get('game', 'courierGame');
|
|
32
|
+
if (!g) return;
|
|
33
|
+
const p = client.get('player', 'transform');
|
|
34
|
+
const pos = p?.pos as number[] | undefined;
|
|
35
|
+
element('message').textContent = String(g.message);
|
|
36
|
+
const outcome = element('outcome');
|
|
37
|
+
outcome.hidden = g.status === 'playing';
|
|
38
|
+
element('outcome-title').textContent = g.status === 'won' ? 'Route complete!' : 'Try again';
|
|
39
|
+
element('outcome-detail').textContent =
|
|
40
|
+
g.status === 'won'
|
|
41
|
+
? 'A complete adventure, powered by Molen.'
|
|
42
|
+
: 'A fresh start is one key away.';
|
|
43
|
+
// Read-only browser telemetry: useful to both automation and human inspectors.
|
|
44
|
+
canvas.dataset.tick = String(client.tick);
|
|
45
|
+
canvas.dataset.status = String(g.status);
|
|
46
|
+
canvas.dataset.x = String(pos?.[0] ?? 0);
|
|
47
|
+
canvas.dataset.y = String(pos?.[1] ?? 0);
|
|
48
|
+
canvas.dataset.z = String(pos?.[2] ?? 0);
|
|
49
|
+
element('stat0').textContent = `${g.delivered} / ${g.total}`;
|
|
50
|
+
element('stat1').textContent = `${g.seconds} s`;
|
|
51
|
+
element('stat2').textContent = `${g.health}%`;
|
|
52
|
+
const route = [
|
|
53
|
+
[0, -20],
|
|
54
|
+
[24, -20],
|
|
55
|
+
[24, 20],
|
|
56
|
+
[0, 20],
|
|
57
|
+
[0, 0],
|
|
58
|
+
];
|
|
59
|
+
const destination = route[Number(g.delivered)];
|
|
60
|
+
document
|
|
61
|
+
.getElementById('destination')
|
|
62
|
+
?.setAttribute('transform', `translate(${destination?.[0] ?? 0} ${destination?.[1] ?? 0})`);
|
|
63
|
+
if (pos) {
|
|
64
|
+
const rot = p?.rot as [number, number, number, number];
|
|
65
|
+
const yaw = 2 * Math.atan2(rot[1] ?? 0, rot[3] ?? 1);
|
|
66
|
+
canvas.dataset.yaw = String(yaw);
|
|
67
|
+
document
|
|
68
|
+
.getElementById('map-player')
|
|
69
|
+
?.setAttribute(
|
|
70
|
+
'transform',
|
|
71
|
+
`translate(${pos[0]} ${pos[2]}) rotate(${(-yaw * 180) / Math.PI})`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
}, 80);
|
|
75
|
+
function dispose(): void {
|
|
76
|
+
clearInterval(timer);
|
|
77
|
+
mounted.dispose();
|
|
78
|
+
worker.terminate();
|
|
79
|
+
}
|
|
80
|
+
window.addEventListener('pagehide', dispose, { once: true });
|
|
81
|
+
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,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:d5bb47f21578dd28540e1027fd1acfb282bebd1e26aa03ecba155ff87d16d6ef',
|
|
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
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { runReplayFile } from '@bendyline/molen-tooling';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
|
|
6
|
+
// A committed replay fixture is the long-lived half of the determinism guarantee. The pinned hash
|
|
7
|
+
// in headless.test.ts freezes one run of the current build; this freezes a *recorded command log*
|
|
8
|
+
// plus per-tick reference hashes, so when behaviour drifts the harness reports the first tick that
|
|
9
|
+
// diverged instead of "the hash moved". It also distinguishes a non-deterministic build from an
|
|
10
|
+
// intentional behaviour change — refresh with `molen replay <fixture> --record`.
|
|
11
|
+
|
|
12
|
+
describe('city-courier: recorded replay', () => {
|
|
13
|
+
it('reproduces the recorded run tick for tick', async () => {
|
|
14
|
+
const result = await runReplayFile({
|
|
15
|
+
path: join(process.cwd(), 'delivery-run.replay.json'),
|
|
16
|
+
});
|
|
17
|
+
expect(result.error).toBeUndefined();
|
|
18
|
+
expect(result.ok, result.report).toBe(true);
|
|
19
|
+
expect(result.actualHash).toBe(result.expectedHash);
|
|
20
|
+
expect(result.firstDivergentTick).toBeUndefined();
|
|
21
|
+
}, 60_000);
|
|
22
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
7
|
+
"types": [],
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noUncheckedIndexedAccess": true,
|
|
10
|
+
"verbatimModuleSyntax": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"resolveJsonModule": true
|
|
15
|
+
},
|
|
16
|
+
"include": ["src", "test"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { molenScripts } from '@bendyline/molen-client/vite';
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
// Scene scripts are authored in TypeScript; strip types when they are read as text.
|
|
6
|
+
plugins: [molenScripts()],
|
|
7
|
+
base: './',
|
|
8
|
+
// Vite gives worker bundles their own plugin pipeline, and the kernel runs in the Worker —
|
|
9
|
+
// without this the Worker would receive unstripped TypeScript.
|
|
10
|
+
worker: { format: 'es', plugins: () => [molenScripts()] },
|
|
11
|
+
build: {
|
|
12
|
+
target: 'es2022',
|
|
13
|
+
// main.ts mounts with a top-level `await`, and the client lazy-loads its WebGPU driver. By
|
|
14
|
+
// default Rollup puts three.js and the client in the entry chunk, so the lazy chunk imports
|
|
15
|
+
// the entry while the entry is still suspended at that `await`: the import never settles and
|
|
16
|
+
// the page stays blank in every browser with a WebGPU adapter. Their own chunk breaks the cycle.
|
|
17
|
+
rollupOptions: { output: { manualChunks: { vendor: ['three', '@bendyline/molen-client'] } } },
|
|
18
|
+
},
|
|
19
|
+
});
|