@kuncat/avoidant 0.2.4 → 0.3.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 (250) hide show
  1. package/README.md +29 -18
  2. package/dist/components/AvoidantGame.svelte +743 -457
  3. package/dist/components/AvoidantGame.svelte.d.ts +2 -1
  4. package/dist/components/GameHistory.svelte +103 -0
  5. package/dist/components/GameHistory.svelte.d.ts +8 -0
  6. package/dist/components/MapIcon.svelte +40 -0
  7. package/dist/components/MapIcon.svelte.d.ts +7 -0
  8. package/dist/components/MatchResults.svelte +29 -0
  9. package/dist/components/MatchResults.svelte.d.ts +8 -0
  10. package/dist/components/MultiplayerGame.svelte +504 -0
  11. package/dist/components/MultiplayerGame.svelte.d.ts +11 -0
  12. package/dist/components/OptionHelp.svelte +96 -0
  13. package/dist/components/OptionHelp.svelte.d.ts +7 -0
  14. package/dist/components/ScoreSummary.svelte +43 -0
  15. package/dist/components/ScoreSummary.svelte.d.ts +8 -0
  16. package/dist/components/board.svelte +54 -5
  17. package/dist/components/board.svelte.d.ts +4 -2
  18. package/dist/components/fragment.glsl +34 -0
  19. package/dist/index.d.ts +1 -0
  20. package/dist/multiplayer/client.d.ts +21 -0
  21. package/dist/multiplayer/client.js +111 -0
  22. package/dist/multiplayer/duration.d.ts +1 -0
  23. package/dist/multiplayer/duration.js +6 -0
  24. package/dist/multiplayer/local-identity.d.ts +1 -0
  25. package/dist/multiplayer/local-identity.js +13 -0
  26. package/dist/multiplayer/maps.json +275 -0
  27. package/dist/multiplayer/reveal.d.ts +11 -0
  28. package/dist/multiplayer/reveal.js +16 -0
  29. package/dist/multiplayer/types.d.ts +80 -0
  30. package/dist/multiplayer/types.js +10 -0
  31. package/dist/paraglide/messages/_index.d.ts +103 -0
  32. package/dist/paraglide/messages/_index.js +104 -1
  33. package/dist/paraglide/messages/action_copied.d.ts +16 -0
  34. package/dist/paraglide/messages/action_copied.js +29 -0
  35. package/dist/paraglide/messages/action_copy_invitation.d.ts +16 -0
  36. package/dist/paraglide/messages/action_copy_invitation.js +29 -0
  37. package/dist/paraglide/messages/action_download_replay.d.ts +16 -0
  38. package/dist/paraglide/messages/action_download_replay.js +29 -0
  39. package/dist/paraglide/messages/action_game_history.d.ts +16 -0
  40. package/dist/paraglide/messages/action_game_history.js +29 -0
  41. package/dist/paraglide/messages/action_load_more.d.ts +16 -0
  42. package/dist/paraglide/messages/action_load_more.js +29 -0
  43. package/dist/paraglide/messages/action_login.d.ts +16 -0
  44. package/dist/paraglide/messages/action_login.js +29 -0
  45. package/dist/paraglide/messages/action_login_again.d.ts +16 -0
  46. package/dist/paraglide/messages/action_login_again.js +29 -0
  47. package/dist/paraglide/messages/action_logout.d.ts +16 -0
  48. package/dist/paraglide/messages/action_logout.js +29 -0
  49. package/dist/paraglide/messages/action_pass.d.ts +16 -0
  50. package/dist/paraglide/messages/action_pass.js +29 -0
  51. package/dist/paraglide/messages/action_reconnect.d.ts +16 -0
  52. package/dist/paraglide/messages/action_reconnect.js +29 -0
  53. package/dist/paraglide/messages/action_register.d.ts +16 -0
  54. package/dist/paraglide/messages/action_register.js +29 -0
  55. package/dist/paraglide/messages/action_save_name.d.ts +16 -0
  56. package/dist/paraglide/messages/action_save_name.js +29 -0
  57. package/dist/paraglide/messages/action_start_match.d.ts +16 -0
  58. package/dist/paraglide/messages/action_start_match.js +29 -0
  59. package/dist/paraglide/messages/error_connection_failed.d.ts +16 -0
  60. package/dist/paraglide/messages/error_connection_failed.js +29 -0
  61. package/dist/paraglide/messages/error_connection_interrupted.d.ts +16 -0
  62. package/dist/paraglide/messages/error_connection_interrupted.js +29 -0
  63. package/dist/paraglide/messages/error_history.d.ts +16 -0
  64. package/dist/paraglide/messages/error_history.js +29 -0
  65. package/dist/paraglide/messages/error_invitation_invalid.d.ts +16 -0
  66. package/dist/paraglide/messages/error_invitation_invalid.js +29 -0
  67. package/dist/paraglide/messages/error_login_to_join.d.ts +16 -0
  68. package/dist/paraglide/messages/error_login_to_join.js +29 -0
  69. package/dist/paraglide/messages/error_map_version.d.ts +16 -0
  70. package/dist/paraglide/messages/error_map_version.js +29 -0
  71. package/dist/paraglide/messages/error_match_join.d.ts +16 -0
  72. package/dist/paraglide/messages/error_match_join.js +29 -0
  73. package/dist/paraglide/messages/error_match_version.d.ts +16 -0
  74. package/dist/paraglide/messages/error_match_version.js +29 -0
  75. package/dist/paraglide/messages/error_name_not_saved.d.ts +16 -0
  76. package/dist/paraglide/messages/error_name_not_saved.js +29 -0
  77. package/dist/paraglide/messages/error_name_server_update.d.ts +16 -0
  78. package/dist/paraglide/messages/error_name_server_update.js +29 -0
  79. package/dist/paraglide/messages/error_player_name.d.ts +16 -0
  80. package/dist/paraglide/messages/error_player_name.js +29 -0
  81. package/dist/paraglide/messages/error_reconnect_to_play.d.ts +16 -0
  82. package/dist/paraglide/messages/error_reconnect_to_play.js +29 -0
  83. package/dist/paraglide/messages/error_replay.d.ts +16 -0
  84. package/dist/paraglide/messages/error_replay.js +29 -0
  85. package/dist/paraglide/messages/error_unsupported_map.d.ts +16 -0
  86. package/dist/paraglide/messages/error_unsupported_map.js +29 -0
  87. package/dist/paraglide/messages/field_bordering.d.ts +16 -0
  88. package/dist/paraglide/messages/field_bordering.js +29 -0
  89. package/dist/paraglide/messages/field_duration_unit.d.ts +16 -0
  90. package/dist/paraglide/messages/field_duration_unit.js +29 -0
  91. package/dist/paraglide/messages/field_finite_flood.d.ts +16 -0
  92. package/dist/paraglide/messages/field_finite_flood.js +29 -0
  93. package/dist/paraglide/messages/field_flood_cells.d.ts +16 -0
  94. package/dist/paraglide/messages/field_flood_cells.js +29 -0
  95. package/dist/paraglide/messages/field_flood_limit.d.ts +16 -0
  96. package/dist/paraglide/messages/field_flood_limit.js +29 -0
  97. package/dist/paraglide/messages/field_infinite_flood.d.ts +16 -0
  98. package/dist/paraglide/messages/field_infinite_flood.js +29 -0
  99. package/dist/paraglide/messages/field_invitation_link.d.ts +16 -0
  100. package/dist/paraglide/messages/field_invitation_link.js +29 -0
  101. package/dist/paraglide/messages/field_language.d.ts +16 -0
  102. package/dist/paraglide/messages/field_language.js +29 -0
  103. package/dist/paraglide/messages/field_map.d.ts +16 -0
  104. package/dist/paraglide/messages/field_map.js +29 -0
  105. package/dist/paraglide/messages/field_map_size.d.ts +1 -1
  106. package/dist/paraglide/messages/field_map_size.js +3 -3
  107. package/dist/paraglide/messages/field_match_duration.d.ts +16 -0
  108. package/dist/paraglide/messages/field_match_duration.js +29 -0
  109. package/dist/paraglide/messages/field_match_minutes.d.ts +16 -0
  110. package/dist/paraglide/messages/field_match_minutes.js +29 -0
  111. package/dist/paraglide/messages/field_play_mode.d.ts +16 -0
  112. package/dist/paraglide/messages/field_play_mode.js +29 -0
  113. package/dist/paraglide/messages/field_size.d.ts +1 -1
  114. package/dist/paraglide/messages/field_size.js +3 -3
  115. package/dist/paraglide/messages/field_turn_based.d.ts +16 -0
  116. package/dist/paraglide/messages/field_turn_based.js +29 -0
  117. package/dist/paraglide/messages/field_turn_duration.d.ts +16 -0
  118. package/dist/paraglide/messages/field_turn_duration.js +29 -0
  119. package/dist/paraglide/messages/field_turn_duration_unit.d.ts +16 -0
  120. package/dist/paraglide/messages/field_turn_duration_unit.js +29 -0
  121. package/dist/paraglide/messages/field_turn_timer.d.ts +16 -0
  122. package/dist/paraglide/messages/field_turn_timer.js +29 -0
  123. package/dist/paraglide/messages/help_bordering.d.ts +16 -0
  124. package/dist/paraglide/messages/help_bordering.js +29 -0
  125. package/dist/paraglide/messages/help_flood_limit.d.ts +16 -0
  126. package/dist/paraglide/messages/help_flood_limit.js +29 -0
  127. package/dist/paraglide/messages/help_map.d.ts +16 -0
  128. package/dist/paraglide/messages/help_map.js +29 -0
  129. package/dist/paraglide/messages/help_map_size.d.ts +16 -0
  130. package/dist/paraglide/messages/help_map_size.js +29 -0
  131. package/dist/paraglide/messages/help_match_duration.d.ts +16 -0
  132. package/dist/paraglide/messages/help_match_duration.js +29 -0
  133. package/dist/paraglide/messages/help_participation_time.d.ts +16 -0
  134. package/dist/paraglide/messages/help_participation_time.js +29 -0
  135. package/dist/paraglide/messages/help_play_mode.d.ts +16 -0
  136. package/dist/paraglide/messages/help_play_mode.js +29 -0
  137. package/dist/paraglide/messages/help_player_name.d.ts +16 -0
  138. package/dist/paraglide/messages/help_player_name.js +29 -0
  139. package/dist/paraglide/messages/help_seed.d.ts +16 -0
  140. package/dist/paraglide/messages/help_seed.js +29 -0
  141. package/dist/paraglide/messages/help_size.d.ts +16 -0
  142. package/dist/paraglide/messages/help_size.js +29 -0
  143. package/dist/paraglide/messages/help_spikiness.d.ts +16 -0
  144. package/dist/paraglide/messages/help_spikiness.js +29 -0
  145. package/dist/paraglide/messages/help_turn_based.d.ts +16 -0
  146. package/dist/paraglide/messages/help_turn_based.js +29 -0
  147. package/dist/paraglide/messages/help_turn_duration.d.ts +16 -0
  148. package/dist/paraglide/messages/help_turn_duration.js +29 -0
  149. package/dist/paraglide/messages/help_turn_time.d.ts +16 -0
  150. package/dist/paraglide/messages/help_turn_time.js +29 -0
  151. package/dist/paraglide/messages/help_turn_timer.d.ts +16 -0
  152. package/dist/paraglide/messages/help_turn_timer.js +29 -0
  153. package/dist/paraglide/messages/help_tutorial_mode.d.ts +16 -0
  154. package/dist/paraglide/messages/help_tutorial_mode.js +29 -0
  155. package/dist/paraglide/messages/help_void_fraction.d.ts +16 -0
  156. package/dist/paraglide/messages/help_void_fraction.js +29 -0
  157. package/dist/paraglide/messages/history_empty.d.ts +16 -0
  158. package/dist/paraglide/messages/history_empty.js +29 -0
  159. package/dist/paraglide/messages/label_claims.d.ts +18 -0
  160. package/dist/paraglide/messages/label_claims.js +29 -0
  161. package/dist/paraglide/messages/label_cumulative_time.d.ts +16 -0
  162. package/dist/paraglide/messages/label_cumulative_time.js +29 -0
  163. package/dist/paraglide/messages/label_custom_map_options.d.ts +16 -0
  164. package/dist/paraglide/messages/label_custom_map_options.js +29 -0
  165. package/dist/paraglide/messages/label_gameplay_options.d.ts +16 -0
  166. package/dist/paraglide/messages/label_gameplay_options.js +29 -0
  167. package/dist/paraglide/messages/label_map_options.d.ts +16 -0
  168. package/dist/paraglide/messages/label_map_options.js +29 -0
  169. package/dist/paraglide/messages/label_match_ends.d.ts +18 -0
  170. package/dist/paraglide/messages/label_match_ends.js +29 -0
  171. package/dist/paraglide/messages/label_match_id.d.ts +18 -0
  172. package/dist/paraglide/messages/label_match_id.js +29 -0
  173. package/dist/paraglide/messages/label_player_number.d.ts +18 -0
  174. package/dist/paraglide/messages/label_player_number.js +29 -0
  175. package/dist/paraglide/messages/label_points.d.ts +18 -0
  176. package/dist/paraglide/messages/label_points.js +29 -0
  177. package/dist/paraglide/messages/label_revealed_count.d.ts +18 -0
  178. package/dist/paraglide/messages/label_revealed_count.js +29 -0
  179. package/dist/paraglide/messages/label_team_score.d.ts +18 -0
  180. package/dist/paraglide/messages/label_team_score.js +29 -0
  181. package/dist/paraglide/messages/label_turn_remaining.d.ts +18 -0
  182. package/dist/paraglide/messages/label_turn_remaining.js +29 -0
  183. package/dist/paraglide/messages/label_you.d.ts +16 -0
  184. package/dist/paraglide/messages/label_you.js +29 -0
  185. package/dist/paraglide/messages/mode_collaborative.d.ts +16 -0
  186. package/dist/paraglide/messages/mode_collaborative.js +29 -0
  187. package/dist/paraglide/messages/mode_collaborative_hint.d.ts +16 -0
  188. package/dist/paraglide/messages/mode_collaborative_hint.js +29 -0
  189. package/dist/paraglide/messages/mode_solo.d.ts +16 -0
  190. package/dist/paraglide/messages/mode_solo.js +29 -0
  191. package/dist/paraglide/messages/mode_solo_hint.d.ts +16 -0
  192. package/dist/paraglide/messages/mode_solo_hint.js +29 -0
  193. package/dist/paraglide/messages/mode_territory.d.ts +16 -0
  194. package/dist/paraglide/messages/mode_territory.js +29 -0
  195. package/dist/paraglide/messages/mode_territory_hint.d.ts +16 -0
  196. package/dist/paraglide/messages/mode_territory_hint.js +29 -0
  197. package/dist/paraglide/messages/multiplayer_title.d.ts +16 -0
  198. package/dist/paraglide/messages/multiplayer_title.js +29 -0
  199. package/dist/paraglide/messages/option_help.d.ts +18 -0
  200. package/dist/paraglide/messages/option_help.js +29 -0
  201. package/dist/paraglide/messages/shape_label.d.ts +5 -5
  202. package/dist/paraglide/messages/shape_label.js +15 -15
  203. package/dist/paraglide/messages/status_connecting.d.ts +16 -0
  204. package/dist/paraglide/messages/status_connecting.js +29 -0
  205. package/dist/paraglide/messages/status_draw.d.ts +16 -0
  206. package/dist/paraglide/messages/status_draw.js +29 -0
  207. package/dist/paraglide/messages/status_match_complete.d.ts +16 -0
  208. package/dist/paraglide/messages/status_match_complete.js +29 -0
  209. package/dist/paraglide/messages/status_match_expired.d.ts +16 -0
  210. package/dist/paraglide/messages/status_match_expired.js +29 -0
  211. package/dist/paraglide/messages/status_name_saved.d.ts +16 -0
  212. package/dist/paraglide/messages/status_name_saved.js +29 -0
  213. package/dist/paraglide/messages/status_named_turn.d.ts +18 -0
  214. package/dist/paraglide/messages/status_named_turn.js +29 -0
  215. package/dist/paraglide/messages/status_named_winner.d.ts +18 -0
  216. package/dist/paraglide/messages/status_named_winner.js +29 -0
  217. package/dist/paraglide/messages/status_player_turn.d.ts +18 -0
  218. package/dist/paraglide/messages/status_player_turn.js +29 -0
  219. package/dist/paraglide/messages/status_realtime_claims.d.ts +16 -0
  220. package/dist/paraglide/messages/status_realtime_claims.js +29 -0
  221. package/dist/paraglide/messages/status_reconnecting.d.ts +16 -0
  222. package/dist/paraglide/messages/status_reconnecting.js +29 -0
  223. package/dist/paraglide/messages/status_session_complete.d.ts +16 -0
  224. package/dist/paraglide/messages/status_session_complete.js +29 -0
  225. package/dist/paraglide/messages/status_winner.d.ts +18 -0
  226. package/dist/paraglide/messages/status_winner.js +29 -0
  227. package/dist/paraglide/messages/text_account_multiplayer.d.ts +16 -0
  228. package/dist/paraglide/messages/text_account_multiplayer.js +29 -0
  229. package/dist/paraglide/messages/text_multiplayer_login.d.ts +16 -0
  230. package/dist/paraglide/messages/text_multiplayer_login.js +29 -0
  231. package/dist/paraglide/messages/text_waiting_lobby.d.ts +16 -0
  232. package/dist/paraglide/messages/text_waiting_lobby.js +29 -0
  233. package/dist/paraglide/messages/unit_hours.d.ts +16 -0
  234. package/dist/paraglide/messages/unit_hours.js +29 -0
  235. package/dist/paraglide/messages/unit_hours_selected.d.ts +19 -0
  236. package/dist/paraglide/messages/unit_hours_selected.js +35 -0
  237. package/dist/paraglide/messages/unit_minutes.d.ts +16 -0
  238. package/dist/paraglide/messages/unit_minutes.js +29 -0
  239. package/dist/paraglide/messages/unit_minutes_selected.d.ts +19 -0
  240. package/dist/paraglide/messages/unit_minutes_selected.js +35 -0
  241. package/dist/paraglide/messages/unit_seconds.d.ts +16 -0
  242. package/dist/paraglide/messages/unit_seconds.js +29 -0
  243. package/dist/paraglide/messages/unit_seconds_selected.d.ts +19 -0
  244. package/dist/paraglide/messages/unit_seconds_selected.js +35 -0
  245. package/dist/styles/global.css +12 -51
  246. package/dist/wasm/avoidant_wasm.d.ts +11 -11
  247. package/dist/wasm/avoidant_wasm.js +43 -43
  248. package/dist/wasm/avoidant_wasm_bg.wasm +0 -0
  249. package/dist/wasm/avoidant_wasm_bg.wasm.d.ts +11 -11
  250. package/package.json +6 -4
@@ -0,0 +1,504 @@
1
+ <script lang="ts">
2
+ import { m } from "../paraglide/messages";
3
+ import { getLocale } from "../paraglide/runtime";
4
+ import { onMount } from "svelte";
5
+ import { SvelteSet, SvelteURL } from "svelte/reactivity";
6
+ import { writable } from "svelte/store";
7
+ import { Canvas, T } from "@threlte/core";
8
+ import { WebGLRenderer } from "three";
9
+ import MatchResults from "./MatchResults.svelte";
10
+ import ScoreSummary from "./ScoreSummary.svelte";
11
+ import Board from "./board.svelte";
12
+ import MapControls from "./MapControls.svelte";
13
+ import { generateMap } from "../workers/mapgen-client";
14
+ import mapOptions from "../multiplayer/maps.json";
15
+ import type { GameOptions } from "../wasm/avoidant_wasm";
16
+ import { revealSweep } from "../multiplayer/reveal";
17
+ import { MatchClient } from "../multiplayer/client";
18
+ import {
19
+ PLAYER_COLORS,
20
+ type BoardState,
21
+ type BoardPulse,
22
+ type MultiplayerSetup,
23
+ type CompetitiveConfig,
24
+ type MatchSnapshot,
25
+ } from "../multiplayer/types";
26
+ import init, {
27
+ type CellMetadataEntry,
28
+ type MapCell,
29
+ type MapData,
30
+ } from "../wasm/avoidant_wasm";
31
+ let {
32
+ config,
33
+ onexit,
34
+ setup,
35
+ invitation,
36
+ playerName = $bindable(),
37
+ }: {
38
+ config: CompetitiveConfig;
39
+ onexit: () => void;
40
+ setup?: MultiplayerSetup;
41
+ invitation?: string;
42
+ playerName: string;
43
+ } = $props();
44
+ let account = $state<{ id: string; capabilities: string[] } | null>(null);
45
+ let message = $state("");
46
+ let connectionIssue = $state(false);
47
+ let flat = $state(false);
48
+ let matchId = $state("");
49
+ let snapshot = $state<MatchSnapshot>();
50
+ let geometry = $state<MapData>();
51
+ let board = $state<BoardState>();
52
+ let client: MatchClient | undefined;
53
+ let geometryPromise: Promise<void> | undefined;
54
+ let disposed = false;
55
+ let connectionGeneration = 0;
56
+ const cells = writable<MapCell[]>([]);
57
+ const metadata = writable<CellMetadataEntry[]>([]);
58
+ const pulses = writable<BoardPulse[]>([]);
59
+ let invitationUrl = $state("");
60
+ let copied = $state(false);
61
+ let savingName = $state(false);
62
+ let nameSaved = $state(false);
63
+ let now = $state(Date.now());
64
+ let renderedSnapshot: MatchSnapshot | undefined;
65
+ let pulseId = 0;
66
+ let clicked: { cell: number; position: [number, number, number] } | undefined;
67
+ const animationTimers = new SvelteSet<ReturnType<typeof setTimeout>>();
68
+ const revealing = new SvelteSet<number>();
69
+ function resetAnimations() {
70
+ for (const timer of animationTimers) clearTimeout(timer);
71
+ animationTimers.clear();
72
+ revealing.clear();
73
+ pulses.set([]);
74
+ renderedSnapshot = undefined;
75
+ clicked = undefined;
76
+ }
77
+ function later(callback: () => void, delay: number) {
78
+ const timer = setTimeout(() => {
79
+ animationTimers.delete(timer);
80
+ callback();
81
+ }, delay);
82
+ animationTimers.add(timer);
83
+ }
84
+ function updateMetadata() {
85
+ if (!renderedSnapshot) return;
86
+ metadata.set(
87
+ renderedSnapshot.cells.map((c, i) => ({
88
+ isExplored: c.revealed && !revealing.has(i),
89
+ isVoid: c.isVoid ?? false,
90
+ voidNeighborCount: c.count ?? 0,
91
+ isRevealing: revealing.has(i),
92
+ })),
93
+ );
94
+ }
95
+ function renderSnapshot(next: MatchSnapshot) {
96
+ if (!geometry || (renderedSnapshot && next.revision <= renderedSnapshot.revision)) return;
97
+ const previous = renderedSnapshot;
98
+ renderedSnapshot = next;
99
+ const opened = previous
100
+ ? next.cells.flatMap((c, i) => (c.revealed && !previous.cells[i].revealed ? [i] : []))
101
+ : [];
102
+ if (opened.length) {
103
+ const originCell = opened.find((i) => next.cells[i].owner !== null) ?? opened[0];
104
+ const id = ++pulseId;
105
+ const localMoved =
106
+ next.players.find((p) => p.id === account?.id)?.sequence !==
107
+ previous?.players.find((p) => p.id === account?.id)?.sequence;
108
+ const sweep = revealSweep(
109
+ geometry.cells,
110
+ opened,
111
+ originCell,
112
+ localMoved && clicked && opened.includes(clicked.cell) ? clicked.position : undefined,
113
+ );
114
+ if (localMoved) clicked = undefined;
115
+ pulses.update((items) => [
116
+ ...items,
117
+ {
118
+ id,
119
+ createdAtMs: performance.now(),
120
+ durationMs: sweep.durationMs,
121
+ position: sweep.position,
122
+ originCell,
123
+ isRemote: !localMoved,
124
+ maxRadius: sweep.maxRadius,
125
+ },
126
+ ]);
127
+ for (const { cell, afterMs } of sweep.finishes) {
128
+ revealing.add(cell);
129
+ later(() => {
130
+ revealing.delete(cell);
131
+ updateMetadata();
132
+ }, afterMs);
133
+ }
134
+ later(() => pulses.update((items) => items.filter((p) => p.id !== id)), sweep.durationMs);
135
+ }
136
+ updateMetadata();
137
+ }
138
+ let player = $derived(snapshot?.players.find((p) => p.id === account?.id));
139
+ function displayName(index: number) {
140
+ return snapshot?.players[index]?.name || m.default_player_name();
141
+ }
142
+ let myIndex = $derived(snapshot?.players.findIndex((p) => p.id === account?.id) ?? -1);
143
+ let canPlay = $derived(
144
+ !!snapshot?.started &&
145
+ !snapshot.finished &&
146
+ (snapshot.turn === null || snapshot.turn === myIndex),
147
+ );
148
+
149
+ onMount(() => {
150
+ const clock = setInterval(() => (now = Date.now()), 1000);
151
+ void (async () => {
152
+ try {
153
+ await init();
154
+ account = await config.account.account();
155
+ if (account && invitation) {
156
+ matchId = invitation;
157
+ await join();
158
+ } else if (account && setup) await create();
159
+ } catch (e) {
160
+ message = String(e);
161
+ }
162
+ })();
163
+ return () => {
164
+ clearInterval(clock);
165
+ disposed = true;
166
+ resetAnimations();
167
+ client?.close();
168
+ };
169
+ });
170
+ async function receive(next: MatchSnapshot, mapName: string, neighbors: number[][]) {
171
+ const generation = connectionGeneration;
172
+ if (snapshot && next.revision < snapshot.revision) return;
173
+ snapshot = next;
174
+ message = "";
175
+ connectionIssue = false;
176
+ const own = next.players.find((p) => p.id === account?.id);
177
+ if (own && own.name === undefined) message = m.error_name_server_update();
178
+ if (savingName && own) {
179
+ savingName = false;
180
+ nameSaved = own.name === playerName.trim();
181
+ if (!nameSaved) message = m.error_name_not_saved();
182
+ }
183
+ geometryPromise ??= (async () => {
184
+ const options = (mapOptions as Record<string, GameOptions>)[mapName];
185
+ if (!options) throw new Error(m.error_unsupported_map());
186
+ const generated = await generateMap(options);
187
+ flat = options.shape?.kind === "flat";
188
+ if (disposed || generation !== connectionGeneration) return;
189
+ if (
190
+ generated.cells.length !== next.cells.length ||
191
+ JSON.stringify(generated.cells.map((c) => c.neighbors)) !== JSON.stringify(neighbors)
192
+ )
193
+ throw new Error(m.error_map_version());
194
+ cells.set(generated.cells);
195
+ geometry = generated;
196
+ board = {
197
+ cells,
198
+ cellMetadata: metadata,
199
+ uiState: { pulses },
200
+ elevationMin: 0,
201
+ elevationMax: 6,
202
+ queueExplorePulse(index, x, y, z) {
203
+ clicked = { cell: index, position: [x, y, z] };
204
+ select(index);
205
+ },
206
+ };
207
+ })();
208
+ try {
209
+ await geometryPromise;
210
+ if (!disposed && generation === connectionGeneration && snapshot) renderSnapshot(snapshot);
211
+ } catch (e) {
212
+ message = String(e);
213
+ client?.close();
214
+ }
215
+ }
216
+ function select(cell: number) {
217
+ const target = snapshot?.cells[cell];
218
+ if (
219
+ !target ||
220
+ target.owner !== null ||
221
+ (target.revealed && (target.isVoid || snapshot?.options.mode !== "territory"))
222
+ )
223
+ return;
224
+ if (canPlay && player) client?.move(player.sequence + 1, { kind: "select", cell });
225
+ }
226
+ async function join() {
227
+ if (!account) return;
228
+ sessionStorage.setItem("avoidant:competitiveMatch", matchId);
229
+ client?.close();
230
+ connectionGeneration++;
231
+ copied = false;
232
+ resetAnimations();
233
+ snapshot = undefined;
234
+ geometry = undefined;
235
+ board = undefined;
236
+ geometryPromise = undefined;
237
+ client = new MatchClient(
238
+ config,
239
+ matchId,
240
+ account.id,
241
+ (s, m, n) => void receive(s, m, n),
242
+ (m, reconnect) => {
243
+ message = m;
244
+ connectionIssue = !!reconnect;
245
+ savingName = false;
246
+ },
247
+ () => playerName,
248
+ );
249
+ const url = new SvelteURL(window.location.href);
250
+ url.search = "";
251
+ url.hash = "";
252
+ url.searchParams.set("match", matchId);
253
+ invitationUrl = url.toString();
254
+ await client.connect();
255
+ }
256
+ async function create() {
257
+ try {
258
+ const response = await fetch(`${config.serverUrl}/matches`, {
259
+ method: "POST",
260
+ headers: {
261
+ Authorization: `Bearer ${await config.account.token()}`,
262
+ "Content-Type": "application/json",
263
+ },
264
+ body: JSON.stringify(setup),
265
+ });
266
+ const data = await response.json();
267
+ if (!response.ok) throw new Error(data.error);
268
+ matchId = data.id;
269
+ await join();
270
+ } catch (e) {
271
+ message = String(e);
272
+ }
273
+ }
274
+ async function copyInvitation() {
275
+ try {
276
+ await navigator.clipboard.writeText(invitationUrl);
277
+ copied = true;
278
+ } catch {
279
+ const input = document.getElementById("competitive-invitation") as HTMLInputElement | null;
280
+ input?.focus();
281
+ input?.select();
282
+ }
283
+ }
284
+ function leave() {
285
+ resetAnimations();
286
+ sessionStorage.removeItem("avoidant:competitiveMatch");
287
+ const url = new SvelteURL(window.location.href);
288
+ url.searchParams.delete("match");
289
+ history.replaceState(null, "", url);
290
+ client?.close();
291
+ onexit();
292
+ }
293
+ </script>
294
+
295
+ <div data-theme="winter" class="not-prose h-dvh bg-transparent text-white">
296
+ <div
297
+ class="panel-wrapper panel-wrapper-header fixed inset-x-0 z-20 flex justify-center bg-transparent"
298
+ >
299
+ <div class="panel-shell panel-header w-full max-w-full">
300
+ <div class="flex flex-wrap items-center gap-3">
301
+ <h1 class="panel-title text-lg font-semibold tracking-wide">Avoidant</h1>
302
+ {#if snapshot?.started}
303
+ {@const match = snapshot}
304
+ <ScoreSummary>
305
+ {#snippet summary()}
306
+ {#if match.options.mode === "collaborative"}
307
+ <strong
308
+ >{m.label_team_score({
309
+ score: match.players
310
+ .reduce((sum, p) => sum + p.score, 0)
311
+ .toLocaleString(getLocale()),
312
+ })}</strong
313
+ >
314
+ {:else}
315
+ {m.label_score()}:
316
+ <strong>{(player?.score ?? 0).toLocaleString(getLocale())}</strong>
317
+ {/if}
318
+ <span class="opacity-80">
319
+ {#if match.finished}
320
+ {#if match.options.mode === "collaborative"}{m.status_session_complete()}
321
+ {:else}
322
+ {@const best = Math.max(...match.players.map((p) => p.score))}
323
+ {m.status_match_complete()} — {match.players.filter((p) => p.score === best)
324
+ .length > 1
325
+ ? m.status_draw()
326
+ : m.status_named_winner({
327
+ name: displayName(match.players.findIndex((p) => p.score === best)),
328
+ })}
329
+ {/if}
330
+ {:else if match.turn !== null}
331
+ {m.status_named_turn({ name: displayName(match.turn) })}
332
+ {#if match.turnDeadline > 0}<span class="tabular-nums">
333
+ · {m.label_turn_remaining({
334
+ seconds: Math.max(
335
+ 0,
336
+ Math.ceil((match.turnDeadline - now) / 1000),
337
+ ).toLocaleString(getLocale()),
338
+ })}</span
339
+ >{/if}
340
+ {:else if match.options.mode === "collaborative"}{m.mode_collaborative_hint()}
341
+ {:else}{m.status_realtime_claims()}{/if}
342
+ </span>
343
+ {/snippet}
344
+ {#snippet breakdown()}
345
+ <div class="grid gap-2">
346
+ {#each match.players as p, i (p.id)}
347
+ <div class="flex items-start justify-between gap-4">
348
+ <span style:color={PLAYER_COLORS[i]}
349
+ >{displayName(i)}{p.id === account?.id ? m.label_you() : ""}</span
350
+ >
351
+ <div class="text-right">
352
+ <strong
353
+ >{m.label_points({ count: p.score.toLocaleString(getLocale()) })}</strong
354
+ >
355
+ {#if match.options.mode === "territory"}<p class="opacity-80">
356
+ {m.label_claims({ count: p.claims.toLocaleString(getLocale()) })}
357
+ </p>{/if}
358
+ <p class="opacity-70">
359
+ {m.label_voids_discovered()}: {p.voids.toLocaleString(getLocale())}
360
+ </p>
361
+ </div>
362
+ </div>
363
+ {/each}
364
+ <p class="border-t border-slate-600 pt-2">
365
+ {m.label_revealed_count({
366
+ count: match.cells
367
+ .filter((c) => c.revealed && !c.isVoid)
368
+ .length.toLocaleString(getLocale()),
369
+ })}
370
+ </p>
371
+ {#if !match.finished}<p class="opacity-70">
372
+ {m.label_match_ends({
373
+ time: new Date(match.deadline).toLocaleTimeString(getLocale()),
374
+ })}
375
+ </p>{/if}
376
+ </div>
377
+ {/snippet}
378
+ </ScoreSummary>
379
+ {/if}
380
+ <div class="ml-auto flex gap-2">
381
+ {#if snapshot?.started && !snapshot.finished && snapshot.turn !== null}
382
+ <button
383
+ class="btn btn-secondary"
384
+ disabled={!canPlay}
385
+ onclick={() => player && client?.move(player.sequence + 1, { kind: "pass" })}
386
+ >{m.action_pass()}</button
387
+ >
388
+ {/if}
389
+ <button class="btn btn-error" onclick={leave}>{m.action_exit()}</button>
390
+ </div>
391
+ </div>
392
+ {#if snapshot?.finished}<MatchResults
393
+ players={snapshot.players}
394
+ turnBased={snapshot.options.turnBased}
395
+ />{/if}
396
+ {#if message}
397
+ <div class="mt-2 flex flex-wrap items-center gap-2 text-sm">
398
+ <p role="status" class="text-amber-300">{message}</p>
399
+ {#if connectionIssue}
400
+ <button class="btn btn-secondary" onclick={() => config.account.login()}
401
+ >{m.action_login_again()}</button
402
+ >
403
+ {#if snapshot}<button class="btn btn-secondary" onclick={() => client?.connect()}
404
+ >{m.action_reconnect()}</button
405
+ >{/if}
406
+ {/if}
407
+ </div>
408
+ {/if}
409
+ </div>
410
+ </div>
411
+ {#if !snapshot?.started}
412
+ <div class="panel-wrapper panel-wrapper-card fixed inset-x-0 z-10 flex justify-center px-3">
413
+ <div class="panel-shell panel-card w-full max-w-md space-y-4 py-6 text-slate-700">
414
+ {#if !account}
415
+ <p>{m.text_account_multiplayer()}</p>
416
+ <button class="btn btn-primary" onclick={() => config.account.login()}
417
+ >{m.action_login()}</button
418
+ >
419
+ <button class="btn btn-secondary" onclick={() => config.account.login(true)}
420
+ >{m.action_register()}</button
421
+ >
422
+ {:else if !snapshot}<p>{m.status_connecting()}</p>
423
+ {:else}
424
+ <p>{m.text_waiting_lobby()}</p>
425
+ <form
426
+ class="flex items-end gap-2"
427
+ onsubmit={(event) => {
428
+ event.preventDefault();
429
+ savingName = true;
430
+ nameSaved = false;
431
+ void client?.connect();
432
+ }}
433
+ >
434
+ <label class="fieldset min-w-0 flex-1 py-0 text-left">
435
+ <span class="fieldset-legend">{m.field_player_name()}</span>
436
+ <input
437
+ class="input w-full input-sm"
438
+ type="text"
439
+ required
440
+ maxlength="32"
441
+ bind:value={playerName}
442
+ />
443
+ </label>
444
+ <button
445
+ class="btn btn-secondary btn-sm"
446
+ type="submit"
447
+ disabled={savingName || playerName.trim() === player?.name}
448
+ >{m.action_save_name()}</button
449
+ >
450
+ </form>
451
+ {#if nameSaved && playerName.trim() === player?.name}<p class="text-sm" role="status">
452
+ {m.status_name_saved()}
453
+ </p>{/if}
454
+ <div class="flex flex-wrap justify-center gap-3">
455
+ {#each snapshot.players as p, i (p.id)}<span
456
+ >{displayName(i)}{p.id === account.id ? m.label_you() : ""}</span
457
+ >{/each}
458
+ </div>
459
+ <label class="fieldset text-left">
460
+ <span class="fieldset-legend">{m.field_invitation_link()}</span>
461
+ <input
462
+ id="competitive-invitation"
463
+ class="input w-full input-sm"
464
+ readonly
465
+ value={invitationUrl}
466
+ onclick={(event) => event.currentTarget.select()}
467
+ />
468
+ </label>
469
+ <div class="flex flex-wrap justify-center gap-2">
470
+ <button class="btn btn-secondary" onclick={copyInvitation}
471
+ >{copied ? m.action_copied() : m.action_copy_invitation()}</button
472
+ >
473
+ {#if myIndex === 0}<button
474
+ class="btn btn-primary"
475
+ disabled={snapshot.players.length < 2}
476
+ onclick={() => client?.start()}>{m.action_start_match()}</button
477
+ >{/if}
478
+ </div>
479
+ {/if}
480
+ </div>
481
+ </div>
482
+ {/if}
483
+ {#if board && geometry}
484
+ <div class="game-canvas-container h-full w-full">
485
+ <Canvas
486
+ colorSpace="srgb-linear"
487
+ renderMode="on-demand"
488
+ shadows={false}
489
+ createRenderer={(canvas) => new WebGLRenderer({ canvas, alpha: true, antialias: true })}
490
+ >
491
+ <T.PerspectiveCamera makeDefault fov={50} near={0.1} far={1000} position={[90, 70, 90]} />
492
+ <Board
493
+ gameState={board}
494
+ terrain={geometry.terrain}
495
+ surfaceArea={geometry.surfaceArea}
496
+ interactive={canPlay}
497
+ owners={snapshot?.cells.map((c) => c.owner) ?? []}
498
+ showZeroCounts={snapshot?.options.floodLimit !== null}
499
+ />
500
+ <MapControls {flat} radius={geometry.boundsRadius} />
501
+ </Canvas>
502
+ </div>
503
+ {/if}
504
+ </div>
@@ -0,0 +1,11 @@
1
+ import { type MultiplayerSetup, type CompetitiveConfig } from "../multiplayer/types";
2
+ type $$ComponentProps = {
3
+ config: CompetitiveConfig;
4
+ onexit: () => void;
5
+ setup?: MultiplayerSetup;
6
+ invitation?: string;
7
+ playerName: string;
8
+ };
9
+ declare const MultiplayerGame: import("svelte").Component<$$ComponentProps, {}, "playerName">;
10
+ type MultiplayerGame = ReturnType<typeof MultiplayerGame>;
11
+ export default MultiplayerGame;
@@ -0,0 +1,96 @@
1
+ <script lang="ts">
2
+ import { onMount } from "svelte";
3
+ import { m } from "../paraglide/messages";
4
+ let { label, help }: { label: string; help: string } = $props();
5
+ const id = $props.id();
6
+ let trigger: HTMLSpanElement;
7
+ let popup: HTMLSpanElement;
8
+ let pinned = false;
9
+ let focused = false;
10
+ let hovered = false;
11
+
12
+ function position() {
13
+ if (!popup?.matches(":popover-open")) return;
14
+ const anchor = trigger.getBoundingClientRect();
15
+ const gap = 8;
16
+ const room = window.innerWidth - anchor.right - gap * 2;
17
+ const width = Math.min(288, window.innerWidth - gap * 2);
18
+ popup.style.width = `${room >= 160 ? Math.min(width, room) : width}px`;
19
+ const height = popup.getBoundingClientRect().height;
20
+ // Prefer the right; narrow screens fall below rather than clipping the text.
21
+ const right = room >= 160;
22
+ popup.style.left = `${right ? anchor.right + gap : Math.max(gap, window.innerWidth - width - gap)}px`;
23
+ popup.style.top = `${Math.max(gap, Math.min(window.innerHeight - height - gap, right ? anchor.top + (anchor.height - height) / 2 : anchor.bottom + gap))}px`;
24
+ }
25
+ function show() {
26
+ if (!popup.matches(":popover-open")) popup.showPopover();
27
+ position();
28
+ }
29
+ function hide() {
30
+ if (popup.matches(":popover-open")) popup.hidePopover();
31
+ }
32
+ function toggle(event: Event) {
33
+ event.preventDefault();
34
+ event.stopPropagation();
35
+ pinned = !pinned;
36
+ if (pinned) show();
37
+ else hide();
38
+ }
39
+ onMount(() => {
40
+ document.addEventListener("scroll", position, true);
41
+ window.addEventListener("resize", position);
42
+ return () => {
43
+ document.removeEventListener("scroll", position, true);
44
+ window.removeEventListener("resize", position);
45
+ };
46
+ });
47
+ </script>
48
+
49
+ <span
50
+ class="inline-flex items-center gap-1"
51
+ role="group"
52
+ onmouseenter={() => {
53
+ hovered = true;
54
+ show();
55
+ }}
56
+ onmouseleave={() => {
57
+ hovered = false;
58
+ if (!pinned && !focused) hide();
59
+ }}
60
+ >
61
+ <span>{label}</span>
62
+ <span
63
+ bind:this={trigger}
64
+ role="button"
65
+ tabindex="0"
66
+ aria-label={m.option_help({ label })}
67
+ aria-describedby={id}
68
+ class="inline-flex size-4 shrink-0 cursor-help items-center justify-center rounded-full border border-current text-[10px] font-normal opacity-70 focus-visible:outline-2 focus-visible:outline-offset-2"
69
+ onclick={toggle}
70
+ onfocus={() => {
71
+ focused = true;
72
+ show();
73
+ }}
74
+ onblur={() => {
75
+ focused = false;
76
+ pinned = false;
77
+ if (!hovered) hide();
78
+ }}
79
+ onkeydown={(event) => {
80
+ if (event.key === "Escape") {
81
+ pinned = false;
82
+ hide();
83
+ event.stopPropagation();
84
+ }
85
+ if (event.key === "Enter" || event.key === " ") toggle(event);
86
+ }}>?</span
87
+ >
88
+ <span
89
+ bind:this={popup}
90
+ {id}
91
+ role="tooltip"
92
+ popover="manual"
93
+ class="pointer-events-none fixed inset-auto m-0 rounded-lg border-0 bg-neutral p-3 text-left text-sm leading-snug font-normal whitespace-normal text-neutral-content normal-case shadow-xl"
94
+ >{help}</span
95
+ >
96
+ </span>
@@ -0,0 +1,7 @@
1
+ type $$ComponentProps = {
2
+ label: string;
3
+ help: string;
4
+ };
5
+ declare const OptionHelp: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type OptionHelp = ReturnType<typeof OptionHelp>;
7
+ export default OptionHelp;
@@ -0,0 +1,43 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import { m } from "../paraglide/messages";
4
+ let { summary, breakdown }: { summary: Snippet; breakdown: Snippet } = $props();
5
+ const id = $props.id();
6
+ let hovered = $state(false);
7
+ let pinned = $state(false);
8
+ let dismissed = $state(false);
9
+ const open = $derived(!dismissed && (hovered || pinned));
10
+ </script>
11
+
12
+ <div
13
+ class="relative min-w-0 text-sm"
14
+ role="group"
15
+ aria-label={m.aria_score_summary()}
16
+ onmouseenter={() => {
17
+ hovered = true;
18
+ dismissed = false;
19
+ }}
20
+ onmouseleave={() => (hovered = false)}
21
+ >
22
+ <button
23
+ type="button"
24
+ class="score-summary h-auto! text-inherit"
25
+ aria-expanded={open}
26
+ aria-controls={id}
27
+ onclick={() => {
28
+ pinned = !pinned;
29
+ dismissed = !pinned;
30
+ }}
31
+ onkeydown={(event) => {
32
+ if (event.key === "Escape") {
33
+ pinned = false;
34
+ dismissed = true;
35
+ }
36
+ }}>{@render summary()}</button
37
+ >
38
+ {#if open}
39
+ <div {id} class="score-breakdown max-w-[calc(100vw-2rem)]" role="status">
40
+ {@render breakdown()}
41
+ </div>
42
+ {/if}
43
+ </div>
@@ -0,0 +1,8 @@
1
+ import type { Snippet } from "svelte";
2
+ type $$ComponentProps = {
3
+ summary: Snippet;
4
+ breakdown: Snippet;
5
+ };
6
+ declare const ScoreSummary: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type ScoreSummary = ReturnType<typeof ScoreSummary>;
8
+ export default ScoreSummary;