create-threenative 0.2.7 → 0.2.8
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 +3 -1
- package/agent-docs/references/capability-reference.md +177 -7
- package/capabilities.json +247 -4
- package/dist/index.js +6 -1
- package/dist/threenative.js +3 -2
- package/package.json +4 -4
- package/templates/action-rpg/package.json +1 -1
- package/templates/minimal/package.json +1 -1
- package/templates/platformer/package.json +1 -1
- package/templates/puzzle/package.json +1 -1
- package/templates/racing/package.json +1 -1
- package/templates/rain/.codex/config.toml +19 -0
- package/templates/rain/.cursor/mcp.json +32 -0
- package/templates/rain/.gemini/settings.json +32 -0
- package/templates/rain/.mcp.json +32 -0
- package/templates/rain/.vscode/mcp.json +36 -0
- package/templates/rain/.zed/settings.json +36 -0
- package/templates/rain/AGENTS.md +96 -0
- package/templates/rain/CLAUDE.md +98 -0
- package/templates/rain/assets/rain-loop.wav +0 -0
- package/templates/rain/assets/thunder.wav +0 -0
- package/templates/rain/assets/wind-loop.wav +0 -0
- package/templates/rain/index.html +18 -0
- package/templates/rain/kit.json +7 -0
- package/templates/rain/native-playtests/boot.playtest.json +13 -0
- package/templates/rain/native-playtests/lightning.playtest.json +173 -0
- package/templates/rain/opencode.json +41 -0
- package/templates/rain/package.json +56 -0
- package/templates/rain/playtests/auto-lightning-clear.playtest.json +66 -0
- package/templates/rain/playtests/auto-lightning.playtest.json +26 -0
- package/templates/rain/playtests/automation.playtest.json +133 -0
- package/templates/rain/playtests/cinematic.playtest.json +59 -0
- package/templates/rain/playtests/flash.playtest.json +27 -0
- package/templates/rain/playtests/fly.playtest.json +54 -0
- package/templates/rain/playtests/lightning.playtest.json +220 -0
- package/templates/rain/playtests/loading.playtest.json +57 -0
- package/templates/rain/playtests/paused.playtest.json +59 -0
- package/templates/rain/playtests/performance.playtest.json +22 -0
- package/templates/rain/playtests/reduced-motion.playtest.json +87 -0
- package/templates/rain/playtests/simulation.playtest.json +20 -0
- package/templates/rain/playtests/storm.playtest.json +150 -0
- package/templates/rain/playtests/survives.playtest.json +58 -0
- package/templates/rain/playtests/tiers.playtest.json +179 -0
- package/templates/rain/playtests/weather.playtest.json +77 -0
- package/templates/rain/public/favicon.svg +5 -0
- package/templates/rain/src/audio/storm.ts +314 -0
- package/templates/rain/src/game.ts +114 -0
- package/templates/rain/src/main.ts +15 -0
- package/templates/rain/src/render/bloom-shader.ts +65 -0
- package/templates/rain/src/render/camera.ts +160 -0
- package/templates/rain/src/render/clouds-shader.ts +242 -0
- package/templates/rain/src/render/clouds.ts +142 -0
- package/templates/rain/src/render/lighting.ts +39 -0
- package/templates/rain/src/render/lightning.ts +360 -0
- package/templates/rain/src/render/loading.ts +327 -0
- package/templates/rain/src/render/materials.ts +19 -0
- package/templates/rain/src/render/noise-volume.ts +159 -0
- package/templates/rain/src/render/palette.ts +18 -0
- package/templates/rain/src/render/post-shader.ts +178 -0
- package/templates/rain/src/render/postprocessing.ts +226 -0
- package/templates/rain/src/render/quality.ts +135 -0
- package/templates/rain/src/render/rain.ts +299 -0
- package/templates/rain/src/render/sky.ts +28 -0
- package/templates/rain/src/render/world-shader.ts +680 -0
- package/templates/rain/src/render/world.ts +146 -0
- package/templates/rain/src/render/worldEnvironment.ts +809 -0
- package/templates/rain/src/scenes/Boot.ts +334 -0
- package/templates/rain/src/state.ts +257 -0
- package/templates/rain/src/style.css +1160 -0
- package/templates/rain/src/ui/App.tsx +29 -0
- package/templates/rain/src/ui/GameUi.tsx +187 -0
- package/templates/rain/src/ui/Hud.tsx +327 -0
- package/templates/rain/src/ui/LoadingOverlay.tsx +46 -0
- package/templates/rain/src/ui/Menu.tsx +370 -0
- package/templates/rain/src/ui/automation.ts +60 -0
- package/templates/rain/src/ui/main.tsx +7 -0
- package/templates/rain/src/ui/tempest.ts +149 -0
- package/templates/rain/tailwind.config.ts +2 -0
- package/templates/rain/threenative.config.ts +66 -0
- package/templates/rain/tools/generate-shaders.mjs +656 -0
- package/templates/rain/tools/make-storm-audio.mjs +387 -0
- package/templates/rain/tools/storm-dsp.mjs +177 -0
- package/templates/rain/tools/tempest-bloom.frag +10 -0
- package/templates/rain/tools/tempest-clouds.frag +86 -0
- package/templates/rain/tools/tempest-post.frag +47 -0
- package/templates/rain/tools/tempest-world.frag +210 -0
- package/templates/rain/tools/verify-noise-volume.mjs +61 -0
- package/templates/rain/tsconfig.json +17 -0
- package/templates/rain/vite.config.ts +37 -0
- package/templates/rts/package.json +1 -1
- package/templates/runner/package.json +1 -1
- package/templates/sailing/package.json +1 -1
- package/templates/shooter/package.json +1 -1
- package/templates/snow/.codex/config.toml +19 -0
- package/templates/snow/.cursor/mcp.json +32 -0
- package/templates/snow/.gemini/settings.json +32 -0
- package/templates/snow/.mcp.json +32 -0
- package/templates/snow/.vscode/mcp.json +36 -0
- package/templates/snow/.zed/settings.json +36 -0
- package/templates/snow/AGENTS.md +88 -0
- package/templates/snow/CLAUDE.md +90 -0
- package/templates/snow/README.md +26 -0
- package/templates/snow/assets/crunch.wav +0 -0
- package/templates/snow/assets/wind.wav +0 -0
- package/templates/snow/index.html +12 -0
- package/templates/snow/kit.json +7 -0
- package/templates/snow/native-playtests/snow-physics.playtest.json +150 -0
- package/templates/snow/native-playtests/survives.playtest.json +47 -0
- package/templates/snow/opencode.json +41 -0
- package/templates/snow/package.json +58 -0
- package/templates/snow/playtests/footsteps.playtest.json +95 -0
- package/templates/snow/playtests/performance.playtest.json +36 -0
- package/templates/snow/playtests/snow-physics.playtest.json +154 -0
- package/templates/snow/playtests/survives.playtest.json +56 -0
- package/templates/snow/playtests/touch-controls.playtest.json +71 -0
- package/templates/snow/playtests/weather.playtest.json +119 -0
- package/templates/snow/public/favicon.svg +5 -0
- package/templates/snow/src/audio.ts +58 -0
- package/templates/snow/src/commands.ts +8 -0
- package/templates/snow/src/entities/Explorer.ts +279 -0
- package/templates/snow/src/game.ts +69 -0
- package/templates/snow/src/main.ts +15 -0
- package/templates/snow/src/render/bootPrint.ts +50 -0
- package/templates/snow/src/render/camera.ts +84 -0
- package/templates/snow/src/render/explorer.ts +321 -0
- package/templates/snow/src/render/lighting.ts +50 -0
- package/templates/snow/src/render/loading.ts +325 -0
- package/templates/snow/src/render/materials.ts +36 -0
- package/templates/snow/src/render/palette.ts +17 -0
- package/templates/snow/src/render/postprocessing.ts +44 -0
- package/templates/snow/src/render/props.ts +42 -0
- package/templates/snow/src/render/quality.ts +135 -0
- package/templates/snow/src/render/scenery.ts +244 -0
- package/templates/snow/src/render/sky.ts +57 -0
- package/templates/snow/src/render/snowSurface.ts +259 -0
- package/templates/snow/src/render/touch-controls.ts +143 -0
- package/templates/snow/src/render/weather.ts +279 -0
- package/templates/snow/src/render/worldEnvironment.ts +809 -0
- package/templates/snow/src/scenes/Boot.ts +12 -0
- package/templates/snow/src/scenes/Snow.ts +635 -0
- package/templates/snow/src/state.ts +46 -0
- package/templates/snow/src/style.css +143 -0
- package/templates/snow/src/terrain.ts +64 -0
- package/templates/snow/src/ui/App.tsx +15 -0
- package/templates/snow/src/ui/Controls.tsx +322 -0
- package/templates/snow/src/ui/GameUi.tsx +354 -0
- package/templates/snow/src/ui/icons.tsx +54 -0
- package/templates/snow/src/ui/main.tsx +7 -0
- package/templates/snow/tailwind.config.ts +2 -0
- package/templates/snow/threenative.config.ts +51 -0
- package/templates/snow/tsconfig.json +17 -0
- package/templates/snow/vite.config.ts +37 -0
- package/templates/starter/package.json +1 -1
- package/templates/tower-defense/package.json +1 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IGame } from "@threenative/core";
|
|
2
|
+
import { DebugOverlay, GameCanvas } from "@threenative/ui";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import type { GameState } from "../state.js";
|
|
5
|
+
import { GameUi } from "./GameUi.js";
|
|
6
|
+
import { installTempest } from "./tempest.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The study's page: the engine's canvas, and the interface from `./GameUi.js` over it.
|
|
10
|
+
*
|
|
11
|
+
* No physics context on the generic, because `game.ts` is `defineGame<GameState>` — a coastal
|
|
12
|
+
* weather study moves the air, not a rigid body. The UI is mounted from `src/main.ts`, so the
|
|
13
|
+
* canvas and the overlay share one root and one React tree.
|
|
14
|
+
*
|
|
15
|
+
* The automation facade is installed here rather than in `game.ts` because `window.tempest` and
|
|
16
|
+
* the query it reads are the UI realm's; the game module stays portable code.
|
|
17
|
+
*/
|
|
18
|
+
export function App({ game }: { game: IGame<GameState> }) {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
installTempest(game);
|
|
21
|
+
}, [game]);
|
|
22
|
+
return (
|
|
23
|
+
<main className="canvas-root">
|
|
24
|
+
<GameCanvas className="canvas-fill" game={game} />
|
|
25
|
+
<GameUi />
|
|
26
|
+
<DebugOverlay />
|
|
27
|
+
</main>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { UiLayer, useUiIntent, useUiState } from "@threenative/ui";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { type GameState, VISIBILITY_INTENT } from "../state.js";
|
|
4
|
+
import { Hud, captureScene, toggleFullscreen } from "./Hud.js";
|
|
5
|
+
import { LoadingOverlay } from "./LoadingOverlay.js";
|
|
6
|
+
import { Menu } from "./Menu.js";
|
|
7
|
+
import { automationRequest } from "./automation.js";
|
|
8
|
+
|
|
9
|
+
const TOAST_MS = 3600;
|
|
10
|
+
|
|
11
|
+
/** Below this width the study asks for the cheap tier, exactly as the source study did. */
|
|
12
|
+
const NARROW_PX = 700;
|
|
13
|
+
|
|
14
|
+
export function GameUi() {
|
|
15
|
+
return (
|
|
16
|
+
<UiLayer>
|
|
17
|
+
<RainInterface />
|
|
18
|
+
</UiLayer>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The interface, and the three things that are behaviour rather than markup.
|
|
24
|
+
*
|
|
25
|
+
* `useUiState` and `useUiIntent` need the bridge `UiLayer` opened, so they live in this inner
|
|
26
|
+
* component rather than in `GameUi` itself — a hook above the provider throws. Everything the page
|
|
27
|
+
* does that is not a control lives here: the status toast, the keyboard, and the two one-time
|
|
28
|
+
* defaults that have to be applied against a real snapshot rather than guessed at mount.
|
|
29
|
+
*/
|
|
30
|
+
function RainInterface() {
|
|
31
|
+
const state = useUiState<GameState>();
|
|
32
|
+
const send = useUiIntent();
|
|
33
|
+
const [toast, setToast] = useState("");
|
|
34
|
+
const [toastVisible, setToastVisible] = useState(false);
|
|
35
|
+
const [panelOpen, setPanelOpen] = useState(false);
|
|
36
|
+
const toastTimer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);
|
|
37
|
+
|
|
38
|
+
const say = useCallback((text: string) => {
|
|
39
|
+
setToast(text);
|
|
40
|
+
setToastVisible(true);
|
|
41
|
+
clearTimeout(toastTimer.current);
|
|
42
|
+
toastTimer.current = setTimeout(() => setToastVisible(false), TOAST_MS);
|
|
43
|
+
}, []);
|
|
44
|
+
useEffect(() => () => clearTimeout(toastTimer.current), []);
|
|
45
|
+
|
|
46
|
+
/** Photosensitivity mode; the intent itself also takes automatic lightning down. */
|
|
47
|
+
const setSafeMode = useCallback((on: boolean) => send("setSafe", on), [send]);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The status line, said on what the game reports rather than on what a control asked for: a
|
|
51
|
+
* shortcut from the game's input map and a click on the panel change the same state, so both are
|
|
52
|
+
* announced the same way, and a strike reads its distance and delay off the strike itself.
|
|
53
|
+
*/
|
|
54
|
+
const previous = useRef<GameState | undefined>(undefined);
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
const before = previous.current;
|
|
57
|
+
previous.current = state;
|
|
58
|
+
if (state === undefined || before === undefined) return;
|
|
59
|
+
const soundOn = state.audioEnabled && !state.muted;
|
|
60
|
+
if (state.safe !== before.safe)
|
|
61
|
+
say(state.safe ? "LIGHTNING DISABLED · photosensitivity mode" : "Lightning flashes enabled");
|
|
62
|
+
if (state.paused !== before.paused)
|
|
63
|
+
say(state.paused ? "SIMULATION PAUSED" : "SIMULATION RESUMED");
|
|
64
|
+
if (soundOn !== (before.audioEnabled && !before.muted))
|
|
65
|
+
say(soundOn ? "Stereo rain, wind and distance-delayed thunder enabled" : "Sound muted");
|
|
66
|
+
if (state.strikes > before.strikes) {
|
|
67
|
+
const { delay, metres } = state.lastStrike;
|
|
68
|
+
say(
|
|
69
|
+
`LIGHTNING · ${(metres / 1000).toFixed(2)} km${soundOn ? ` · thunder in ${delay.toFixed(1)} s` : ""}`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}, [say, state]);
|
|
73
|
+
|
|
74
|
+
const toggleAutoLightning = useCallback(() => {
|
|
75
|
+
if (state?.safe === true) {
|
|
76
|
+
say("Disable photosensitivity mode first to enable lightning.");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
send("setAutoLightning", state?.autoLightning !== true);
|
|
80
|
+
}, [say, send, state?.autoLightning, state?.safe]);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The keyboard, and only the keys that are browser APIs. Everything else — `W A S D`, `Q E`,
|
|
84
|
+
* `Shift`, `R`, `L`, `X`, `H`, `M` and `Space` — is the game's input map, which a native host
|
|
85
|
+
* delivers too; handling them here as well would act twice per press.
|
|
86
|
+
*/
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (state === undefined) return;
|
|
89
|
+
const actions: Record<string, () => void> = {
|
|
90
|
+
KeyF: () => void toggleFullscreen(say),
|
|
91
|
+
KeyP: () => {
|
|
92
|
+
void captureScene(say).catch((why: Error) => say(`Scene image failed: ${why.message}`));
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
96
|
+
if (event.code === "Escape") {
|
|
97
|
+
send("closeHelp");
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// A focused slider, select or text field owns its own keys.
|
|
101
|
+
const tag = document.activeElement?.tagName;
|
|
102
|
+
if (tag === "INPUT" || tag === "SELECT" || tag === "TEXTAREA") return;
|
|
103
|
+
if (event.repeat) return;
|
|
104
|
+
const run = actions[event.code];
|
|
105
|
+
if (run === undefined) return;
|
|
106
|
+
// Space scrolls the page and the shortcuts must not reach the browser's own bindings.
|
|
107
|
+
event.preventDefault();
|
|
108
|
+
run();
|
|
109
|
+
};
|
|
110
|
+
window.addEventListener("keydown", onKeyDown);
|
|
111
|
+
return () => window.removeEventListener("keydown", onKeyDown);
|
|
112
|
+
}, [say, send, state]);
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Tab visibility, held in the UI realm because `document` is a browser API: this is the only
|
|
116
|
+
* place that knows whether the frame is still on screen, and a hidden tab stops the engine loop,
|
|
117
|
+
* so nothing in a scene frame would ever notice. Separate from the pause intent on purpose — the
|
|
118
|
+
* two clear independently, and a tab that comes back must not resume a paused storm.
|
|
119
|
+
*/
|
|
120
|
+
useEffect(() => {
|
|
121
|
+
const report = () => send(VISIBILITY_INTENT, document.hidden);
|
|
122
|
+
document.addEventListener("visibilitychange", report);
|
|
123
|
+
return () => document.removeEventListener("visibilitychange", report);
|
|
124
|
+
}, [send]);
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Reduced motion, read in the UI realm and applied once. A reader who then flips a switch has
|
|
128
|
+
* said something newer than their operating system, so the preference is never re-applied over a
|
|
129
|
+
* snapshot — which is also why it needs a ref rather than an effect dependency.
|
|
130
|
+
*/
|
|
131
|
+
const reducedApplied = useRef(false);
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
if (state === undefined || reducedApplied.current) return;
|
|
134
|
+
reducedApplied.current = true;
|
|
135
|
+
if (!window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
|
|
136
|
+
send("setSafe", true);
|
|
137
|
+
send("setAutoLightning", false);
|
|
138
|
+
send("setCinematic", false);
|
|
139
|
+
}, [send, state]);
|
|
140
|
+
|
|
141
|
+
/** The first snapshot picks a tier from the width; a later choice is the player's and is kept. */
|
|
142
|
+
const qualityChosen = useRef(false);
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
if (state === undefined || qualityChosen.current) return;
|
|
145
|
+
qualityChosen.current = true;
|
|
146
|
+
// `?quality=` outranks the width default: an operator asking for `high` on a phone-sized
|
|
147
|
+
// window is asking for the tier, not for the guess this would otherwise make.
|
|
148
|
+
const asked = automationRequest(window.location.search).quality;
|
|
149
|
+
if (asked !== undefined) {
|
|
150
|
+
send("setQuality", asked);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
send("setQuality", window.innerWidth < NARROW_PX ? "performance" : "high");
|
|
154
|
+
}, [send, state]);
|
|
155
|
+
|
|
156
|
+
// Nothing yet from the game, so nothing is claimed: the engine's own loading screen is still up.
|
|
157
|
+
if (state === undefined) return null;
|
|
158
|
+
|
|
159
|
+
// Until the storm is ready, the curtain is all there is, as in the study: no controls over a
|
|
160
|
+
// world that is not on screen yet.
|
|
161
|
+
if (!state.loading.ready)
|
|
162
|
+
return <LoadingOverlay progress={state.loading.progress} ready={false} />;
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<>
|
|
166
|
+
<Hud
|
|
167
|
+
panelOpen={panelOpen}
|
|
168
|
+
say={say}
|
|
169
|
+
send={send}
|
|
170
|
+
setPanelOpen={setPanelOpen}
|
|
171
|
+
state={state}
|
|
172
|
+
toast={toast}
|
|
173
|
+
toastVisible={toastVisible}
|
|
174
|
+
/>
|
|
175
|
+
<Menu
|
|
176
|
+
panelOpen={panelOpen}
|
|
177
|
+
say={say}
|
|
178
|
+
send={send}
|
|
179
|
+
setPanelOpen={setPanelOpen}
|
|
180
|
+
setSafeMode={setSafeMode}
|
|
181
|
+
state={state}
|
|
182
|
+
toggleAutoLightning={toggleAutoLightning}
|
|
183
|
+
/>
|
|
184
|
+
<LoadingOverlay progress={state.loading.progress} ready={state.loading.ready} />
|
|
185
|
+
</>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import type { GameState } from "../state.js";
|
|
2
|
+
|
|
3
|
+
export interface IHudProps {
|
|
4
|
+
/** The game's published state. The mirror, never the live store, so it works on every target. */
|
|
5
|
+
readonly state: GameState;
|
|
6
|
+
readonly send: (intent: string, payload?: unknown) => void;
|
|
7
|
+
readonly say: (text: string) => void;
|
|
8
|
+
/** Whether the weather panel is open on a narrow screen. Pure presentation, so it is local. */
|
|
9
|
+
readonly panelOpen: boolean;
|
|
10
|
+
readonly setPanelOpen: (open: boolean) => void;
|
|
11
|
+
/** The toast line and whether it is showing. Held by `GameUi`, printed here in the sheet. */
|
|
12
|
+
readonly toast: string;
|
|
13
|
+
readonly toastVisible: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ISceneSizes {
|
|
17
|
+
readonly height: number;
|
|
18
|
+
readonly width: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** What a capture really produced: the encoded image's own size, or why there was none. */
|
|
22
|
+
export interface ICaptureResult extends ISceneSizes {
|
|
23
|
+
readonly blob?: Blob;
|
|
24
|
+
readonly bytes: number;
|
|
25
|
+
readonly ok: boolean;
|
|
26
|
+
readonly reason?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The page's own scene canvas. Null where there is no canvas to read, which is the honest answer. */
|
|
30
|
+
export function sceneCanvas(): HTMLCanvasElement | null {
|
|
31
|
+
return document.querySelector<HTMLCanvasElement>('[data-threenative-canvas="true"] canvas');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Fullscreen, as the browser actually does it, reported as what the document says afterwards.
|
|
36
|
+
*
|
|
37
|
+
* There is no engine capability for this and no cross-platform promise to make here: this is the
|
|
38
|
+
* document's own fullscreen element, so the failure is reported in the toast rather than swallowed
|
|
39
|
+
* into a button that looks like it worked, and the returned answer is the element's own state.
|
|
40
|
+
*/
|
|
41
|
+
export async function toggleFullscreen(say: (text: string) => void): Promise<boolean> {
|
|
42
|
+
try {
|
|
43
|
+
if (document.fullscreenElement === null) {
|
|
44
|
+
await document.documentElement.requestFullscreen();
|
|
45
|
+
} else {
|
|
46
|
+
await document.exitFullscreen();
|
|
47
|
+
}
|
|
48
|
+
} catch (why) {
|
|
49
|
+
say(`Fullscreen is not available in this viewer: ${(why as Error).message}`);
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const on = document.fullscreenElement !== null;
|
|
53
|
+
say(on ? "Fullscreen on" : "Fullscreen off");
|
|
54
|
+
return on;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const PNG_MAGIC = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
|
|
58
|
+
const PROBE_PX = 32;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Prove the frame is a real image rather than guessing at it.
|
|
62
|
+
*
|
|
63
|
+
* A byte floor is a guess: it rejected a valid 390x844 phone capture for being small and would
|
|
64
|
+
* have accepted a large blank one. What a blank frame actually is, is a PNG that decodes to a
|
|
65
|
+
* single flat colour — so the guard decodes the bytes and counts distinct colours. The magic bytes
|
|
66
|
+
* are read too, because a renderer that hands the page a buffer which is not a PNG at all must be
|
|
67
|
+
* named as that rather than as a dark picture.
|
|
68
|
+
*/
|
|
69
|
+
async function proveFrame(canvas: HTMLCanvasElement): Promise<ICaptureResult> {
|
|
70
|
+
const empty = { bytes: 0, height: 0, ok: false, width: 0 } as const;
|
|
71
|
+
const blob = await new Promise<Blob | null>((done) => {
|
|
72
|
+
canvas.toBlob(done, "image/png");
|
|
73
|
+
});
|
|
74
|
+
if (blob === null || blob.size === 0) return { ...empty, reason: "the canvas encoded no image" };
|
|
75
|
+
const magic = new Uint8Array(await blob.slice(0, PNG_MAGIC.length).arrayBuffer());
|
|
76
|
+
if (magic.length !== PNG_MAGIC.length || !magic.every((byte, at) => byte === PNG_MAGIC.at(at))) {
|
|
77
|
+
return { ...empty, reason: "the encoded bytes are not a PNG" };
|
|
78
|
+
}
|
|
79
|
+
const bitmap = await createImageBitmap(blob).catch(() => undefined);
|
|
80
|
+
if (bitmap === undefined) return { ...empty, reason: "the PNG did not decode" };
|
|
81
|
+
const probe = document.createElement("canvas");
|
|
82
|
+
probe.width = PROBE_PX;
|
|
83
|
+
probe.height = PROBE_PX;
|
|
84
|
+
const sampled = probe.getContext("2d", { willReadFrequently: true });
|
|
85
|
+
if (sampled === null) {
|
|
86
|
+
bitmap.close();
|
|
87
|
+
return { ...empty, reason: "no 2d context to sample the frame with" };
|
|
88
|
+
}
|
|
89
|
+
sampled.drawImage(bitmap, 0, 0, PROBE_PX, PROBE_PX);
|
|
90
|
+
bitmap.close();
|
|
91
|
+
const pixels = sampled.getImageData(0, 0, PROBE_PX, PROBE_PX).data;
|
|
92
|
+
const colours = new Set<number>();
|
|
93
|
+
for (let at = 0; at < pixels.length; at += 4) {
|
|
94
|
+
colours.add(
|
|
95
|
+
((pixels.at(at) ?? 0) << 16) | ((pixels.at(at + 1) ?? 0) << 8) | (pixels.at(at + 2) ?? 0),
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
if (colours.size < 2) {
|
|
99
|
+
return { ...empty, reason: "the frame decoded to a single flat colour" };
|
|
100
|
+
}
|
|
101
|
+
return { blob, bytes: blob.size, height: canvas.height, ok: true, width: canvas.width };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Save the frame, through the page's own canvas, and report what was really written.
|
|
106
|
+
*
|
|
107
|
+
* A WebGPU canvas can hand the page a blank read, so the image is proved before the download is
|
|
108
|
+
* offered rather than after: the toast carries the encoded size and a failed read says why.
|
|
109
|
+
*/
|
|
110
|
+
export async function captureScene(say: (text: string) => void): Promise<ICaptureResult> {
|
|
111
|
+
const canvas = sceneCanvas();
|
|
112
|
+
const result =
|
|
113
|
+
canvas === null
|
|
114
|
+
? ({ bytes: 0, height: 0, ok: false, reason: "no scene canvas", width: 0 } as const)
|
|
115
|
+
: await proveFrame(canvas);
|
|
116
|
+
if (!result.ok || result.blob === undefined) {
|
|
117
|
+
say(`Scene image unavailable: ${result.reason ?? "unknown"}`);
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
const url = URL.createObjectURL(result.blob);
|
|
121
|
+
const link = document.createElement("a");
|
|
122
|
+
link.download = `rain-${Date.now()}.png`;
|
|
123
|
+
link.href = url;
|
|
124
|
+
link.click();
|
|
125
|
+
URL.revokeObjectURL(url);
|
|
126
|
+
say(`Scene image saved · ${result.width}x${result.height} · ${result.bytes} bytes`);
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The parts of the interface that are not the weather panel: the topbar and its controls, the
|
|
132
|
+
* compass, the hero title, the sound pill, the telemetry footer, the status toast, and the button
|
|
133
|
+
* that brings a hidden interface back.
|
|
134
|
+
*
|
|
135
|
+
* Every readout is the game's published value — the live atmosphere for telemetry, the mirrored
|
|
136
|
+
* booleans for the controls — so nothing here can drift from what the simulation is doing.
|
|
137
|
+
*/
|
|
138
|
+
export function Hud({ send, say, panelOpen, setPanelOpen, state, toast, toastVisible }: IHudProps) {
|
|
139
|
+
const soundOn = state.audioEnabled && !state.muted;
|
|
140
|
+
return (
|
|
141
|
+
<>
|
|
142
|
+
<div className={`interface${state.uiHidden ? " hidden" : ""}`}>
|
|
143
|
+
<header className="topbar">
|
|
144
|
+
<div className="brand">
|
|
145
|
+
<div className="mark">
|
|
146
|
+
<svg
|
|
147
|
+
width="20"
|
|
148
|
+
height="20"
|
|
149
|
+
viewBox="0 0 24 24"
|
|
150
|
+
fill="none"
|
|
151
|
+
stroke="currentColor"
|
|
152
|
+
strokeWidth="1"
|
|
153
|
+
aria-hidden="true"
|
|
154
|
+
>
|
|
155
|
+
<path d="M6 15a4 4 0 0 1 0-8 6 6 0 0 1 11.4-.5A4.5 4.5 0 0 1 18 15M10 12l-2 5h4l-2 5" />
|
|
156
|
+
</svg>
|
|
157
|
+
</div>
|
|
158
|
+
<div>
|
|
159
|
+
<div className="brand-title">ATMOSPHERICS</div>
|
|
160
|
+
<div className="brand-sub">INTERACTIVE FIELD STUDIES / 001</div>
|
|
161
|
+
</div>
|
|
162
|
+
</div>
|
|
163
|
+
<div className="top-actions">
|
|
164
|
+
<div className="status">
|
|
165
|
+
<span className="dot" />
|
|
166
|
+
REALTIME ENVIRONMENT
|
|
167
|
+
</div>
|
|
168
|
+
<button
|
|
169
|
+
aria-label="Toggle weather controls"
|
|
170
|
+
className="icon-btn panel-toggle"
|
|
171
|
+
data-tn-interactive
|
|
172
|
+
onClick={() => setPanelOpen(!panelOpen)}
|
|
173
|
+
title="Weather controls"
|
|
174
|
+
type="button"
|
|
175
|
+
>
|
|
176
|
+
<svg aria-hidden="true" viewBox="0 0 24 24">
|
|
177
|
+
<path d="M4 7h16M4 17h16" />
|
|
178
|
+
<circle cx="9" cy="7" r="2" />
|
|
179
|
+
<circle cx="15" cy="17" r="2" />
|
|
180
|
+
</svg>
|
|
181
|
+
</button>
|
|
182
|
+
<button
|
|
183
|
+
aria-label={state.paused ? "Resume simulation" : "Pause simulation"}
|
|
184
|
+
aria-pressed={state.paused}
|
|
185
|
+
className={`icon-btn${state.paused ? " active" : ""}`}
|
|
186
|
+
data-tn-interactive
|
|
187
|
+
onClick={() => send(state.paused ? "resume" : "pause")}
|
|
188
|
+
title="Pause [Space]"
|
|
189
|
+
type="button"
|
|
190
|
+
>
|
|
191
|
+
<svg aria-hidden="true" viewBox="0 0 24 24">
|
|
192
|
+
<path d="M9 5v14M15 5v14" />
|
|
193
|
+
</svg>
|
|
194
|
+
</button>
|
|
195
|
+
<button
|
|
196
|
+
aria-label="Save scene image"
|
|
197
|
+
className="icon-btn desktop"
|
|
198
|
+
data-tn-interactive
|
|
199
|
+
onClick={() => captureScene(say)}
|
|
200
|
+
title="Save scene image [P]"
|
|
201
|
+
type="button"
|
|
202
|
+
>
|
|
203
|
+
<svg aria-hidden="true" viewBox="0 0 24 24">
|
|
204
|
+
<path d="M4 7h4l2-3h4l2 3h4v13H4z" />
|
|
205
|
+
<circle cx="12" cy="13" r="4" />
|
|
206
|
+
</svg>
|
|
207
|
+
</button>
|
|
208
|
+
<button
|
|
209
|
+
aria-label="Fullscreen"
|
|
210
|
+
className="icon-btn desktop"
|
|
211
|
+
data-tn-interactive
|
|
212
|
+
onClick={() => {
|
|
213
|
+
void toggleFullscreen(say);
|
|
214
|
+
}}
|
|
215
|
+
title="Fullscreen [F]"
|
|
216
|
+
type="button"
|
|
217
|
+
>
|
|
218
|
+
<svg aria-hidden="true" viewBox="0 0 24 24">
|
|
219
|
+
<path d="M9 4H4v5m11-5h5v5M4 15v5h5m11-5v5h-5" />
|
|
220
|
+
</svg>
|
|
221
|
+
</button>
|
|
222
|
+
<button
|
|
223
|
+
aria-label="Controls and accessibility"
|
|
224
|
+
className="icon-btn"
|
|
225
|
+
data-tn-interactive
|
|
226
|
+
onClick={() => send("help")}
|
|
227
|
+
title="Controls and accessibility"
|
|
228
|
+
type="button"
|
|
229
|
+
>
|
|
230
|
+
<svg aria-hidden="true" viewBox="0 0 24 24">
|
|
231
|
+
<circle cx="12" cy="12" r="9" />
|
|
232
|
+
<path d="M9.5 8.5a2.5 2.5 0 0 1 5 0c0 2-2.5 2-2.5 4M12 16h.01" />
|
|
233
|
+
</svg>
|
|
234
|
+
</button>
|
|
235
|
+
</div>
|
|
236
|
+
</header>
|
|
237
|
+
|
|
238
|
+
<div className="compass">
|
|
239
|
+
<div className="letters">
|
|
240
|
+
<span>NW</span>
|
|
241
|
+
<span>{state.heading}°</span>
|
|
242
|
+
<span>NE</span>
|
|
243
|
+
</div>
|
|
244
|
+
<div className="ticks" />
|
|
245
|
+
</div>
|
|
246
|
+
|
|
247
|
+
<section className="hero">
|
|
248
|
+
<div className="eyebrow">A COASTAL WEATHER STUDY</div>
|
|
249
|
+
<h1>TEMPEST</h1>
|
|
250
|
+
<p>Somewhere between stillness and the storm.</p>
|
|
251
|
+
</section>
|
|
252
|
+
|
|
253
|
+
<footer className="bottom-bar">
|
|
254
|
+
<div className="telemetry">
|
|
255
|
+
<div>
|
|
256
|
+
<div className="metric-label">PRECIPITATION</div>
|
|
257
|
+
<div className="metric-value">
|
|
258
|
+
<span>{(state.weather.rain * 48).toFixed(1)}</span>
|
|
259
|
+
<small>mm/h</small>
|
|
260
|
+
</div>
|
|
261
|
+
</div>
|
|
262
|
+
<div>
|
|
263
|
+
<div className="metric-label">WIND SPEED</div>
|
|
264
|
+
<div className="metric-value">
|
|
265
|
+
<span>{(state.weather.wind * 72).toFixed(1)}</span>
|
|
266
|
+
<small>km/h</small>
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
<div>
|
|
270
|
+
<div className="metric-label">FRAME RATE</div>
|
|
271
|
+
<div className="metric-value">
|
|
272
|
+
<span>{state.fps > 0 ? Math.round(state.fps) : "—"}</span>
|
|
273
|
+
<small>fps</small>
|
|
274
|
+
</div>
|
|
275
|
+
</div>
|
|
276
|
+
</div>
|
|
277
|
+
{/* The pill and the key hints share one column, so neither can be drawn over the other or
|
|
278
|
+
over the panel above them however short the window is. */}
|
|
279
|
+
<div className="bottom-actions">
|
|
280
|
+
<button
|
|
281
|
+
aria-label={soundOn ? "Mute rain and thunder audio" : "Enable rain and thunder audio"}
|
|
282
|
+
aria-pressed={soundOn}
|
|
283
|
+
className={`sound-pill${soundOn ? " active" : ""}`}
|
|
284
|
+
data-tn-interactive
|
|
285
|
+
id="sound"
|
|
286
|
+
onClick={() => {
|
|
287
|
+
if (soundOn) {
|
|
288
|
+
send("setMuted", true);
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
send("setAudioEnabled", true);
|
|
292
|
+
send("setMuted", false);
|
|
293
|
+
}}
|
|
294
|
+
type="button"
|
|
295
|
+
>
|
|
296
|
+
<span className="sound-wave">
|
|
297
|
+
<span />
|
|
298
|
+
<span />
|
|
299
|
+
<span />
|
|
300
|
+
<span />
|
|
301
|
+
</span>
|
|
302
|
+
<span>{soundOn ? "SOUND ON" : "ENABLE SOUND"}</span>
|
|
303
|
+
</button>
|
|
304
|
+
<div className="key-hint">
|
|
305
|
+
<kbd>DRAG</kbd> LOOK <kbd>W A S D</kbd> MOVE <kbd>Q E</kbd> ALTITUDE
|
|
306
|
+
<br />
|
|
307
|
+
<kbd>H</kbd> HIDE INTERFACE <kbd>R</kbd> RESET CAMERA
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
</footer>
|
|
311
|
+
|
|
312
|
+
<output aria-live="polite" className={`toast${toastVisible ? " visible" : ""}`}>
|
|
313
|
+
{toast}
|
|
314
|
+
</output>
|
|
315
|
+
</div>
|
|
316
|
+
{/* Outside the sheet, because the sheet is hidden when this is the way back. */}
|
|
317
|
+
<button
|
|
318
|
+
className={`restore${state.uiHidden ? " visible" : ""}`}
|
|
319
|
+
data-tn-interactive
|
|
320
|
+
onClick={() => send("showUi")}
|
|
321
|
+
type="button"
|
|
322
|
+
>
|
|
323
|
+
SHOW INTERFACE · H
|
|
324
|
+
</button>
|
|
325
|
+
</>
|
|
326
|
+
);
|
|
327
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/** How long the curtain fades once the storm is ready; matches `.loading`'s CSS transition. */
|
|
4
|
+
const FADE_MS = 800;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The study's staged loading overlay, over the engine's own loading bar until the frame the storm
|
|
8
|
+
* is ready. The stages are read off the engine's real startup progress, so the text never claims a
|
|
9
|
+
* stage the launch has not reached. It paints only its text over the engine's own opaque loading
|
|
10
|
+
* screen (the same night colour), and once faded it leaves the page entirely.
|
|
11
|
+
*/
|
|
12
|
+
export function LoadingOverlay({ progress, ready }: { progress: number; ready: boolean }) {
|
|
13
|
+
const [removed, setRemoved] = useState(false);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (!ready) return;
|
|
16
|
+
const timer = setTimeout(() => setRemoved(true), FADE_MS);
|
|
17
|
+
return () => clearTimeout(timer);
|
|
18
|
+
}, [ready]);
|
|
19
|
+
if (removed) return null;
|
|
20
|
+
|
|
21
|
+
const stage = ready
|
|
22
|
+
? "ENTERING THE STORM"
|
|
23
|
+
: progress < 0.34
|
|
24
|
+
? "BUILDING THE CLOUD VOLUME"
|
|
25
|
+
: progress < 0.67
|
|
26
|
+
? "LIGHTING THE COAST"
|
|
27
|
+
: "ENTERING THE STORM";
|
|
28
|
+
return (
|
|
29
|
+
<div aria-busy={!ready} aria-hidden={ready} className={`loading${ready ? " gone" : ""}`}>
|
|
30
|
+
{/* The progress line itself is the engine's canvas loading bar, centred between these two. */}
|
|
31
|
+
<div className="loading-head">
|
|
32
|
+
<div className="loading-title">TEMPEST</div>
|
|
33
|
+
<div aria-live="polite" className="loading-text">
|
|
34
|
+
{stage}
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
<div className="loading-note">
|
|
38
|
+
A procedural, real-time weather study.
|
|
39
|
+
<br />
|
|
40
|
+
Contains lightning flashes. Disable them in
|
|
41
|
+
<br />
|
|
42
|
+
Rendering & Accessibility or press <kbd>X</kbd>.
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|