@kuncat/avoidant 0.2.4 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/README.md +25 -16
  2. package/dist/components/AvoidantGame.svelte +744 -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 +28 -0
  9. package/dist/components/MatchResults.svelte.d.ts +7 -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 +23 -0
  21. package/dist/multiplayer/client.js +119 -0
  22. package/dist/multiplayer/duration.d.ts +1 -0
  23. package/dist/multiplayer/duration.js +6 -0
  24. package/dist/multiplayer/invitations.d.ts +2 -0
  25. package/dist/multiplayer/invitations.js +23 -0
  26. package/dist/multiplayer/local-identity.d.ts +1 -0
  27. package/dist/multiplayer/local-identity.js +13 -0
  28. package/dist/multiplayer/maps.json +275 -0
  29. package/dist/multiplayer/reveal.d.ts +11 -0
  30. package/dist/multiplayer/reveal.js +16 -0
  31. package/dist/multiplayer/types.d.ts +80 -0
  32. package/dist/multiplayer/types.js +10 -0
  33. package/dist/paraglide/messages/_index.d.ts +103 -1
  34. package/dist/paraglide/messages/_index.js +104 -2
  35. package/dist/paraglide/messages/action_copied.d.ts +16 -0
  36. package/dist/paraglide/messages/action_copied.js +29 -0
  37. package/dist/paraglide/messages/action_copy_invitation.d.ts +16 -0
  38. package/dist/paraglide/messages/action_copy_invitation.js +29 -0
  39. package/dist/paraglide/messages/action_download_replay.d.ts +16 -0
  40. package/dist/paraglide/messages/action_download_replay.js +29 -0
  41. package/dist/paraglide/messages/{field_relay_servers.d.ts → action_game_history.d.ts} +5 -5
  42. package/dist/paraglide/messages/action_game_history.js +29 -0
  43. package/dist/paraglide/messages/action_load_more.d.ts +16 -0
  44. package/dist/paraglide/messages/action_load_more.js +29 -0
  45. package/dist/paraglide/messages/action_login.d.ts +16 -0
  46. package/dist/paraglide/messages/action_login.js +29 -0
  47. package/dist/paraglide/messages/action_login_again.d.ts +16 -0
  48. package/dist/paraglide/messages/action_login_again.js +29 -0
  49. package/dist/paraglide/messages/action_logout.d.ts +16 -0
  50. package/dist/paraglide/messages/action_logout.js +29 -0
  51. package/dist/paraglide/messages/action_pass.d.ts +16 -0
  52. package/dist/paraglide/messages/action_pass.js +29 -0
  53. package/dist/paraglide/messages/action_reconnect.d.ts +16 -0
  54. package/dist/paraglide/messages/action_reconnect.js +29 -0
  55. package/dist/paraglide/messages/action_register.d.ts +16 -0
  56. package/dist/paraglide/messages/action_register.js +29 -0
  57. package/dist/paraglide/messages/action_save_name.d.ts +16 -0
  58. package/dist/paraglide/messages/action_save_name.js +29 -0
  59. package/dist/paraglide/messages/action_start_match.d.ts +16 -0
  60. package/dist/paraglide/messages/action_start_match.js +29 -0
  61. package/dist/paraglide/messages/error_connection_failed.d.ts +16 -0
  62. package/dist/paraglide/messages/error_connection_failed.js +29 -0
  63. package/dist/paraglide/messages/error_connection_interrupted.d.ts +16 -0
  64. package/dist/paraglide/messages/error_connection_interrupted.js +29 -0
  65. package/dist/paraglide/messages/error_history.d.ts +16 -0
  66. package/dist/paraglide/messages/error_history.js +29 -0
  67. package/dist/paraglide/messages/error_invitation_invalid.d.ts +16 -0
  68. package/dist/paraglide/messages/error_invitation_invalid.js +29 -0
  69. package/dist/paraglide/messages/error_login_to_join.d.ts +16 -0
  70. package/dist/paraglide/messages/error_login_to_join.js +29 -0
  71. package/dist/paraglide/messages/error_map_version.d.ts +16 -0
  72. package/dist/paraglide/messages/error_map_version.js +29 -0
  73. package/dist/paraglide/messages/error_match_join.d.ts +16 -0
  74. package/dist/paraglide/messages/error_match_join.js +29 -0
  75. package/dist/paraglide/messages/error_match_version.d.ts +16 -0
  76. package/dist/paraglide/messages/error_match_version.js +29 -0
  77. package/dist/paraglide/messages/error_name_not_saved.d.ts +16 -0
  78. package/dist/paraglide/messages/error_name_not_saved.js +29 -0
  79. package/dist/paraglide/messages/error_name_server_update.d.ts +16 -0
  80. package/dist/paraglide/messages/error_name_server_update.js +29 -0
  81. package/dist/paraglide/messages/error_player_name.d.ts +16 -0
  82. package/dist/paraglide/messages/error_player_name.js +29 -0
  83. package/dist/paraglide/messages/error_reconnect_to_play.d.ts +16 -0
  84. package/dist/paraglide/messages/error_reconnect_to_play.js +29 -0
  85. package/dist/paraglide/messages/error_replay.d.ts +16 -0
  86. package/dist/paraglide/messages/error_replay.js +29 -0
  87. package/dist/paraglide/messages/error_unsupported_map.d.ts +16 -0
  88. package/dist/paraglide/messages/error_unsupported_map.js +29 -0
  89. package/dist/paraglide/messages/field_bordering.d.ts +16 -0
  90. package/dist/paraglide/messages/field_bordering.js +29 -0
  91. package/dist/paraglide/messages/field_duration_unit.d.ts +16 -0
  92. package/dist/paraglide/messages/field_duration_unit.js +29 -0
  93. package/dist/paraglide/messages/field_finite_flood.d.ts +16 -0
  94. package/dist/paraglide/messages/field_finite_flood.js +29 -0
  95. package/dist/paraglide/messages/field_flood_cells.d.ts +16 -0
  96. package/dist/paraglide/messages/field_flood_cells.js +29 -0
  97. package/dist/paraglide/messages/field_flood_limit.d.ts +16 -0
  98. package/dist/paraglide/messages/field_flood_limit.js +29 -0
  99. package/dist/paraglide/messages/field_infinite_flood.d.ts +16 -0
  100. package/dist/paraglide/messages/field_infinite_flood.js +29 -0
  101. package/dist/paraglide/messages/field_invitation_link.d.ts +16 -0
  102. package/dist/paraglide/messages/field_invitation_link.js +29 -0
  103. package/dist/paraglide/messages/field_language.d.ts +16 -0
  104. package/dist/paraglide/messages/field_language.js +29 -0
  105. package/dist/paraglide/messages/field_map.d.ts +16 -0
  106. package/dist/paraglide/messages/field_map.js +29 -0
  107. package/dist/paraglide/messages/field_map_size.d.ts +1 -1
  108. package/dist/paraglide/messages/field_map_size.js +3 -3
  109. package/dist/paraglide/messages/field_match_duration.d.ts +16 -0
  110. package/dist/paraglide/messages/field_match_duration.js +29 -0
  111. package/dist/paraglide/messages/field_match_minutes.d.ts +16 -0
  112. package/dist/paraglide/messages/field_match_minutes.js +29 -0
  113. package/dist/paraglide/messages/field_play_mode.d.ts +16 -0
  114. package/dist/paraglide/messages/field_play_mode.js +29 -0
  115. package/dist/paraglide/messages/field_size.d.ts +1 -1
  116. package/dist/paraglide/messages/field_size.js +3 -3
  117. package/dist/paraglide/messages/field_turn_based.d.ts +16 -0
  118. package/dist/paraglide/messages/field_turn_based.js +29 -0
  119. package/dist/paraglide/messages/field_turn_duration.d.ts +16 -0
  120. package/dist/paraglide/messages/field_turn_duration.js +29 -0
  121. package/dist/paraglide/messages/field_turn_duration_unit.d.ts +16 -0
  122. package/dist/paraglide/messages/field_turn_duration_unit.js +29 -0
  123. package/dist/paraglide/messages/field_turn_timer.d.ts +16 -0
  124. package/dist/paraglide/messages/field_turn_timer.js +29 -0
  125. package/dist/paraglide/messages/help_bordering.d.ts +16 -0
  126. package/dist/paraglide/messages/help_bordering.js +29 -0
  127. package/dist/paraglide/messages/help_flood_limit.d.ts +16 -0
  128. package/dist/paraglide/messages/help_flood_limit.js +29 -0
  129. package/dist/paraglide/messages/help_map.d.ts +16 -0
  130. package/dist/paraglide/messages/help_map.js +29 -0
  131. package/dist/paraglide/messages/help_map_size.d.ts +16 -0
  132. package/dist/paraglide/messages/help_map_size.js +29 -0
  133. package/dist/paraglide/messages/help_match_duration.d.ts +16 -0
  134. package/dist/paraglide/messages/help_match_duration.js +29 -0
  135. package/dist/paraglide/messages/help_participation_time.d.ts +16 -0
  136. package/dist/paraglide/messages/help_participation_time.js +29 -0
  137. package/dist/paraglide/messages/help_play_mode.d.ts +16 -0
  138. package/dist/paraglide/messages/help_play_mode.js +29 -0
  139. package/dist/paraglide/messages/help_player_name.d.ts +16 -0
  140. package/dist/paraglide/messages/help_player_name.js +29 -0
  141. package/dist/paraglide/messages/help_seed.d.ts +16 -0
  142. package/dist/paraglide/messages/help_seed.js +29 -0
  143. package/dist/paraglide/messages/help_size.d.ts +16 -0
  144. package/dist/paraglide/messages/help_size.js +29 -0
  145. package/dist/paraglide/messages/help_spikiness.d.ts +16 -0
  146. package/dist/paraglide/messages/help_spikiness.js +29 -0
  147. package/dist/paraglide/messages/help_turn_based.d.ts +16 -0
  148. package/dist/paraglide/messages/help_turn_based.js +29 -0
  149. package/dist/paraglide/messages/help_turn_duration.d.ts +16 -0
  150. package/dist/paraglide/messages/help_turn_duration.js +29 -0
  151. package/dist/paraglide/messages/help_turn_time.d.ts +16 -0
  152. package/dist/paraglide/messages/help_turn_time.js +29 -0
  153. package/dist/paraglide/messages/help_turn_timer.d.ts +16 -0
  154. package/dist/paraglide/messages/help_turn_timer.js +29 -0
  155. package/dist/paraglide/messages/help_tutorial_mode.d.ts +16 -0
  156. package/dist/paraglide/messages/help_tutorial_mode.js +29 -0
  157. package/dist/paraglide/messages/help_void_fraction.d.ts +16 -0
  158. package/dist/paraglide/messages/help_void_fraction.js +29 -0
  159. package/dist/paraglide/messages/history_empty.d.ts +16 -0
  160. package/dist/paraglide/messages/history_empty.js +29 -0
  161. package/dist/paraglide/messages/label_claims.d.ts +18 -0
  162. package/dist/paraglide/messages/label_claims.js +29 -0
  163. package/dist/paraglide/messages/label_cumulative_time.d.ts +16 -0
  164. package/dist/paraglide/messages/label_cumulative_time.js +29 -0
  165. package/dist/paraglide/messages/label_custom_map_options.d.ts +16 -0
  166. package/dist/paraglide/messages/label_custom_map_options.js +29 -0
  167. package/dist/paraglide/messages/label_gameplay_options.d.ts +16 -0
  168. package/dist/paraglide/messages/label_gameplay_options.js +29 -0
  169. package/dist/paraglide/messages/label_map_options.d.ts +16 -0
  170. package/dist/paraglide/messages/label_map_options.js +29 -0
  171. package/dist/paraglide/messages/label_match_ends.d.ts +18 -0
  172. package/dist/paraglide/messages/label_match_ends.js +29 -0
  173. package/dist/paraglide/messages/label_match_id.d.ts +18 -0
  174. package/dist/paraglide/messages/label_match_id.js +29 -0
  175. package/dist/paraglide/messages/label_player_number.d.ts +18 -0
  176. package/dist/paraglide/messages/label_player_number.js +29 -0
  177. package/dist/paraglide/messages/label_points.d.ts +18 -0
  178. package/dist/paraglide/messages/label_points.js +29 -0
  179. package/dist/paraglide/messages/label_revealed_count.d.ts +18 -0
  180. package/dist/paraglide/messages/label_revealed_count.js +29 -0
  181. package/dist/paraglide/messages/label_team_score.d.ts +18 -0
  182. package/dist/paraglide/messages/label_team_score.js +29 -0
  183. package/dist/paraglide/messages/label_turn_remaining.d.ts +18 -0
  184. package/dist/paraglide/messages/label_turn_remaining.js +29 -0
  185. package/dist/paraglide/messages/label_you.d.ts +16 -0
  186. package/dist/paraglide/messages/label_you.js +29 -0
  187. package/dist/paraglide/messages/mode_collaborative.d.ts +16 -0
  188. package/dist/paraglide/messages/mode_collaborative.js +29 -0
  189. package/dist/paraglide/messages/mode_collaborative_hint.d.ts +16 -0
  190. package/dist/paraglide/messages/mode_collaborative_hint.js +29 -0
  191. package/dist/paraglide/messages/mode_solo.d.ts +16 -0
  192. package/dist/paraglide/messages/mode_solo.js +29 -0
  193. package/dist/paraglide/messages/mode_solo_hint.d.ts +16 -0
  194. package/dist/paraglide/messages/mode_solo_hint.js +29 -0
  195. package/dist/paraglide/messages/mode_territory.d.ts +16 -0
  196. package/dist/paraglide/messages/mode_territory.js +29 -0
  197. package/dist/paraglide/messages/mode_territory_hint.d.ts +16 -0
  198. package/dist/paraglide/messages/mode_territory_hint.js +29 -0
  199. package/dist/paraglide/messages/multiplayer_title.d.ts +16 -0
  200. package/dist/paraglide/messages/multiplayer_title.js +29 -0
  201. package/dist/paraglide/messages/option_help.d.ts +18 -0
  202. package/dist/paraglide/messages/option_help.js +29 -0
  203. package/dist/paraglide/messages/shape_label.d.ts +5 -5
  204. package/dist/paraglide/messages/shape_label.js +15 -15
  205. package/dist/paraglide/messages/status_connecting.d.ts +16 -0
  206. package/dist/paraglide/messages/status_connecting.js +29 -0
  207. package/dist/paraglide/messages/status_draw.d.ts +16 -0
  208. package/dist/paraglide/messages/status_draw.js +29 -0
  209. package/dist/paraglide/messages/status_match_complete.d.ts +16 -0
  210. package/dist/paraglide/messages/status_match_complete.js +29 -0
  211. package/dist/paraglide/messages/status_match_expired.d.ts +16 -0
  212. package/dist/paraglide/messages/status_match_expired.js +29 -0
  213. package/dist/paraglide/messages/status_name_saved.d.ts +16 -0
  214. package/dist/paraglide/messages/status_name_saved.js +29 -0
  215. package/dist/paraglide/messages/status_named_turn.d.ts +18 -0
  216. package/dist/paraglide/messages/status_named_turn.js +29 -0
  217. package/dist/paraglide/messages/status_named_winner.d.ts +18 -0
  218. package/dist/paraglide/messages/status_named_winner.js +29 -0
  219. package/dist/paraglide/messages/status_player_turn.d.ts +18 -0
  220. package/dist/paraglide/messages/status_player_turn.js +29 -0
  221. package/dist/paraglide/messages/status_realtime_claims.d.ts +16 -0
  222. package/dist/paraglide/messages/status_realtime_claims.js +29 -0
  223. package/dist/paraglide/messages/status_reconnecting.d.ts +16 -0
  224. package/dist/paraglide/messages/status_reconnecting.js +29 -0
  225. package/dist/paraglide/messages/status_session_complete.d.ts +16 -0
  226. package/dist/paraglide/messages/status_session_complete.js +29 -0
  227. package/dist/paraglide/messages/status_winner.d.ts +18 -0
  228. package/dist/paraglide/messages/status_winner.js +29 -0
  229. package/dist/paraglide/messages/text_account_multiplayer.d.ts +16 -0
  230. package/dist/paraglide/messages/text_account_multiplayer.js +29 -0
  231. package/dist/paraglide/messages/text_multiplayer_login.d.ts +16 -0
  232. package/dist/paraglide/messages/text_multiplayer_login.js +29 -0
  233. package/dist/paraglide/messages/text_waiting_lobby.d.ts +16 -0
  234. package/dist/paraglide/messages/text_waiting_lobby.js +29 -0
  235. package/dist/paraglide/messages/unit_hours.d.ts +16 -0
  236. package/dist/paraglide/messages/unit_hours.js +29 -0
  237. package/dist/paraglide/messages/unit_hours_selected.d.ts +19 -0
  238. package/dist/paraglide/messages/unit_hours_selected.js +35 -0
  239. package/dist/paraglide/messages/unit_minutes.d.ts +16 -0
  240. package/dist/paraglide/messages/unit_minutes.js +29 -0
  241. package/dist/paraglide/messages/unit_minutes_selected.d.ts +19 -0
  242. package/dist/paraglide/messages/unit_minutes_selected.js +35 -0
  243. package/dist/paraglide/messages/unit_seconds.d.ts +16 -0
  244. package/dist/paraglide/messages/unit_seconds.js +29 -0
  245. package/dist/paraglide/messages/unit_seconds_selected.d.ts +19 -0
  246. package/dist/paraglide/messages/unit_seconds_selected.js +35 -0
  247. package/dist/styles/global.css +14 -51
  248. package/dist/wasm/avoidant_wasm.d.ts +3 -208
  249. package/dist/wasm/avoidant_wasm.js +20 -1101
  250. package/dist/wasm/avoidant_wasm_bg.wasm +0 -0
  251. package/dist/wasm/avoidant_wasm_bg.wasm.d.ts +3 -65
  252. package/package.json +6 -4
  253. package/dist/paraglide/messages/field_relay_servers.js +0 -29
@@ -54,7 +54,8 @@
54
54
  import { TerrainDepthSort } from "./terrain-depth-sort";
55
55
  import { SvelteMap, SvelteSet } from "svelte/reactivity";
56
56
  import { Pulse } from "../wasm/avoidant_wasm";
57
- import type { GameState } from "../wasm/avoidant_wasm";
57
+ import type { BoardState } from "../multiplayer/types";
58
+ import { PLAYER_COLORS } from "../multiplayer/types";
58
59
  import { T, useTask, useThrelte } from "@threlte/core";
59
60
  import { interactivity, Text } from "@threlte/extras";
60
61
  import {
@@ -77,7 +78,9 @@
77
78
  const { invalidate } = useThrelte();
78
79
 
79
80
  interface Props {
80
- gameState: GameState;
81
+ gameState: BoardState;
82
+ owners?: (number | null)[];
83
+ showZeroCounts?: boolean;
81
84
  terrain?:
82
85
  | { positions: number[]; normals: number[]; cellIndices: number[]; heights: number[] }
83
86
  | undefined;
@@ -96,6 +99,8 @@
96
99
  interactive = true,
97
100
  highlightedCellIndex = undefined,
98
101
  onCellClicked = undefined,
102
+ owners = [],
103
+ showZeroCounts = false,
99
104
  }: Props = $props();
100
105
  let cells = $derived(gameState?.cells);
101
106
  let cellMetadata = $derived(gameState?.cellMetadata);
@@ -395,6 +400,43 @@
395
400
  };
396
401
  });
397
402
 
403
+ const ownershipTexture = $derived.by(() => {
404
+ const texture = new DataTexture(
405
+ new Uint8Array(cellMeta.width * 4),
406
+ cellMeta.width,
407
+ 1,
408
+ RGBAFormat,
409
+ UnsignedByteType,
410
+ );
411
+ texture.minFilter = NearestFilter;
412
+ texture.magFilter = NearestFilter;
413
+ return texture;
414
+ });
415
+ $effect(() => {
416
+ const texture = ownershipTexture;
417
+ const data = texture.image.data as Uint8Array;
418
+ data.fill(0);
419
+ owners.forEach((owner, index) => {
420
+ if (owner === null || index >= $cells.length) return;
421
+ const color = new Color(PLAYER_COLORS[owner]);
422
+ data.set(
423
+ [
424
+ Math.round(color.r * 255),
425
+ Math.round(color.g * 255),
426
+ Math.round(color.b * 255),
427
+ owner + 1,
428
+ ],
429
+ index * 4,
430
+ );
431
+ });
432
+ texture.needsUpdate = true;
433
+ invalidate();
434
+ });
435
+ $effect(() => {
436
+ const texture = ownershipTexture;
437
+ return () => texture.dispose();
438
+ });
439
+
398
440
  let terrainMaterial = $derived(
399
441
  new ShaderMaterial({
400
442
  vertexShader,
@@ -409,6 +451,7 @@
409
451
  elevationMin: { value: gameState.elevationMin },
410
452
  elevationMax: { value: gameState.elevationMax },
411
453
  uCellMeta: { value: cellMeta.texture },
454
+ uOwnership: { value: ownershipTexture },
412
455
  uCellMetaSize: { value: cellMeta.width },
413
456
  pulseCount: { value: 0 },
414
457
  pulseTimers: { value: new Array(MAX_PULSES).fill(0) },
@@ -481,7 +524,13 @@
481
524
  const entry = $cellMetadata[i];
482
525
  const anchor = cellLabelAnchors[i];
483
526
  const surface = labelPlacements[i]?.surface;
484
- if (!entry.isExplored || entry.isVoid || entry.voidNeighborCount <= 0 || !anchor || !surface)
527
+ if (
528
+ !entry.isExplored ||
529
+ entry.isVoid ||
530
+ (!showZeroCounts && entry.voidNeighborCount <= 0) ||
531
+ !anchor ||
532
+ !surface
533
+ )
485
534
  continue;
486
535
  points.push(surface, new Vector3(anchor.x, anchor.y, anchor.z));
487
536
  const color = new Color(
@@ -499,7 +548,7 @@
499
548
  });
500
549
 
501
550
  const LABEL_COLORS = [
502
- undefined,
551
+ "#0f172a",
503
552
  "#1d4ed8",
504
553
  "#15803d",
505
554
  "#b91c1c",
@@ -606,7 +655,7 @@
606
655
  </T.LineSegments>
607
656
 
608
657
  {#each $cellMetadata as entry, i (i)}
609
- {#if entry.isExplored && !entry.isVoid && entry.voidNeighborCount > 0}
658
+ {#if entry.isExplored && !entry.isVoid && (showZeroCounts || entry.voidNeighborCount > 0)}
610
659
  {@const anchor = cellLabelAnchors[i]}
611
660
  {#if anchor}
612
661
  <IdleBillboard position={[anchor.x, anchor.y, anchor.z]}>
@@ -18,9 +18,11 @@ export declare const CellMetaChannel: {
18
18
  export declare const cellMetaDefines: string;
19
19
  export declare const vertexShader: string;
20
20
  export declare const fragmentShader: string;
21
- import type { GameState } from "../wasm/avoidant_wasm";
21
+ import type { BoardState } from "../multiplayer/types";
22
22
  interface Props {
23
- gameState: GameState;
23
+ gameState: BoardState;
24
+ owners?: (number | null)[];
25
+ showZeroCounts?: boolean;
24
26
  terrain?: {
25
27
  positions: number[];
26
28
  normals: number[];
@@ -9,6 +9,7 @@ uniform bool uTransparentPass;
9
9
  uniform float elevationMin;
10
10
  uniform float elevationMax;
11
11
  uniform sampler2D uCellMeta;
12
+ uniform sampler2D uOwnership;
12
13
  uniform float uCellMetaSize;
13
14
  uniform int pulseCount;
14
15
  uniform float pulseTimers[MAX_PULSES];
@@ -24,6 +25,32 @@ float remapClamped(float value, float inMin, float inMax, float outMin, float ou
24
25
  return mix(outMin, outMax, t);
25
26
  }
26
27
 
28
+ // Screen-space patterns stay legible at any zoom, use the existing ownership
29
+ // texture, and add no meshes, draw calls, or per-frame texture uploads.
30
+ float stripe(float x) {
31
+ float d = abs(fract(x) - 0.5);
32
+ return 1.0 - smoothstep(0.1, 0.1 + max(fwidth(x), 0.025), d);
33
+ }
34
+ float territoryPattern(float owner, vec2 p) {
35
+ // Each slot uses a different motif, not merely a rotated version of a rival's.
36
+ if (owner < 1.5) return stripe(p.x + p.y); // Diagonal hatching.
37
+ if (owner < 2.5) {
38
+ // Dots.
39
+ float d = length(fract(p) - 0.5);
40
+ return 1.0 - smoothstep(0.14, 0.23, d);
41
+ }
42
+ if (owner < 3.5) return max(stripe(p.x + p.y), stripe(p.x - p.y)); // Cross-hatching.
43
+ if (owner < 4.5) return stripe(p.y) * step(0.35, fract(p.x * 0.5)); // Dashes.
44
+ if (owner < 5.5) return stripe(p.y + abs(fract(p.x * 0.5) - 0.5) * 2.0); // Zigzags.
45
+ if (owner < 6.5) return max(stripe(p.x), stripe(p.y)); // Square grid.
46
+ if (owner < 7.5) {
47
+ // Rings.
48
+ float d = abs(length(fract(p) - 0.5) - 0.3);
49
+ return 1.0 - smoothstep(0.035, 0.11, d);
50
+ }
51
+ return stripe(p.y + sin(p.x * 3.14159) * 0.3); // Waves.
52
+ }
53
+
27
54
  void main() {
28
55
  vec2 metaUv = vec2((vCellIndex + 0.5) / uCellMetaSize, 0.5);
29
56
  vec4 meta = texture2D(uCellMeta, metaUv);
@@ -87,6 +114,13 @@ void main() {
87
114
  vec3 lowColor = mix(unexploredLow, exploredLow, colorFactor);
88
115
  vec3 highColor = mix(unexploredHigh, exploredHigh, colorFactor);
89
116
  vec3 terrainColor = mix(lowColor, highColor, elevation);
117
+ vec4 ownership = texture2D(uOwnership, metaUv);
118
+ float owner = floor(ownership.a * 255.0 + 0.5);
119
+ if (owner > 0.5) {
120
+ terrainColor = mix(terrainColor, ownership.rgb, 0.7);
121
+ float pattern = territoryPattern(owner, gl_FragCoord.xy / 12.0);
122
+ terrainColor = mix(terrainColor, terrainColor * 0.45, pattern * 0.65);
123
+ }
90
124
 
91
125
  // Uniform illumination keeps every face readable regardless of its
92
126
  // orientation, with a subdued level that avoids near-white revealed cells.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { default as favicon } from "./assets/favicon.svg";
2
2
  export { default as AvoidantGame } from "./components/AvoidantGame.svelte";
3
+ export type { CompetitiveConfig } from "./multiplayer/types";
@@ -0,0 +1,23 @@
1
+ import type { CompetitiveConfig, MatchSnapshot } from "./types";
2
+ /** One pending action at a time; retries reuse the sequence after reconnection. */
3
+ export declare class MatchClient {
4
+ private config;
5
+ id: string;
6
+ private actor;
7
+ private receive;
8
+ private report;
9
+ private playerName;
10
+ private invitationReceived?;
11
+ private socket?;
12
+ private pending?;
13
+ private stopped;
14
+ private finished;
15
+ private retry?;
16
+ private retryCount;
17
+ 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);
18
+ connect(): Promise<void>;
19
+ start(): void;
20
+ move(sequence: number, action: unknown): void;
21
+ private send;
22
+ close(): void;
23
+ }
@@ -0,0 +1,119 @@
1
+ import { m } from "../paraglide/messages";
2
+ /** One pending action at a time; retries reuse the sequence after reconnection. */
3
+ export class MatchClient {
4
+ config;
5
+ id;
6
+ actor;
7
+ receive;
8
+ report;
9
+ playerName;
10
+ invitationReceived;
11
+ socket;
12
+ pending;
13
+ stopped = false;
14
+ finished = false;
15
+ retry;
16
+ retryCount = 0;
17
+ constructor(config, id, actor, receive, report, playerName, invitationReceived) {
18
+ this.config = config;
19
+ this.id = id;
20
+ this.actor = actor;
21
+ this.receive = receive;
22
+ this.report = report;
23
+ this.playerName = playerName;
24
+ this.invitationReceived = invitationReceived;
25
+ }
26
+ async connect() {
27
+ clearTimeout(this.retry);
28
+ if (this.socket) {
29
+ this.socket.onclose = null;
30
+ this.socket.close();
31
+ }
32
+ try {
33
+ const response = await fetch(`${this.config.serverUrl}/matches/${this.id}/connect`, {
34
+ method: "POST",
35
+ headers: {
36
+ Authorization: `Bearer ${await this.config.account.token()}`,
37
+ "Content-Type": "application/json",
38
+ },
39
+ body: JSON.stringify({ name: this.playerName().trim() }),
40
+ });
41
+ const data = await response.json();
42
+ if (!response.ok)
43
+ throw new Error(data.error === "Invalid player name"
44
+ ? m.error_player_name()
45
+ : (data.error ?? m.error_match_join()));
46
+ if (this.stopped)
47
+ return;
48
+ if (data.id)
49
+ this.id = data.id;
50
+ if (data.invitationUrl)
51
+ this.invitationReceived?.(data.invitationUrl);
52
+ const url = new URL(`${this.config.serverUrl}/matches/${this.id}/socket`);
53
+ url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
54
+ url.searchParams.set("ticket", data.ticket);
55
+ this.socket = new WebSocket(url);
56
+ this.socket.onmessage = (event) => {
57
+ const message = JSON.parse(event.data);
58
+ if (message.type === "error") {
59
+ this.pending = undefined;
60
+ if (message.error !== "Cell unavailable")
61
+ this.report(message.error);
62
+ return;
63
+ }
64
+ if (message.type !== "snapshot")
65
+ return;
66
+ const s = message.snapshot;
67
+ if (s.version !== 1) {
68
+ this.report(m.error_match_version());
69
+ this.close();
70
+ return;
71
+ }
72
+ const player = s.players.find((p) => p.id === this.actor);
73
+ if (this.pending && player && player.sequence >= this.pending.sequence)
74
+ this.pending = undefined;
75
+ this.finished = s.finished;
76
+ this.retryCount = 0;
77
+ this.receive(s, message.map, message.neighbors);
78
+ if (this.pending)
79
+ this.socket?.send(JSON.stringify(this.pending));
80
+ };
81
+ this.socket.onclose = (event) => {
82
+ if (this.stopped || this.finished)
83
+ return;
84
+ if (event.code === 1000) {
85
+ this.report(m.status_match_expired());
86
+ return;
87
+ }
88
+ this.report(m.status_reconnecting(), true);
89
+ this.retry = setTimeout(() => void this.connect(), Math.min(1000 * 2 ** this.retryCount++, 15000));
90
+ };
91
+ this.socket.onerror = () => this.report(m.error_connection_interrupted(), true);
92
+ }
93
+ catch (error) {
94
+ this.report(error instanceof Error ? error.message : m.error_connection_failed(), true);
95
+ }
96
+ }
97
+ start() {
98
+ this.send({ kind: "start" });
99
+ }
100
+ move(sequence, action) {
101
+ if (this.pending)
102
+ return;
103
+ if (this.socket?.readyState !== WebSocket.OPEN) {
104
+ this.report(m.error_reconnect_to_play(), true);
105
+ return;
106
+ }
107
+ this.pending = { kind: "move", sequence, action };
108
+ this.send(this.pending);
109
+ }
110
+ send(value) {
111
+ if (this.socket?.readyState === WebSocket.OPEN)
112
+ this.socket.send(JSON.stringify(value));
113
+ }
114
+ close() {
115
+ this.stopped = true;
116
+ clearTimeout(this.retry);
117
+ this.socket?.close();
118
+ }
119
+ }
@@ -0,0 +1 @@
1
+ export declare function formatDuration(milliseconds: number, locale: string): string;
@@ -0,0 +1,6 @@
1
+ export function formatDuration(milliseconds, locale) {
2
+ const seconds = Math.floor(Math.max(0, milliseconds) / 1000);
3
+ return [Math.floor(seconds / 3600), Math.floor(seconds / 60) % 60, seconds % 60]
4
+ .map((value) => value.toLocaleString(locale, { minimumIntegerDigits: 2, useGrouping: false }))
5
+ .join(":");
6
+ }
@@ -0,0 +1,2 @@
1
+ /** Accept existing UUID invitations, share codes, and exact kuga.run links. */
2
+ export declare function parseInvitation(input: string): string | null;
@@ -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
+ }
@@ -0,0 +1 @@
1
+ export declare function localActorId(actor: string): string;
@@ -0,0 +1,13 @@
1
+ // Stable, non-secret UUIDs for the explicit local multiplayer harness only.
2
+ // This also works on LAN HTTP origins where SubtleCrypto is unavailable.
3
+ export function localActorId(actor) {
4
+ const hex = [0, 1, 2, 3]
5
+ .map((salt) => {
6
+ let hash = 2166136261 ^ salt;
7
+ for (const character of actor)
8
+ hash = Math.imul(hash ^ character.codePointAt(0), 16777619);
9
+ return (hash >>> 0).toString(16).padStart(8, "0");
10
+ })
11
+ .join("");
12
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-4${hex.slice(13, 16)}-8${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
13
+ }
@@ -0,0 +1,275 @@
1
+ {
2
+ "cube-large": {
3
+ "elevationMax": 6,
4
+ "elevationMin": 0,
5
+ "numCells": 320,
6
+ "rngSeed": 42,
7
+ "shape": {
8
+ "kind": "cube",
9
+ "radius": 50
10
+ },
11
+ "spikiness": 0.8
12
+ },
13
+ "cube-medium": {
14
+ "elevationMax": 6,
15
+ "elevationMin": 0,
16
+ "numCells": 160,
17
+ "rngSeed": 42,
18
+ "shape": {
19
+ "kind": "cube",
20
+ "radius": 50
21
+ },
22
+ "spikiness": 0.8
23
+ },
24
+ "cube-small": {
25
+ "elevationMax": 6,
26
+ "elevationMin": 0,
27
+ "numCells": 80,
28
+ "rngSeed": 42,
29
+ "shape": {
30
+ "kind": "cube",
31
+ "radius": 50
32
+ },
33
+ "spikiness": 0.8
34
+ },
35
+ "dodecahedron-large": {
36
+ "elevationMax": 6,
37
+ "elevationMin": 0,
38
+ "numCells": 320,
39
+ "rngSeed": 42,
40
+ "shape": {
41
+ "kind": "dodecahedron",
42
+ "radius": 50
43
+ },
44
+ "spikiness": 0.8
45
+ },
46
+ "dodecahedron-medium": {
47
+ "elevationMax": 6,
48
+ "elevationMin": 0,
49
+ "numCells": 160,
50
+ "rngSeed": 42,
51
+ "shape": {
52
+ "kind": "dodecahedron",
53
+ "radius": 50
54
+ },
55
+ "spikiness": 0.8
56
+ },
57
+ "dodecahedron-small": {
58
+ "elevationMax": 6,
59
+ "elevationMin": 0,
60
+ "numCells": 80,
61
+ "rngSeed": 42,
62
+ "shape": {
63
+ "kind": "dodecahedron",
64
+ "radius": 50
65
+ },
66
+ "spikiness": 0.8
67
+ },
68
+ "flat-large": {
69
+ "elevationMax": 6,
70
+ "elevationMin": 0,
71
+ "numCells": 320,
72
+ "rngSeed": 42,
73
+ "shape": {
74
+ "kind": "flat",
75
+ "radius": 50
76
+ },
77
+ "spikiness": 0.8
78
+ },
79
+ "flat-medium": {
80
+ "elevationMax": 6,
81
+ "elevationMin": 0,
82
+ "numCells": 160,
83
+ "rngSeed": 42,
84
+ "shape": {
85
+ "kind": "flat",
86
+ "radius": 50
87
+ },
88
+ "spikiness": 0.8
89
+ },
90
+ "flat-small": {
91
+ "elevationMax": 6,
92
+ "elevationMin": 0,
93
+ "numCells": 80,
94
+ "rngSeed": 42,
95
+ "shape": {
96
+ "kind": "flat",
97
+ "radius": 50
98
+ },
99
+ "spikiness": 0.8
100
+ },
101
+ "geodesicIcosphere-large": {
102
+ "elevationMax": 6,
103
+ "elevationMin": 0,
104
+ "numCells": 320,
105
+ "rngSeed": 42,
106
+ "shape": {
107
+ "kind": "geodesicIcosphere",
108
+ "radius": 50,
109
+ "subdivisions": 1
110
+ },
111
+ "spikiness": 0.8
112
+ },
113
+ "geodesicIcosphere-medium": {
114
+ "elevationMax": 6,
115
+ "elevationMin": 0,
116
+ "numCells": 160,
117
+ "rngSeed": 42,
118
+ "shape": {
119
+ "kind": "geodesicIcosphere",
120
+ "radius": 50,
121
+ "subdivisions": 1
122
+ },
123
+ "spikiness": 0.8
124
+ },
125
+ "geodesicIcosphere-small": {
126
+ "elevationMax": 6,
127
+ "elevationMin": 0,
128
+ "numCells": 80,
129
+ "rngSeed": 42,
130
+ "shape": {
131
+ "kind": "geodesicIcosphere",
132
+ "radius": 50,
133
+ "subdivisions": 1
134
+ },
135
+ "spikiness": 0.8
136
+ },
137
+ "large": {
138
+ "elevationMax": 6,
139
+ "elevationMin": 0,
140
+ "numCells": 320,
141
+ "rngSeed": 42,
142
+ "shape": {
143
+ "kind": "icosahedron",
144
+ "radius": 50
145
+ },
146
+ "spikiness": 0.8
147
+ },
148
+ "medium": {
149
+ "elevationMax": 6,
150
+ "elevationMin": 0,
151
+ "numCells": 160,
152
+ "rngSeed": 42,
153
+ "shape": {
154
+ "kind": "icosahedron",
155
+ "radius": 50
156
+ },
157
+ "spikiness": 0.8
158
+ },
159
+ "octahedron-large": {
160
+ "elevationMax": 6,
161
+ "elevationMin": 0,
162
+ "numCells": 320,
163
+ "rngSeed": 42,
164
+ "shape": {
165
+ "kind": "octahedron",
166
+ "radius": 50
167
+ },
168
+ "spikiness": 0.8
169
+ },
170
+ "octahedron-medium": {
171
+ "elevationMax": 6,
172
+ "elevationMin": 0,
173
+ "numCells": 160,
174
+ "rngSeed": 42,
175
+ "shape": {
176
+ "kind": "octahedron",
177
+ "radius": 50
178
+ },
179
+ "spikiness": 0.8
180
+ },
181
+ "octahedron-small": {
182
+ "elevationMax": 6,
183
+ "elevationMin": 0,
184
+ "numCells": 80,
185
+ "rngSeed": 42,
186
+ "shape": {
187
+ "kind": "octahedron",
188
+ "radius": 50
189
+ },
190
+ "spikiness": 0.8
191
+ },
192
+ "small": {
193
+ "elevationMax": 6,
194
+ "elevationMin": 0,
195
+ "numCells": 80,
196
+ "rngSeed": 42,
197
+ "shape": {
198
+ "kind": "icosahedron",
199
+ "radius": 50
200
+ },
201
+ "spikiness": 0.8
202
+ },
203
+ "spheroid-large": {
204
+ "elevationMax": 6,
205
+ "elevationMin": 0,
206
+ "numCells": 320,
207
+ "rngSeed": 42,
208
+ "shape": {
209
+ "kind": "spheroid",
210
+ "radiusX": 50,
211
+ "radiusY": 40,
212
+ "radiusZ": 50
213
+ },
214
+ "spikiness": 0.8
215
+ },
216
+ "spheroid-medium": {
217
+ "elevationMax": 6,
218
+ "elevationMin": 0,
219
+ "numCells": 160,
220
+ "rngSeed": 42,
221
+ "shape": {
222
+ "kind": "spheroid",
223
+ "radiusX": 50,
224
+ "radiusY": 40,
225
+ "radiusZ": 50
226
+ },
227
+ "spikiness": 0.8
228
+ },
229
+ "spheroid-small": {
230
+ "elevationMax": 6,
231
+ "elevationMin": 0,
232
+ "numCells": 80,
233
+ "rngSeed": 42,
234
+ "shape": {
235
+ "kind": "spheroid",
236
+ "radiusX": 50,
237
+ "radiusY": 40,
238
+ "radiusZ": 50
239
+ },
240
+ "spikiness": 0.8
241
+ },
242
+ "tetrahedron-large": {
243
+ "elevationMax": 6,
244
+ "elevationMin": 0,
245
+ "numCells": 320,
246
+ "rngSeed": 42,
247
+ "shape": {
248
+ "kind": "tetrahedron",
249
+ "radius": 50
250
+ },
251
+ "spikiness": 0.8
252
+ },
253
+ "tetrahedron-medium": {
254
+ "elevationMax": 6,
255
+ "elevationMin": 0,
256
+ "numCells": 160,
257
+ "rngSeed": 42,
258
+ "shape": {
259
+ "kind": "tetrahedron",
260
+ "radius": 50
261
+ },
262
+ "spikiness": 0.8
263
+ },
264
+ "tetrahedron-small": {
265
+ "elevationMax": 6,
266
+ "elevationMin": 0,
267
+ "numCells": 80,
268
+ "rngSeed": 42,
269
+ "shape": {
270
+ "kind": "tetrahedron",
271
+ "radius": 50
272
+ },
273
+ "spikiness": 0.8
274
+ }
275
+ }
@@ -0,0 +1,11 @@
1
+ import type { MapCell } from "../wasm/avoidant_wasm";
2
+ /** Match the cooperative renderer's world-space sweep speed and soft-edge timing. */
3
+ export declare function revealSweep(cells: MapCell[], opened: number[], originCell: number, position?: [number, number, number]): {
4
+ position: Float64Array<ArrayBuffer>;
5
+ maxRadius: number;
6
+ durationMs: number;
7
+ finishes: {
8
+ cell: number;
9
+ afterMs: number;
10
+ }[];
11
+ };
@@ -0,0 +1,16 @@
1
+ /** Match the cooperative renderer's world-space sweep speed and soft-edge timing. */
2
+ export function revealSweep(cells, opened, originCell, position = cells[originCell].centroid) {
3
+ const distance = (v) => Math.hypot(...v.map((n, i) => n - position[i]));
4
+ const radii = opened.map((i) => Math.max(...cells[i].vertices.map(distance)));
5
+ const maxRadius = Math.max(...radii) + 1.5;
6
+ const durationMs = Math.max(80, maxRadius / 0.1);
7
+ return {
8
+ position: new Float64Array(position),
9
+ maxRadius,
10
+ durationMs,
11
+ finishes: opened.map((cell, i) => ({
12
+ cell,
13
+ afterMs: Math.min(durationMs, (radii[i] / maxRadius + 0.12) * durationMs),
14
+ })),
15
+ };
16
+ }