@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.
- package/README.md +29 -18
- package/dist/components/AvoidantGame.svelte +743 -457
- package/dist/components/AvoidantGame.svelte.d.ts +2 -1
- package/dist/components/GameHistory.svelte +103 -0
- package/dist/components/GameHistory.svelte.d.ts +8 -0
- package/dist/components/MapIcon.svelte +40 -0
- package/dist/components/MapIcon.svelte.d.ts +7 -0
- package/dist/components/MatchResults.svelte +29 -0
- package/dist/components/MatchResults.svelte.d.ts +8 -0
- package/dist/components/MultiplayerGame.svelte +504 -0
- package/dist/components/MultiplayerGame.svelte.d.ts +11 -0
- package/dist/components/OptionHelp.svelte +96 -0
- package/dist/components/OptionHelp.svelte.d.ts +7 -0
- package/dist/components/ScoreSummary.svelte +43 -0
- package/dist/components/ScoreSummary.svelte.d.ts +8 -0
- package/dist/components/board.svelte +54 -5
- package/dist/components/board.svelte.d.ts +4 -2
- package/dist/components/fragment.glsl +34 -0
- package/dist/index.d.ts +1 -0
- package/dist/multiplayer/client.d.ts +21 -0
- package/dist/multiplayer/client.js +111 -0
- package/dist/multiplayer/duration.d.ts +1 -0
- package/dist/multiplayer/duration.js +6 -0
- package/dist/multiplayer/local-identity.d.ts +1 -0
- package/dist/multiplayer/local-identity.js +13 -0
- package/dist/multiplayer/maps.json +275 -0
- package/dist/multiplayer/reveal.d.ts +11 -0
- package/dist/multiplayer/reveal.js +16 -0
- package/dist/multiplayer/types.d.ts +80 -0
- package/dist/multiplayer/types.js +10 -0
- package/dist/paraglide/messages/_index.d.ts +103 -0
- package/dist/paraglide/messages/_index.js +104 -1
- package/dist/paraglide/messages/action_copied.d.ts +16 -0
- package/dist/paraglide/messages/action_copied.js +29 -0
- package/dist/paraglide/messages/action_copy_invitation.d.ts +16 -0
- package/dist/paraglide/messages/action_copy_invitation.js +29 -0
- package/dist/paraglide/messages/action_download_replay.d.ts +16 -0
- package/dist/paraglide/messages/action_download_replay.js +29 -0
- package/dist/paraglide/messages/action_game_history.d.ts +16 -0
- package/dist/paraglide/messages/action_game_history.js +29 -0
- package/dist/paraglide/messages/action_load_more.d.ts +16 -0
- package/dist/paraglide/messages/action_load_more.js +29 -0
- package/dist/paraglide/messages/action_login.d.ts +16 -0
- package/dist/paraglide/messages/action_login.js +29 -0
- package/dist/paraglide/messages/action_login_again.d.ts +16 -0
- package/dist/paraglide/messages/action_login_again.js +29 -0
- package/dist/paraglide/messages/action_logout.d.ts +16 -0
- package/dist/paraglide/messages/action_logout.js +29 -0
- package/dist/paraglide/messages/action_pass.d.ts +16 -0
- package/dist/paraglide/messages/action_pass.js +29 -0
- package/dist/paraglide/messages/action_reconnect.d.ts +16 -0
- package/dist/paraglide/messages/action_reconnect.js +29 -0
- package/dist/paraglide/messages/action_register.d.ts +16 -0
- package/dist/paraglide/messages/action_register.js +29 -0
- package/dist/paraglide/messages/action_save_name.d.ts +16 -0
- package/dist/paraglide/messages/action_save_name.js +29 -0
- package/dist/paraglide/messages/action_start_match.d.ts +16 -0
- package/dist/paraglide/messages/action_start_match.js +29 -0
- package/dist/paraglide/messages/error_connection_failed.d.ts +16 -0
- package/dist/paraglide/messages/error_connection_failed.js +29 -0
- package/dist/paraglide/messages/error_connection_interrupted.d.ts +16 -0
- package/dist/paraglide/messages/error_connection_interrupted.js +29 -0
- package/dist/paraglide/messages/error_history.d.ts +16 -0
- package/dist/paraglide/messages/error_history.js +29 -0
- package/dist/paraglide/messages/error_invitation_invalid.d.ts +16 -0
- package/dist/paraglide/messages/error_invitation_invalid.js +29 -0
- package/dist/paraglide/messages/error_login_to_join.d.ts +16 -0
- package/dist/paraglide/messages/error_login_to_join.js +29 -0
- package/dist/paraglide/messages/error_map_version.d.ts +16 -0
- package/dist/paraglide/messages/error_map_version.js +29 -0
- package/dist/paraglide/messages/error_match_join.d.ts +16 -0
- package/dist/paraglide/messages/error_match_join.js +29 -0
- package/dist/paraglide/messages/error_match_version.d.ts +16 -0
- package/dist/paraglide/messages/error_match_version.js +29 -0
- package/dist/paraglide/messages/error_name_not_saved.d.ts +16 -0
- package/dist/paraglide/messages/error_name_not_saved.js +29 -0
- package/dist/paraglide/messages/error_name_server_update.d.ts +16 -0
- package/dist/paraglide/messages/error_name_server_update.js +29 -0
- package/dist/paraglide/messages/error_player_name.d.ts +16 -0
- package/dist/paraglide/messages/error_player_name.js +29 -0
- package/dist/paraglide/messages/error_reconnect_to_play.d.ts +16 -0
- package/dist/paraglide/messages/error_reconnect_to_play.js +29 -0
- package/dist/paraglide/messages/error_replay.d.ts +16 -0
- package/dist/paraglide/messages/error_replay.js +29 -0
- package/dist/paraglide/messages/error_unsupported_map.d.ts +16 -0
- package/dist/paraglide/messages/error_unsupported_map.js +29 -0
- package/dist/paraglide/messages/field_bordering.d.ts +16 -0
- package/dist/paraglide/messages/field_bordering.js +29 -0
- package/dist/paraglide/messages/field_duration_unit.d.ts +16 -0
- package/dist/paraglide/messages/field_duration_unit.js +29 -0
- package/dist/paraglide/messages/field_finite_flood.d.ts +16 -0
- package/dist/paraglide/messages/field_finite_flood.js +29 -0
- package/dist/paraglide/messages/field_flood_cells.d.ts +16 -0
- package/dist/paraglide/messages/field_flood_cells.js +29 -0
- package/dist/paraglide/messages/field_flood_limit.d.ts +16 -0
- package/dist/paraglide/messages/field_flood_limit.js +29 -0
- package/dist/paraglide/messages/field_infinite_flood.d.ts +16 -0
- package/dist/paraglide/messages/field_infinite_flood.js +29 -0
- package/dist/paraglide/messages/field_invitation_link.d.ts +16 -0
- package/dist/paraglide/messages/field_invitation_link.js +29 -0
- package/dist/paraglide/messages/field_language.d.ts +16 -0
- package/dist/paraglide/messages/field_language.js +29 -0
- package/dist/paraglide/messages/field_map.d.ts +16 -0
- package/dist/paraglide/messages/field_map.js +29 -0
- package/dist/paraglide/messages/field_map_size.d.ts +1 -1
- package/dist/paraglide/messages/field_map_size.js +3 -3
- package/dist/paraglide/messages/field_match_duration.d.ts +16 -0
- package/dist/paraglide/messages/field_match_duration.js +29 -0
- package/dist/paraglide/messages/field_match_minutes.d.ts +16 -0
- package/dist/paraglide/messages/field_match_minutes.js +29 -0
- package/dist/paraglide/messages/field_play_mode.d.ts +16 -0
- package/dist/paraglide/messages/field_play_mode.js +29 -0
- package/dist/paraglide/messages/field_size.d.ts +1 -1
- package/dist/paraglide/messages/field_size.js +3 -3
- package/dist/paraglide/messages/field_turn_based.d.ts +16 -0
- package/dist/paraglide/messages/field_turn_based.js +29 -0
- package/dist/paraglide/messages/field_turn_duration.d.ts +16 -0
- package/dist/paraglide/messages/field_turn_duration.js +29 -0
- package/dist/paraglide/messages/field_turn_duration_unit.d.ts +16 -0
- package/dist/paraglide/messages/field_turn_duration_unit.js +29 -0
- package/dist/paraglide/messages/field_turn_timer.d.ts +16 -0
- package/dist/paraglide/messages/field_turn_timer.js +29 -0
- package/dist/paraglide/messages/help_bordering.d.ts +16 -0
- package/dist/paraglide/messages/help_bordering.js +29 -0
- package/dist/paraglide/messages/help_flood_limit.d.ts +16 -0
- package/dist/paraglide/messages/help_flood_limit.js +29 -0
- package/dist/paraglide/messages/help_map.d.ts +16 -0
- package/dist/paraglide/messages/help_map.js +29 -0
- package/dist/paraglide/messages/help_map_size.d.ts +16 -0
- package/dist/paraglide/messages/help_map_size.js +29 -0
- package/dist/paraglide/messages/help_match_duration.d.ts +16 -0
- package/dist/paraglide/messages/help_match_duration.js +29 -0
- package/dist/paraglide/messages/help_participation_time.d.ts +16 -0
- package/dist/paraglide/messages/help_participation_time.js +29 -0
- package/dist/paraglide/messages/help_play_mode.d.ts +16 -0
- package/dist/paraglide/messages/help_play_mode.js +29 -0
- package/dist/paraglide/messages/help_player_name.d.ts +16 -0
- package/dist/paraglide/messages/help_player_name.js +29 -0
- package/dist/paraglide/messages/help_seed.d.ts +16 -0
- package/dist/paraglide/messages/help_seed.js +29 -0
- package/dist/paraglide/messages/help_size.d.ts +16 -0
- package/dist/paraglide/messages/help_size.js +29 -0
- package/dist/paraglide/messages/help_spikiness.d.ts +16 -0
- package/dist/paraglide/messages/help_spikiness.js +29 -0
- package/dist/paraglide/messages/help_turn_based.d.ts +16 -0
- package/dist/paraglide/messages/help_turn_based.js +29 -0
- package/dist/paraglide/messages/help_turn_duration.d.ts +16 -0
- package/dist/paraglide/messages/help_turn_duration.js +29 -0
- package/dist/paraglide/messages/help_turn_time.d.ts +16 -0
- package/dist/paraglide/messages/help_turn_time.js +29 -0
- package/dist/paraglide/messages/help_turn_timer.d.ts +16 -0
- package/dist/paraglide/messages/help_turn_timer.js +29 -0
- package/dist/paraglide/messages/help_tutorial_mode.d.ts +16 -0
- package/dist/paraglide/messages/help_tutorial_mode.js +29 -0
- package/dist/paraglide/messages/help_void_fraction.d.ts +16 -0
- package/dist/paraglide/messages/help_void_fraction.js +29 -0
- package/dist/paraglide/messages/history_empty.d.ts +16 -0
- package/dist/paraglide/messages/history_empty.js +29 -0
- package/dist/paraglide/messages/label_claims.d.ts +18 -0
- package/dist/paraglide/messages/label_claims.js +29 -0
- package/dist/paraglide/messages/label_cumulative_time.d.ts +16 -0
- package/dist/paraglide/messages/label_cumulative_time.js +29 -0
- package/dist/paraglide/messages/label_custom_map_options.d.ts +16 -0
- package/dist/paraglide/messages/label_custom_map_options.js +29 -0
- package/dist/paraglide/messages/label_gameplay_options.d.ts +16 -0
- package/dist/paraglide/messages/label_gameplay_options.js +29 -0
- package/dist/paraglide/messages/label_map_options.d.ts +16 -0
- package/dist/paraglide/messages/label_map_options.js +29 -0
- package/dist/paraglide/messages/label_match_ends.d.ts +18 -0
- package/dist/paraglide/messages/label_match_ends.js +29 -0
- package/dist/paraglide/messages/label_match_id.d.ts +18 -0
- package/dist/paraglide/messages/label_match_id.js +29 -0
- package/dist/paraglide/messages/label_player_number.d.ts +18 -0
- package/dist/paraglide/messages/label_player_number.js +29 -0
- package/dist/paraglide/messages/label_points.d.ts +18 -0
- package/dist/paraglide/messages/label_points.js +29 -0
- package/dist/paraglide/messages/label_revealed_count.d.ts +18 -0
- package/dist/paraglide/messages/label_revealed_count.js +29 -0
- package/dist/paraglide/messages/label_team_score.d.ts +18 -0
- package/dist/paraglide/messages/label_team_score.js +29 -0
- package/dist/paraglide/messages/label_turn_remaining.d.ts +18 -0
- package/dist/paraglide/messages/label_turn_remaining.js +29 -0
- package/dist/paraglide/messages/label_you.d.ts +16 -0
- package/dist/paraglide/messages/label_you.js +29 -0
- package/dist/paraglide/messages/mode_collaborative.d.ts +16 -0
- package/dist/paraglide/messages/mode_collaborative.js +29 -0
- package/dist/paraglide/messages/mode_collaborative_hint.d.ts +16 -0
- package/dist/paraglide/messages/mode_collaborative_hint.js +29 -0
- package/dist/paraglide/messages/mode_solo.d.ts +16 -0
- package/dist/paraglide/messages/mode_solo.js +29 -0
- package/dist/paraglide/messages/mode_solo_hint.d.ts +16 -0
- package/dist/paraglide/messages/mode_solo_hint.js +29 -0
- package/dist/paraglide/messages/mode_territory.d.ts +16 -0
- package/dist/paraglide/messages/mode_territory.js +29 -0
- package/dist/paraglide/messages/mode_territory_hint.d.ts +16 -0
- package/dist/paraglide/messages/mode_territory_hint.js +29 -0
- package/dist/paraglide/messages/multiplayer_title.d.ts +16 -0
- package/dist/paraglide/messages/multiplayer_title.js +29 -0
- package/dist/paraglide/messages/option_help.d.ts +18 -0
- package/dist/paraglide/messages/option_help.js +29 -0
- package/dist/paraglide/messages/shape_label.d.ts +5 -5
- package/dist/paraglide/messages/shape_label.js +15 -15
- package/dist/paraglide/messages/status_connecting.d.ts +16 -0
- package/dist/paraglide/messages/status_connecting.js +29 -0
- package/dist/paraglide/messages/status_draw.d.ts +16 -0
- package/dist/paraglide/messages/status_draw.js +29 -0
- package/dist/paraglide/messages/status_match_complete.d.ts +16 -0
- package/dist/paraglide/messages/status_match_complete.js +29 -0
- package/dist/paraglide/messages/status_match_expired.d.ts +16 -0
- package/dist/paraglide/messages/status_match_expired.js +29 -0
- package/dist/paraglide/messages/status_name_saved.d.ts +16 -0
- package/dist/paraglide/messages/status_name_saved.js +29 -0
- package/dist/paraglide/messages/status_named_turn.d.ts +18 -0
- package/dist/paraglide/messages/status_named_turn.js +29 -0
- package/dist/paraglide/messages/status_named_winner.d.ts +18 -0
- package/dist/paraglide/messages/status_named_winner.js +29 -0
- package/dist/paraglide/messages/status_player_turn.d.ts +18 -0
- package/dist/paraglide/messages/status_player_turn.js +29 -0
- package/dist/paraglide/messages/status_realtime_claims.d.ts +16 -0
- package/dist/paraglide/messages/status_realtime_claims.js +29 -0
- package/dist/paraglide/messages/status_reconnecting.d.ts +16 -0
- package/dist/paraglide/messages/status_reconnecting.js +29 -0
- package/dist/paraglide/messages/status_session_complete.d.ts +16 -0
- package/dist/paraglide/messages/status_session_complete.js +29 -0
- package/dist/paraglide/messages/status_winner.d.ts +18 -0
- package/dist/paraglide/messages/status_winner.js +29 -0
- package/dist/paraglide/messages/text_account_multiplayer.d.ts +16 -0
- package/dist/paraglide/messages/text_account_multiplayer.js +29 -0
- package/dist/paraglide/messages/text_multiplayer_login.d.ts +16 -0
- package/dist/paraglide/messages/text_multiplayer_login.js +29 -0
- package/dist/paraglide/messages/text_waiting_lobby.d.ts +16 -0
- package/dist/paraglide/messages/text_waiting_lobby.js +29 -0
- package/dist/paraglide/messages/unit_hours.d.ts +16 -0
- package/dist/paraglide/messages/unit_hours.js +29 -0
- package/dist/paraglide/messages/unit_hours_selected.d.ts +19 -0
- package/dist/paraglide/messages/unit_hours_selected.js +35 -0
- package/dist/paraglide/messages/unit_minutes.d.ts +16 -0
- package/dist/paraglide/messages/unit_minutes.js +29 -0
- package/dist/paraglide/messages/unit_minutes_selected.d.ts +19 -0
- package/dist/paraglide/messages/unit_minutes_selected.js +35 -0
- package/dist/paraglide/messages/unit_seconds.d.ts +16 -0
- package/dist/paraglide/messages/unit_seconds.js +29 -0
- package/dist/paraglide/messages/unit_seconds_selected.d.ts +19 -0
- package/dist/paraglide/messages/unit_seconds_selected.js +35 -0
- package/dist/styles/global.css +12 -51
- package/dist/wasm/avoidant_wasm.d.ts +11 -11
- package/dist/wasm/avoidant_wasm.js +43 -43
- package/dist/wasm/avoidant_wasm_bg.wasm +0 -0
- package/dist/wasm/avoidant_wasm_bg.wasm.d.ts +11 -11
- 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,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;
|