@roster-lock/match-agent 0.1.0 → 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 (110) hide show
  1. package/client/dist/assets/index-CX6eCHuc.js +125 -0
  2. package/client/dist/assets/index-gxAuIfGQ.css +1 -0
  3. package/client/dist/index.html +13 -0
  4. package/client/index.html +12 -0
  5. package/client/node_modules/.bin/terser +17 -0
  6. package/client/node_modules/.bin/tsc +17 -0
  7. package/client/node_modules/.bin/vite +17 -0
  8. package/client/node_modules/.vite/deps/@rjsf_core.js +6609 -0
  9. package/client/node_modules/.vite/deps/@rjsf_core.js.map +7 -0
  10. package/client/node_modules/.vite/deps/@rjsf_validator-ajv8.js +14 -0
  11. package/client/node_modules/.vite/deps/@rjsf_validator-ajv8.js.map +7 -0
  12. package/client/node_modules/.vite/deps/@roster-lock_ts-client.js +419 -0
  13. package/client/node_modules/.vite/deps/@roster-lock_ts-client.js.map +7 -0
  14. package/client/node_modules/.vite/deps/@roster-lock_types.js +6 -0
  15. package/client/node_modules/.vite/deps/@roster-lock_types.js.map +7 -0
  16. package/client/node_modules/.vite/deps/@roster-lock_utils.js +6 -0
  17. package/client/node_modules/.vite/deps/@roster-lock_utils.js.map +7 -0
  18. package/client/node_modules/.vite/deps/_metadata.json +97 -0
  19. package/client/node_modules/.vite/deps/chunk-3IRPLLFB.js +16036 -0
  20. package/client/node_modules/.vite/deps/chunk-3IRPLLFB.js.map +7 -0
  21. package/client/node_modules/.vite/deps/chunk-7DRNB6P7.js +1004 -0
  22. package/client/node_modules/.vite/deps/chunk-7DRNB6P7.js.map +7 -0
  23. package/client/node_modules/.vite/deps/chunk-CKYX73LL.js +467 -0
  24. package/client/node_modules/.vite/deps/chunk-CKYX73LL.js.map +7 -0
  25. package/client/node_modules/.vite/deps/chunk-EDVVVQBR.js +2337 -0
  26. package/client/node_modules/.vite/deps/chunk-EDVVVQBR.js.map +7 -0
  27. package/client/node_modules/.vite/deps/chunk-FFVS6IUX.js +280 -0
  28. package/client/node_modules/.vite/deps/chunk-FFVS6IUX.js.map +7 -0
  29. package/client/node_modules/.vite/deps/chunk-G44QLPFQ.js +292 -0
  30. package/client/node_modules/.vite/deps/chunk-G44QLPFQ.js.map +7 -0
  31. package/client/node_modules/.vite/deps/chunk-WMTNK64S.js +53 -0
  32. package/client/node_modules/.vite/deps/chunk-WMTNK64S.js.map +7 -0
  33. package/client/node_modules/.vite/deps/package.json +3 -0
  34. package/client/node_modules/.vite/deps/react-dom.js +7 -0
  35. package/client/node_modules/.vite/deps/react-dom.js.map +7 -0
  36. package/client/node_modules/.vite/deps/react-dom_client.js +20217 -0
  37. package/client/node_modules/.vite/deps/react-dom_client.js.map +7 -0
  38. package/client/node_modules/.vite/deps/react-router-dom.js +14735 -0
  39. package/client/node_modules/.vite/deps/react-router-dom.js.map +7 -0
  40. package/client/node_modules/.vite/deps/react.js +6 -0
  41. package/client/node_modules/.vite/deps/react.js.map +7 -0
  42. package/client/node_modules/.vite/deps/react_jsx-dev-runtime.js +278 -0
  43. package/client/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +7 -0
  44. package/client/node_modules/.vite/deps/react_jsx-runtime.js +7 -0
  45. package/client/node_modules/.vite/deps/react_jsx-runtime.js.map +7 -0
  46. package/client/package.json +30 -0
  47. package/client/src/App.tsx +56 -0
  48. package/client/src/NavBar.tsx +13 -0
  49. package/client/src/api/matchAgent.ts +174 -0
  50. package/client/src/bridge/hostBridge.ts +168 -0
  51. package/client/src/components/GameLauncherSettingsForm.tsx +140 -0
  52. package/client/src/components/InstallGameLauncherLightbox.tsx +44 -0
  53. package/client/src/components/Lightbox.tsx +15 -0
  54. package/client/src/components/RequireConnection.tsx +9 -0
  55. package/client/src/components/Selection/PieceCard.tsx +36 -0
  56. package/client/src/components/Selection/PieceTypeSection.tsx +112 -0
  57. package/client/src/components/Selection/PieceTypeTabs.tsx +31 -0
  58. package/client/src/components/Selection/PlayerSelectionPanel.tsx +40 -0
  59. package/client/src/components/Selection/index.tsx +147 -0
  60. package/client/src/components/Selection/selectionPlan.ts +75 -0
  61. package/client/src/context/DownloadSessionContext.tsx +48 -0
  62. package/client/src/context/IdentityContext.tsx +53 -0
  63. package/client/src/context/JoinSettingsContext.tsx +83 -0
  64. package/client/src/context/MatchAgentContext.tsx +85 -0
  65. package/client/src/hooks/useCursorInput.ts +55 -0
  66. package/client/src/hooks/useGamepads.ts +31 -0
  67. package/client/src/main.tsx +10 -0
  68. package/client/src/pages/Connect/index.tsx +46 -0
  69. package/client/src/pages/Download/index.tsx +175 -0
  70. package/client/src/pages/Game/index.tsx +65 -0
  71. package/client/src/pages/GameLauncher/Detail.tsx +12 -0
  72. package/client/src/pages/GameLauncher/index.tsx +32 -0
  73. package/client/src/pages/JoinSettings/index.tsx +58 -0
  74. package/client/src/pages/MatchMaking/index.tsx +194 -0
  75. package/client/src/styles/global.css +355 -0
  76. package/client/tsconfig.json +17 -0
  77. package/client/tsconfig.tsbuildinfo +1 -0
  78. package/client/vite.config.ts +33 -0
  79. package/dist/config/manage.js.map +1 -1
  80. package/dist/handle-room/version-1/game-launcher.js +197 -0
  81. package/dist/handle-room/version-1/game-launcher.js.map +1 -0
  82. package/dist/handle-room/version-1/index.js +16 -2
  83. package/dist/handle-room/version-1/index.js.map +1 -1
  84. package/dist/handle-room/version-1/piece-sort.js +1 -0
  85. package/dist/handle-room/version-1/piece-sort.js.map +1 -1
  86. package/dist/index.js +7 -4
  87. package/dist/index.js.map +1 -1
  88. package/dist/serve-client.js +88 -0
  89. package/dist/serve-client.js.map +1 -0
  90. package/dist/server.js +1 -1
  91. package/dist/server.js.map +1 -1
  92. package/package.json +16 -8
  93. package/src/config/manage.ts +5 -1
  94. package/src/handle-room/version-1/game-launcher.ts +287 -0
  95. package/src/handle-room/version-1/globals/types.ts +24 -0
  96. package/src/handle-room/version-1/index.ts +24 -3
  97. package/src/handle-room/version-1/piece-sort.ts +1 -1
  98. package/src/index.ts +25 -5
  99. package/src/serve-client.ts +100 -0
  100. package/src/server.ts +1 -1
  101. package/tests/integration/game-launcher-list.test.ts +77 -0
  102. package/tests/integration/game-launcher-settings.test.ts +138 -0
  103. package/tests/integration/game-launcher-start.test.ts +81 -0
  104. package/tests/integration/helpers/fakePluginRuntime.ts +26 -1
  105. package/tests/integration/helpers/relayHarness.ts +24 -0
  106. package/tests/integration/helpers/server.ts +8 -2
  107. package/tests/integration/piece-ensure-ws.test.ts +1 -1
  108. package/tests/integration/relay-protocol.test.ts +100 -0
  109. package/tests/integration/sync-dl.test.ts +1 -1
  110. package/src/index.old.ts +0 -71
@@ -0,0 +1,168 @@
1
+ import { RefObject, useEffect, useRef, useState } from "react";
2
+ import { MessageBridge, waitForBridgeEvent } from "@roster-lock/utils";
3
+ import {
4
+ MATCHMAKER_BRIDGE_PATHS,
5
+ InstallGameLauncherPluginRequest, InstallGameLauncherPluginResponse,
6
+ GetInstalledGameLauncherPluginsResponse,
7
+ GetIdentityResponse,
8
+ RequestSelectionRequest, RequestSelectionResponse,
9
+ UpdateGameLauncherSettingsRequest, UpdateGameLauncherSettingsResponse,
10
+ ValidateGameConfigRequest, ValidateGameConfigResponse,
11
+ InitiateRelayEvent,
12
+ } from "@roster-lock/types";
13
+ import { UserKeyPair } from "@roster-lock/ts-client";
14
+ import { listAvailableGameLaunchers, validateGameLauncherGameConfig } from "../api/matchAgent";
15
+ import { PlayerSlot } from "../context/JoinSettingsContext";
16
+ import { DownloadSession } from "../context/DownloadSessionContext";
17
+
18
+ export type PendingLightbox = (
19
+ | { type: "install", pluginName: string, resolve: () => void, reject: (e: Error) => void }
20
+ | { type: "selection", rosterConfig: RequestSelectionRequest["rosterLockConfig"], numPlayers: number, resolve: (v: RequestSelectionResponse) => void, reject: (e: Error) => void }
21
+ );
22
+
23
+ // Host-side half of the matchmaker bridge protocol (see
24
+ // core/types/src/v1/runtime/matchmaker-bridge) - one instance per mounted
25
+ // <iframe>, built once the guest signals "ready" (mirrors the "wait for the
26
+ // other side's bridge to come up" handshake @roster-lock/ts-client's
27
+ // sync-dl.ws.ts uses over WebSocket, just over postMessage here).
28
+ export function useHostBridge(args: {
29
+ iframeRef: RefObject<HTMLIFrameElement | null>,
30
+ iframeLoaded: boolean,
31
+ matchAgent: { url: string, authCode: string },
32
+ identityKeys: UserKeyPair,
33
+ machineId: string,
34
+ playerSlots: Array<PlayerSlot>,
35
+ onInitiateRelay: (session: DownloadSession) => void,
36
+ }) {
37
+ const { iframeRef, iframeLoaded, matchAgent, identityKeys, machineId, playerSlots, onInitiateRelay } = args;
38
+
39
+ const [pendingLightbox, setPendingLightbox] = useState<PendingLightbox | null>(null);
40
+ const [connected, setConnected] = useState(false);
41
+ const [connectionError, setConnectionError] = useState(false);
42
+ const bridgeRef = useRef<MessageBridge | null>(null);
43
+ const pendingGameConfigRef = useRef<unknown>(undefined);
44
+ const pendingSelectionRef = useRef<Record<number, unknown> | null>(null);
45
+
46
+ // Stable across renders via refs, so the bridge's onRequest handlers
47
+ // always see current props without needing to be torn down/rebuilt.
48
+ const latest = useRef(args);
49
+ latest.current = args;
50
+
51
+ useEffect(() => {
52
+ if (!iframeLoaded) return;
53
+ setConnected(false);
54
+ setConnectionError(false);
55
+
56
+ const bridge = new MessageBridge((message) => {
57
+ iframeRef.current?.contentWindow?.postMessage(message, "*");
58
+ });
59
+ bridgeRef.current = bridge;
60
+
61
+ const onMessage = (event: MessageEvent) => {
62
+ if (event.source !== iframeRef.current?.contentWindow) return;
63
+ bridge.handleMessage(event.data).catch(() => {});
64
+ };
65
+ window.addEventListener("message", onMessage);
66
+
67
+ bridge.onRequest(MATCHMAKER_BRIDGE_PATHS.installGameLauncherPlugin, ({ pluginName }: InstallGameLauncherPluginRequest) => {
68
+ return new Promise<InstallGameLauncherPluginResponse>((resolve, reject) => {
69
+ setPendingLightbox({ type: "install", pluginName, resolve: () => resolve({}), reject: (e) => reject(e) });
70
+ });
71
+ });
72
+
73
+ bridge.onRequest(MATCHMAKER_BRIDGE_PATHS.getInstalledGameLauncherPlugins, async (): Promise<GetInstalledGameLauncherPluginsResponse> => {
74
+ const runners = await listAvailableGameLaunchers(latest.current.matchAgent.url, latest.current.matchAgent.authCode);
75
+ return runners.map((r) => ({ id: r.pluginName, version: r.version, gameConfigSchema: r.gameConfigSchema }));
76
+ });
77
+
78
+ bridge.onRequest(MATCHMAKER_BRIDGE_PATHS.getIdentity, (): GetIdentityResponse => ({
79
+ publicKey: latest.current.identityKeys.publicKey,
80
+ machineId: latest.current.machineId,
81
+ playerCount: latest.current.playerSlots.length,
82
+ }));
83
+
84
+ bridge.onRequest(
85
+ MATCHMAKER_BRIDGE_PATHS.requestSelection,
86
+ ({ rosterLockConfig, numPlayers }: RequestSelectionRequest) => {
87
+ return new Promise<RequestSelectionResponse>((resolve, reject) => {
88
+ setPendingLightbox({
89
+ type: "selection",
90
+ rosterConfig: rosterLockConfig,
91
+ numPlayers,
92
+ resolve: (selection) => {
93
+ pendingSelectionRef.current = selection;
94
+ resolve(selection);
95
+ },
96
+ reject: (e) => reject(e),
97
+ });
98
+ });
99
+ }
100
+ );
101
+
102
+ bridge.onRequest(
103
+ MATCHMAKER_BRIDGE_PATHS.updateGameLauncherSettings,
104
+ ({ gameConfig }: UpdateGameLauncherSettingsRequest): UpdateGameLauncherSettingsResponse => {
105
+ pendingGameConfigRef.current = gameConfig;
106
+ return {};
107
+ }
108
+ );
109
+
110
+ bridge.onRequest(
111
+ MATCHMAKER_BRIDGE_PATHS.validateGameConfig,
112
+ async ({ pluginName, gameConfig, rosterConfig }: ValidateGameConfigRequest): Promise<ValidateGameConfigResponse> => {
113
+ const problems = await validateGameLauncherGameConfig(
114
+ latest.current.matchAgent.url, latest.current.matchAgent.authCode, pluginName, gameConfig, rosterConfig
115
+ );
116
+ return { problems };
117
+ }
118
+ );
119
+
120
+ bridge.onEvent(MATCHMAKER_BRIDGE_PATHS.initiateRelay, (payload: InitiateRelayEvent) => {
121
+ if (!pendingSelectionRef.current) return;
122
+ latest.current.onInitiateRelay({
123
+ relay: payload.relay,
124
+ rosterConfig: payload.rosterConfig,
125
+ gameLauncherPlugin: payload.gameLauncherPlugin,
126
+ gameConfig: pendingGameConfigRef.current,
127
+ playerSelections: pendingSelectionRef.current as DownloadSession["playerSelections"],
128
+ isHost: payload.isHost,
129
+ coordinator: payload.coordinator,
130
+ });
131
+ });
132
+
133
+ waitForBridgeEvent(bridge, MATCHMAKER_BRIDGE_PATHS.ready, 15_000)
134
+ .then(() => setConnected(true))
135
+ .catch(() => setConnectionError(true));
136
+
137
+ return () => {
138
+ window.removeEventListener("message", onMessage);
139
+ bridgeRef.current = null;
140
+ };
141
+ // eslint-disable-next-line react-hooks/exhaustive-deps
142
+ }, [iframeLoaded]);
143
+
144
+ const resolveInstallLightbox = () => {
145
+ if (pendingLightbox?.type === "install") pendingLightbox.resolve();
146
+ setPendingLightbox(null);
147
+ };
148
+
149
+ const cancelInstallLightbox = () => {
150
+ if (pendingLightbox?.type === "install") pendingLightbox.reject(new Error("cancelled"));
151
+ setPendingLightbox(null);
152
+ };
153
+
154
+ const resolveSelectionLightbox = (selection: RequestSelectionResponse) => {
155
+ if (pendingLightbox?.type === "selection") pendingLightbox.resolve(selection);
156
+ setPendingLightbox(null);
157
+ };
158
+
159
+ const cancelSelectionLightbox = () => {
160
+ if (pendingLightbox?.type === "selection") pendingLightbox.reject(new Error("cancelled"));
161
+ setPendingLightbox(null);
162
+ };
163
+
164
+ return {
165
+ connected, connectionError, pendingLightbox,
166
+ resolveInstallLightbox, cancelInstallLightbox, resolveSelectionLightbox, cancelSelectionLightbox,
167
+ };
168
+ }
@@ -0,0 +1,140 @@
1
+ import { useEffect, useState } from "react";
2
+ import Form from "@rjsf/core";
3
+ import validator from "@rjsf/validator-ajv8";
4
+ import type { RJSFSchema } from "@rjsf/utils";
5
+ import { useMatchAgent } from "../context/MatchAgentContext";
6
+ import {
7
+ getGameLauncherSettings, setGameLauncherSettings, getGameLauncherVersion, updateGameLauncherBinary,
8
+ validateGameLauncherBinaryLocation, listAvailableGameLaunchers,
9
+ } from "../api/matchAgent";
10
+
11
+ // A schema with no declared properties renders nothing useful in rjsf - most
12
+ // plugins (e.g. ikemen-go today) have nothing beyond binaryLocation, so this
13
+ // is what most of the time skips rendering the form at all rather than
14
+ // showing an empty box.
15
+ function hasProperties(schema: unknown): schema is RJSFSchema {
16
+ return !!schema && typeof schema === "object" && !!(schema as RJSFSchema).properties
17
+ && Object.keys((schema as RJSFSchema).properties!).length > 0;
18
+ }
19
+
20
+ // binaryLocation/version/update form for one game-launcher plugin - shared by
21
+ // pages/GameLauncher/Detail.tsx (the standalone settings route) and
22
+ // components/InstallGameLauncherLightbox.tsx (the same form, right after a
23
+ // fresh install, inside the lightbox the host opens for the
24
+ // installGameLauncherPlugin bridge call).
25
+ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string }) {
26
+ const { settings } = useMatchAgent();
27
+ const [binaryLocation, setBinaryLocation] = useState("");
28
+ const [version, setVersion] = useState<{ local: { title: string }, supported: { title: string } } | null>(null);
29
+ // Set right after load/save, not just on-demand - so a bad folder is
30
+ // flagged before the user ever hits "Check version" or "Download / update"
31
+ // and gets a raw spawn/ENOENT-flavored error instead (see
32
+ // docs/v2/binary-location.md's Validation section). Left `undefined` while
33
+ // there's no binaryLocation to check at all, as opposed to `null` (never
34
+ // checked yet) or a real result.
35
+ const [validation, setValidation] = useState<{ valid: true } | { valid: false, message: string } | null>(null);
36
+ // The plugin's own per-machine settings beyond binaryLocation - schema
37
+ // comes from AvailableGameLauncher.localConfigSchema (listAvailableGameLaunchers),
38
+ // not from getGameLauncherSettings, since that route only ever returns the
39
+ // stored *value* (GameLauncherLocalSettings), never the plugin's schema.
40
+ const [localConfigSchema, setLocalConfigSchema] = useState<unknown>(null);
41
+ const [localConfig, setLocalConfig] = useState<unknown>(undefined);
42
+ const [busy, setBusy] = useState(false);
43
+ const [error, setError] = useState<string | null>(null);
44
+
45
+ const validate = async (location: string) => {
46
+ if(!location){
47
+ setValidation(null);
48
+ return;
49
+ }
50
+ try {
51
+ setValidation(await validateGameLauncherBinaryLocation(settings.url, settings.authCode, pluginName));
52
+ } catch (e) {
53
+ setValidation({ valid: false, message: (e as Error).message });
54
+ }
55
+ };
56
+
57
+ const load = () => {
58
+ setError(null);
59
+ Promise.all([
60
+ getGameLauncherSettings(settings.url, settings.authCode, pluginName),
61
+ listAvailableGameLaunchers(settings.url, settings.authCode),
62
+ ])
63
+ .then(([s, available]) => {
64
+ setBinaryLocation(s.binaryLocation ?? "");
65
+ setLocalConfig(s.localConfig);
66
+ setLocalConfigSchema(available.find((a) => a.pluginName === pluginName)?.localConfigSchema ?? null);
67
+ return validate(s.binaryLocation ?? "");
68
+ })
69
+ .catch((e) => setError(e.message));
70
+ };
71
+
72
+ useEffect(load, [pluginName, settings]);
73
+
74
+ const save = async () => {
75
+ setBusy(true);
76
+ setError(null);
77
+ try {
78
+ await setGameLauncherSettings(settings.url, settings.authCode, pluginName, { binaryLocation, localConfig });
79
+ await validate(binaryLocation);
80
+ } catch (e) {
81
+ setError((e as Error).message);
82
+ } finally {
83
+ setBusy(false);
84
+ }
85
+ };
86
+
87
+ const checkVersion = async () => {
88
+ setBusy(true);
89
+ setError(null);
90
+ try {
91
+ setVersion(await getGameLauncherVersion(settings.url, settings.authCode, pluginName));
92
+ } catch (e) {
93
+ setError((e as Error).message);
94
+ } finally {
95
+ setBusy(false);
96
+ }
97
+ };
98
+
99
+ const download = async () => {
100
+ setBusy(true);
101
+ setError(null);
102
+ try {
103
+ await updateGameLauncherBinary(settings.url, settings.authCode, pluginName);
104
+ await checkVersion();
105
+ } catch (e) {
106
+ setError((e as Error).message);
107
+ } finally {
108
+ setBusy(false);
109
+ }
110
+ };
111
+
112
+ return (
113
+ <div className="game-launcher-settings-form">
114
+ <label>
115
+ Binary location
116
+ <input value={binaryLocation} onChange={(e) => setBinaryLocation(e.target.value)} />
117
+ </label>
118
+ {hasProperties(localConfigSchema) && (
119
+ // Own submit button suppressed - localConfig just feeds into this
120
+ // component's own state via onChange, and goes out through the
121
+ // Save button below alongside binaryLocation, as one settings write.
122
+ <Form
123
+ schema={localConfigSchema}
124
+ formData={localConfig}
125
+ validator={validator}
126
+ onChange={(e) => setLocalConfig(e.formData)}
127
+ uiSchema={{ "ui:submitButtonOptions": { norender: true } }}
128
+ />
129
+ )}
130
+ <button type="button" disabled={busy} onClick={save}>Save</button>
131
+ <button type="button" disabled={busy || !binaryLocation} onClick={checkVersion}>Check version</button>
132
+ <button type="button" disabled={busy || !binaryLocation} onClick={download}>Download / update</button>
133
+ {validation && !validation.valid && <p className="error">{validation.message}</p>}
134
+ {version && (
135
+ <p>Local: {version.local.title} - Supported: {version.supported.title}</p>
136
+ )}
137
+ {error && <p className="error">{error}</p>}
138
+ </div>
139
+ );
140
+ }
@@ -0,0 +1,44 @@
1
+ import { useState } from "react";
2
+ import { useMatchAgent } from "../context/MatchAgentContext";
3
+ import { installGameLauncherPlugin } from "../api/matchAgent";
4
+ import { GameLauncherSettingsForm } from "./GameLauncherSettingsForm";
5
+
6
+ type Phase = "confirm" | "installing" | "done";
7
+
8
+ // Content for the Lightbox opened by the installGameLauncherPlugin bridge request. Starts by
9
+ // asking the user to confirm - the embedding game picked this plugin name, not the user, so
10
+ // nothing gets installed on their machine without them explicitly agreeing to it here. Only after
11
+ // that does it install the plugin package, then let the user finish local config (binaryLocation)
12
+ // with the same form the standalone /game-launcher/:pluginName route uses, before resolving the
13
+ // bridge request.
14
+ export function InstallGameLauncherLightbox(
15
+ { pluginName, onDone, onCancel }: { pluginName: string, onDone: () => void, onCancel: () => void }
16
+ ) {
17
+ const { settings } = useMatchAgent();
18
+ const [phase, setPhase] = useState<Phase>("confirm");
19
+ const [error, setError] = useState<string | null>(null);
20
+
21
+ const confirmInstall = () => {
22
+ setPhase("installing");
23
+ installGameLauncherPlugin(settings.url, settings.authCode, pluginName)
24
+ .catch((e) => setError((e as Error).message))
25
+ .finally(() => setPhase("done"));
26
+ };
27
+
28
+ return (
29
+ <div className="page">
30
+ <h1>Install {pluginName}</h1>
31
+ {phase === "confirm" && (
32
+ <>
33
+ <p>This game wants to install the "{pluginName}" game launcher plugin on this machine.</p>
34
+ <button type="button" onClick={confirmInstall}>Install</button>
35
+ <button type="button" onClick={onCancel}>Cancel</button>
36
+ </>
37
+ )}
38
+ {phase === "installing" && <p>Installing...</p>}
39
+ {error && <p className="error">{error}</p>}
40
+ {phase === "done" && <GameLauncherSettingsForm pluginName={pluginName} />}
41
+ {phase === "done" && <button type="button" onClick={onDone}>Done</button>}
42
+ </div>
43
+ );
44
+ }
@@ -0,0 +1,15 @@
1
+ import { ReactNode } from "react";
2
+
3
+ // Generic overlay used by pages/MatchMaking to host whichever bridge request
4
+ // is currently pending (installGameLauncherPlugin or requestSelection) -
5
+ // rendered by the host shell, on top of the matchmaker <iframe>, never
6
+ // inside it.
7
+ export function Lightbox({ children, onClose }: { children: ReactNode, onClose?: () => void }) {
8
+ return (
9
+ <div className="lightbox-backdrop" onClick={onClose}>
10
+ <div className="lightbox-box" onClick={(e) => e.stopPropagation()}>
11
+ {children}
12
+ </div>
13
+ </div>
14
+ );
15
+ }
@@ -0,0 +1,9 @@
1
+ import { ReactNode } from "react";
2
+ import { Navigate } from "react-router-dom";
3
+ import { useMatchAgent } from "../context/MatchAgentContext";
4
+
5
+ export function RequireConnection({ children }: { children: ReactNode }) {
6
+ const { connected } = useMatchAgent();
7
+ if (!connected) return <Navigate to="/connect" replace />;
8
+ return <>{children}</>;
9
+ }
@@ -0,0 +1,36 @@
1
+ import { RosterLockPiece } from "@roster-lock/types";
2
+
3
+ export function PieceCard({ piece, selected, orderNumber, downloaded, cursored, disabled, onClick }: {
4
+ piece: RosterLockPiece,
5
+ selected: boolean,
6
+ orderNumber: number | undefined,
7
+ downloaded: boolean | undefined,
8
+ cursored: boolean,
9
+ disabled: boolean,
10
+ onClick: () => void,
11
+ }) {
12
+ return (
13
+ <button
14
+ type="button"
15
+ className="piece-card"
16
+ onClick={onClick}
17
+ disabled={disabled && !selected}
18
+ data-selected={selected}
19
+ data-cursored={cursored}
20
+ title={piece.humanInfo.author ? `by ${piece.humanInfo.author}` : undefined}
21
+ >
22
+ <div className="piece-card-image">
23
+ {orderNumber !== undefined && <span className="piece-card-order-badge">{orderNumber}</span>}
24
+ {piece.humanInfo.image ? (
25
+ <img src={piece.humanInfo.image} alt={piece.humanInfo.name} />
26
+ ) : (
27
+ <span className="piece-card-placeholder">{piece.humanInfo.name.slice(0, 1).toUpperCase()}</span>
28
+ )}
29
+ </div>
30
+ <div className="piece-card-name">{piece.humanInfo.name}</div>
31
+ <div className="piece-card-status">
32
+ {downloaded === undefined ? "" : downloaded ? "Downloaded" : "Not downloaded"}
33
+ </div>
34
+ </button>
35
+ );
36
+ }
@@ -0,0 +1,112 @@
1
+ import { useEffect, useState } from "react";
2
+ import { RosterLockV1Config } from "@roster-lock/types";
3
+ import { PieceTypePlan } from "./selectionPlan";
4
+ import { PieceCard } from "./PieceCard";
5
+ import { InputSource } from "../../context/JoinSettingsContext";
6
+ import { useCursorInput } from "../../hooks/useCursorInput";
7
+ import { listDownloadedPiecesFromConfig } from "@roster-lock/ts-client";
8
+
9
+ export function PieceTypeSection({
10
+ rosterConfig, pieceType, plan, picks, onTogglePick, onReorderPick, inputSource, matchAgentUrl, matchAgentAuth,
11
+ }: {
12
+ rosterConfig: RosterLockV1Config,
13
+ pieceType: string,
14
+ plan: Extract<PieceTypePlan, { kind: "pickable" }>,
15
+ picks: Array<string>,
16
+ onTogglePick: (pieceId: string) => void,
17
+ onReorderPick: (fromIndex: number, toIndex: number) => void,
18
+ inputSource: InputSource,
19
+ matchAgentUrl: string,
20
+ matchAgentAuth: string,
21
+ }) {
22
+ const pieces = (rosterConfig.rosters[pieceType] ?? []).filter((p) => !plan.banList.includes(p.id));
23
+ const [downloaded, setDownloaded] = useState<Record<string, boolean>>({});
24
+ const [cursorIndex, setCursorIndex] = useState(0);
25
+
26
+ useEffect(() => {
27
+ let cancelled = false;
28
+ listDownloadedPiecesFromConfig(
29
+ { version: 1, rosterConfig, pieceType }, { page: 0, limit: 500 }, matchAgentAuth, matchAgentUrl
30
+ ).then((rows) => {
31
+ if (cancelled) return;
32
+ const byLogic = new Set(rows.map((r) => r.version.logic));
33
+ const next: Record<string, boolean> = {};
34
+ for (const piece of pieces) next[piece.id] = byLogic.has(piece.version.logic);
35
+ setDownloaded(next);
36
+ }).catch(() => {});
37
+ return () => { cancelled = true; };
38
+ // eslint-disable-next-line react-hooks/exhaustive-deps
39
+ }, [pieceType]);
40
+
41
+ const atMax = picks.length >= plan.max;
42
+ const move = (delta: number) => setCursorIndex((i) => (i + delta + pieces.length) % Math.max(pieces.length, 1));
43
+ const confirm = () => {
44
+ const piece = pieces[cursorIndex];
45
+ if (piece) onTogglePick(piece.id);
46
+ };
47
+ useCursorInput(inputSource, pieces.length > 0, move, confirm);
48
+
49
+ const countLabel = plan.min === plan.max
50
+ ? `pick exactly ${plan.min}`
51
+ : plan.max === Number.POSITIVE_INFINITY
52
+ ? `pick ${plan.min}-any`
53
+ : `pick ${plan.min}-${plan.max}`;
54
+
55
+ const pieceById = new Map(pieces.map((piece) => [piece.id, piece]));
56
+
57
+ return (
58
+ <div className="piece-type-section">
59
+ <div className="piece-type-header">
60
+ <span className="piece-type-count">{countLabel} ({picks.length} picked)</span>
61
+ </div>
62
+ <div className="card-grid">
63
+ {pieces.map((piece, index) => {
64
+ const orderIndex = picks.indexOf(piece.id);
65
+ return (
66
+ <PieceCard
67
+ key={piece.id}
68
+ piece={piece}
69
+ selected={orderIndex !== -1}
70
+ orderNumber={orderIndex === -1 ? undefined : orderIndex + 1}
71
+ downloaded={downloaded[piece.id]}
72
+ cursored={index === cursorIndex}
73
+ disabled={atMax}
74
+ onClick={() => onTogglePick(piece.id)}
75
+ />
76
+ );
77
+ })}
78
+ </div>
79
+ {picks.length > 0 && (
80
+ <ol className="pick-order-list">
81
+ {picks.map((pieceId, index) => (
82
+ <li key={pieceId} className="pick-order-item">
83
+ <span className="pick-order-index">{index + 1}</span>
84
+ <span className="pick-order-name">{pieceById.get(pieceId)?.humanInfo.name ?? pieceId}</span>
85
+ <button
86
+ type="button"
87
+ className="pick-order-move"
88
+ disabled={index === 0}
89
+ onClick={() => onReorderPick(index, index - 1)}
90
+ aria-label="Move earlier"
91
+ >
92
+ ↑
93
+ </button>
94
+ <button
95
+ type="button"
96
+ className="pick-order-move"
97
+ disabled={index === picks.length - 1}
98
+ onClick={() => onReorderPick(index, index + 1)}
99
+ aria-label="Move later"
100
+ >
101
+ ↓
102
+ </button>
103
+ <button type="button" className="pick-order-remove" onClick={() => onTogglePick(pieceId)}>
104
+ Remove
105
+ </button>
106
+ </li>
107
+ ))}
108
+ </ol>
109
+ )}
110
+ </div>
111
+ );
112
+ }
@@ -0,0 +1,31 @@
1
+ // Piece-type tabs are shared across every player slot - switching a tab
2
+ // swaps which piece type's grid is mounted for all slots at once, rather
3
+ // than each slot owning its own tab state. The dot reflects whether every
4
+ // slot's picks for that piece type currently satisfy its min/max, so
5
+ // players can see at a glance which tabs still need attention before
6
+ // Confirm unlocks (see SelectionBoard.allValid).
7
+ export function PieceTypeTabs({ types, activeType, readyByType, onSelect }: {
8
+ types: Array<string>,
9
+ activeType: string,
10
+ readyByType: Record<string, boolean>,
11
+ onSelect: (pieceType: string) => void,
12
+ }) {
13
+ if (types.length === 0) return null;
14
+
15
+ return (
16
+ <nav className="piece-type-tabs">
17
+ {types.map((pieceType) => (
18
+ <button
19
+ key={pieceType}
20
+ type="button"
21
+ className="piece-type-tab"
22
+ data-active={pieceType === activeType}
23
+ onClick={() => onSelect(pieceType)}
24
+ >
25
+ <span className="piece-type-tab-dot" data-ready={readyByType[pieceType] ?? false} aria-hidden="true" />
26
+ {pieceType}
27
+ </button>
28
+ ))}
29
+ </nav>
30
+ );
31
+ }
@@ -0,0 +1,40 @@
1
+ import { RosterLockV1Config } from "@roster-lock/types";
2
+ import { PlayerSlot } from "../../context/JoinSettingsContext";
3
+ import { PieceTypePlan } from "./selectionPlan";
4
+ import { PieceTypeSection } from "./PieceTypeSection";
5
+
6
+ export function PlayerSelectionPanel({
7
+ rosterConfig, slot, pieceType, plan, picks, onTogglePick, onReorderPick, matchAgentUrl, matchAgentAuth,
8
+ }: {
9
+ rosterConfig: RosterLockV1Config,
10
+ slot: PlayerSlot,
11
+ pieceType: string,
12
+ plan: Extract<PieceTypePlan, { kind: "pickable" }>,
13
+ picks: Array<string>,
14
+ onTogglePick: (pieceId: string) => void,
15
+ onReorderPick: (fromIndex: number, toIndex: number) => void,
16
+ matchAgentUrl: string,
17
+ matchAgentAuth: string,
18
+ }) {
19
+ return (
20
+ <div className="player-selection-panel">
21
+ <div className="player-selection-header">
22
+ {slot.label}
23
+ <span className="player-selection-input">
24
+ {slot.input.type === "keyboard" ? "Keyboard" : `Gamepad ${slot.input.index + 1}`}
25
+ </span>
26
+ </div>
27
+ <PieceTypeSection
28
+ rosterConfig={rosterConfig}
29
+ pieceType={pieceType}
30
+ plan={plan}
31
+ picks={picks}
32
+ onTogglePick={onTogglePick}
33
+ onReorderPick={onReorderPick}
34
+ inputSource={slot.input}
35
+ matchAgentUrl={matchAgentUrl}
36
+ matchAgentAuth={matchAgentAuth}
37
+ />
38
+ </div>
39
+ );
40
+ }