@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.
- package/README.md +22 -4
- package/dist/capture/harness.js +216 -216
- package/dist/capture/worldgen-preview.js +288 -288
- package/dist/cli.mjs +134 -12
- package/dist/docs-src/guide/3d-art-guidelines.md +2 -2
- package/dist/docs-src/guide/3d-model-assets.md +49 -13
- package/dist/docs-src/guide/adaptive-performance.md +4 -0
- package/dist/docs-src/guide/agent-loop.md +6 -6
- package/dist/docs-src/guide/aircraft.md +25 -17
- package/dist/docs-src/guide/audio.md +247 -0
- package/dist/docs-src/guide/browser-mount.md +17 -1
- package/dist/docs-src/guide/building-interiors.md +7 -5
- package/dist/docs-src/guide/determinism.md +27 -22
- package/dist/docs-src/guide/earth-view.md +444 -0
- package/dist/docs-src/guide/entities.md +17 -6
- package/dist/docs-src/guide/examples.md +39 -23
- package/dist/docs-src/guide/experience-playback.md +2 -3
- package/dist/docs-src/guide/game-samples.md +50 -21
- package/dist/docs-src/guide/graphics-performance.md +40 -8
- package/dist/docs-src/guide/input.md +9 -0
- package/dist/docs-src/guide/markers.md +52 -0
- package/dist/docs-src/guide/materials.md +10 -3
- package/dist/docs-src/guide/navigation.md +144 -0
- package/dist/docs-src/guide/project.md +23 -3
- package/dist/docs-src/guide/quickstart.md +39 -30
- package/dist/docs-src/guide/recognizable-places.md +24 -17
- package/dist/docs-src/guide/rendering-backends.md +5 -4
- package/dist/docs-src/guide/scripting.md +8 -4
- package/dist/docs-src/guide/sky.md +26 -9
- package/dist/docs-src/guide/source-bundles.md +0 -1
- package/dist/docs-src/guide/structure-library.md +20 -10
- package/dist/docs-src/guide/terrain.md +51 -6
- package/dist/docs-src/guide/vehicles.md +27 -14
- package/dist/docs-src/guide/worldgen.md +34 -24
- package/dist/docs-src/llms.txt +35 -18
- package/dist/docs-src/schemas/README.md +4 -1
- package/dist/docs-src/schemas/archive-set.md +175 -0
- package/dist/docs-src/schemas/components.md +1104 -1
- package/dist/docs-src/schemas/matgraph.md +6 -0
- package/dist/docs-src/schemas/soundbank.md +251 -0
- package/dist/docs-src/schemas/structure-placements.md +496 -0
- package/dist/docs-src/schemas/terrain-package.md +120 -0
- package/dist/index.d.mts +31 -3
- package/dist/index.mjs +2 -2
- package/dist/{mcp-BFnCWrg0.mjs → mcp-BTVwVKFb.mjs} +78 -4
- package/dist/{ops-BGxhSP6w.mjs → ops-BPdHodFR.mjs} +1181 -61
- package/dist/templates/city-courier/README.md +66 -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 +1016 -0
- package/dist/templates/city-courier/index.html +2 -0
- package/dist/templates/city-courier/package.json +26 -0
- package/dist/templates/city-courier/project.json +8 -0
- package/dist/templates/city-courier/scene.json +3474 -0
- package/dist/templates/city-courier/scripts/game.ts +131 -0
- package/dist/templates/city-courier/scripts/molen-scripts.d.ts +1288 -0
- package/dist/templates/city-courier/scripts/tsconfig.json +16 -0
- package/dist/templates/city-courier/src/audio.ts +96 -0
- package/dist/templates/city-courier/src/game-shell.css +317 -0
- package/dist/templates/city-courier/src/main.ts +84 -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 +191 -0
- package/dist/templates/skybound/README.md +66 -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 +1016 -0
- package/dist/templates/skybound/index.html +2 -0
- package/dist/templates/skybound/package.json +26 -0
- package/dist/templates/skybound/project.json +8 -0
- package/dist/templates/skybound/scene.json +1777 -0
- package/dist/templates/skybound/scripts/game.ts +122 -0
- package/dist/templates/skybound/scripts/molen-scripts.d.ts +1288 -0
- package/dist/templates/skybound/scripts/tsconfig.json +16 -0
- package/dist/templates/skybound/src/audio.ts +96 -0
- package/dist/templates/skybound/src/game-shell.css +317 -0
- package/dist/templates/skybound/src/main.ts +63 -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 +65 -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 +26 -0
- package/dist/templates/top-down-arena/project.json +10 -0
- package/dist/templates/top-down-arena/scene.json +182 -0
- package/dist/templates/top-down-arena/scripts/chase.ts +17 -0
- package/dist/templates/top-down-arena/scripts/combat.ts +13 -0
- package/dist/templates/top-down-arena/scripts/control.ts +8 -0
- package/dist/templates/top-down-arena/scripts/molen-scripts.d.ts +1258 -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/audio.ts +96 -0
- package/dist/templates/top-down-arena/src/gen/molen-types.ts +1020 -0
- package/dist/templates/top-down-arena/src/main.ts +34 -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,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,63 @@
|
|
|
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 = 'skybound';
|
|
8
|
+
element('interface').innerHTML =
|
|
9
|
+
`<header class="topbar"><div><div class="eyebrow">MOLEN / 03 / PLATFORM ADVENTURE</div><h1>Skybound</h1><div class="subtitle">A LITTLE LEAP GOES A LONG WAY</div></div><div class="stats"><div class="stat"><label>SEEDS</label><strong id="stat0">0 / 15</strong></div><div class="stat"><label>LIVES</label><strong id="stat1">3</strong></div><div class="stat"><label>CHECKPOINT</label><strong id="stat2">START</strong></div></div></header><div class="bottom"><div class="brief"><div class="label">Five islands. One lighthouse.</div><p id="message">Loading the experience...</p><div class="controls"><kbd>A D / ← →</kbd> run <kbd>Space</kbd> jump (hold for height)<br/>Stomp the purple creatures. Avoid pink thorns. <kbd>R</kbd> restart</div></div><div class="brief"><div class="label">TO THE LIGHTHOUSE</div><div class="progress"><span id="progress"></span></div><div class="controls">Eastbound · 75 meters</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>`;
|
|
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', 'skyGame');
|
|
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' ? 'You made it!' : '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.coins} / ${g.total}`;
|
|
52
|
+
element('stat1').textContent = String(g.lives);
|
|
53
|
+
element('stat2').textContent = g.checkpoint ? 'SAVED' : 'START';
|
|
54
|
+
element('progress').style.width = `${Math.max(0, Math.min(100, ((pos?.[0] ?? 0) / 75) * 100))}%`;
|
|
55
|
+
}, 80);
|
|
56
|
+
function dispose(): void {
|
|
57
|
+
clearInterval(timer);
|
|
58
|
+
void stopAudio.then((stop) => stop());
|
|
59
|
+
mounted.dispose();
|
|
60
|
+
worker.terminate();
|
|
61
|
+
}
|
|
62
|
+
window.addEventListener('pagehide', dispose, { once: true });
|
|
63
|
+
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,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyKeyframeTo,
|
|
3
|
+
buildWorld,
|
|
4
|
+
componentHandle,
|
|
5
|
+
stateHash,
|
|
6
|
+
Transform,
|
|
7
|
+
takeKeyframe,
|
|
8
|
+
type World,
|
|
9
|
+
} from '@bendyline/molen-kernel';
|
|
10
|
+
import type { JsonObject } from '@bendyline/molen-schema';
|
|
11
|
+
import { describe, expect, it } from 'vitest';
|
|
12
|
+
import { scene } from '../src/scene';
|
|
13
|
+
|
|
14
|
+
const build = (): World => buildWorld(scene());
|
|
15
|
+
function command(w: World, type: string, payload: JsonObject = {}): void {
|
|
16
|
+
const result = w.submitCommand({
|
|
17
|
+
kind: 'command',
|
|
18
|
+
source: type,
|
|
19
|
+
seq: w.tick * 10 + w.commandTypes().indexOf(type),
|
|
20
|
+
tick: w.tick,
|
|
21
|
+
type,
|
|
22
|
+
payload,
|
|
23
|
+
});
|
|
24
|
+
expect(result.accepted, result.reason).toBe(true);
|
|
25
|
+
}
|
|
26
|
+
function data(w: World, id: string, name: string): JsonObject {
|
|
27
|
+
const value = w.get(id, componentHandle(name));
|
|
28
|
+
if (value === undefined) throw new Error(`Missing ${id}.${name}`);
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('skybound: authored scene + scripts', () => {
|
|
33
|
+
// A pinned hash, not just run-to-run equality: two runs of the same build always agree, so
|
|
34
|
+
// that check cannot see a refactor that moved the whole simulation. This literal can only be
|
|
35
|
+
// updated on purpose, which is the point — it is the skybound run's behaviour, frozen.
|
|
36
|
+
it('matches the pinned state hash across engine versions', () => {
|
|
37
|
+
const w = build();
|
|
38
|
+
command(w, 'move', { dir: [1, 0] });
|
|
39
|
+
w.stepN(90);
|
|
40
|
+
expect(stateHash(w)).toBe(
|
|
41
|
+
'sha256:cb40e56449dcc4916b0f80b3dd33fe2783f4105f87259f5d47f70642cb91c58e',
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('runs the same world twice and continues from a checkpoint', () => {
|
|
46
|
+
const a = build();
|
|
47
|
+
const b = build();
|
|
48
|
+
command(a, 'move', { dir: [0, -1] });
|
|
49
|
+
command(b, 'move', { dir: [0, -1] });
|
|
50
|
+
a.stepN(20);
|
|
51
|
+
b.stepN(20);
|
|
52
|
+
expect(stateHash(a)).toBe(stateHash(b));
|
|
53
|
+
const c = build();
|
|
54
|
+
applyKeyframeTo(c, takeKeyframe(a));
|
|
55
|
+
a.stepN(30);
|
|
56
|
+
c.stepN(30);
|
|
57
|
+
expect(stateHash(a)).toBe(stateHash(c));
|
|
58
|
+
});
|
|
59
|
+
it('rejects malformed input and restarts through the declared command', () => {
|
|
60
|
+
const w = build();
|
|
61
|
+
expect(
|
|
62
|
+
w.submitCommand({
|
|
63
|
+
kind: 'command',
|
|
64
|
+
source: 'bad',
|
|
65
|
+
seq: 0,
|
|
66
|
+
tick: 0,
|
|
67
|
+
type: 'move',
|
|
68
|
+
payload: { dir: [20, 0] },
|
|
69
|
+
}).accepted,
|
|
70
|
+
).toBe(false);
|
|
71
|
+
w.stepN(30);
|
|
72
|
+
command(w, 'restart');
|
|
73
|
+
w.stepN(2);
|
|
74
|
+
expect(data(w, 'game', 'skyGame').status).toBe('playing');
|
|
75
|
+
});
|
|
76
|
+
it('jumps, collects seeds, falls, and respawns with one fewer life', () => {
|
|
77
|
+
const w = build();
|
|
78
|
+
w.step();
|
|
79
|
+
command(w, 'move', { dir: [1, 0] });
|
|
80
|
+
w.stepN(18);
|
|
81
|
+
expect(data(w, 'game', 'skyGame').coins).toBeGreaterThan(0);
|
|
82
|
+
command(w, 'jump', { held: true });
|
|
83
|
+
w.stepN(8);
|
|
84
|
+
expect(w.get('player', Transform)?.pos[1]).toBeGreaterThan(2);
|
|
85
|
+
w.patch('player', Transform, { pos: [9, -7, 0] });
|
|
86
|
+
w.step();
|
|
87
|
+
expect(data(w, 'game', 'skyGame').lives).toBe(2);
|
|
88
|
+
expect(w.get('player', Transform)?.pos[0]).toBe(0);
|
|
89
|
+
});
|
|
90
|
+
it('saves a checkpoint and restarts all collectibles and lives', () => {
|
|
91
|
+
const w = build();
|
|
92
|
+
w.patch('player', Transform, { pos: [38, 1.25, 0] });
|
|
93
|
+
w.step();
|
|
94
|
+
expect(data(w, 'game', 'skyGame').checkpoint).toBe(1);
|
|
95
|
+
w.patch('player', Transform, { pos: [42, -7, 0] });
|
|
96
|
+
w.step();
|
|
97
|
+
expect(w.get('player', Transform)?.pos[0]).toBe(38);
|
|
98
|
+
command(w, 'restart');
|
|
99
|
+
w.stepN(2);
|
|
100
|
+
expect(data(w, 'game', 'skyGame').lives).toBe(3);
|
|
101
|
+
expect(data(w, 'game', 'skyGame').checkpoint).toBe(0);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('keeps a fast jump tap when press and release arrive in the same simulation tick', () => {
|
|
106
|
+
const w = build();
|
|
107
|
+
w.step();
|
|
108
|
+
for (const [seq, held] of [
|
|
109
|
+
[0, true],
|
|
110
|
+
[1, false],
|
|
111
|
+
] as const) {
|
|
112
|
+
const result = w.submitCommand({
|
|
113
|
+
kind: 'command',
|
|
114
|
+
source: 'tap',
|
|
115
|
+
seq,
|
|
116
|
+
tick: w.tick + 1,
|
|
117
|
+
type: 'jump',
|
|
118
|
+
payload: { held },
|
|
119
|
+
});
|
|
120
|
+
expect(result.accepted).toBe(true);
|
|
121
|
+
}
|
|
122
|
+
w.stepN(4);
|
|
123
|
+
expect(w.get('player', Transform)?.pos[1]).toBeGreaterThan(1.6);
|
|
124
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
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 skybound 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 jumps = [6, 16, 21.5, 27, 38.5, 44.5, 55.5, 65, 72];
|
|
23
|
+
for (let n = 0; n < 1600 && get(w, 'game', 'skyGame').status === 'playing'; n++) {
|
|
24
|
+
const [x] = p(w);
|
|
25
|
+
const b = get(w, 'player', 'platformBody');
|
|
26
|
+
send(w, 'move', { dir: [1, 0] });
|
|
27
|
+
if (x >= jumps[i] && b.grounded) {
|
|
28
|
+
send(w, 'jump', { held: true });
|
|
29
|
+
i++;
|
|
30
|
+
}
|
|
31
|
+
w.step();
|
|
32
|
+
}
|
|
33
|
+
expect(get(w, 'game', 'skyGame').status).toBe('won');
|
|
34
|
+
send(w, 'restart');
|
|
35
|
+
w.stepN(2);
|
|
36
|
+
expect(get(w, 'game', 'skyGame').status).toBe('playing');
|
|
37
|
+
expect(get(w, 'game', 'skyGame').coins).toBe(0);
|
|
38
|
+
});
|