@kuncat/avoidant 0.1.5 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/dist/components/AvoidantGame.svelte +240 -148
- package/dist/components/IdleBillboard.svelte +27 -0
- package/dist/components/IdleBillboard.svelte.d.ts +8 -0
- package/dist/components/MapControls.svelte +158 -0
- package/dist/components/MapControls.svelte.d.ts +7 -0
- package/dist/components/board.svelte +241 -100
- package/dist/components/board.svelte.d.ts +3 -0
- package/dist/components/fragment.glsl +29 -19
- package/dist/components/map-camera.d.ts +10 -0
- package/dist/components/map-camera.js +73 -0
- package/dist/components/terrain-depth-sort.d.ts +17 -0
- package/dist/components/terrain-depth-sort.js +63 -0
- package/dist/components/vertex.glsl +12 -7
- package/dist/generated/shared-constants.d.ts +0 -3
- package/dist/generated/shared-constants.js +0 -3
- package/dist/paraglide/messages/_index.d.ts +14 -0
- package/dist/paraglide/messages/_index.js +15 -1
- package/dist/paraglide/messages/cells_per_face.d.ts +18 -0
- package/dist/paraglide/messages/cells_per_face.js +29 -0
- package/dist/paraglide/messages/faces_count.d.ts +18 -0
- package/dist/paraglide/messages/faces_count.js +29 -0
- package/dist/paraglide/messages/field_cell_density.d.ts +16 -0
- package/dist/paraglide/messages/field_cell_density.js +29 -0
- package/dist/paraglide/messages/field_map_shape.d.ts +16 -0
- package/dist/paraglide/messages/field_map_shape.js +29 -0
- package/dist/paraglide/messages/field_radius.d.ts +16 -0
- package/dist/paraglide/messages/field_radius.js +29 -0
- package/dist/paraglide/messages/field_radius_x.d.ts +16 -0
- package/dist/paraglide/messages/field_radius_x.js +29 -0
- package/dist/paraglide/messages/field_radius_y.d.ts +16 -0
- package/dist/paraglide/messages/field_radius_y.js +29 -0
- package/dist/paraglide/messages/field_radius_z.d.ts +16 -0
- package/dist/paraglide/messages/field_radius_z.js +29 -0
- package/dist/paraglide/messages/field_spikiness.d.ts +16 -0
- package/dist/paraglide/messages/field_spikiness.js +29 -0
- package/dist/paraglide/messages/field_subdivisions.d.ts +16 -0
- package/dist/paraglide/messages/field_subdivisions.js +29 -0
- package/dist/paraglide/messages/field_surface_detail.d.ts +16 -0
- package/dist/paraglide/messages/field_surface_detail.js +29 -0
- package/dist/paraglide/messages/shape_label.d.ts +26 -0
- package/dist/paraglide/messages/shape_label.js +55 -0
- package/dist/paraglide/messages/text_density_summary.d.ts +19 -0
- package/dist/paraglide/messages/text_density_summary.js +29 -0
- package/dist/paraglide/messages/text_invite_after_opening.d.ts +16 -0
- package/dist/paraglide/messages/text_invite_after_opening.js +29 -0
- package/dist/paraglide/messages/tutorial_intro.d.ts +1 -1
- package/dist/paraglide/messages/tutorial_intro.js +3 -3
- package/dist/wasm/avoidant_wasm.d.ts +77 -35
- package/dist/wasm/avoidant_wasm.js +236 -223
- package/dist/wasm/avoidant_wasm_bg.wasm +0 -0
- package/dist/wasm/avoidant_wasm_bg.wasm.d.ts +27 -27
- package/dist/workers/mapgen-client.js +2 -0
- package/dist/workers/mapgen.worker.d.ts +2 -0
- package/dist/workers/mapgen.worker.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,3 +60,29 @@ You can preview the production build with `npm run preview`.
|
|
|
60
60
|
```
|
|
61
61
|
cd crates/game && wasm-pack test --headless --firefox
|
|
62
62
|
```
|
|
63
|
+
|
|
64
|
+
## Multiplayer synchronization
|
|
65
|
+
|
|
66
|
+
The player who creates the game is its authority and must remain online. Invitations
|
|
67
|
+
become available after the safe opening move. Invitees rebuild the same map and void
|
|
68
|
+
layout, then wait for the host's complete explored-cell and score snapshot before
|
|
69
|
+
playing. Create fresh invitations after updating from older protocol versions.
|
|
70
|
+
|
|
71
|
+
Moves carry request IDs. The host applies each request once and publishes a numbered
|
|
72
|
+
snapshot; peers ignore older snapshots. Requests and snapshots are retried every
|
|
73
|
+
three seconds, including after a reconnect. Reveal animations only update display
|
|
74
|
+
flags; they cannot change the canonical board, score, streak, or completion state.
|
|
75
|
+
Host migration and playing offline as a guest are not supported.
|
|
76
|
+
|
|
77
|
+
Native synchronization regression tests:
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
cargo test -p avoidant --lib
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
WASM integration test (Node.js, with the matching wasm-bindgen-test-runner on PATH):
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
NODE_PATH="$PWD/node_modules" CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner \
|
|
87
|
+
cargo test -p avoidant --lib --target wasm32-unknown-unknown
|
|
88
|
+
```
|
|
@@ -1,38 +1,47 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount } from "svelte";
|
|
3
|
+
import { devicePixelRatio } from "svelte/reactivity/window";
|
|
3
4
|
import { slide } from "svelte/transition";
|
|
4
5
|
import { SvelteSet } from "svelte/reactivity";
|
|
5
|
-
import init, {
|
|
6
|
+
import init, {
|
|
7
|
+
GameState,
|
|
8
|
+
type GameOptions,
|
|
9
|
+
type MapData,
|
|
10
|
+
type MapShape,
|
|
11
|
+
} from "../wasm/avoidant_wasm";
|
|
6
12
|
import { Canvas, T } from "@threlte/core";
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
13
|
+
import MapControls from "./MapControls.svelte";
|
|
14
|
+
import { WebGLRenderer } from "three";
|
|
9
15
|
import Board from "./board.svelte";
|
|
10
|
-
import { MAP_HEIGHT, MAP_WIDTH } from "../generated/shared-constants";
|
|
11
16
|
import { m } from "../paraglide/messages";
|
|
12
17
|
import { getLocale, locales, setLocale } from "../paraglide/runtime";
|
|
13
18
|
import { generateMap } from "../workers/mapgen-client";
|
|
14
19
|
import { TutorialState } from "../tutorial.svelte";
|
|
15
20
|
|
|
21
|
+
const SETTINGS_STORAGE_KEY = "avoidant:gameSettings:v1";
|
|
16
22
|
const PLAYER_NAME_STORAGE_KEY = "avoidant:playerName";
|
|
17
23
|
const SIZE_PRESETS = { small: 80, medium: 160, large: 320 } as const;
|
|
18
|
-
const MAP_MIN_X = 0;
|
|
19
|
-
const MAP_MIN_Z = 0;
|
|
20
|
-
const MAP_MAX_X = MAP_MIN_X + MAP_WIDTH;
|
|
21
|
-
const MAP_MAX_Z = MAP_MIN_Z + MAP_HEIGHT;
|
|
22
|
-
const MAP_CENTER_X = MAP_MIN_X + MAP_WIDTH / 2;
|
|
23
|
-
const MAP_CENTER_Z = MAP_MIN_Z + MAP_HEIGHT / 2;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const CAMERA_ORBIT_RADIUS = 240;
|
|
25
|
+
// Default mapshape parameters used when a preset is picked or no custom value has been entered yet.
|
|
26
|
+
const DEFAULT_RADIUS = 50;
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
type ShapeKind = MapShape["kind"];
|
|
29
|
+
const SHAPE_KINDS: ShapeKind[] = [
|
|
30
|
+
"flat",
|
|
31
|
+
"icosahedron",
|
|
32
|
+
"spheroid",
|
|
33
|
+
"geodesicIcosphere",
|
|
34
|
+
"tetrahedron",
|
|
35
|
+
"cube",
|
|
36
|
+
"octahedron",
|
|
37
|
+
"dodecahedron",
|
|
34
38
|
];
|
|
35
39
|
|
|
40
|
+
const CAMERA_AZIMUTH_RAD = Math.PI / 4;
|
|
41
|
+
const CAMERA_ELEVATION_RAD = Math.atan(0.5);
|
|
42
|
+
/// Camera orbit distance, derived from the generated map's bounds radius so the camera frames any 3D shape consistently.
|
|
43
|
+
const CAMERA_ORBIT_MULTIPLIER = 2.5;
|
|
44
|
+
|
|
36
45
|
type SizePreset = keyof typeof SIZE_PRESETS | "custom";
|
|
37
46
|
type Locale = (typeof locales)[number];
|
|
38
47
|
type AvoidantGameProps = {
|
|
@@ -68,14 +77,17 @@
|
|
|
68
77
|
let status: string | undefined = $state(undefined);
|
|
69
78
|
let gameState = $state<GameState | undefined>(undefined);
|
|
70
79
|
let terrain = $state<MapData["terrain"] | undefined>(undefined);
|
|
80
|
+
let surfaceArea = $state(0);
|
|
81
|
+
let isFlatMap = $state(false);
|
|
82
|
+
let boundsRadius = $state(DEFAULT_RADIUS);
|
|
71
83
|
let numCellsInput = $state(SIZE_PRESETS.medium);
|
|
72
84
|
let voidFractionInput = $state(0.15625);
|
|
85
|
+
let spikinessInput = $state(0.8);
|
|
73
86
|
let rngSeedInput = $state(0);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
);
|
|
87
|
+
// Shape selection state. The shape kind drives which numeric inputs are shown; each per-shape numeric value persists independently so switching back and forth doesn't reset the user's edits.
|
|
88
|
+
let shapeKindInput = $state<ShapeKind>("icosahedron");
|
|
89
|
+
let playerNameInput = $state<string>(m.default_player_name());
|
|
90
|
+
let settingsLoaded = $state(false);
|
|
79
91
|
let isTutorialMode = $state(false);
|
|
80
92
|
let tutorial = $state<TutorialState | undefined>(undefined);
|
|
81
93
|
let exploredCellsSeen = new SvelteSet<number>();
|
|
@@ -84,7 +96,6 @@
|
|
|
84
96
|
let sizePreset = $state<SizePreset>("medium");
|
|
85
97
|
let isAdvancedSettingsOpen = $state(false);
|
|
86
98
|
let relayServersInput = $state("");
|
|
87
|
-
let relayServersInitialized = false;
|
|
88
99
|
let hasRelayServersConfigured = $derived(parseRelayServersInput(relayServersInput).length > 0);
|
|
89
100
|
let ticketInput = $state("");
|
|
90
101
|
let joinError: string | undefined = $state(undefined);
|
|
@@ -111,6 +122,63 @@
|
|
|
111
122
|
);
|
|
112
123
|
let cameraFov = $state(50);
|
|
113
124
|
|
|
125
|
+
let selectedCellCount = $derived(
|
|
126
|
+
sizePreset === "custom" ? numCellsInput : SIZE_PRESETS[sizePreset],
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
let shapeSubdivisionsInput = $derived(
|
|
130
|
+
Math.max(
|
|
131
|
+
0,
|
|
132
|
+
Math.min(2, Math.floor(Math.log(Math.max(1, selectedCellCount / 80)) / Math.log(4))),
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
let faceCount = $derived(
|
|
137
|
+
{
|
|
138
|
+
tetrahedron: 4,
|
|
139
|
+
cube: 6,
|
|
140
|
+
octahedron: 8,
|
|
141
|
+
dodecahedron: 12,
|
|
142
|
+
icosahedron: 20,
|
|
143
|
+
geodesicIcosphere: 20 * 4 ** shapeSubdivisionsInput,
|
|
144
|
+
flat: 0,
|
|
145
|
+
spheroid: 0,
|
|
146
|
+
}[shapeKindInput],
|
|
147
|
+
);
|
|
148
|
+
let usesFaceDensity = $derived(faceCount > 0);
|
|
149
|
+
|
|
150
|
+
function resolveShape(): MapShape {
|
|
151
|
+
const radius = DEFAULT_RADIUS * Math.sqrt(selectedCellCount / SIZE_PRESETS.medium);
|
|
152
|
+
switch (shapeKindInput) {
|
|
153
|
+
case "spheroid":
|
|
154
|
+
return {
|
|
155
|
+
kind: "spheroid",
|
|
156
|
+
radiusX: radius * 1.2,
|
|
157
|
+
radiusY: radius * 0.8,
|
|
158
|
+
radiusZ: radius,
|
|
159
|
+
};
|
|
160
|
+
case "geodesicIcosphere":
|
|
161
|
+
return {
|
|
162
|
+
kind: "geodesicIcosphere",
|
|
163
|
+
radius,
|
|
164
|
+
subdivisions: shapeSubdivisionsInput,
|
|
165
|
+
};
|
|
166
|
+
default:
|
|
167
|
+
return { kind: shapeKindInput, radius };
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let cameraOrbitRadius = $derived(Math.max(1, boundsRadius) * CAMERA_ORBIT_MULTIPLIER);
|
|
172
|
+
let cameraPosition = $derived<[number, number, number]>(
|
|
173
|
+
isFlatMap
|
|
174
|
+
? [0, cameraOrbitRadius, 0.0001]
|
|
175
|
+
: [
|
|
176
|
+
Math.cos(CAMERA_ELEVATION_RAD) * Math.sin(CAMERA_AZIMUTH_RAD) * cameraOrbitRadius,
|
|
177
|
+
Math.sin(CAMERA_ELEVATION_RAD) * cameraOrbitRadius,
|
|
178
|
+
Math.cos(CAMERA_ELEVATION_RAD) * Math.cos(CAMERA_AZIMUTH_RAD) * cameraOrbitRadius,
|
|
179
|
+
],
|
|
180
|
+
);
|
|
181
|
+
|
|
114
182
|
function toggleScoreBreakdown() {
|
|
115
183
|
isScoreBreakdownPinned = !isScoreBreakdownPinned;
|
|
116
184
|
}
|
|
@@ -122,78 +190,70 @@
|
|
|
122
190
|
}
|
|
123
191
|
}
|
|
124
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Pick a perspective FOV so the bounding sphere of the generated shape (including the maximum elevation displacement) fits the viewport on both axes, with a small margin so cells near the silhouette aren't clipped.
|
|
195
|
+
*/
|
|
125
196
|
function calculateCoverFov(
|
|
126
197
|
viewportWidth: number,
|
|
127
198
|
viewportHeight: number,
|
|
128
|
-
|
|
129
|
-
|
|
199
|
+
contentRadius: number,
|
|
200
|
+
cameraDistance: number,
|
|
130
201
|
): number {
|
|
131
|
-
const forwardX = -Math.cos(CAMERA_ELEVATION_RAD) * Math.sin(CAMERA_AZIMUTH_RAD);
|
|
132
|
-
const forwardY = -Math.sin(CAMERA_ELEVATION_RAD);
|
|
133
|
-
const forwardZ = -Math.cos(CAMERA_ELEVATION_RAD) * Math.cos(CAMERA_AZIMUTH_RAD);
|
|
134
|
-
|
|
135
|
-
const rightX = -forwardZ;
|
|
136
|
-
const rightZ = forwardX;
|
|
137
|
-
const rightLength = Math.hypot(rightX, rightZ);
|
|
138
|
-
const normalizedRightX = rightX / rightLength;
|
|
139
|
-
const normalizedRightZ = rightZ / rightLength;
|
|
140
|
-
|
|
141
|
-
const upX = normalizedRightZ * forwardY;
|
|
142
|
-
const upY = -(normalizedRightX * forwardZ - normalizedRightZ * forwardX);
|
|
143
|
-
const upZ = -normalizedRightX * forwardY;
|
|
144
|
-
|
|
145
|
-
const yMin = Math.min(elevationMin, elevationMax);
|
|
146
|
-
const yMax = Math.max(elevationMin, elevationMax);
|
|
147
|
-
const corners = [
|
|
148
|
-
[MAP_MIN_X, yMin, MAP_MIN_Z],
|
|
149
|
-
[MAP_MIN_X, yMin, MAP_MAX_Z],
|
|
150
|
-
[MAP_MAX_X, yMin, MAP_MIN_Z],
|
|
151
|
-
[MAP_MAX_X, yMin, MAP_MAX_Z],
|
|
152
|
-
[MAP_MIN_X, yMax, MAP_MIN_Z],
|
|
153
|
-
[MAP_MIN_X, yMax, MAP_MAX_Z],
|
|
154
|
-
[MAP_MAX_X, yMax, MAP_MIN_Z],
|
|
155
|
-
[MAP_MAX_X, yMax, MAP_MAX_Z],
|
|
156
|
-
];
|
|
157
|
-
|
|
158
|
-
let minRight = Infinity;
|
|
159
|
-
let maxRight = -Infinity;
|
|
160
|
-
let minUp = Infinity;
|
|
161
|
-
let maxUp = -Infinity;
|
|
162
|
-
|
|
163
|
-
for (const [x, y, z] of corners) {
|
|
164
|
-
const projectedRight = x * normalizedRightX + z * normalizedRightZ;
|
|
165
|
-
const projectedUp = x * upX + y * upY + z * upZ;
|
|
166
|
-
minRight = Math.min(minRight, projectedRight);
|
|
167
|
-
maxRight = Math.max(maxRight, projectedRight);
|
|
168
|
-
minUp = Math.min(minUp, projectedUp);
|
|
169
|
-
maxUp = Math.max(maxUp, projectedUp);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const projectedWidth = Math.max(1e-6, maxRight - minRight);
|
|
173
|
-
const projectedHeight = Math.max(1e-6, maxUp - minUp);
|
|
174
|
-
|
|
175
202
|
const aspect = Math.max(1e-6, viewportWidth / viewportHeight);
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const verticalFovForWidth =
|
|
180
|
-
|
|
203
|
+
// Vertical FOV that exactly fits the bounding sphere's diameter on screen.
|
|
204
|
+
const verticalFov = 2 * Math.atan(contentRadius / Math.max(1e-6, cameraDistance));
|
|
205
|
+
// Adjust for the viewport aspect ratio so the sphere fits horizontally too.
|
|
206
|
+
const verticalFovForWidth =
|
|
207
|
+
2 * Math.atan(contentRadius / (Math.max(1e-6, cameraDistance) * aspect));
|
|
208
|
+
const coverFovRadians = Math.max(verticalFov, verticalFovForWidth);
|
|
181
209
|
const coverFovDegrees = (coverFovRadians * 180) / Math.PI;
|
|
182
|
-
|
|
210
|
+
// Add 5% margin so silhouette cells aren't clipped at the viewport edges.
|
|
211
|
+
return Math.min(120, Math.max(10, coverFovDegrees * 1.05));
|
|
183
212
|
}
|
|
184
213
|
|
|
185
214
|
function setInitialCameraFov() {
|
|
186
215
|
if (typeof window !== "undefined") {
|
|
187
216
|
const viewportWidth = Math.max(1, window.innerWidth);
|
|
188
217
|
const viewportHeight = Math.max(1, window.innerHeight);
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
cameraFov = calculateCoverFov(
|
|
218
|
+
const elevationMax = Math.abs(gameState?.elevationMax ?? 0);
|
|
219
|
+
const contentRadius = boundsRadius + elevationMax;
|
|
220
|
+
cameraFov = calculateCoverFov(
|
|
221
|
+
viewportWidth,
|
|
222
|
+
viewportHeight,
|
|
223
|
+
contentRadius,
|
|
224
|
+
cameraOrbitRadius,
|
|
225
|
+
);
|
|
192
226
|
}
|
|
193
227
|
}
|
|
194
228
|
|
|
195
229
|
onMount(() => {
|
|
196
230
|
rngSeedInput = Math.floor(Date.now() / 1000);
|
|
231
|
+
relayServersInput = normalizeRelayServerList(relayServers).join("\n");
|
|
232
|
+
try {
|
|
233
|
+
playerNameInput = localStorage.getItem(PLAYER_NAME_STORAGE_KEY) ?? playerNameInput;
|
|
234
|
+
const saved = JSON.parse(localStorage.getItem(SETTINGS_STORAGE_KEY) ?? "null");
|
|
235
|
+
if (saved && typeof saved === "object" && !Array.isArray(saved)) {
|
|
236
|
+
if (SHAPE_KINDS.includes(saved.shapeKind)) shapeKindInput = saved.shapeKind;
|
|
237
|
+
if (["small", "medium", "large", "custom"].includes(saved.sizePreset))
|
|
238
|
+
sizePreset = saved.sizePreset;
|
|
239
|
+
if (Number.isInteger(saved.numCells) && saved.numCells >= 32 && saved.numCells <= 5000)
|
|
240
|
+
numCellsInput = saved.numCells;
|
|
241
|
+
if (
|
|
242
|
+
typeof saved.voidFraction === "number" &&
|
|
243
|
+
saved.voidFraction >= 0 &&
|
|
244
|
+
saved.voidFraction <= 0.999
|
|
245
|
+
)
|
|
246
|
+
voidFractionInput = saved.voidFraction;
|
|
247
|
+
if (typeof saved.spikiness === "number" && saved.spikiness >= 0 && saved.spikiness <= 1)
|
|
248
|
+
spikinessInput = saved.spikiness;
|
|
249
|
+
if (Number.isSafeInteger(saved.rngSeed) && saved.rngSeed >= 0) rngSeedInput = saved.rngSeed;
|
|
250
|
+
if (typeof saved.relayServers === "string") relayServersInput = saved.relayServers;
|
|
251
|
+
if (typeof saved.tutorialMode === "boolean") isTutorialMode = saved.tutorialMode;
|
|
252
|
+
}
|
|
253
|
+
} catch {
|
|
254
|
+
// Storage may be unavailable or contain malformed data; keep usable defaults.
|
|
255
|
+
}
|
|
256
|
+
settingsLoaded = true;
|
|
197
257
|
|
|
198
258
|
const initializeWasm = async () => {
|
|
199
259
|
try {
|
|
@@ -217,15 +277,6 @@
|
|
|
217
277
|
void initializeWasm();
|
|
218
278
|
});
|
|
219
279
|
|
|
220
|
-
$effect(() => {
|
|
221
|
-
if (relayServersInitialized) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
relayServersInput = normalizeRelayServerList(relayServers).join("\n");
|
|
226
|
-
relayServersInitialized = true;
|
|
227
|
-
});
|
|
228
|
-
|
|
229
280
|
$effect(() => {
|
|
230
281
|
if (!gameState) return;
|
|
231
282
|
setInitialCameraFov();
|
|
@@ -238,11 +289,22 @@
|
|
|
238
289
|
});
|
|
239
290
|
|
|
240
291
|
$effect(() => {
|
|
241
|
-
if (
|
|
292
|
+
if (settingsLoaded) {
|
|
293
|
+
const settings = {
|
|
294
|
+
shapeKind: shapeKindInput,
|
|
295
|
+
sizePreset,
|
|
296
|
+
numCells: numCellsInput,
|
|
297
|
+
voidFraction: voidFractionInput,
|
|
298
|
+
spikiness: spikinessInput,
|
|
299
|
+
rngSeed: rngSeedInput,
|
|
300
|
+
relayServers: relayServersInput,
|
|
301
|
+
tutorialMode: isTutorialMode,
|
|
302
|
+
};
|
|
242
303
|
try {
|
|
243
304
|
localStorage.setItem(PLAYER_NAME_STORAGE_KEY, playerNameInput);
|
|
305
|
+
localStorage.setItem(SETTINGS_STORAGE_KEY, JSON.stringify(settings));
|
|
244
306
|
} catch (error) {
|
|
245
|
-
console.warn("Failed to persist
|
|
307
|
+
console.warn("Failed to persist game settings", error);
|
|
246
308
|
}
|
|
247
309
|
}
|
|
248
310
|
});
|
|
@@ -343,30 +405,38 @@
|
|
|
343
405
|
];
|
|
344
406
|
|
|
345
407
|
async function startGame() {
|
|
408
|
+
if (status) return;
|
|
409
|
+
let nextGameState: GameState | undefined;
|
|
346
410
|
try {
|
|
347
|
-
const resolvedNumCells =
|
|
348
|
-
sizePreset === "custom" ? $state.snapshot(numCellsInput) : SIZE_PRESETS[sizePreset];
|
|
349
|
-
const voidFraction = sizePreset === "custom" ? $state.snapshot(voidFractionInput) : 0.15625;
|
|
350
411
|
const relayUrls = parseRelayServersInput($state.snapshot(relayServersInput));
|
|
351
412
|
const options: GameOptions = {
|
|
352
413
|
elevationMax: 6.0,
|
|
353
414
|
elevationMin: 0.0,
|
|
354
|
-
numCells:
|
|
415
|
+
numCells: selectedCellCount,
|
|
355
416
|
relayUrls: relayUrls.length > 0 ? relayUrls : undefined,
|
|
356
417
|
rngSeed: $state.snapshot(rngSeedInput),
|
|
357
|
-
|
|
358
|
-
|
|
418
|
+
shape: resolveShape(),
|
|
419
|
+
spikiness: $state.snapshot(spikinessInput),
|
|
420
|
+
voidFraction: $state.snapshot(voidFractionInput),
|
|
359
421
|
};
|
|
360
422
|
status = m.status_generating_map();
|
|
361
|
-
|
|
423
|
+
setupMode = undefined;
|
|
362
424
|
const generated = await generateMap(options);
|
|
363
|
-
|
|
425
|
+
nextGameState = new GameState(options);
|
|
426
|
+
nextGameState.applyMapCells(generated.cells);
|
|
427
|
+
// Publish only a complete map: mounting an empty game while old terrain
|
|
428
|
+
// remains makes the board look up terrain indices in an empty cell list.
|
|
429
|
+
isFlatMap = options.shape?.kind === "flat";
|
|
364
430
|
terrain = generated.terrain;
|
|
431
|
+
surfaceArea = generated.surfaceArea;
|
|
432
|
+
boundsRadius = generated.boundsRadius;
|
|
365
433
|
inviteTicket = "";
|
|
366
434
|
exploredCellsSeen = new SvelteSet<number>();
|
|
367
435
|
pendingTutorialClick = undefined;
|
|
368
436
|
tutorial = isTutorialMode ? new TutorialState() : undefined;
|
|
437
|
+
gameState = nextGameState;
|
|
369
438
|
} catch (error) {
|
|
439
|
+
nextGameState?.free();
|
|
370
440
|
console.error("Failed to start game", error);
|
|
371
441
|
} finally {
|
|
372
442
|
setupMode = undefined;
|
|
@@ -421,8 +491,11 @@
|
|
|
421
491
|
}
|
|
422
492
|
throw new Error(m.error_join_connect_failed(), { cause: error });
|
|
423
493
|
}
|
|
494
|
+
isFlatMap = options.shape?.kind === "flat";
|
|
424
495
|
gameState = nextGameState;
|
|
425
496
|
terrain = generated.terrain;
|
|
497
|
+
surfaceArea = generated.surfaceArea;
|
|
498
|
+
boundsRadius = generated.boundsRadius;
|
|
426
499
|
inviteTicket = "";
|
|
427
500
|
succeeded = true;
|
|
428
501
|
} catch (error) {
|
|
@@ -446,6 +519,9 @@
|
|
|
446
519
|
console.error("Failed to release game state", error);
|
|
447
520
|
}
|
|
448
521
|
gameState = undefined;
|
|
522
|
+
terrain = undefined;
|
|
523
|
+
surfaceArea = 0;
|
|
524
|
+
boundsRadius = DEFAULT_RADIUS;
|
|
449
525
|
setupMode = undefined;
|
|
450
526
|
inviteTicket = "";
|
|
451
527
|
ticketInput = "";
|
|
@@ -454,7 +530,6 @@
|
|
|
454
530
|
tutorial = undefined;
|
|
455
531
|
exploredCellsSeen = new SvelteSet<number>();
|
|
456
532
|
pendingTutorialClick = undefined;
|
|
457
|
-
rngSeedInput = Math.floor(Date.now() / 1000);
|
|
458
533
|
}
|
|
459
534
|
|
|
460
535
|
async function copyInviteTicket() {
|
|
@@ -589,12 +664,13 @@
|
|
|
589
664
|
{/if}
|
|
590
665
|
</div>
|
|
591
666
|
<div class="flex gap-2">
|
|
592
|
-
{#if !isTutorialMode && hasRelayServersConfigured
|
|
667
|
+
{#if !isTutorialMode && hasRelayServersConfigured}
|
|
593
668
|
<button
|
|
594
669
|
class="btn btn-primary"
|
|
595
670
|
type="button"
|
|
596
671
|
onclick={generateInvite}
|
|
597
|
-
disabled={isGeneratingInvite}
|
|
672
|
+
disabled={isGeneratingInvite || ($score?.safeExplored ?? 0) === 0}
|
|
673
|
+
title={($score?.safeExplored ?? 0) === 0 ? m.text_invite_after_opening() : undefined}
|
|
598
674
|
>
|
|
599
675
|
{#if isGeneratingInvite}
|
|
600
676
|
<span class="spinner" aria-hidden="true"></span>
|
|
@@ -613,7 +689,7 @@
|
|
|
613
689
|
<p class="mt-2 text-sm text-slate-600!">{status}</p>
|
|
614
690
|
{/if}
|
|
615
691
|
|
|
616
|
-
{#if !gameState}
|
|
692
|
+
{#if !gameState && !status}
|
|
617
693
|
{#if setupMode === "host"}
|
|
618
694
|
<form
|
|
619
695
|
class="mt-4 w-full"
|
|
@@ -628,6 +704,14 @@
|
|
|
628
704
|
<label class="field-label" for="player-name">{m.field_player_name()}</label>
|
|
629
705
|
<input class="field" id="player-name" type="text" bind:value={playerNameInput} />
|
|
630
706
|
</div>
|
|
707
|
+
<div class="mb-4 w-full px-3">
|
|
708
|
+
<label class="field-label" for="shape-select">{m.field_map_shape()}</label>
|
|
709
|
+
<select id="shape-select" class="field" bind:value={shapeKindInput}>
|
|
710
|
+
{#each SHAPE_KINDS as kind (kind)}
|
|
711
|
+
<option value={kind}>{m.shape_label({ kind })}</option>
|
|
712
|
+
{/each}
|
|
713
|
+
</select>
|
|
714
|
+
</div>
|
|
631
715
|
<div class="mb-4 w-full px-3">
|
|
632
716
|
<span class="field-label">{m.field_map_size()}</span>
|
|
633
717
|
<div class="grid grid-cols-4 gap-2">
|
|
@@ -674,9 +758,7 @@
|
|
|
674
758
|
<span class="preset-label">{preset.label}</span>
|
|
675
759
|
<span class="preset-count">
|
|
676
760
|
{preset.value === "custom"
|
|
677
|
-
?
|
|
678
|
-
? m.cells_count({ count: numCellsInput })
|
|
679
|
-
: ""
|
|
761
|
+
? ""
|
|
680
762
|
: m.cells_count({ count: SIZE_PRESETS[preset.value] })}
|
|
681
763
|
</span>
|
|
682
764
|
</button>
|
|
@@ -684,39 +766,26 @@
|
|
|
684
766
|
</div>
|
|
685
767
|
</div>
|
|
686
768
|
{#if sizePreset === "custom"}
|
|
687
|
-
<div class="w-full px-3"
|
|
688
|
-
<
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
/>
|
|
701
|
-
</div>
|
|
702
|
-
<div class="w-full px-3 md:w-1/2">
|
|
703
|
-
<label class="field-label" for="void-fraction-input">
|
|
704
|
-
{m.field_void_fraction()}
|
|
705
|
-
</label>
|
|
706
|
-
<input
|
|
707
|
-
class="field"
|
|
708
|
-
id="void-fraction-input"
|
|
709
|
-
type="number"
|
|
710
|
-
inputmode="numeric"
|
|
711
|
-
bind:value={voidFractionInput}
|
|
712
|
-
max="0.999"
|
|
713
|
-
min="0"
|
|
714
|
-
step="0.001"
|
|
715
|
-
/>
|
|
716
|
-
</div>
|
|
717
|
-
</div>
|
|
769
|
+
<div class="mb-4 w-full px-3">
|
|
770
|
+
<label class="field-label" for="size-input">{m.field_size()}</label>
|
|
771
|
+
|
|
772
|
+
<input
|
|
773
|
+
class="field"
|
|
774
|
+
id="size-input"
|
|
775
|
+
type="number"
|
|
776
|
+
required
|
|
777
|
+
min="32"
|
|
778
|
+
max="5000"
|
|
779
|
+
step="1"
|
|
780
|
+
bind:value={numCellsInput}
|
|
781
|
+
/>
|
|
718
782
|
</div>
|
|
719
783
|
{/if}
|
|
784
|
+
<p class="field-help mb-4 w-full px-3">
|
|
785
|
+
{usesFaceDensity
|
|
786
|
+
? m.text_density_summary({ faces: faceCount, count: selectedCellCount })
|
|
787
|
+
: m.cells_count({ count: selectedCellCount })}
|
|
788
|
+
</p>
|
|
720
789
|
<div class="mb-4 w-full px-3">
|
|
721
790
|
<div class="advanced-settings" class:advanced-settings-open={isAdvancedSettingsOpen}>
|
|
722
791
|
<button
|
|
@@ -734,6 +803,30 @@
|
|
|
734
803
|
class="advanced-settings-content"
|
|
735
804
|
transition:slide={{ duration: 180 }}
|
|
736
805
|
>
|
|
806
|
+
<label class="field-label" for="void-fraction-input"
|
|
807
|
+
>{m.field_void_fraction()}</label
|
|
808
|
+
>
|
|
809
|
+
<input
|
|
810
|
+
class="field mb-3"
|
|
811
|
+
id="void-fraction-input"
|
|
812
|
+
type="number"
|
|
813
|
+
required
|
|
814
|
+
min="0"
|
|
815
|
+
max="0.999"
|
|
816
|
+
step="0.00001"
|
|
817
|
+
bind:value={voidFractionInput}
|
|
818
|
+
/>
|
|
819
|
+
<label class="field-label" for="spikiness-input">{m.field_spikiness()}</label>
|
|
820
|
+
<input
|
|
821
|
+
class="field mb-3"
|
|
822
|
+
id="spikiness-input"
|
|
823
|
+
type="number"
|
|
824
|
+
required
|
|
825
|
+
min="0"
|
|
826
|
+
max="1"
|
|
827
|
+
step="0.05"
|
|
828
|
+
bind:value={spikinessInput}
|
|
829
|
+
/>
|
|
737
830
|
<label class="field-label" for="relay-servers"
|
|
738
831
|
><a
|
|
739
832
|
href="https://docs.iroh.computer/deployment/dedicated-infrastructure"
|
|
@@ -887,7 +980,14 @@
|
|
|
887
980
|
|
|
888
981
|
{#if gameState}
|
|
889
982
|
<div id="game-canvas-container" style="height: 100vh; width: 100%;">
|
|
890
|
-
<Canvas
|
|
983
|
+
<Canvas
|
|
984
|
+
colorSpace="srgb-linear"
|
|
985
|
+
renderMode="on-demand"
|
|
986
|
+
dpr={Math.min(devicePixelRatio.current ?? 1, 1.5)}
|
|
987
|
+
shadows={false}
|
|
988
|
+
createRenderer={(canvas) =>
|
|
989
|
+
new WebGLRenderer({ canvas, alpha: true, antialias: true, powerPreference: "default" })}
|
|
990
|
+
>
|
|
891
991
|
<T.PerspectiveCamera
|
|
892
992
|
makeDefault
|
|
893
993
|
fov={cameraFov}
|
|
@@ -896,25 +996,17 @@
|
|
|
896
996
|
position={cameraPosition}
|
|
897
997
|
/>
|
|
898
998
|
<Board
|
|
999
|
+
flat={isFlatMap}
|
|
899
1000
|
bind:gameState
|
|
900
1001
|
{terrain}
|
|
1002
|
+
{surfaceArea}
|
|
901
1003
|
interactive={tutorial?.isExplorationAllowed ?? true}
|
|
902
1004
|
highlightedCellIndex={tutorial?.highlightedCellIndex}
|
|
903
1005
|
onCellClicked={(cellIndex) => {
|
|
904
1006
|
if (tutorial) pendingTutorialClick = cellIndex;
|
|
905
1007
|
}}
|
|
906
1008
|
/>
|
|
907
|
-
<
|
|
908
|
-
enableDamping
|
|
909
|
-
enablePan={true}
|
|
910
|
-
enableZoom={true}
|
|
911
|
-
enableRotate={true}
|
|
912
|
-
minPolarAngle={0}
|
|
913
|
-
maxPolarAngle={Math.PI / 2}
|
|
914
|
-
mouseButtons={{ LEFT: MOUSE.PAN, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.ROTATE }}
|
|
915
|
-
target={[MAP_CENTER_X, 0, MAP_CENTER_Z]}
|
|
916
|
-
touches={{ ONE: TOUCH.PAN, TWO: TOUCH.DOLLY_ROTATE }}
|
|
917
|
-
/>
|
|
1009
|
+
<MapControls flat={isFlatMap} radius={boundsRadius} />
|
|
918
1010
|
</Canvas>
|
|
919
1011
|
</div>
|
|
920
1012
|
{/if}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import { T, useTask, useThrelte } from "@threlte/core";
|
|
4
|
+
import { Group, Quaternion } from "three";
|
|
5
|
+
|
|
6
|
+
let { position, children }: { position: [number, number, number]; children: Snippet } = $props();
|
|
7
|
+
const group = new Group();
|
|
8
|
+
const parentRotation = new Quaternion();
|
|
9
|
+
const { camera, renderStage, autoRenderTask } = useThrelte();
|
|
10
|
+
|
|
11
|
+
// Orient labels only when a frame is already needed. The stock Billboard's
|
|
12
|
+
// auto-invalidating task keeps the entire scene rendering while idle.
|
|
13
|
+
useTask(
|
|
14
|
+
() => {
|
|
15
|
+
$camera.getWorldQuaternion(group.quaternion);
|
|
16
|
+
if (group.parent) {
|
|
17
|
+
group.parent.getWorldQuaternion(parentRotation);
|
|
18
|
+
group.quaternion.premultiply(parentRotation.invert());
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{ stage: renderStage, before: autoRenderTask, autoInvalidate: false },
|
|
22
|
+
);
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<T is={group} {position}>
|
|
26
|
+
{@render children()}
|
|
27
|
+
</T>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
position: [number, number, number];
|
|
4
|
+
children: Snippet;
|
|
5
|
+
};
|
|
6
|
+
declare const IdleBillboard: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
7
|
+
type IdleBillboard = ReturnType<typeof IdleBillboard>;
|
|
8
|
+
export default IdleBillboard;
|