@kuncat/avoidant 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +26 -0
  2. package/dist/components/AvoidantGame.svelte +226 -137
  3. package/dist/components/IdleBillboard.svelte +27 -0
  4. package/dist/components/IdleBillboard.svelte.d.ts +8 -0
  5. package/dist/components/board.svelte +240 -99
  6. package/dist/components/board.svelte.d.ts +3 -0
  7. package/dist/components/fragment.glsl +29 -19
  8. package/dist/components/terrain-depth-sort.d.ts +17 -0
  9. package/dist/components/terrain-depth-sort.js +63 -0
  10. package/dist/components/vertex.glsl +12 -7
  11. package/dist/generated/shared-constants.d.ts +0 -3
  12. package/dist/generated/shared-constants.js +0 -3
  13. package/dist/paraglide/messages/_index.d.ts +14 -0
  14. package/dist/paraglide/messages/_index.js +15 -1
  15. package/dist/paraglide/messages/cells_per_face.d.ts +18 -0
  16. package/dist/paraglide/messages/cells_per_face.js +29 -0
  17. package/dist/paraglide/messages/faces_count.d.ts +18 -0
  18. package/dist/paraglide/messages/faces_count.js +29 -0
  19. package/dist/paraglide/messages/field_cell_density.d.ts +16 -0
  20. package/dist/paraglide/messages/field_cell_density.js +29 -0
  21. package/dist/paraglide/messages/field_map_shape.d.ts +16 -0
  22. package/dist/paraglide/messages/field_map_shape.js +29 -0
  23. package/dist/paraglide/messages/field_radius.d.ts +16 -0
  24. package/dist/paraglide/messages/field_radius.js +29 -0
  25. package/dist/paraglide/messages/field_radius_x.d.ts +16 -0
  26. package/dist/paraglide/messages/field_radius_x.js +29 -0
  27. package/dist/paraglide/messages/field_radius_y.d.ts +16 -0
  28. package/dist/paraglide/messages/field_radius_y.js +29 -0
  29. package/dist/paraglide/messages/field_radius_z.d.ts +16 -0
  30. package/dist/paraglide/messages/field_radius_z.js +29 -0
  31. package/dist/paraglide/messages/field_spikiness.d.ts +16 -0
  32. package/dist/paraglide/messages/field_spikiness.js +29 -0
  33. package/dist/paraglide/messages/field_subdivisions.d.ts +16 -0
  34. package/dist/paraglide/messages/field_subdivisions.js +29 -0
  35. package/dist/paraglide/messages/field_surface_detail.d.ts +16 -0
  36. package/dist/paraglide/messages/field_surface_detail.js +29 -0
  37. package/dist/paraglide/messages/shape_label.d.ts +26 -0
  38. package/dist/paraglide/messages/shape_label.js +55 -0
  39. package/dist/paraglide/messages/text_density_summary.d.ts +19 -0
  40. package/dist/paraglide/messages/text_density_summary.js +29 -0
  41. package/dist/paraglide/messages/text_invite_after_opening.d.ts +16 -0
  42. package/dist/paraglide/messages/text_invite_after_opening.js +29 -0
  43. package/dist/wasm/avoidant_wasm.d.ts +77 -35
  44. package/dist/wasm/avoidant_wasm.js +236 -223
  45. package/dist/wasm/avoidant_wasm_bg.wasm +0 -0
  46. package/dist/wasm/avoidant_wasm_bg.wasm.d.ts +27 -27
  47. package/dist/workers/mapgen-client.js +2 -0
  48. package/dist/workers/mapgen.worker.d.ts +2 -0
  49. package/dist/workers/mapgen.worker.js +3 -0
  50. 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, { GameState, type GameOptions, type MapData } from "../wasm/avoidant_wasm";
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
13
  import { OrbitControls } from "@threlte/extras";
8
- import { MOUSE, TOUCH } from "three";
14
+ import { MOUSE, TOUCH, 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
- const CAMERA_AZIMUTH_RAD = Math.PI / 4;
26
- const CAMERA_ELEVATION_RAD = Math.atan(0.5);
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
- const horizontalDistance = Math.cos(CAMERA_ELEVATION_RAD) * CAMERA_ORBIT_RADIUS;
30
- const cameraPosition: [number, number, number] = [
31
- MAP_CENTER_X + horizontalDistance * Math.sin(CAMERA_AZIMUTH_RAD),
32
- Math.sin(CAMERA_ELEVATION_RAD) * CAMERA_ORBIT_RADIUS,
33
- MAP_CENTER_Z + horizontalDistance * Math.cos(CAMERA_AZIMUTH_RAD),
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
- let playerNameInput = $state(
75
- typeof window !== "undefined"
76
- ? (localStorage.getItem(PLAYER_NAME_STORAGE_KEY) ?? m.default_player_name())
77
- : m.default_player_name(),
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
- elevationMin: number,
129
- elevationMax: number,
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
- // For perspective cover framing, choose the smaller of width/height fitting FOVs so the map fills the viewport similarly to the previous orthographic cover zoom.
178
- const verticalFovForHeight = 2 * Math.atan(projectedHeight / (2 * CAMERA_ORBIT_RADIUS));
179
- const verticalFovForWidth = 2 * Math.atan(projectedWidth / (2 * CAMERA_ORBIT_RADIUS * aspect));
180
- const coverFovRadians = Math.min(verticalFovForHeight, verticalFovForWidth) * 0.99;
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
- return Math.min(120, Math.max(10, coverFovDegrees));
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 elevationMin = gameState?.elevationMin ?? 0;
190
- const elevationMax = gameState?.elevationMax ?? 0;
191
- cameraFov = calculateCoverFov(viewportWidth, viewportHeight, elevationMin, elevationMax);
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 (typeof window !== "undefined") {
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 player name", error);
307
+ console.warn("Failed to persist game settings", error);
246
308
  }
247
309
  }
248
310
  });
@@ -344,24 +406,25 @@
344
406
 
345
407
  async function startGame() {
346
408
  try {
347
- const resolvedNumCells =
348
- sizePreset === "custom" ? $state.snapshot(numCellsInput) : SIZE_PRESETS[sizePreset];
349
- const voidFraction = sizePreset === "custom" ? $state.snapshot(voidFractionInput) : 0.15625;
350
409
  const relayUrls = parseRelayServersInput($state.snapshot(relayServersInput));
351
410
  const options: GameOptions = {
352
411
  elevationMax: 6.0,
353
412
  elevationMin: 0.0,
354
- numCells: resolvedNumCells,
413
+ numCells: selectedCellCount,
355
414
  relayUrls: relayUrls.length > 0 ? relayUrls : undefined,
356
415
  rngSeed: $state.snapshot(rngSeedInput),
357
- spikiness: 0.8,
358
- voidFraction: voidFraction,
416
+ shape: resolveShape(),
417
+ spikiness: $state.snapshot(spikinessInput),
418
+ voidFraction: $state.snapshot(voidFractionInput),
359
419
  };
360
420
  status = m.status_generating_map();
421
+ isFlatMap = options.shape?.kind === "flat";
361
422
  gameState = new GameState(options);
362
423
  const generated = await generateMap(options);
363
424
  gameState.applyMapCells(generated.cells);
364
425
  terrain = generated.terrain;
426
+ surfaceArea = generated.surfaceArea;
427
+ boundsRadius = generated.boundsRadius;
365
428
  inviteTicket = "";
366
429
  exploredCellsSeen = new SvelteSet<number>();
367
430
  pendingTutorialClick = undefined;
@@ -421,8 +484,11 @@
421
484
  }
422
485
  throw new Error(m.error_join_connect_failed(), { cause: error });
423
486
  }
487
+ isFlatMap = options.shape?.kind === "flat";
424
488
  gameState = nextGameState;
425
489
  terrain = generated.terrain;
490
+ surfaceArea = generated.surfaceArea;
491
+ boundsRadius = generated.boundsRadius;
426
492
  inviteTicket = "";
427
493
  succeeded = true;
428
494
  } catch (error) {
@@ -454,7 +520,6 @@
454
520
  tutorial = undefined;
455
521
  exploredCellsSeen = new SvelteSet<number>();
456
522
  pendingTutorialClick = undefined;
457
- rngSeedInput = Math.floor(Date.now() / 1000);
458
523
  }
459
524
 
460
525
  async function copyInviteTicket() {
@@ -589,12 +654,13 @@
589
654
  {/if}
590
655
  </div>
591
656
  <div class="flex gap-2">
592
- {#if !isTutorialMode && hasRelayServersConfigured && ($score?.safeExplored ?? 0) + ($score?.voidExplored ?? 0) === 0}
657
+ {#if !isTutorialMode && hasRelayServersConfigured}
593
658
  <button
594
659
  class="btn btn-primary"
595
660
  type="button"
596
661
  onclick={generateInvite}
597
- disabled={isGeneratingInvite}
662
+ disabled={isGeneratingInvite || ($score?.safeExplored ?? 0) === 0}
663
+ title={($score?.safeExplored ?? 0) === 0 ? m.text_invite_after_opening() : undefined}
598
664
  >
599
665
  {#if isGeneratingInvite}
600
666
  <span class="spinner" aria-hidden="true"></span>
@@ -628,6 +694,14 @@
628
694
  <label class="field-label" for="player-name">{m.field_player_name()}</label>
629
695
  <input class="field" id="player-name" type="text" bind:value={playerNameInput} />
630
696
  </div>
697
+ <div class="mb-4 w-full px-3">
698
+ <label class="field-label" for="shape-select">{m.field_map_shape()}</label>
699
+ <select id="shape-select" class="field" bind:value={shapeKindInput}>
700
+ {#each SHAPE_KINDS as kind (kind)}
701
+ <option value={kind}>{m.shape_label({ kind })}</option>
702
+ {/each}
703
+ </select>
704
+ </div>
631
705
  <div class="mb-4 w-full px-3">
632
706
  <span class="field-label">{m.field_map_size()}</span>
633
707
  <div class="grid grid-cols-4 gap-2">
@@ -674,9 +748,7 @@
674
748
  <span class="preset-label">{preset.label}</span>
675
749
  <span class="preset-count">
676
750
  {preset.value === "custom"
677
- ? sizePreset === "custom"
678
- ? m.cells_count({ count: numCellsInput })
679
- : ""
751
+ ? ""
680
752
  : m.cells_count({ count: SIZE_PRESETS[preset.value] })}
681
753
  </span>
682
754
  </button>
@@ -684,39 +756,26 @@
684
756
  </div>
685
757
  </div>
686
758
  {#if sizePreset === "custom"}
687
- <div class="w-full px-3" transition:slide={{ duration: 180 }}>
688
- <div class="-mx-3 flex flex-wrap">
689
- <div class="mb-6 w-full px-3 md:mb-0 md:w-1/2">
690
- <label class="field-label" for="size-input">{m.field_size()}</label>
691
- <input
692
- class="field"
693
- id="size-input"
694
- type="number"
695
- inputmode="numeric"
696
- bind:value={numCellsInput}
697
- min="32"
698
- max="5000"
699
- step="1"
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>
759
+ <div class="mb-4 w-full px-3">
760
+ <label class="field-label" for="size-input">{m.field_size()}</label>
761
+
762
+ <input
763
+ class="field"
764
+ id="size-input"
765
+ type="number"
766
+ required
767
+ min="32"
768
+ max="5000"
769
+ step="1"
770
+ bind:value={numCellsInput}
771
+ />
718
772
  </div>
719
773
  {/if}
774
+ <p class="field-help mb-4 w-full px-3">
775
+ {usesFaceDensity
776
+ ? m.text_density_summary({ faces: faceCount, count: selectedCellCount })
777
+ : m.cells_count({ count: selectedCellCount })}
778
+ </p>
720
779
  <div class="mb-4 w-full px-3">
721
780
  <div class="advanced-settings" class:advanced-settings-open={isAdvancedSettingsOpen}>
722
781
  <button
@@ -734,6 +793,30 @@
734
793
  class="advanced-settings-content"
735
794
  transition:slide={{ duration: 180 }}
736
795
  >
796
+ <label class="field-label" for="void-fraction-input"
797
+ >{m.field_void_fraction()}</label
798
+ >
799
+ <input
800
+ class="field mb-3"
801
+ id="void-fraction-input"
802
+ type="number"
803
+ required
804
+ min="0"
805
+ max="0.999"
806
+ step="0.00001"
807
+ bind:value={voidFractionInput}
808
+ />
809
+ <label class="field-label" for="spikiness-input">{m.field_spikiness()}</label>
810
+ <input
811
+ class="field mb-3"
812
+ id="spikiness-input"
813
+ type="number"
814
+ required
815
+ min="0"
816
+ max="1"
817
+ step="0.05"
818
+ bind:value={spikinessInput}
819
+ />
737
820
  <label class="field-label" for="relay-servers"
738
821
  ><a
739
822
  href="https://docs.iroh.computer/deployment/dedicated-infrastructure"
@@ -887,7 +970,14 @@
887
970
 
888
971
  {#if gameState}
889
972
  <div id="game-canvas-container" style="height: 100vh; width: 100%;">
890
- <Canvas colorSpace="srgb-linear">
973
+ <Canvas
974
+ colorSpace="srgb-linear"
975
+ renderMode="on-demand"
976
+ dpr={Math.min(devicePixelRatio.current ?? 1, 1.5)}
977
+ shadows={false}
978
+ createRenderer={(canvas) =>
979
+ new WebGLRenderer({ canvas, alpha: true, antialias: true, powerPreference: "default" })}
980
+ >
891
981
  <T.PerspectiveCamera
892
982
  makeDefault
893
983
  fov={cameraFov}
@@ -896,8 +986,10 @@
896
986
  position={cameraPosition}
897
987
  />
898
988
  <Board
989
+ flat={isFlatMap}
899
990
  bind:gameState
900
991
  {terrain}
992
+ {surfaceArea}
901
993
  interactive={tutorial?.isExplorationAllowed ?? true}
902
994
  highlightedCellIndex={tutorial?.highlightedCellIndex}
903
995
  onCellClicked={(cellIndex) => {
@@ -905,14 +997,11 @@
905
997
  }}
906
998
  />
907
999
  <OrbitControls
908
- enableDamping
909
1000
  enablePan={true}
910
1001
  enableZoom={true}
911
1002
  enableRotate={true}
912
- minPolarAngle={0}
913
- maxPolarAngle={Math.PI / 2}
914
1003
  mouseButtons={{ LEFT: MOUSE.PAN, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.ROTATE }}
915
- target={[MAP_CENTER_X, 0, MAP_CENTER_Z]}
1004
+ target={[0, 0, 0]}
916
1005
  touches={{ ONE: TOUCH.PAN, TWO: TOUCH.DOLLY_ROTATE }}
917
1006
  />
918
1007
  </Canvas>
@@ -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;