@kuncat/avoidant 0.3.0 → 0.4.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.
- package/README.md +43 -3
- package/dist/assets/favicon.svg +1 -1
- package/dist/assets/fonts/NOTO-SANS-SYMBOLS-LICENSE.txt +93 -0
- package/dist/assets/fonts/noto-sans-symbols-arrows.woff2 +0 -0
- package/dist/components/AvoidantGame.svelte +98 -44
- package/dist/components/AvoidantGame.svelte.d.ts +11 -0
- package/dist/components/GameHistory.svelte +1 -1
- package/dist/components/MapControls.svelte +27 -1
- package/dist/components/MapControls.svelte.d.ts +2 -0
- package/dist/components/MatchResults.svelte +1 -2
- package/dist/components/MatchResults.svelte.d.ts +0 -1
- package/dist/components/MultiplayerGame.svelte +73 -14
- package/dist/components/MultiplayerGame.svelte.d.ts +3 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/dist/multiplayer/client.d.ts +5 -2
- package/dist/multiplayer/client.js +22 -6
- package/dist/multiplayer/current-match.d.ts +3 -0
- package/dist/multiplayer/current-match.js +37 -0
- package/dist/multiplayer/invitations.d.ts +2 -0
- package/dist/multiplayer/invitations.js +23 -0
- package/dist/multiplayer/types.d.ts +10 -0
- package/dist/paraglide/messages/_index.d.ts +8 -1
- package/dist/paraglide/messages/_index.js +8 -1
- package/dist/paraglide/messages/{field_relay_servers.d.ts → action_see_plans.d.ts} +5 -5
- package/dist/paraglide/messages/action_see_plans.js +29 -0
- package/dist/paraglide/messages/error_tv_pairing.d.ts +16 -0
- package/dist/paraglide/messages/error_tv_pairing.js +29 -0
- package/dist/paraglide/messages/field_public_game.d.ts +16 -0
- package/dist/paraglide/messages/field_public_game.js +29 -0
- package/dist/paraglide/messages/help_public_game.d.ts +16 -0
- package/dist/paraglide/messages/help_public_game.js +29 -0
- package/dist/paraglide/messages/share_watch_help.d.ts +16 -0
- package/dist/paraglide/messages/share_watch_help.js +29 -0
- package/dist/paraglide/messages/status_public_unlisted.d.ts +16 -0
- package/dist/paraglide/messages/status_public_unlisted.js +29 -0
- package/dist/paraglide/messages/status_tv_showing.d.ts +16 -0
- package/dist/paraglide/messages/status_tv_showing.js +29 -0
- package/dist/paraglide/messages/text_multiplayer_subscription.d.ts +16 -0
- package/dist/paraglide/messages/text_multiplayer_subscription.js +29 -0
- package/dist/paraglide/messages/text_waiting_lobby.d.ts +1 -1
- package/dist/paraglide/messages/text_waiting_lobby.js +2 -2
- package/dist/styles/global.css +13 -0
- package/dist/wasm/avoidant_wasm.d.ts +3 -208
- package/dist/wasm/avoidant_wasm.js +20 -1101
- package/dist/wasm/avoidant_wasm_bg.wasm +0 -0
- package/dist/wasm/avoidant_wasm_bg.wasm.d.ts +3 -65
- package/package.json +1 -1
- package/dist/paraglide/messages/field_relay_servers.js +0 -29
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import type { GameOptions } from "../wasm/avoidant_wasm";
|
|
16
16
|
import { revealSweep } from "../multiplayer/reveal";
|
|
17
17
|
import { MatchClient } from "../multiplayer/client";
|
|
18
|
+
import { forgetMatch, rememberMatch } from "../multiplayer/current-match";
|
|
18
19
|
import {
|
|
19
20
|
PLAYER_COLORS,
|
|
20
21
|
type BoardState,
|
|
@@ -22,6 +23,7 @@
|
|
|
22
23
|
type MultiplayerSetup,
|
|
23
24
|
type CompetitiveConfig,
|
|
24
25
|
type MatchSnapshot,
|
|
26
|
+
type SpectatorSession,
|
|
25
27
|
} from "../multiplayer/types";
|
|
26
28
|
import init, {
|
|
27
29
|
type CellMetadataEntry,
|
|
@@ -30,12 +32,16 @@
|
|
|
30
32
|
} from "../wasm/avoidant_wasm";
|
|
31
33
|
let {
|
|
32
34
|
config,
|
|
35
|
+
spectator,
|
|
36
|
+
cameraPan = false,
|
|
33
37
|
onexit,
|
|
34
38
|
setup,
|
|
35
39
|
invitation,
|
|
36
40
|
playerName = $bindable(),
|
|
37
41
|
}: {
|
|
38
42
|
config: CompetitiveConfig;
|
|
43
|
+
spectator?: SpectatorSession;
|
|
44
|
+
cameraPan?: boolean;
|
|
39
45
|
onexit: () => void;
|
|
40
46
|
setup?: MultiplayerSetup;
|
|
41
47
|
invitation?: string;
|
|
@@ -43,6 +49,8 @@
|
|
|
43
49
|
} = $props();
|
|
44
50
|
let account = $state<{ id: string; capabilities: string[] } | null>(null);
|
|
45
51
|
let message = $state("");
|
|
52
|
+
let discoveryNotice = $state("");
|
|
53
|
+
let tvNotice = $state("");
|
|
46
54
|
let connectionIssue = $state(false);
|
|
47
55
|
let flat = $state(false);
|
|
48
56
|
let matchId = $state("");
|
|
@@ -141,7 +149,8 @@
|
|
|
141
149
|
}
|
|
142
150
|
let myIndex = $derived(snapshot?.players.findIndex((p) => p.id === account?.id) ?? -1);
|
|
143
151
|
let canPlay = $derived(
|
|
144
|
-
|
|
152
|
+
!spectator &&
|
|
153
|
+
!!snapshot?.started &&
|
|
145
154
|
!snapshot.finished &&
|
|
146
155
|
(snapshot.turn === null || snapshot.turn === myIndex),
|
|
147
156
|
);
|
|
@@ -151,6 +160,11 @@
|
|
|
151
160
|
void (async () => {
|
|
152
161
|
try {
|
|
153
162
|
await init();
|
|
163
|
+
if (spectator) {
|
|
164
|
+
matchId = spectator.id;
|
|
165
|
+
await join();
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
154
168
|
account = await config.account.account();
|
|
155
169
|
if (account && invitation) {
|
|
156
170
|
matchId = invitation;
|
|
@@ -224,8 +238,11 @@
|
|
|
224
238
|
if (canPlay && player) client?.move(player.sequence + 1, { kind: "select", cell });
|
|
225
239
|
}
|
|
226
240
|
async function join() {
|
|
227
|
-
if (!account) return;
|
|
228
|
-
|
|
241
|
+
if (!account && !spectator) return;
|
|
242
|
+
if (!spectator) {
|
|
243
|
+
sessionStorage.setItem("avoidant:competitiveMatch", matchId);
|
|
244
|
+
if (account) rememberMatch(matchId, account.id);
|
|
245
|
+
}
|
|
229
246
|
client?.close();
|
|
230
247
|
connectionGeneration++;
|
|
231
248
|
copied = false;
|
|
@@ -237,7 +254,7 @@
|
|
|
237
254
|
client = new MatchClient(
|
|
238
255
|
config,
|
|
239
256
|
matchId,
|
|
240
|
-
account
|
|
257
|
+
account?.id ?? "",
|
|
241
258
|
(s, m, n) => void receive(s, m, n),
|
|
242
259
|
(m, reconnect) => {
|
|
243
260
|
message = m;
|
|
@@ -245,14 +262,40 @@
|
|
|
245
262
|
savingName = false;
|
|
246
263
|
},
|
|
247
264
|
() => playerName,
|
|
265
|
+
(url) => {
|
|
266
|
+
invitationUrl = url;
|
|
267
|
+
},
|
|
268
|
+
spectator?.capability,
|
|
248
269
|
);
|
|
249
270
|
const url = new SvelteURL(window.location.href);
|
|
250
271
|
url.search = "";
|
|
251
272
|
url.hash = "";
|
|
252
273
|
url.searchParams.set("match", matchId);
|
|
253
274
|
invitationUrl = url.toString();
|
|
275
|
+
if (!spectator) history.replaceState(null, "", url);
|
|
254
276
|
await client.connect();
|
|
277
|
+
if (config.tvPair && !spectator) await showOnTV(config.tvPair);
|
|
255
278
|
}
|
|
279
|
+
/** A phone that scanned a TV's code and then joined a game sends that game to the TV. */
|
|
280
|
+
async function showOnTV(pair: { id: string; claim: string }) {
|
|
281
|
+
try {
|
|
282
|
+
const response = await fetch(`${config.serverUrl}/tv/${pair.id}/attach`, {
|
|
283
|
+
method: "POST",
|
|
284
|
+
headers: { "Content-Type": "application/json" },
|
|
285
|
+
body: JSON.stringify({ claim: pair.claim, code: matchId }),
|
|
286
|
+
});
|
|
287
|
+
if (!response.ok) throw new Error((await response.json()).error);
|
|
288
|
+
tvNotice = m.status_tv_showing();
|
|
289
|
+
} catch {
|
|
290
|
+
tvNotice = m.error_tv_pairing();
|
|
291
|
+
} finally {
|
|
292
|
+
sessionStorage.removeItem("avoidant:tv-pair");
|
|
293
|
+
config.tvPair = undefined;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
$effect(() => {
|
|
297
|
+
if (snapshot?.finished && !spectator) forgetMatch();
|
|
298
|
+
});
|
|
256
299
|
async function create() {
|
|
257
300
|
try {
|
|
258
301
|
const response = await fetch(`${config.serverUrl}/matches`, {
|
|
@@ -261,14 +304,20 @@
|
|
|
261
304
|
Authorization: `Bearer ${await config.account.token()}`,
|
|
262
305
|
"Content-Type": "application/json",
|
|
263
306
|
},
|
|
264
|
-
body: JSON.stringify(setup),
|
|
307
|
+
body: JSON.stringify({ ...setup, tvPair: config.tvPair }),
|
|
265
308
|
});
|
|
266
309
|
const data = await response.json();
|
|
267
310
|
if (!response.ok) throw new Error(data.error);
|
|
311
|
+
if (setup?.public && !data.listed) discoveryNotice = m.status_public_unlisted();
|
|
268
312
|
matchId = data.id;
|
|
313
|
+
if (config.tvPair) {
|
|
314
|
+
sessionStorage.removeItem("avoidant:tv-pair");
|
|
315
|
+
config.tvPair = undefined;
|
|
316
|
+
history.replaceState(null, "", location.pathname);
|
|
317
|
+
}
|
|
269
318
|
await join();
|
|
270
319
|
} catch (e) {
|
|
271
|
-
message = String(e);
|
|
320
|
+
message = e instanceof Error ? e.message : String(e);
|
|
272
321
|
}
|
|
273
322
|
}
|
|
274
323
|
async function copyInvitation() {
|
|
@@ -284,6 +333,7 @@
|
|
|
284
333
|
function leave() {
|
|
285
334
|
resetAnimations();
|
|
286
335
|
sessionStorage.removeItem("avoidant:competitiveMatch");
|
|
336
|
+
forgetMatch();
|
|
287
337
|
const url = new SvelteURL(window.location.href);
|
|
288
338
|
url.searchParams.delete("match");
|
|
289
339
|
history.replaceState(null, "", url);
|
|
@@ -299,6 +349,13 @@
|
|
|
299
349
|
<div class="panel-shell panel-header w-full max-w-full">
|
|
300
350
|
<div class="flex flex-wrap items-center gap-3">
|
|
301
351
|
<h1 class="panel-title text-lg font-semibold tracking-wide">Avoidant</h1>
|
|
352
|
+
{#if spectator && snapshot}
|
|
353
|
+
<div class="flex flex-wrap gap-4" aria-label="Player scores">
|
|
354
|
+
{#each snapshot.players as p, i (p.id)}<span style:color={PLAYER_COLORS[i]}
|
|
355
|
+
>{displayName(i)} · {p.score}</span
|
|
356
|
+
>{/each}
|
|
357
|
+
</div>
|
|
358
|
+
{/if}
|
|
302
359
|
{#if snapshot?.started}
|
|
303
360
|
{@const match = snapshot}
|
|
304
361
|
<ScoreSummary>
|
|
@@ -311,7 +368,7 @@
|
|
|
311
368
|
.toLocaleString(getLocale()),
|
|
312
369
|
})}</strong
|
|
313
370
|
>
|
|
314
|
-
{:else}
|
|
371
|
+
{:else if !spectator}
|
|
315
372
|
{m.label_score()}:
|
|
316
373
|
<strong>{(player?.score ?? 0).toLocaleString(getLocale())}</strong>
|
|
317
374
|
{/if}
|
|
@@ -389,14 +446,15 @@
|
|
|
389
446
|
<button class="btn btn-error" onclick={leave}>{m.action_exit()}</button>
|
|
390
447
|
</div>
|
|
391
448
|
</div>
|
|
392
|
-
{#if snapshot?.finished}<MatchResults
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
449
|
+
{#if snapshot?.finished}<MatchResults players={snapshot.players} />{/if}
|
|
450
|
+
{#if discoveryNotice}<p role="status" class="mt-2 text-sm opacity-80">
|
|
451
|
+
{discoveryNotice}
|
|
452
|
+
</p>{/if}
|
|
453
|
+
{#if tvNotice}<p role="status" class="mt-2 text-sm opacity-80">{tvNotice}</p>{/if}
|
|
396
454
|
{#if message}
|
|
397
455
|
<div class="mt-2 flex flex-wrap items-center gap-2 text-sm">
|
|
398
456
|
<p role="status" class="text-amber-300">{message}</p>
|
|
399
|
-
{#if connectionIssue}
|
|
457
|
+
{#if connectionIssue && !spectator}
|
|
400
458
|
<button class="btn btn-secondary" onclick={() => config.account.login()}
|
|
401
459
|
>{m.action_login_again()}</button
|
|
402
460
|
>
|
|
@@ -408,7 +466,7 @@
|
|
|
408
466
|
{/if}
|
|
409
467
|
</div>
|
|
410
468
|
</div>
|
|
411
|
-
{#if !snapshot?.started}
|
|
469
|
+
{#if !snapshot?.started && !spectator}
|
|
412
470
|
<div class="panel-wrapper panel-wrapper-card fixed inset-x-0 z-10 flex justify-center px-3">
|
|
413
471
|
<div class="panel-shell panel-card w-full max-w-md space-y-4 py-6 text-slate-700">
|
|
414
472
|
{#if !account}
|
|
@@ -466,6 +524,7 @@
|
|
|
466
524
|
onclick={(event) => event.currentTarget.select()}
|
|
467
525
|
/>
|
|
468
526
|
</label>
|
|
527
|
+
<p class="text-sm">{m.share_watch_help()}</p>
|
|
469
528
|
<div class="flex flex-wrap justify-center gap-2">
|
|
470
529
|
<button class="btn btn-secondary" onclick={copyInvitation}
|
|
471
530
|
>{copied ? m.action_copied() : m.action_copy_invitation()}</button
|
|
@@ -497,7 +556,7 @@
|
|
|
497
556
|
owners={snapshot?.cells.map((c) => c.owner) ?? []}
|
|
498
557
|
showZeroCounts={snapshot?.options.floodLimit !== null}
|
|
499
558
|
/>
|
|
500
|
-
<MapControls {flat} radius={geometry.boundsRadius} />
|
|
559
|
+
<MapControls {flat} radius={geometry.boundsRadius} keyboard={!!spectator} pan={cameraPan} />
|
|
501
560
|
</Canvas>
|
|
502
561
|
</div>
|
|
503
562
|
{/if}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { type MultiplayerSetup, type CompetitiveConfig } from "../multiplayer/types";
|
|
1
|
+
import { type MultiplayerSetup, type CompetitiveConfig, type SpectatorSession } from "../multiplayer/types";
|
|
2
2
|
type $$ComponentProps = {
|
|
3
3
|
config: CompetitiveConfig;
|
|
4
|
+
spectator?: SpectatorSession;
|
|
5
|
+
cameraPan?: boolean;
|
|
4
6
|
onexit: () => void;
|
|
5
7
|
setup?: MultiplayerSetup;
|
|
6
8
|
invitation?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { default as favicon } from "./assets/favicon.svg";
|
|
2
2
|
export { default as AvoidantGame } from "./components/AvoidantGame.svelte";
|
|
3
3
|
export type { CompetitiveConfig } from "./multiplayer/types";
|
|
4
|
+
export { default as AvoidantSpectator } from "./components/MultiplayerGame.svelte";
|
|
5
|
+
export type { SpectatorSession } from "./multiplayer/types";
|
|
6
|
+
export { currentMatch, forgetMatch } from "./multiplayer/current-match";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { default as favicon } from "./assets/favicon.svg";
|
|
2
2
|
export { default as AvoidantGame } from "./components/AvoidantGame.svelte";
|
|
3
|
+
export { default as AvoidantSpectator } from "./components/MultiplayerGame.svelte";
|
|
4
|
+
export { currentMatch, forgetMatch } from "./multiplayer/current-match";
|
|
@@ -2,17 +2,20 @@ import type { CompetitiveConfig, MatchSnapshot } from "./types";
|
|
|
2
2
|
/** One pending action at a time; retries reuse the sequence after reconnection. */
|
|
3
3
|
export declare class MatchClient {
|
|
4
4
|
private config;
|
|
5
|
-
|
|
5
|
+
id: string;
|
|
6
6
|
private actor;
|
|
7
7
|
private receive;
|
|
8
8
|
private report;
|
|
9
9
|
private playerName;
|
|
10
|
+
private invitationReceived?;
|
|
11
|
+
private spectatorCapability?;
|
|
10
12
|
private socket?;
|
|
11
13
|
private pending?;
|
|
12
14
|
private stopped;
|
|
15
|
+
private finished;
|
|
13
16
|
private retry?;
|
|
14
17
|
private retryCount;
|
|
15
|
-
constructor(config: CompetitiveConfig, id: string, actor: string, receive: (s: MatchSnapshot, map: string, neighbors: number[][]) => void, report: (s: string, reconnect?: boolean) => void, playerName: () => string);
|
|
18
|
+
constructor(config: CompetitiveConfig, id: string, actor: string, receive: (s: MatchSnapshot, map: string, neighbors: number[][]) => void, report: (s: string, reconnect?: boolean) => void, playerName: () => string, invitationReceived?: ((url: string) => void) | undefined, spectatorCapability?: string | undefined);
|
|
16
19
|
connect(): Promise<void>;
|
|
17
20
|
start(): void;
|
|
18
21
|
move(sequence: number, action: unknown): void;
|
|
@@ -7,18 +7,23 @@ export class MatchClient {
|
|
|
7
7
|
receive;
|
|
8
8
|
report;
|
|
9
9
|
playerName;
|
|
10
|
+
invitationReceived;
|
|
11
|
+
spectatorCapability;
|
|
10
12
|
socket;
|
|
11
13
|
pending;
|
|
12
14
|
stopped = false;
|
|
15
|
+
finished = false;
|
|
13
16
|
retry;
|
|
14
17
|
retryCount = 0;
|
|
15
|
-
constructor(config, id, actor, receive, report, playerName) {
|
|
18
|
+
constructor(config, id, actor, receive, report, playerName, invitationReceived, spectatorCapability) {
|
|
16
19
|
this.config = config;
|
|
17
20
|
this.id = id;
|
|
18
21
|
this.actor = actor;
|
|
19
22
|
this.receive = receive;
|
|
20
23
|
this.report = report;
|
|
21
24
|
this.playerName = playerName;
|
|
25
|
+
this.invitationReceived = invitationReceived;
|
|
26
|
+
this.spectatorCapability = spectatorCapability;
|
|
22
27
|
}
|
|
23
28
|
async connect() {
|
|
24
29
|
clearTimeout(this.retry);
|
|
@@ -27,10 +32,12 @@ export class MatchClient {
|
|
|
27
32
|
this.socket.close();
|
|
28
33
|
}
|
|
29
34
|
try {
|
|
30
|
-
const response = await fetch(`${this.config.serverUrl}/matches/${this.id}
|
|
35
|
+
const response = await fetch(`${this.config.serverUrl}/matches/${this.id}/${this.spectatorCapability ? "watch" : "connect"}`, {
|
|
31
36
|
method: "POST",
|
|
32
37
|
headers: {
|
|
33
|
-
Authorization:
|
|
38
|
+
Authorization: this.spectatorCapability
|
|
39
|
+
? `Spectator ${this.spectatorCapability}`
|
|
40
|
+
: `Bearer ${await this.config.account.token()}`,
|
|
34
41
|
"Content-Type": "application/json",
|
|
35
42
|
},
|
|
36
43
|
body: JSON.stringify({ name: this.playerName().trim() }),
|
|
@@ -42,6 +49,10 @@ export class MatchClient {
|
|
|
42
49
|
: (data.error ?? m.error_match_join()));
|
|
43
50
|
if (this.stopped)
|
|
44
51
|
return;
|
|
52
|
+
if (data.id)
|
|
53
|
+
this.id = data.id;
|
|
54
|
+
if (data.invitationUrl)
|
|
55
|
+
this.invitationReceived?.(data.invitationUrl);
|
|
45
56
|
const url = new URL(`${this.config.serverUrl}/matches/${this.id}/socket`);
|
|
46
57
|
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
47
58
|
url.searchParams.set("ticket", data.ticket);
|
|
@@ -65,13 +76,14 @@ export class MatchClient {
|
|
|
65
76
|
const player = s.players.find((p) => p.id === this.actor);
|
|
66
77
|
if (this.pending && player && player.sequence >= this.pending.sequence)
|
|
67
78
|
this.pending = undefined;
|
|
79
|
+
this.finished = s.finished;
|
|
68
80
|
this.retryCount = 0;
|
|
69
81
|
this.receive(s, message.map, message.neighbors);
|
|
70
82
|
if (this.pending)
|
|
71
83
|
this.socket?.send(JSON.stringify(this.pending));
|
|
72
84
|
};
|
|
73
85
|
this.socket.onclose = (event) => {
|
|
74
|
-
if (this.stopped)
|
|
86
|
+
if (this.stopped || this.finished)
|
|
75
87
|
return;
|
|
76
88
|
if (event.code === 1000) {
|
|
77
89
|
this.report(m.status_match_expired());
|
|
@@ -84,13 +96,17 @@ export class MatchClient {
|
|
|
84
96
|
}
|
|
85
97
|
catch (error) {
|
|
86
98
|
this.report(error instanceof Error ? error.message : m.error_connection_failed(), true);
|
|
99
|
+
if (this.spectatorCapability && !this.stopped && !this.finished) {
|
|
100
|
+
this.retry = setTimeout(() => void this.connect(), Math.min(1000 * 2 ** this.retryCount++, 15000));
|
|
101
|
+
}
|
|
87
102
|
}
|
|
88
103
|
}
|
|
89
104
|
start() {
|
|
90
|
-
this.
|
|
105
|
+
if (!this.spectatorCapability)
|
|
106
|
+
this.send({ kind: "start" });
|
|
91
107
|
}
|
|
92
108
|
move(sequence, action) {
|
|
93
|
-
if (this.pending)
|
|
109
|
+
if (this.spectatorCapability || this.pending)
|
|
94
110
|
return;
|
|
95
111
|
if (this.socket?.readyState !== WebSocket.OPEN) {
|
|
96
112
|
this.report(m.error_reconnect_to_play(), true);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The game this browser last joined. Scanning a TV's QR code opens a new tab, which has
|
|
3
|
+
* no session storage, so the TV pairing page reads this to offer the game in progress.
|
|
4
|
+
* It is kept per account: another account on the same browser must not join that game.
|
|
5
|
+
*/
|
|
6
|
+
const KEY = "avoidant:currentMatch";
|
|
7
|
+
const MAX_AGE = 12 * 3600_000;
|
|
8
|
+
export function rememberMatch(id, actor) {
|
|
9
|
+
try {
|
|
10
|
+
localStorage.setItem(KEY, JSON.stringify({ id, actor, at: Date.now() }));
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
/* Storage can be unavailable in private windows. */
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function forgetMatch() {
|
|
17
|
+
try {
|
|
18
|
+
localStorage.removeItem(KEY);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
/* Nothing was stored. */
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function currentMatch(actor) {
|
|
25
|
+
try {
|
|
26
|
+
const saved = JSON.parse(localStorage.getItem(KEY) ?? "null");
|
|
27
|
+
return typeof saved?.id === "string" &&
|
|
28
|
+
actor &&
|
|
29
|
+
saved.actor === actor &&
|
|
30
|
+
Date.now() - saved.at < MAX_AGE
|
|
31
|
+
? saved.id
|
|
32
|
+
: null;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Accept existing UUID invitations, share codes, and exact kuga.run links. */
|
|
2
|
+
export function parseInvitation(input) {
|
|
3
|
+
let value = input.trim();
|
|
4
|
+
try {
|
|
5
|
+
if (/^(?:https?:\/\/)?kuga\.run\//i.test(value)) {
|
|
6
|
+
const url = new URL(/^https?:/i.test(value) ? value : `https://${value}`);
|
|
7
|
+
if (url.hostname !== "kuga.run" || url.username || url.password || url.port)
|
|
8
|
+
return null;
|
|
9
|
+
value = url.pathname.slice(1);
|
|
10
|
+
}
|
|
11
|
+
else if (/^https?:\/\//i.test(value)) {
|
|
12
|
+
value = new URL(value).searchParams.get("match") ?? "";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (/^[A-Za-z]{4,32}$/.test(value))
|
|
19
|
+
return value.toUpperCase();
|
|
20
|
+
return /^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/.test(value)
|
|
21
|
+
? value
|
|
22
|
+
: null;
|
|
23
|
+
}
|
|
@@ -11,7 +11,16 @@ export interface BoardState {
|
|
|
11
11
|
elevationMax: number;
|
|
12
12
|
queueExplorePulse(index: number, x: number, y: number, z: number): void;
|
|
13
13
|
}
|
|
14
|
+
export interface SpectatorSession {
|
|
15
|
+
id: string;
|
|
16
|
+
capability: string;
|
|
17
|
+
invitationUrl?: string;
|
|
18
|
+
}
|
|
14
19
|
export interface CompetitiveConfig {
|
|
20
|
+
tvPair?: {
|
|
21
|
+
id: string;
|
|
22
|
+
claim: string;
|
|
23
|
+
};
|
|
15
24
|
serverUrl: string;
|
|
16
25
|
account: {
|
|
17
26
|
login(register?: boolean): Promise<void>;
|
|
@@ -61,6 +70,7 @@ export interface MatchSnapshot {
|
|
|
61
70
|
}
|
|
62
71
|
export declare const PLAYER_COLORS: string[];
|
|
63
72
|
export interface MultiplayerSetup {
|
|
73
|
+
public?: boolean;
|
|
64
74
|
mode: "collaborative" | "territory";
|
|
65
75
|
map: string;
|
|
66
76
|
bordering: boolean;
|
|
@@ -18,6 +18,7 @@ export * from "./action_random.js";
|
|
|
18
18
|
export * from "./action_reconnect.js";
|
|
19
19
|
export * from "./action_register.js";
|
|
20
20
|
export * from "./action_save_name.js";
|
|
21
|
+
export * from "./action_see_plans.js";
|
|
21
22
|
export * from "./action_start.js";
|
|
22
23
|
export * from "./action_start_match.js";
|
|
23
24
|
export * from "./aria_close_invitation.js";
|
|
@@ -42,6 +43,7 @@ export * from "./error_name_server_update.js";
|
|
|
42
43
|
export * from "./error_player_name.js";
|
|
43
44
|
export * from "./error_reconnect_to_play.js";
|
|
44
45
|
export * from "./error_replay.js";
|
|
46
|
+
export * from "./error_tv_pairing.js";
|
|
45
47
|
export * from "./error_unsupported_map.js";
|
|
46
48
|
export * from "./faces_count.js";
|
|
47
49
|
export * from "./field_bordering.js";
|
|
@@ -61,11 +63,11 @@ export * from "./field_match_duration.js";
|
|
|
61
63
|
export * from "./field_match_minutes.js";
|
|
62
64
|
export * from "./field_play_mode.js";
|
|
63
65
|
export * from "./field_player_name.js";
|
|
66
|
+
export * from "./field_public_game.js";
|
|
64
67
|
export * from "./field_radius.js";
|
|
65
68
|
export * from "./field_radius_x.js";
|
|
66
69
|
export * from "./field_radius_y.js";
|
|
67
70
|
export * from "./field_radius_z.js";
|
|
68
|
-
export * from "./field_relay_servers.js";
|
|
69
71
|
export * from "./field_seed.js";
|
|
70
72
|
export * from "./field_size.js";
|
|
71
73
|
export * from "./field_spikiness.js";
|
|
@@ -86,6 +88,7 @@ export * from "./help_match_duration.js";
|
|
|
86
88
|
export * from "./help_participation_time.js";
|
|
87
89
|
export * from "./help_play_mode.js";
|
|
88
90
|
export * from "./help_player_name.js";
|
|
91
|
+
export * from "./help_public_game.js";
|
|
89
92
|
export * from "./help_seed.js";
|
|
90
93
|
export * from "./help_size.js";
|
|
91
94
|
export * from "./help_spikiness.js";
|
|
@@ -129,6 +132,7 @@ export * from "./preset_large.js";
|
|
|
129
132
|
export * from "./preset_medium.js";
|
|
130
133
|
export * from "./preset_small.js";
|
|
131
134
|
export * from "./shape_label.js";
|
|
135
|
+
export * from "./share_watch_help.js";
|
|
132
136
|
export * from "./status_connecting.js";
|
|
133
137
|
export * from "./status_draw.js";
|
|
134
138
|
export * from "./status_generating_map.js";
|
|
@@ -142,15 +146,18 @@ export * from "./status_named_turn.js";
|
|
|
142
146
|
export * from "./status_named_winner.js";
|
|
143
147
|
export * from "./status_player_turn.js";
|
|
144
148
|
export * from "./status_preparing.js";
|
|
149
|
+
export * from "./status_public_unlisted.js";
|
|
145
150
|
export * from "./status_realtime_claims.js";
|
|
146
151
|
export * from "./status_reconnecting.js";
|
|
147
152
|
export * from "./status_session_complete.js";
|
|
153
|
+
export * from "./status_tv_showing.js";
|
|
148
154
|
export * from "./status_winner.js";
|
|
149
155
|
export * from "./text_account_multiplayer.js";
|
|
150
156
|
export * from "./text_avoided.js";
|
|
151
157
|
export * from "./text_density_summary.js";
|
|
152
158
|
export * from "./text_invite_after_opening.js";
|
|
153
159
|
export * from "./text_multiplayer_login.js";
|
|
160
|
+
export * from "./text_multiplayer_subscription.js";
|
|
154
161
|
export * from "./text_relay_servers_hint.js";
|
|
155
162
|
export * from "./text_waiting_lobby.js";
|
|
156
163
|
export * from "./tutorial_action_dismiss.js";
|
|
@@ -20,6 +20,7 @@ export * from './action_random.js'
|
|
|
20
20
|
export * from './action_reconnect.js'
|
|
21
21
|
export * from './action_register.js'
|
|
22
22
|
export * from './action_save_name.js'
|
|
23
|
+
export * from './action_see_plans.js'
|
|
23
24
|
export * from './action_start.js'
|
|
24
25
|
export * from './action_start_match.js'
|
|
25
26
|
export * from './aria_close_invitation.js'
|
|
@@ -44,6 +45,7 @@ export * from './error_name_server_update.js'
|
|
|
44
45
|
export * from './error_player_name.js'
|
|
45
46
|
export * from './error_reconnect_to_play.js'
|
|
46
47
|
export * from './error_replay.js'
|
|
48
|
+
export * from './error_tv_pairing.js'
|
|
47
49
|
export * from './error_unsupported_map.js'
|
|
48
50
|
export * from './faces_count.js'
|
|
49
51
|
export * from './field_bordering.js'
|
|
@@ -63,11 +65,11 @@ export * from './field_match_duration.js'
|
|
|
63
65
|
export * from './field_match_minutes.js'
|
|
64
66
|
export * from './field_play_mode.js'
|
|
65
67
|
export * from './field_player_name.js'
|
|
68
|
+
export * from './field_public_game.js'
|
|
66
69
|
export * from './field_radius.js'
|
|
67
70
|
export * from './field_radius_x.js'
|
|
68
71
|
export * from './field_radius_y.js'
|
|
69
72
|
export * from './field_radius_z.js'
|
|
70
|
-
export * from './field_relay_servers.js'
|
|
71
73
|
export * from './field_seed.js'
|
|
72
74
|
export * from './field_size.js'
|
|
73
75
|
export * from './field_spikiness.js'
|
|
@@ -88,6 +90,7 @@ export * from './help_match_duration.js'
|
|
|
88
90
|
export * from './help_participation_time.js'
|
|
89
91
|
export * from './help_play_mode.js'
|
|
90
92
|
export * from './help_player_name.js'
|
|
93
|
+
export * from './help_public_game.js'
|
|
91
94
|
export * from './help_seed.js'
|
|
92
95
|
export * from './help_size.js'
|
|
93
96
|
export * from './help_spikiness.js'
|
|
@@ -131,6 +134,7 @@ export * from './preset_large.js'
|
|
|
131
134
|
export * from './preset_medium.js'
|
|
132
135
|
export * from './preset_small.js'
|
|
133
136
|
export * from './shape_label.js'
|
|
137
|
+
export * from './share_watch_help.js'
|
|
134
138
|
export * from './status_connecting.js'
|
|
135
139
|
export * from './status_draw.js'
|
|
136
140
|
export * from './status_generating_map.js'
|
|
@@ -144,15 +148,18 @@ export * from './status_named_turn.js'
|
|
|
144
148
|
export * from './status_named_winner.js'
|
|
145
149
|
export * from './status_player_turn.js'
|
|
146
150
|
export * from './status_preparing.js'
|
|
151
|
+
export * from './status_public_unlisted.js'
|
|
147
152
|
export * from './status_realtime_claims.js'
|
|
148
153
|
export * from './status_reconnecting.js'
|
|
149
154
|
export * from './status_session_complete.js'
|
|
155
|
+
export * from './status_tv_showing.js'
|
|
150
156
|
export * from './status_winner.js'
|
|
151
157
|
export * from './text_account_multiplayer.js'
|
|
152
158
|
export * from './text_avoided.js'
|
|
153
159
|
export * from './text_density_summary.js'
|
|
154
160
|
export * from './text_invite_after_opening.js'
|
|
155
161
|
export * from './text_multiplayer_login.js'
|
|
162
|
+
export * from './text_multiplayer_subscription.js'
|
|
156
163
|
export * from './text_relay_servers_hint.js'
|
|
157
164
|
export * from './text_waiting_lobby.js'
|
|
158
165
|
export * from './tutorial_action_dismiss.js'
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* | output |
|
|
3
3
|
* | --- |
|
|
4
|
-
* | "
|
|
4
|
+
* | "See plans" |
|
|
5
5
|
*
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {Action_See_PlansInputs} inputs
|
|
7
7
|
* @param {{ locale?: "en" | "bn" }} options
|
|
8
8
|
* @returns {LocalizedString}
|
|
9
9
|
*/
|
|
10
|
-
export const
|
|
10
|
+
export const action_see_plans: ((inputs?: Action_See_PlansInputs, options?: {
|
|
11
11
|
locale?: "en" | "bn";
|
|
12
|
-
}) => LocalizedString) & import("../runtime.js").MessageMetadata<
|
|
12
|
+
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Action_See_PlansInputs, {
|
|
13
13
|
locale?: "en" | "bn";
|
|
14
14
|
}, {}>;
|
|
15
15
|
export type LocalizedString = import("../runtime.js").LocalizedString;
|
|
16
|
-
export type
|
|
16
|
+
export type Action_See_PlansInputs = {};
|
|
@@ -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 {{}} Action_See_PlansInputs */
|
|
7
|
+
|
|
8
|
+
const en_action_see_plans = /** @type {(inputs: Action_See_PlansInputs) => LocalizedString} */ () => {
|
|
9
|
+
return /** @type {LocalizedString} */ (`See plans`)
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const bn_action_see_plans = /** @type {(inputs: Action_See_PlansInputs) => LocalizedString} */ () => {
|
|
13
|
+
return /** @type {LocalizedString} */ (`প্ল্যান দেখুন`)
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* | output |
|
|
18
|
+
* | --- |
|
|
19
|
+
* | "See plans" |
|
|
20
|
+
*
|
|
21
|
+
* @param {Action_See_PlansInputs} inputs
|
|
22
|
+
* @param {{ locale?: "en" | "bn" }} options
|
|
23
|
+
* @returns {LocalizedString}
|
|
24
|
+
*/
|
|
25
|
+
export const action_see_plans = /** @type {((inputs?: Action_See_PlansInputs, options?: { locale?: "en" | "bn" }) => LocalizedString) & import('../runtime.js').MessageMetadata<Action_See_PlansInputs, { locale?: "en" | "bn" }, {}>} */ ((inputs = {}, options = {}) => {
|
|
26
|
+
const locale = experimentalStaticLocale ?? options.locale ?? getLocale()
|
|
27
|
+
if (locale === "bn") return bn_action_see_plans(inputs)
|
|
28
|
+
return en_action_see_plans(inputs)
|
|
29
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* | output |
|
|
3
|
+
* | --- |
|
|
4
|
+
* | "Couldn’t reach the TV. Scan its code again." |
|
|
5
|
+
*
|
|
6
|
+
* @param {Error_Tv_PairingInputs} inputs
|
|
7
|
+
* @param {{ locale?: "en" | "bn" }} options
|
|
8
|
+
* @returns {LocalizedString}
|
|
9
|
+
*/
|
|
10
|
+
export const error_tv_pairing: ((inputs?: Error_Tv_PairingInputs, options?: {
|
|
11
|
+
locale?: "en" | "bn";
|
|
12
|
+
}) => LocalizedString) & import("../runtime.js").MessageMetadata<Error_Tv_PairingInputs, {
|
|
13
|
+
locale?: "en" | "bn";
|
|
14
|
+
}, {}>;
|
|
15
|
+
export type LocalizedString = import("../runtime.js").LocalizedString;
|
|
16
|
+
export type Error_Tv_PairingInputs = {};
|