@kuncat/avoidant 0.1.2 → 0.1.4
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/dist/components/AvoidantGame.svelte +185 -57
- package/dist/components/board.svelte +19 -2
- package/dist/components/board.svelte.d.ts +3 -0
- package/dist/components/fragment.glsl +9 -0
- package/dist/paraglide/messages/_index.d.ts +10 -0
- package/dist/paraglide/messages/_index.js +11 -1
- package/dist/paraglide/messages/field_tutorial_mode.d.ts +16 -0
- package/dist/paraglide/messages/field_tutorial_mode.js +29 -0
- package/dist/paraglide/messages/field_void_fraction.d.ts +16 -0
- package/dist/paraglide/messages/field_void_fraction.js +29 -0
- package/dist/paraglide/messages/tutorial_action_dismiss.d.ts +16 -0
- package/dist/paraglide/messages/tutorial_action_dismiss.js +29 -0
- package/dist/paraglide/messages/tutorial_action_next.d.ts +16 -0
- package/dist/paraglide/messages/tutorial_action_next.js +29 -0
- package/dist/paraglide/messages/tutorial_after_safe_deducible.d.ts +16 -0
- package/dist/paraglide/messages/tutorial_after_safe_deducible.js +29 -0
- package/dist/paraglide/messages/tutorial_after_safe_guess.d.ts +16 -0
- package/dist/paraglide/messages/tutorial_after_safe_guess.js +29 -0
- package/dist/paraglide/messages/tutorial_after_void.d.ts +16 -0
- package/dist/paraglide/messages/tutorial_after_void.js +29 -0
- package/dist/paraglide/messages/tutorial_awaiting_first_click.d.ts +16 -0
- package/dist/paraglide/messages/tutorial_awaiting_first_click.js +29 -0
- package/dist/paraglide/messages/tutorial_intro.d.ts +16 -0
- package/dist/paraglide/messages/tutorial_intro.js +29 -0
- package/dist/paraglide/messages/tutorial_won.d.ts +18 -0
- package/dist/paraglide/messages/tutorial_won.js +29 -0
- package/dist/styles/global.css +1 -1
- package/dist/tutorial.svelte.d.ts +42 -0
- package/dist/tutorial.svelte.js +116 -0
- package/dist/wasm/avoidant_wasm.d.ts +3 -3
- package/dist/wasm/avoidant_wasm.js +15 -15
- package/dist/wasm/avoidant_wasm_bg.wasm +0 -0
- package/dist/wasm/avoidant_wasm_bg.wasm.d.ts +3 -3
- package/package.json +1 -1
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount } from "svelte";
|
|
3
3
|
import { slide } from "svelte/transition";
|
|
4
|
+
import { SvelteSet } from "svelte/reactivity";
|
|
4
5
|
import init, { GameState, type GameOptions, type MapData } from "../wasm/avoidant_wasm";
|
|
5
6
|
import { Canvas, T } from "@threlte/core";
|
|
6
7
|
import { OrbitControls } from "@threlte/extras";
|
|
7
|
-
import { MOUSE } from "three";
|
|
8
|
+
import { MOUSE, TOUCH } from "three";
|
|
8
9
|
import Board from "./board.svelte";
|
|
9
10
|
import { MAP_HEIGHT, MAP_WIDTH } from "../generated/shared-constants";
|
|
10
11
|
import { m } from "../paraglide/messages";
|
|
11
12
|
import { getLocale, locales, setLocale } from "../paraglide/runtime";
|
|
12
13
|
import { generateMap } from "../workers/mapgen-client";
|
|
14
|
+
import { TutorialState } from "../tutorial.svelte";
|
|
13
15
|
|
|
14
16
|
const PLAYER_NAME_STORAGE_KEY = "avoidant:playerName";
|
|
15
17
|
const SIZE_PRESETS = { small: 80, medium: 160, large: 320 } as const;
|
|
@@ -67,6 +69,7 @@
|
|
|
67
69
|
let gameState = $state<GameState | undefined>(undefined);
|
|
68
70
|
let terrain = $state<MapData["terrain"] | undefined>(undefined);
|
|
69
71
|
let numCellsInput = $state(SIZE_PRESETS.medium);
|
|
72
|
+
let voidFractionInput = $state(0.15625);
|
|
70
73
|
let rngSeedInput = $state(0);
|
|
71
74
|
let playerNameInput = $state(
|
|
72
75
|
typeof window !== "undefined"
|
|
@@ -74,9 +77,12 @@
|
|
|
74
77
|
: m.default_player_name(),
|
|
75
78
|
);
|
|
76
79
|
let isTutorialMode = $state(false);
|
|
77
|
-
let
|
|
80
|
+
let tutorial = $state<TutorialState | undefined>(undefined);
|
|
81
|
+
let exploredCellsSeen = new SvelteSet<number>();
|
|
82
|
+
let pendingTutorialClick = $state<number | undefined>(undefined);
|
|
78
83
|
let setupMode: "host" | "join" | undefined = $state(undefined);
|
|
79
84
|
let sizePreset = $state<SizePreset>("medium");
|
|
85
|
+
let isAdvancedSettingsOpen = $state(false);
|
|
80
86
|
let relayServersInput = $state("");
|
|
81
87
|
let relayServersInitialized = false;
|
|
82
88
|
let hasRelayServersConfigured = $derived(parseRelayServersInput(relayServersInput).length > 0);
|
|
@@ -91,6 +97,9 @@
|
|
|
91
97
|
let isGeneratingInvite = $state(false);
|
|
92
98
|
let networkSnapshot = $derived(gameState?.networkSnapshot);
|
|
93
99
|
let score = $derived(gameState?.score);
|
|
100
|
+
let cellMetadataStore = $derived(gameState?.cellMetadata);
|
|
101
|
+
let cellsStore = $derived(gameState?.cells);
|
|
102
|
+
let pulsesStore = $derived(gameState?.uiState?.pulses);
|
|
94
103
|
let numSafeUnexploredCells = $derived(
|
|
95
104
|
$score ? Math.max(0, $score.totalCells - $score.voidTotal - $score.safeExplored) : 0,
|
|
96
105
|
);
|
|
@@ -100,7 +109,7 @@
|
|
|
100
109
|
let connectedPeerCount = $derived(
|
|
101
110
|
($networkSnapshot?.peers ?? []).filter((peer) => peer.isConnected).length,
|
|
102
111
|
);
|
|
103
|
-
let
|
|
112
|
+
let cameraFov = $state(50);
|
|
104
113
|
|
|
105
114
|
function toggleScoreBreakdown() {
|
|
106
115
|
isScoreBreakdownPinned = !isScoreBreakdownPinned;
|
|
@@ -113,7 +122,7 @@
|
|
|
113
122
|
}
|
|
114
123
|
}
|
|
115
124
|
|
|
116
|
-
function
|
|
125
|
+
function calculateCoverFov(
|
|
117
126
|
viewportWidth: number,
|
|
118
127
|
viewportHeight: number,
|
|
119
128
|
elevationMin: number,
|
|
@@ -163,17 +172,23 @@
|
|
|
163
172
|
const projectedWidth = Math.max(1e-6, maxRight - minRight);
|
|
164
173
|
const projectedHeight = Math.max(1e-6, maxUp - minUp);
|
|
165
174
|
|
|
166
|
-
|
|
167
|
-
|
|
175
|
+
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;
|
|
181
|
+
const coverFovDegrees = (coverFovRadians * 180) / Math.PI;
|
|
182
|
+
return Math.min(120, Math.max(10, coverFovDegrees));
|
|
168
183
|
}
|
|
169
184
|
|
|
170
|
-
function
|
|
185
|
+
function setInitialCameraFov() {
|
|
171
186
|
if (typeof window !== "undefined") {
|
|
172
187
|
const viewportWidth = Math.max(1, window.innerWidth);
|
|
173
188
|
const viewportHeight = Math.max(1, window.innerHeight);
|
|
174
189
|
const elevationMin = gameState?.elevationMin ?? 0;
|
|
175
190
|
const elevationMax = gameState?.elevationMax ?? 0;
|
|
176
|
-
|
|
191
|
+
cameraFov = calculateCoverFov(viewportWidth, viewportHeight, elevationMin, elevationMax);
|
|
177
192
|
}
|
|
178
193
|
}
|
|
179
194
|
|
|
@@ -213,7 +228,7 @@
|
|
|
213
228
|
|
|
214
229
|
$effect(() => {
|
|
215
230
|
if (!gameState) return;
|
|
216
|
-
|
|
231
|
+
setInitialCameraFov();
|
|
217
232
|
});
|
|
218
233
|
|
|
219
234
|
$effect(() => {
|
|
@@ -232,6 +247,35 @@
|
|
|
232
247
|
}
|
|
233
248
|
});
|
|
234
249
|
|
|
250
|
+
$effect(() => {
|
|
251
|
+
if (sizePreset === "custom") isTutorialMode = false;
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
$effect(() => {
|
|
255
|
+
if (!tutorial || !$cellMetadataStore || !$cellsStore) return;
|
|
256
|
+
const metadata = $cellMetadataStore;
|
|
257
|
+
// Track every newly-explored cell immediately so we don't backfill later, but defer the tutorial state transition until any chord/flood pulses have settled — otherwise we'd announce the result and highlight the next safe cell mid-sweep.
|
|
258
|
+
for (let i = 0; i < metadata.length; i++) {
|
|
259
|
+
if (metadata[i].isExplored && !exploredCellsSeen.has(i)) {
|
|
260
|
+
exploredCellsSeen.add(i);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
const pulsesActive = ($pulsesStore?.length ?? 0) > 0;
|
|
264
|
+
const anyRevealing = metadata.some((entry) => entry.isRevealing);
|
|
265
|
+
if (pulsesActive || anyRevealing) return;
|
|
266
|
+
const clicked = pendingTutorialClick;
|
|
267
|
+
if (clicked === undefined) return;
|
|
268
|
+
pendingTutorialClick = undefined;
|
|
269
|
+
tutorial.observeExplore(clicked, $cellsStore, metadata);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
$effect(() => {
|
|
273
|
+
if (!tutorial || !$score) return;
|
|
274
|
+
if ($score.completed) {
|
|
275
|
+
tutorial.observeWin($score.efficiency);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
235
279
|
function hexCells(radius: number): string[] {
|
|
236
280
|
const cells: string[] = [];
|
|
237
281
|
const dx = radius * Math.sqrt(3);
|
|
@@ -302,6 +346,7 @@
|
|
|
302
346
|
try {
|
|
303
347
|
const resolvedNumCells =
|
|
304
348
|
sizePreset === "custom" ? $state.snapshot(numCellsInput) : SIZE_PRESETS[sizePreset];
|
|
349
|
+
const voidFraction = sizePreset === "custom" ? $state.snapshot(voidFractionInput) : 0.15625;
|
|
305
350
|
const relayUrls = parseRelayServersInput($state.snapshot(relayServersInput));
|
|
306
351
|
const options: GameOptions = {
|
|
307
352
|
elevationMax: 6.0,
|
|
@@ -310,6 +355,7 @@
|
|
|
310
355
|
relayUrls: relayUrls.length > 0 ? relayUrls : undefined,
|
|
311
356
|
rngSeed: $state.snapshot(rngSeedInput),
|
|
312
357
|
spikiness: 0.8,
|
|
358
|
+
voidFraction: voidFraction,
|
|
313
359
|
};
|
|
314
360
|
status = m.status_generating_map();
|
|
315
361
|
gameState = new GameState(options);
|
|
@@ -317,6 +363,9 @@
|
|
|
317
363
|
gameState.applyMapCells(generated.cells);
|
|
318
364
|
terrain = generated.terrain;
|
|
319
365
|
inviteTicket = "";
|
|
366
|
+
exploredCellsSeen = new SvelteSet<number>();
|
|
367
|
+
pendingTutorialClick = undefined;
|
|
368
|
+
tutorial = isTutorialMode ? new TutorialState() : undefined;
|
|
320
369
|
} catch (error) {
|
|
321
370
|
console.error("Failed to start game", error);
|
|
322
371
|
} finally {
|
|
@@ -402,6 +451,9 @@
|
|
|
402
451
|
ticketInput = "";
|
|
403
452
|
joinError = undefined;
|
|
404
453
|
status = undefined;
|
|
454
|
+
tutorial = undefined;
|
|
455
|
+
exploredCellsSeen = new SvelteSet<number>();
|
|
456
|
+
pendingTutorialClick = undefined;
|
|
405
457
|
rngSeedInput = Math.floor(Date.now() / 1000);
|
|
406
458
|
}
|
|
407
459
|
|
|
@@ -481,14 +533,26 @@
|
|
|
481
533
|
onblur={() => (isScoreBreakdownHovered = false)}
|
|
482
534
|
onkeydown={handleScoreSummaryKeydown}
|
|
483
535
|
>
|
|
484
|
-
{m.label_score()}:
|
|
485
|
-
<
|
|
536
|
+
{m.label_score()}:
|
|
537
|
+
<strong class="text-slate-200!"
|
|
538
|
+
>{Math.round($score.score).toLocaleString(getLocale())}</strong
|
|
539
|
+
>
|
|
540
|
+
<span class="opacity-70"
|
|
541
|
+
>({$score.efficiency.toLocaleString(getLocale(), {
|
|
542
|
+
maximumFractionDigits: 0,
|
|
543
|
+
style: "percent",
|
|
544
|
+
})})</span
|
|
545
|
+
>
|
|
486
546
|
{#if $score.completed}
|
|
487
547
|
<span class="font-semibold text-emerald-600!">{m.text_avoided()}</span>
|
|
488
548
|
{:else}
|
|
489
549
|
<span class="opacity-80">
|
|
490
|
-
{m.label_safe_cells_remaining({
|
|
491
|
-
|
|
550
|
+
{m.label_safe_cells_remaining({
|
|
551
|
+
count: numSafeUnexploredCells.toLocaleString(getLocale()),
|
|
552
|
+
})}:
|
|
553
|
+
<strong class="text-slate-200!"
|
|
554
|
+
>{numSafeUnexploredCells.toLocaleString(getLocale())}</strong
|
|
555
|
+
>
|
|
492
556
|
</span>
|
|
493
557
|
{/if}
|
|
494
558
|
</div>
|
|
@@ -497,17 +561,22 @@
|
|
|
497
561
|
<div id="score-breakdown" class="score-breakdown" role="status">
|
|
498
562
|
{#if $score.streak > 1}<p>
|
|
499
563
|
<span class="opacity-70"
|
|
500
|
-
>×{(1 + Math.min($score.streak, 10) * 0.1).
|
|
564
|
+
>×{(1 + Math.min($score.streak, 10) * 0.1).toLocaleString(getLocale(), {
|
|
565
|
+
maximumFractionDigits: 1,
|
|
566
|
+
})}
|
|
501
567
|
{m.label_streak()}</span
|
|
502
568
|
>
|
|
503
569
|
</p>
|
|
504
570
|
{/if}
|
|
505
571
|
<p class="text-emerald-600!">
|
|
506
|
-
{m.label_safe_cells_explored({
|
|
507
|
-
|
|
572
|
+
{m.label_safe_cells_explored({
|
|
573
|
+
count: $score.safeExplored.toLocaleString(getLocale()),
|
|
574
|
+
})}:
|
|
575
|
+
<strong>{$score.safeExplored.toLocaleString(getLocale())}</strong>
|
|
508
576
|
</p>
|
|
509
577
|
<p class="text-rose-500!">
|
|
510
|
-
{m.label_voids_discovered()}:
|
|
578
|
+
{m.label_voids_discovered()}:
|
|
579
|
+
<strong>{$score.voidExplored.toLocaleString(getLocale())}</strong>
|
|
511
580
|
</p>
|
|
512
581
|
</div>
|
|
513
582
|
{/if}
|
|
@@ -614,36 +683,14 @@
|
|
|
614
683
|
{/each}
|
|
615
684
|
</div>
|
|
616
685
|
</div>
|
|
617
|
-
<div class="mb-4 w-full px-3">
|
|
618
|
-
<details class="advanced-settings">
|
|
619
|
-
<summary class="advanced-settings-summary">{m.label_advanced_settings()}</summary>
|
|
620
|
-
<div class="advanced-settings-content">
|
|
621
|
-
<label class="field-label" for="relay-servers"
|
|
622
|
-
><a
|
|
623
|
-
href="https://docs.iroh.computer/deployment/dedicated-infrastructure"
|
|
624
|
-
target="_blank"
|
|
625
|
-
rel="noopener noreferrer">{m.field_relay_servers()}</a
|
|
626
|
-
></label
|
|
627
|
-
>
|
|
628
|
-
<textarea
|
|
629
|
-
class="field field-textarea mb-1"
|
|
630
|
-
id="relay-servers"
|
|
631
|
-
bind:value={relayServersInput}
|
|
632
|
-
rows="4"
|
|
633
|
-
spellcheck="false"
|
|
634
|
-
></textarea>
|
|
635
|
-
<p class="field-help">{m.text_relay_servers_hint()}</p>
|
|
636
|
-
</div>
|
|
637
|
-
</details>
|
|
638
|
-
</div>
|
|
639
686
|
{#if sizePreset === "custom"}
|
|
640
687
|
<div class="w-full px-3" transition:slide={{ duration: 180 }}>
|
|
641
688
|
<div class="-mx-3 flex flex-wrap">
|
|
642
689
|
<div class="mb-6 w-full px-3 md:mb-0 md:w-1/2">
|
|
643
|
-
<label class="field-label" for="
|
|
690
|
+
<label class="field-label" for="size-input">{m.field_size()}</label>
|
|
644
691
|
<input
|
|
645
692
|
class="field"
|
|
646
|
-
id="
|
|
693
|
+
id="size-input"
|
|
647
694
|
type="number"
|
|
648
695
|
inputmode="numeric"
|
|
649
696
|
bind:value={numCellsInput}
|
|
@@ -653,23 +700,79 @@
|
|
|
653
700
|
/>
|
|
654
701
|
</div>
|
|
655
702
|
<div class="w-full px-3 md:w-1/2">
|
|
656
|
-
<label class="field-label" for="
|
|
703
|
+
<label class="field-label" for="void-fraction-input">
|
|
704
|
+
{m.field_void_fraction()}
|
|
705
|
+
</label>
|
|
657
706
|
<input
|
|
658
707
|
class="field"
|
|
659
|
-
id="
|
|
708
|
+
id="void-fraction-input"
|
|
660
709
|
type="number"
|
|
661
710
|
inputmode="numeric"
|
|
662
|
-
bind:value={
|
|
711
|
+
bind:value={voidFractionInput}
|
|
712
|
+
max="0.999"
|
|
663
713
|
min="0"
|
|
714
|
+
step="0.001"
|
|
664
715
|
/>
|
|
665
716
|
</div>
|
|
666
717
|
</div>
|
|
667
718
|
</div>
|
|
668
719
|
{/if}
|
|
669
|
-
|
|
670
|
-
<
|
|
671
|
-
|
|
672
|
-
|
|
720
|
+
<div class="mb-4 w-full px-3">
|
|
721
|
+
<div class="advanced-settings" class:advanced-settings-open={isAdvancedSettingsOpen}>
|
|
722
|
+
<button
|
|
723
|
+
type="button"
|
|
724
|
+
class="advanced-settings-summary w-full"
|
|
725
|
+
aria-expanded={isAdvancedSettingsOpen}
|
|
726
|
+
aria-controls="advanced-settings-content"
|
|
727
|
+
onclick={() => (isAdvancedSettingsOpen = !isAdvancedSettingsOpen)}
|
|
728
|
+
>
|
|
729
|
+
{m.label_advanced_settings()}
|
|
730
|
+
</button>
|
|
731
|
+
{#if isAdvancedSettingsOpen}
|
|
732
|
+
<div
|
|
733
|
+
id="advanced-settings-content"
|
|
734
|
+
class="advanced-settings-content"
|
|
735
|
+
transition:slide={{ duration: 180 }}
|
|
736
|
+
>
|
|
737
|
+
<label class="field-label" for="relay-servers"
|
|
738
|
+
><a
|
|
739
|
+
href="https://docs.iroh.computer/deployment/dedicated-infrastructure"
|
|
740
|
+
target="_blank"
|
|
741
|
+
rel="noopener noreferrer">{m.field_relay_servers()}</a
|
|
742
|
+
></label
|
|
743
|
+
>
|
|
744
|
+
<textarea
|
|
745
|
+
class="field field-textarea mb-1"
|
|
746
|
+
id="relay-servers"
|
|
747
|
+
bind:value={relayServersInput}
|
|
748
|
+
rows="4"
|
|
749
|
+
spellcheck="false"
|
|
750
|
+
></textarea>
|
|
751
|
+
<p class="field-help">{m.text_relay_servers_hint()}</p>
|
|
752
|
+
<div class="mt-6 w-full">
|
|
753
|
+
<label class="field-label" for="rng-seed-input">{m.field_seed()}</label>
|
|
754
|
+
<input
|
|
755
|
+
class="field"
|
|
756
|
+
id="rng-seed-input"
|
|
757
|
+
type="number"
|
|
758
|
+
inputmode="numeric"
|
|
759
|
+
bind:value={rngSeedInput}
|
|
760
|
+
min="0"
|
|
761
|
+
/>
|
|
762
|
+
</div>
|
|
763
|
+
</div>
|
|
764
|
+
{/if}
|
|
765
|
+
</div>
|
|
766
|
+
</div>
|
|
767
|
+
<div class="checkbox-field mb-4 flex w-full items-center gap-2 px-3">
|
|
768
|
+
<label class="field-label mb-0!" for="tutorial-mode">{m.field_tutorial_mode()}</label>
|
|
769
|
+
<input
|
|
770
|
+
id="tutorial-mode"
|
|
771
|
+
type="checkbox"
|
|
772
|
+
bind:checked={isTutorialMode}
|
|
773
|
+
disabled={sizePreset === "custom"}
|
|
774
|
+
/>
|
|
775
|
+
</div>
|
|
673
776
|
</div>
|
|
674
777
|
<div class="flex flex-wrap justify-center gap-2">
|
|
675
778
|
<button class="btn btn-secondary" type="button" onclick={() => (setupMode = undefined)}>
|
|
@@ -693,12 +796,12 @@
|
|
|
693
796
|
<input class="field" id="join-player-name" type="text" bind:value={playerNameInput} />
|
|
694
797
|
</div>
|
|
695
798
|
<div class="mb-6 w-full px-3 md:mb-0">
|
|
696
|
-
<label class="field-label" for="
|
|
799
|
+
<label class="field-label" for="ticket-input"
|
|
697
800
|
>{m.field_ticket_or_invitation_url()}</label
|
|
698
801
|
>
|
|
699
802
|
<input
|
|
700
803
|
class="field"
|
|
701
|
-
id="
|
|
804
|
+
id="ticket-input"
|
|
702
805
|
type="text"
|
|
703
806
|
bind:value={ticketInput}
|
|
704
807
|
oninput={() => (joinError = undefined)}
|
|
@@ -785,14 +888,22 @@
|
|
|
785
888
|
{#if gameState}
|
|
786
889
|
<div id="game-canvas-container" style="height: 100vh; width: 100%;">
|
|
787
890
|
<Canvas colorSpace="srgb-linear">
|
|
788
|
-
<T.
|
|
891
|
+
<T.PerspectiveCamera
|
|
789
892
|
makeDefault
|
|
790
|
-
|
|
893
|
+
fov={cameraFov}
|
|
791
894
|
near={0.1}
|
|
792
895
|
far={1000}
|
|
793
896
|
position={cameraPosition}
|
|
794
897
|
/>
|
|
795
|
-
<Board
|
|
898
|
+
<Board
|
|
899
|
+
bind:gameState
|
|
900
|
+
{terrain}
|
|
901
|
+
interactive={tutorial?.isExplorationAllowed ?? true}
|
|
902
|
+
highlightedCellIndex={tutorial?.highlightedCellIndex}
|
|
903
|
+
onCellClicked={(cellIndex) => {
|
|
904
|
+
if (tutorial) pendingTutorialClick = cellIndex;
|
|
905
|
+
}}
|
|
906
|
+
/>
|
|
796
907
|
<OrbitControls
|
|
797
908
|
enableDamping
|
|
798
909
|
enablePan={true}
|
|
@@ -800,15 +911,32 @@
|
|
|
800
911
|
enableRotate={true}
|
|
801
912
|
minPolarAngle={0}
|
|
802
913
|
maxPolarAngle={Math.PI / 2}
|
|
803
|
-
target={[MAP_CENTER_X, 0, MAP_CENTER_Z]}
|
|
804
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 }}
|
|
805
917
|
/>
|
|
806
918
|
</Canvas>
|
|
807
919
|
</div>
|
|
808
920
|
{/if}
|
|
809
921
|
|
|
810
|
-
{#if
|
|
811
|
-
<div
|
|
812
|
-
|
|
922
|
+
{#if tutorial && tutorial.phase.kind !== "done"}
|
|
923
|
+
<div
|
|
924
|
+
class="tutorial-panel fixed inset-x-0 bottom-0 z-20 flex justify-center px-4 pb-4"
|
|
925
|
+
transition:slide={{ duration: 180 }}
|
|
926
|
+
>
|
|
927
|
+
<div
|
|
928
|
+
class="pointer-events-auto flex w-full max-w-2xl items-start gap-3 rounded-md bg-slate-900/85 px-4 py-3 text-sm text-slate-100 shadow-lg backdrop-blur"
|
|
929
|
+
>
|
|
930
|
+
{tutorial.text}
|
|
931
|
+
{#if tutorial.canAdvance}
|
|
932
|
+
<button class="btn btn-primary" type="button" onclick={() => tutorial?.next()}>
|
|
933
|
+
{m.tutorial_action_next()}
|
|
934
|
+
</button>
|
|
935
|
+
{:else if tutorial.phase.kind === "won"}
|
|
936
|
+
<button class="btn btn-primary" type="button" onclick={() => tutorial?.dismiss()}>
|
|
937
|
+
{m.tutorial_action_dismiss()}
|
|
938
|
+
</button>
|
|
939
|
+
{/if}
|
|
940
|
+
</div>
|
|
813
941
|
</div>
|
|
814
942
|
{/if}
|
|
@@ -70,9 +70,18 @@
|
|
|
70
70
|
interface Props {
|
|
71
71
|
gameState: GameState;
|
|
72
72
|
terrain?: { positions: number[]; normals: number[]; cellIndices: number[] } | undefined;
|
|
73
|
+
interactive?: boolean;
|
|
74
|
+
highlightedCellIndex?: number | undefined;
|
|
75
|
+
onCellClicked?: (cellIndex: number) => void;
|
|
73
76
|
}
|
|
74
77
|
|
|
75
|
-
let {
|
|
78
|
+
let {
|
|
79
|
+
gameState = $bindable(),
|
|
80
|
+
terrain = undefined,
|
|
81
|
+
interactive = true,
|
|
82
|
+
highlightedCellIndex = undefined,
|
|
83
|
+
onCellClicked = undefined,
|
|
84
|
+
}: Props = $props();
|
|
76
85
|
let cells = $derived(gameState?.cells);
|
|
77
86
|
let cellMetadata = $derived(gameState?.cellMetadata);
|
|
78
87
|
let pulses = $derived(gameState?.uiState?.pulses);
|
|
@@ -84,7 +93,8 @@
|
|
|
84
93
|
const now = performance.now();
|
|
85
94
|
const hasActivePulses = $pulses.some((p) => now - p.createdAtMs < Math.max(1, p.durationMs));
|
|
86
95
|
const hasFallingCells = fallStart.size > 0;
|
|
87
|
-
|
|
96
|
+
const hasHighlight = highlightedCellIndex !== undefined;
|
|
97
|
+
if (hasActivePulses || hasFallingCells || hasHighlight) {
|
|
88
98
|
nowMs = now;
|
|
89
99
|
|
|
90
100
|
if (hasFallingCells) {
|
|
@@ -303,6 +313,8 @@
|
|
|
303
313
|
pulseOriginCells: { value: new Array(MAX_PULSES).fill(-1) },
|
|
304
314
|
pulseIsRemote: { value: new Array(MAX_PULSES).fill(0) },
|
|
305
315
|
pulseMaxRadii: { value: new Array(MAX_PULSES).fill(0) },
|
|
316
|
+
uHighlightedCell: { value: -1 },
|
|
317
|
+
uTime: { value: 0 },
|
|
306
318
|
},
|
|
307
319
|
}),
|
|
308
320
|
);
|
|
@@ -413,15 +425,20 @@
|
|
|
413
425
|
terrainMaterial.uniforms.pulseOriginCells.value = pulseOriginCellsUniform;
|
|
414
426
|
terrainMaterial.uniforms.pulseIsRemote.value = pulseIsRemoteUniform;
|
|
415
427
|
terrainMaterial.uniforms.pulseMaxRadii.value = pulseMaxRadiiUniform;
|
|
428
|
+
terrainMaterial.uniforms.uHighlightedCell.value =
|
|
429
|
+
highlightedCellIndex === undefined ? -1 : highlightedCellIndex;
|
|
430
|
+
terrainMaterial.uniforms.uTime.value = nowMs;
|
|
416
431
|
invalidate();
|
|
417
432
|
});
|
|
418
433
|
|
|
419
434
|
function handleTerrainClick(event: { point: Vector3; face: { a: number } | null }) {
|
|
435
|
+
if (!interactive) return;
|
|
420
436
|
if (!event.face || $cells.length === 0) return;
|
|
421
437
|
const aCellIndexArr = terrainGeometry.attributes.aCellIndex.array as Float32Array;
|
|
422
438
|
const cellIndex = aCellIndexArr[event.face.a];
|
|
423
439
|
if (cellIndex === undefined) return;
|
|
424
440
|
gameState.queueExplorePulse(cellIndex, event.point.x, event.point.y, event.point.z);
|
|
441
|
+
onCellClicked?.(cellIndex);
|
|
425
442
|
}
|
|
426
443
|
</script>
|
|
427
444
|
|
|
@@ -26,6 +26,9 @@ interface Props {
|
|
|
26
26
|
normals: number[];
|
|
27
27
|
cellIndices: number[];
|
|
28
28
|
} | undefined;
|
|
29
|
+
interactive?: boolean;
|
|
30
|
+
highlightedCellIndex?: number | undefined;
|
|
31
|
+
onCellClicked?: (cellIndex: number) => void;
|
|
29
32
|
}
|
|
30
33
|
declare const Board: import("svelte").Component<Props, {}, "gameState">;
|
|
31
34
|
type Board = ReturnType<typeof Board>;
|
|
@@ -17,6 +17,8 @@ uniform float pulseMaxRadii[MAX_PULSES];
|
|
|
17
17
|
uniform vec3 uLightDir;
|
|
18
18
|
uniform float uAmbient;
|
|
19
19
|
uniform float uDiffuse;
|
|
20
|
+
uniform float uHighlightedCell;
|
|
21
|
+
uniform float uTime;
|
|
20
22
|
|
|
21
23
|
float remapClamped(float value, float inMin, float inMax, float outMin, float outMax) {
|
|
22
24
|
float t = clamp((value - inMin) / (inMax - inMin), 0.0, 1.0);
|
|
@@ -88,6 +90,13 @@ void main() {
|
|
|
88
90
|
vec3 pulseTint = mix(localPulseTint, remotePulseTint, remoteFactor);
|
|
89
91
|
vec3 finalColor = mix(terrainColor, pulseTint, totalRing * 0.85);
|
|
90
92
|
|
|
93
|
+
// Pulsing glow for a tutorial-highlighted cell. `uHighlightedCell` is -1 when no cell is highlighted.
|
|
94
|
+
if (uHighlightedCell >= 0.0 && abs(vCellIndex - uHighlightedCell) < 0.5) {
|
|
95
|
+
float glowPulse = 0.5 + 0.5 * sin(uTime * 0.005);
|
|
96
|
+
vec3 glowColor = vec3(0.4745, 0.8667, 0.6706);
|
|
97
|
+
finalColor = mix(finalColor, glowColor, 0.35 + 0.45 * glowPulse);
|
|
98
|
+
}
|
|
99
|
+
|
|
91
100
|
float alpha = isExplored > 0.5 ? 1.0 : 0.25;
|
|
92
101
|
// Fade alpha while an explored void cell is falling.
|
|
93
102
|
if (isVoid > 0.5 && isExplored > 0.5) {
|
|
@@ -21,6 +21,8 @@ export * from "./field_relay_servers.js";
|
|
|
21
21
|
export * from "./field_seed.js";
|
|
22
22
|
export * from "./field_size.js";
|
|
23
23
|
export * from "./field_ticket_or_invitation_url.js";
|
|
24
|
+
export * from "./field_tutorial_mode.js";
|
|
25
|
+
export * from "./field_void_fraction.js";
|
|
24
26
|
export * from "./label_advanced_settings.js";
|
|
25
27
|
export * from "./label_players.js";
|
|
26
28
|
export * from "./label_safe_cells_explored.js";
|
|
@@ -39,4 +41,12 @@ export * from "./status_loading.js";
|
|
|
39
41
|
export * from "./status_preparing.js";
|
|
40
42
|
export * from "./text_avoided.js";
|
|
41
43
|
export * from "./text_relay_servers_hint.js";
|
|
44
|
+
export * from "./tutorial_action_dismiss.js";
|
|
45
|
+
export * from "./tutorial_action_next.js";
|
|
46
|
+
export * from "./tutorial_after_safe_deducible.js";
|
|
47
|
+
export * from "./tutorial_after_safe_guess.js";
|
|
48
|
+
export * from "./tutorial_after_void.js";
|
|
49
|
+
export * from "./tutorial_awaiting_first_click.js";
|
|
50
|
+
export * from "./tutorial_intro.js";
|
|
51
|
+
export * from "./tutorial_won.js";
|
|
42
52
|
export type LocalizedString = import("../runtime.js").LocalizedString;
|
|
@@ -23,6 +23,8 @@ export * from './field_relay_servers.js'
|
|
|
23
23
|
export * from './field_seed.js'
|
|
24
24
|
export * from './field_size.js'
|
|
25
25
|
export * from './field_ticket_or_invitation_url.js'
|
|
26
|
+
export * from './field_tutorial_mode.js'
|
|
27
|
+
export * from './field_void_fraction.js'
|
|
26
28
|
export * from './label_advanced_settings.js'
|
|
27
29
|
export * from './label_players.js'
|
|
28
30
|
export * from './label_safe_cells_explored.js'
|
|
@@ -40,4 +42,12 @@ export * from './status_joining_game.js'
|
|
|
40
42
|
export * from './status_loading.js'
|
|
41
43
|
export * from './status_preparing.js'
|
|
42
44
|
export * from './text_avoided.js'
|
|
43
|
-
export * from './text_relay_servers_hint.js'
|
|
45
|
+
export * from './text_relay_servers_hint.js'
|
|
46
|
+
export * from './tutorial_action_dismiss.js'
|
|
47
|
+
export * from './tutorial_action_next.js'
|
|
48
|
+
export * from './tutorial_after_safe_deducible.js'
|
|
49
|
+
export * from './tutorial_after_safe_guess.js'
|
|
50
|
+
export * from './tutorial_after_void.js'
|
|
51
|
+
export * from './tutorial_awaiting_first_click.js'
|
|
52
|
+
export * from './tutorial_intro.js'
|
|
53
|
+
export * from './tutorial_won.js'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* | output |
|
|
3
|
+
* | --- |
|
|
4
|
+
* | "Tutorial Mode" |
|
|
5
|
+
*
|
|
6
|
+
* @param {Field_Tutorial_ModeInputs} inputs
|
|
7
|
+
* @param {{ locale?: "en" | "bn" }} options
|
|
8
|
+
* @returns {LocalizedString}
|
|
9
|
+
*/
|
|
10
|
+
export const field_tutorial_mode: ((inputs?: Field_Tutorial_ModeInputs, options?: {
|
|
11
|
+
locale?: "en" | "bn";
|
|
12
|
+
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Field_Tutorial_ModeInputs, {
|
|
13
|
+
locale?: "en" | "bn";
|
|
14
|
+
}, {}>;
|
|
15
|
+
export type LocalizedString = import("../runtime.js").LocalizedString;
|
|
16
|
+
export type Field_Tutorial_ModeInputs = {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
|
3
|
+
|
|
4
|
+
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
|
5
|
+
|
|
6
|
+
/** @typedef {{}} Field_Tutorial_ModeInputs */
|
|
7
|
+
|
|
8
|
+
const en_field_tutorial_mode = /** @type {(inputs: Field_Tutorial_ModeInputs) => LocalizedString} */ () => {
|
|
9
|
+
return /** @type {LocalizedString} */ (`Tutorial Mode`)
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const bn_field_tutorial_mode = /** @type {(inputs: Field_Tutorial_ModeInputs) => LocalizedString} */ () => {
|
|
13
|
+
return /** @type {LocalizedString} */ (`তালিম মোড`)
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* | output |
|
|
18
|
+
* | --- |
|
|
19
|
+
* | "Tutorial Mode" |
|
|
20
|
+
*
|
|
21
|
+
* @param {Field_Tutorial_ModeInputs} inputs
|
|
22
|
+
* @param {{ locale?: "en" | "bn" }} options
|
|
23
|
+
* @returns {LocalizedString}
|
|
24
|
+
*/
|
|
25
|
+
export const field_tutorial_mode = /** @type {((inputs?: Field_Tutorial_ModeInputs, options?: { locale?: "en" | "bn" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Field_Tutorial_ModeInputs, { locale?: "en" | "bn" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
26
|
+
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
27
|
+
if (locale === "en") return en_field_tutorial_mode(inputs)
|
|
28
|
+
return bn_field_tutorial_mode(inputs)
|
|
29
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* | output |
|
|
3
|
+
* | --- |
|
|
4
|
+
* | "Void Cell Fraction" |
|
|
5
|
+
*
|
|
6
|
+
* @param {Field_Void_FractionInputs} inputs
|
|
7
|
+
* @param {{ locale?: "en" | "bn" }} options
|
|
8
|
+
* @returns {LocalizedString}
|
|
9
|
+
*/
|
|
10
|
+
export const field_void_fraction: ((inputs?: Field_Void_FractionInputs, options?: {
|
|
11
|
+
locale?: "en" | "bn";
|
|
12
|
+
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Field_Void_FractionInputs, {
|
|
13
|
+
locale?: "en" | "bn";
|
|
14
|
+
}, {}>;
|
|
15
|
+
export type LocalizedString = import("../runtime.js").LocalizedString;
|
|
16
|
+
export type Field_Void_FractionInputs = {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
import { getLocale, experimentalStaticLocale } from '../runtime.js';
|
|
3
|
+
|
|
4
|
+
/** @typedef {import('../runtime.js').LocalizedString} LocalizedString */
|
|
5
|
+
|
|
6
|
+
/** @typedef {{}} Field_Void_FractionInputs */
|
|
7
|
+
|
|
8
|
+
const en_field_void_fraction = /** @type {(inputs: Field_Void_FractionInputs) => LocalizedString} */ () => {
|
|
9
|
+
return /** @type {LocalizedString} */ (`Void Cell Fraction`)
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const bn_field_void_fraction = /** @type {(inputs: Field_Void_FractionInputs) => LocalizedString} */ () => {
|
|
13
|
+
return /** @type {LocalizedString} */ (`শূন্য সেলের অনুপাত`)
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* | output |
|
|
18
|
+
* | --- |
|
|
19
|
+
* | "Void Cell Fraction" |
|
|
20
|
+
*
|
|
21
|
+
* @param {Field_Void_FractionInputs} inputs
|
|
22
|
+
* @param {{ locale?: "en" | "bn" }} options
|
|
23
|
+
* @returns {LocalizedString}
|
|
24
|
+
*/
|
|
25
|
+
export const field_void_fraction = /** @type {((inputs?: Field_Void_FractionInputs, options?: { locale?: "en" | "bn" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Field_Void_FractionInputs, { locale?: "en" | "bn" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
26
|
+
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
27
|
+
if (locale === "en") return en_field_void_fraction(inputs)
|
|
28
|
+
return bn_field_void_fraction(inputs)
|
|
29
|
+
});
|