@roster-lock/match-agent 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/client/dist/assets/index-D2395vmC.css +1 -0
  2. package/client/dist/assets/index-DcKsa72V.js +125 -0
  3. package/client/dist/index.html +2 -2
  4. package/client/e2e/lib/env.ts +50 -0
  5. package/client/e2e/lib/fileDialog.ts +31 -0
  6. package/client/e2e/lib/mockGamepad.ts +71 -0
  7. package/client/e2e/lib/onscreenKeyboard.ts +32 -0
  8. package/client/e2e/playwright.config.ts +48 -0
  9. package/client/e2e/tests/gamepad-only.spec.ts +274 -0
  10. package/client/e2e/tests/keyboard-only.spec.ts +67 -0
  11. package/client/e2e/tsconfig.json +15 -0
  12. package/client/node_modules/.bin/playwright +17 -0
  13. package/client/node_modules/.bin/roster-lock-plugin-manager +17 -0
  14. package/client/node_modules/.vite/deps/@roster-lock_ts-client.js +2 -2
  15. package/client/node_modules/.vite/deps/@roster-lock_types.js +1 -1
  16. package/client/node_modules/.vite/deps/@roster-lock_utils.js +1 -1
  17. package/client/node_modules/.vite/deps/_metadata.json +18 -18
  18. package/client/node_modules/.vite/deps/{chunk-CKYX73LL.js → chunk-3HBL6DQ6.js} +1 -1
  19. package/client/node_modules/.vite/deps/{chunk-CKYX73LL.js.map → chunk-3HBL6DQ6.js.map} +2 -2
  20. package/client/node_modules/.vite/deps/{chunk-EDVVVQBR.js → chunk-QTQN6EZX.js} +2 -2
  21. package/client/node_modules/.vite/deps/chunk-QTQN6EZX.js.map +7 -0
  22. package/client/package.json +4 -1
  23. package/client/src/App.tsx +23 -14
  24. package/client/src/NavBar.tsx +15 -5
  25. package/client/src/api/matchAgent.ts +193 -5
  26. package/client/src/bridge/hostBridge.ts +15 -5
  27. package/client/src/components/FullScreenMenu.tsx +32 -0
  28. package/client/src/components/GameLauncherSettingsForm.tsx +80 -5
  29. package/client/src/components/InputHints.tsx +37 -0
  30. package/client/src/components/OnScreenFileDialog.tsx +83 -0
  31. package/client/src/components/OnScreenKeyboard.tsx +75 -0
  32. package/client/src/components/Selection/PieceCard.tsx +29 -4
  33. package/client/src/components/Selection/PiecePreviewPanel.tsx +48 -0
  34. package/client/src/components/Selection/PieceTypeSection.tsx +124 -46
  35. package/client/src/components/Selection/PlayerSelectionPanel.tsx +1 -5
  36. package/client/src/components/Selection/index.tsx +72 -47
  37. package/client/src/context/GlobalNavContext.tsx +340 -0
  38. package/client/src/context/SelectionSourceContext.tsx +26 -0
  39. package/client/src/hooks/useCursorInput.ts +66 -24
  40. package/client/src/hooks/useDownloadedPieceVersions.ts +39 -0
  41. package/client/src/hooks/useGridColumns.ts +29 -0
  42. package/client/src/hooks/useInView.ts +32 -0
  43. package/client/src/hooks/usePiecePreview.ts +124 -0
  44. package/client/src/pages/Controls/index.tsx +126 -0
  45. package/client/src/pages/Game/index.tsx +11 -15
  46. package/client/src/pages/MatchMaking/index.tsx +6 -3
  47. package/client/src/pages/PreviewRoster/index.tsx +118 -0
  48. package/client/src/styles/global.css +355 -6
  49. package/client/src/utils/inputLabels.ts +25 -0
  50. package/client/test-results/.last-run.json +4 -0
  51. package/client/tsconfig.tsbuildinfo +1 -1
  52. package/dist/config/index.js +2 -0
  53. package/dist/config/index.js.map +1 -1
  54. package/dist/config/inputBindings.js +40 -0
  55. package/dist/config/inputBindings.js.map +1 -0
  56. package/dist/config/manage.js +1 -0
  57. package/dist/config/manage.js.map +1 -1
  58. package/dist/handle-room/version-1/game-launcher/binaries.js +36 -0
  59. package/dist/handle-room/version-1/game-launcher/binaries.js.map +1 -0
  60. package/dist/handle-room/version-1/game-launcher/listing.js +24 -0
  61. package/dist/handle-room/version-1/game-launcher/listing.js.map +1 -0
  62. package/dist/handle-room/version-1/game-launcher/preview.js +38 -0
  63. package/dist/handle-room/version-1/game-launcher/preview.js.map +1 -0
  64. package/dist/handle-room/version-1/game-launcher/process.js +52 -0
  65. package/dist/handle-room/version-1/game-launcher/process.js.map +1 -0
  66. package/dist/handle-room/version-1/game-launcher/router.js +32 -0
  67. package/dist/handle-room/version-1/game-launcher/router.js.map +1 -0
  68. package/dist/handle-room/version-1/game-launcher/settings.js +49 -0
  69. package/dist/handle-room/version-1/game-launcher/settings.js.map +1 -0
  70. package/dist/handle-room/version-1/game-launcher/shared.js +28 -0
  71. package/dist/handle-room/version-1/game-launcher/shared.js.map +1 -0
  72. package/dist/handle-room/version-1/game-launcher/start.js +76 -0
  73. package/dist/handle-room/version-1/game-launcher/start.js.map +1 -0
  74. package/dist/handle-room/version-1/game-launcher/version.js +63 -0
  75. package/dist/handle-room/version-1/game-launcher/version.js.map +1 -0
  76. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js +22 -9
  77. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js.map +1 -1
  78. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js +50 -1
  79. package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js.map +1 -1
  80. package/dist/handle-room/version-1/index.js +15 -16
  81. package/dist/handle-room/version-1/index.js.map +1 -1
  82. package/dist/handle-room/version-1/input-bindings.js +22 -0
  83. package/dist/handle-room/version-1/input-bindings.js.map +1 -0
  84. package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js +2 -1
  85. package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js.map +1 -1
  86. package/dist/handle-room/version-1/room-handler-bridge/http-handler.js +1 -1
  87. package/dist/handle-room/version-1/room-handler-bridge/http-handler.js.map +1 -1
  88. package/dist/handle-room/version-1/room-handler-bridge/steps.js +2 -1
  89. package/dist/handle-room/version-1/room-handler-bridge/steps.js.map +1 -1
  90. package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js +2 -2
  91. package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js.map +1 -1
  92. package/dist/index.js +18 -4
  93. package/dist/index.js.map +1 -1
  94. package/dist/util-routers/file-system/env.js +3 -0
  95. package/dist/util-routers/file-system/env.js.map +1 -0
  96. package/dist/util-routers/file-system/index.js +31 -0
  97. package/dist/util-routers/file-system/index.js.map +1 -0
  98. package/dist/util-routers/file-system/list.js +50 -0
  99. package/dist/util-routers/file-system/list.js.map +1 -0
  100. package/dist/util-routers/file-system/resolve-within-root.js +18 -0
  101. package/dist/util-routers/file-system/resolve-within-root.js.map +1 -0
  102. package/dist/util-routers/file-system/roster-lock.js +56 -0
  103. package/dist/util-routers/file-system/roster-lock.js.map +1 -0
  104. package/dist/utils/pick-file.js +82 -0
  105. package/dist/utils/pick-file.js.map +1 -0
  106. package/dist/utils/pick-folder.js +84 -0
  107. package/dist/utils/pick-folder.js.map +1 -0
  108. package/package.json +9 -8
  109. package/src/config/index.ts +8 -3
  110. package/src/config/inputBindings.ts +56 -0
  111. package/src/config/manage.ts +7 -0
  112. package/src/handle-room/version-1/game-launcher/binaries.ts +52 -0
  113. package/src/handle-room/version-1/game-launcher/listing.ts +36 -0
  114. package/src/handle-room/version-1/game-launcher/preview.ts +54 -0
  115. package/src/handle-room/version-1/game-launcher/process.ts +75 -0
  116. package/src/handle-room/version-1/game-launcher/router.ts +42 -0
  117. package/src/handle-room/version-1/game-launcher/settings.ts +58 -0
  118. package/src/handle-room/version-1/game-launcher/shared.ts +34 -0
  119. package/src/handle-room/version-1/game-launcher/start.ts +113 -0
  120. package/src/handle-room/version-1/game-launcher/version.ts +85 -0
  121. package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.ts +39 -14
  122. package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.ts +83 -1
  123. package/src/handle-room/version-1/globals/FolderDB/types.ts +24 -0
  124. package/src/handle-room/version-1/globals/types.ts +24 -2
  125. package/src/handle-room/version-1/index.ts +27 -26
  126. package/src/handle-room/version-1/input-bindings.ts +19 -0
  127. package/src/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.ts +4 -1
  128. package/src/handle-room/version-1/room-handler-bridge/http-handler.ts +4 -1
  129. package/src/handle-room/version-1/room-handler-bridge/steps.ts +8 -0
  130. package/src/handle-room/version-1/room-handler-bridge/ws-handler.ts +2 -2
  131. package/src/index.ts +42 -10
  132. package/src/util-routers/file-system/env.ts +7 -0
  133. package/src/util-routers/file-system/index.ts +23 -0
  134. package/src/util-routers/file-system/list.ts +62 -0
  135. package/src/util-routers/file-system/resolve-within-root.ts +25 -0
  136. package/src/util-routers/file-system/roster-lock.ts +74 -0
  137. package/src/utils/pick-file.ts +81 -0
  138. package/src/utils/pick-folder.ts +92 -0
  139. package/tests/integration/filesystem.test.ts +117 -0
  140. package/tests/integration/game-launcher-binaries.test.ts +263 -0
  141. package/tests/integration/game-launcher-game-complete.test.ts +111 -0
  142. package/tests/integration/game-launcher-preview.test.ts +107 -0
  143. package/tests/integration/game-launcher-settings.test.ts +123 -8
  144. package/tests/integration/game-processes-ws.test.ts +122 -0
  145. package/tests/integration/helpers/fakeFolderDB.ts +16 -0
  146. package/tests/integration/helpers/fakePluginRuntime.ts +10 -1
  147. package/tests/integration/helpers/server.ts +23 -3
  148. package/tests/integration/input-bindings.test.ts +94 -0
  149. package/tests/integration/piece-files.test.ts +1 -1
  150. package/tests/integration/roster-lock.test.ts +86 -0
  151. package/vitest.config.ts +7 -1
  152. package/client/dist/assets/index-CX6eCHuc.js +0 -125
  153. package/client/dist/assets/index-gxAuIfGQ.css +0 -1
  154. package/client/node_modules/.vite/deps/chunk-EDVVVQBR.js.map +0 -7
  155. package/dist/handle-room/version-1/game-launcher.js +0 -197
  156. package/dist/handle-room/version-1/game-launcher.js.map +0 -1
  157. package/src/handle-room/version-1/game-launcher.ts +0 -287
@@ -0,0 +1,83 @@
1
+ import { RefObject, useEffect, useState } from "react";
2
+ import { useMatchAgent } from "../context/MatchAgentContext";
3
+ import { useGlobalNav, FileDialogState } from "../context/GlobalNavContext";
4
+ import { listDirectory, DirectoryListing } from "../api/matchAgent";
5
+ import { backHint } from "../utils/inputLabels";
6
+
7
+ // A file picker rendered in the page itself - every row is a plain
8
+ // <button>, so it's reachable through the exact same Move/Select/Back
9
+ // scheme (GlobalNavContext) as everything else in the shell, unlike a
10
+ // native OS file dialog (pick-file.ts/api/matchAgent's
11
+ // pickRosterLockFile), which is a window outside the browser entirely and
12
+ // so has no way for a gamepad to reach it at all. Opened via
13
+ // useGlobalNav().pickFile(...), not mounted directly by callers.
14
+ export function OnScreenFileDialog({ containerRef, state }: {
15
+ containerRef: RefObject<HTMLDivElement | null>,
16
+ state: FileDialogState | null,
17
+ }) {
18
+ const { settings } = useMatchAgent();
19
+ const { inputDevice, keyboardBindings, gamepadBindings } = useGlobalNav();
20
+ const [currentPath, setCurrentPath] = useState<string | undefined>(undefined);
21
+ const [listing, setListing] = useState<DirectoryListing | null>(null);
22
+ const [error, setError] = useState<string | null>(null);
23
+
24
+ // Resets to the dialog's own starting folder each time it's (re)opened,
25
+ // rather than wherever a previous use of it left off.
26
+ useEffect(() => {
27
+ setCurrentPath(state?.startPath);
28
+ setListing(null);
29
+ setError(null);
30
+ }, [state]);
31
+
32
+ useEffect(() => {
33
+ if (!state) return;
34
+ let cancelled = false;
35
+ listDirectory(settings.url, settings.authCode, currentPath, state.extension)
36
+ .then((result) => { if (!cancelled) setListing(result); })
37
+ .catch((e) => { if (!cancelled) setError(e.message); });
38
+ return () => { cancelled = true; };
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ }, [state, currentPath, settings.url, settings.authCode]);
41
+
42
+ // Re-focuses the first row once a (new) folder's listing actually
43
+ // renders - GlobalNavContext's own open-focus effect only fires when the
44
+ // dialog first opens, since it has no visibility into which folder is
45
+ // currently showing (that state lives here, not there).
46
+ useEffect(() => {
47
+ if (listing) containerRef.current?.querySelector<HTMLElement>("button")?.focus();
48
+ }, [listing, containerRef]);
49
+
50
+ if (!state) return null;
51
+
52
+ return (
53
+ <div className="onscreen-keyboard-backdrop">
54
+ <div className="onscreen-file-dialog" ref={containerRef}>
55
+ <div className="onscreen-file-dialog-path">{listing?.path ?? currentPath ?? "Loading..."}</div>
56
+ {error && <p className="error">{error}</p>}
57
+ <div className="onscreen-file-dialog-list">
58
+ {listing?.parent !== null && listing && (
59
+ <button type="button" onClick={() => setCurrentPath(listing.parent!)}>.. (up a folder)</button>
60
+ )}
61
+ {listing?.entries.map((entry) => (
62
+ <button
63
+ key={entry.path}
64
+ type="button"
65
+ data-directory={entry.isDirectory}
66
+ onClick={() => (entry.isDirectory ? setCurrentPath(entry.path) : state.resolve(entry.path))}
67
+ >
68
+ {entry.name}{entry.isDirectory ? "/" : ""}
69
+ </button>
70
+ ))}
71
+ {listing && listing.entries.length === 0 && listing.parent !== null && (
72
+ <p className="onscreen-file-dialog-empty">Nothing here{state.extensionLabel ? ` (showing ${state.extensionLabel})` : ""}.</p>
73
+ )}
74
+ </div>
75
+ <div className="onscreen-file-dialog-footer">
76
+ <button type="button" className="onscreen-file-dialog-cancel" onClick={() => state.resolve(null)}>
77
+ Cancel ({backHint(inputDevice, keyboardBindings, gamepadBindings)})
78
+ </button>
79
+ </div>
80
+ </div>
81
+ </div>
82
+ );
83
+ }
@@ -0,0 +1,75 @@
1
+ import { RefObject } from "react";
2
+ import { useGlobalNav } from "../context/GlobalNavContext";
3
+ import { backHint } from "../utils/inputLabels";
4
+
5
+ // Punctuation matters here specifically because this app's own text
6
+ // fields need it - a matchmaker URL ("http://localhost:58732") or a saved
7
+ // IP address is unusable without ":", "/", and ".", and without this row a
8
+ // gamepad-only player (no physical keyboard to fall back to) would have no
9
+ // way to type one at all.
10
+ const ROWS = [
11
+ ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"],
12
+ ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],
13
+ ["a", "s", "d", "f", "g", "h", "j", "k", "l"],
14
+ ["z", "x", "c", "v", "b", "n", "m"],
15
+ [".", ":", "/", "-", "_"],
16
+ ];
17
+
18
+ // The standard trick for writing into a React-controlled input from outside
19
+ // React: assigning el.value directly is intercepted by React's own tracked
20
+ // setter, so the native setter has to be called explicitly before the
21
+ // "input" event is dispatched for React to pick the change up.
22
+ function setNativeValue(el: HTMLInputElement | HTMLTextAreaElement, value: string) {
23
+ const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
24
+ const setter = Object.getOwnPropertyDescriptor(proto, "value")?.set;
25
+ setter?.call(el, value);
26
+ el.dispatchEvent(new Event("input", { bubbles: true }));
27
+ }
28
+
29
+ // Shown whenever a gamepad confirms a text field (see GlobalNavContext) -
30
+ // a controller has no other way to type into it. Only appends/removes at
31
+ // the end of the field rather than supporting mid-string cursor placement;
32
+ // for the short fields this is used on (player labels, a matchmaker URL)
33
+ // clearing and retyping is an acceptable trade-off against the complexity
34
+ // of gamepad-driven cursor placement.
35
+ export function OnScreenKeyboard({ containerRef, target, onClose }: {
36
+ containerRef: RefObject<HTMLDivElement | null>,
37
+ target: HTMLInputElement | HTMLTextAreaElement | null,
38
+ onClose: () => void,
39
+ }) {
40
+ const { inputDevice, keyboardBindings, gamepadBindings } = useGlobalNav();
41
+ if (!target) return null;
42
+
43
+ // Deliberately doesn't re-focus `target` afterwards: setNativeValue
44
+ // doesn't need it focused, and doing so would yank document.activeElement
45
+ // off whichever OSK button was just pressed - the next Move press (see
46
+ // GlobalNavContext) would then lose its place and reset to the start of
47
+ // the keyboard instead of continuing from a key that's probably still
48
+ // nearby.
49
+ const press = (key: string) => {
50
+ if (key === "back") setNativeValue(target, target.value.slice(0, -1));
51
+ else if (key === "space") setNativeValue(target, `${target.value} `);
52
+ else setNativeValue(target, `${target.value}${key}`);
53
+ };
54
+
55
+ return (
56
+ <div className="onscreen-keyboard-backdrop">
57
+ <div className="onscreen-keyboard" ref={containerRef}>
58
+ {ROWS.map((row, i) => (
59
+ <div key={i} className="onscreen-keyboard-row">
60
+ {row.map((key) => (
61
+ <button key={key} type="button" onClick={() => press(key)}>{key}</button>
62
+ ))}
63
+ </div>
64
+ ))}
65
+ <div className="onscreen-keyboard-row">
66
+ <button type="button" className="onscreen-keyboard-space" onClick={() => press("space")}>Space</button>
67
+ <button type="button" onClick={() => press("back")}>Back</button>
68
+ <button type="button" className="onscreen-keyboard-done" onClick={onClose}>
69
+ Done ({backHint(inputDevice, keyboardBindings, gamepadBindings)})
70
+ </button>
71
+ </div>
72
+ </div>
73
+ </div>
74
+ );
75
+ }
@@ -1,19 +1,44 @@
1
1
  import { RosterLockPiece } from "@roster-lock/types";
2
+ import { useInView } from "../../hooks/useInView";
3
+ import { usePiecePreview, previewImage } from "../../hooks/usePiecePreview";
2
4
 
3
- export function PieceCard({ piece, selected, orderNumber, downloaded, cursored, disabled, onClick }: {
5
+ export function PieceCard({
6
+ piece, pieceType, selected, orderNumber, downloaded, cursored, disabled, onClick, onHoverChange,
7
+ }: {
4
8
  piece: RosterLockPiece,
9
+ pieceType: string,
5
10
  selected: boolean,
6
11
  orderNumber: number | undefined,
7
12
  downloaded: boolean | undefined,
8
13
  cursored: boolean,
9
14
  disabled: boolean,
10
15
  onClick: () => void,
16
+ onHoverChange?: (hovering: boolean) => void,
11
17
  }) {
18
+ const [inViewRef, inView] = useInView<HTMLButtonElement>();
19
+
20
+ // Only a downloaded piece has assets for the game launcher to read a real
21
+ // portrait out of. Asking about an undownloaded one gets the plugin's
22
+ // generic engine placeholder instead (source "default"), which across a
23
+ // whole grid would paint every unowned piece with the same silhouette and
24
+ // hide the roster author's own thumbnails - so those cards don't ask, and
25
+ // the ones that do ignore a "default" answer. Gated on inView as well:
26
+ // each answer costs match-agent a sprite decode, and a several-hundred
27
+ // piece roster shouldn't pay for the rows nobody has scrolled to.
28
+ const preview = usePiecePreview({ pieceType, piece, enabled: inView && downloaded === true });
29
+ const launcherImage = preview.status === "ready" && preview.source === "piece"
30
+ ? previewImage(preview.preview)
31
+ : undefined;
32
+ const image = launcherImage ?? piece.humanInfo.image;
33
+
12
34
  return (
13
35
  <button
36
+ ref={inViewRef}
14
37
  type="button"
15
38
  className="piece-card"
16
39
  onClick={onClick}
40
+ onMouseEnter={() => onHoverChange?.(true)}
41
+ onMouseLeave={() => onHoverChange?.(false)}
17
42
  disabled={disabled && !selected}
18
43
  data-selected={selected}
19
44
  data-cursored={cursored}
@@ -21,14 +46,14 @@ export function PieceCard({ piece, selected, orderNumber, downloaded, cursored,
21
46
  >
22
47
  <div className="piece-card-image">
23
48
  {orderNumber !== undefined && <span className="piece-card-order-badge">{orderNumber}</span>}
24
- {piece.humanInfo.image ? (
25
- <img src={piece.humanInfo.image} alt={piece.humanInfo.name} />
49
+ {image ? (
50
+ <img src={image} alt={piece.humanInfo.name} />
26
51
  ) : (
27
52
  <span className="piece-card-placeholder">{piece.humanInfo.name.slice(0, 1).toUpperCase()}</span>
28
53
  )}
29
54
  </div>
30
55
  <div className="piece-card-name">{piece.humanInfo.name}</div>
31
- <div className="piece-card-status">
56
+ <div className="piece-card-status" data-downloaded={downloaded === undefined ? "unknown" : downloaded}>
32
57
  {downloaded === undefined ? "" : downloaded ? "Downloaded" : "Not downloaded"}
33
58
  </div>
34
59
  </button>
@@ -0,0 +1,48 @@
1
+ import { RosterLockPiece } from "@roster-lock/types";
2
+ import { usePiecePreview, previewImage } from "../../hooks/usePiecePreview";
3
+
4
+ // The one large preview beside the grid, for whichever piece is hovered or
5
+ // under a player's cursor. Three images can answer for a piece, and they're
6
+ // not equally good:
7
+ //
8
+ // 1. the game launcher's own preview, read out of the piece's downloaded
9
+ // assets (Ikemen's 9000,1 select portrait, say) - the real thing,
10
+ // 2. humanInfo.image, the roster author's thumbnail baked into the lock
11
+ // file - always available, but only as good as the author made it,
12
+ // 3. the launcher's generic engine placeholder, which is all it can offer
13
+ // for a piece that isn't downloaded yet.
14
+ //
15
+ // Both (1) and (3) arrive as one PiecePreview; `source` is what separates
16
+ // them, and it's the reason a not-yet-downloaded piece still shows its own
17
+ // author thumbnail here instead of the same silhouette as everything else.
18
+ export function PiecePreviewPanel({ piece, pieceType }: {
19
+ piece: RosterLockPiece | null,
20
+ pieceType: string,
21
+ }) {
22
+ // priority: this is answering a piece the player is pointing at right now,
23
+ // so it jumps ahead of the card thumbnails queued behind it.
24
+ const preview = usePiecePreview({ pieceType, piece, priority: true });
25
+
26
+ if (!piece) return null;
27
+
28
+ const launcherImage = preview.status === "ready" ? previewImage(preview.preview) : undefined;
29
+ const image = (preview.status === "ready" && preview.source === "piece" && launcherImage)
30
+ || piece.humanInfo.image
31
+ || launcherImage;
32
+
33
+ return (
34
+ <div className="piece-preview-panel">
35
+ <div className="piece-preview-frame">
36
+ {image ? (
37
+ <img className="piece-preview-image" src={image} alt={piece.humanInfo.name} />
38
+ ) : preview.status === "loading" ? (
39
+ <span className="piece-preview-loading">Loading preview…</span>
40
+ ) : (
41
+ <span className="piece-preview-placeholder">No preview</span>
42
+ )}
43
+ </div>
44
+ <div className="piece-preview-name">{piece.humanInfo.name}</div>
45
+ {piece.humanInfo.author && <div className="piece-preview-author">by {piece.humanInfo.author}</div>}
46
+ </div>
47
+ );
48
+ }
@@ -1,13 +1,34 @@
1
- import { useEffect, useState } from "react";
1
+ import { useEffect, useMemo, useRef, useState } from "react";
2
2
  import { RosterLockV1Config } from "@roster-lock/types";
3
3
  import { PieceTypePlan } from "./selectionPlan";
4
4
  import { PieceCard } from "./PieceCard";
5
+ import { PiecePreviewPanel } from "./PiecePreviewPanel";
5
6
  import { InputSource } from "../../context/JoinSettingsContext";
6
7
  import { useCursorInput } from "../../hooks/useCursorInput";
7
- import { listDownloadedPiecesFromConfig } from "@roster-lock/ts-client";
8
+ import { useGridColumns } from "../../hooks/useGridColumns";
9
+ import { useDownloadedPieceVersions } from "../../hooks/useDownloadedPieceVersions";
10
+
11
+ // Rosters here run from a handful of pieces (a curated tournament lock) to
12
+ // several hundred (a full MUGEN-style collection), and one fixed card size
13
+ // serves neither end: large cards turn a 300-piece roster into an endless
14
+ // scroll, small ones leave a 6-piece roster as a row of stamps in a mostly
15
+ // empty panel. Density scales the cards off how many there are (the actual
16
+ // sizes live in global.css, keyed off data-density) and only the crowded
17
+ // tiers pay for a filter box and a height-capped scrolling grid.
18
+ const COZY_MAX_PIECES = 12;
19
+ const COMFY_MAX_PIECES = 60;
20
+ const FILTER_MIN_PIECES = 24;
21
+
22
+ type Density = "cozy" | "comfy" | "dense";
23
+
24
+ function densityFor(pieceCount: number): Density {
25
+ if (pieceCount <= COZY_MAX_PIECES) return "cozy";
26
+ if (pieceCount <= COMFY_MAX_PIECES) return "comfy";
27
+ return "dense";
28
+ }
8
29
 
9
30
  export function PieceTypeSection({
10
- rosterConfig, pieceType, plan, picks, onTogglePick, onReorderPick, inputSource, matchAgentUrl, matchAgentAuth,
31
+ rosterConfig, pieceType, plan, picks, onTogglePick, onReorderPick, inputSource,
11
32
  }: {
12
33
  rosterConfig: RosterLockV1Config,
13
34
  pieceType: string,
@@ -16,65 +37,122 @@ export function PieceTypeSection({
16
37
  onTogglePick: (pieceId: string) => void,
17
38
  onReorderPick: (fromIndex: number, toIndex: number) => void,
18
39
  inputSource: InputSource,
19
- matchAgentUrl: string,
20
- matchAgentAuth: string,
21
40
  }) {
22
- const pieces = (rosterConfig.rosters[pieceType] ?? []).filter((p) => !plan.banList.includes(p.id));
23
- const [downloaded, setDownloaded] = useState<Record<string, boolean>>({});
41
+ const allPieces = useMemo(
42
+ () => (rosterConfig.rosters[pieceType] ?? []).filter((piece) => !plan.banList.includes(piece.id)),
43
+ [rosterConfig, pieceType, plan]
44
+ );
45
+ const downloadedLogic = useDownloadedPieceVersions(rosterConfig, pieceType);
46
+
47
+ const [filter, setFilter] = useState("");
24
48
  const [cursorIndex, setCursorIndex] = useState(0);
49
+ const [hoveredId, setHoveredId] = useState<string | null>(null);
50
+ const gridRef = useRef<HTMLDivElement>(null);
51
+ const columns = useGridColumns(gridRef);
25
52
 
53
+ const density = densityFor(allPieces.length);
54
+ const showFilter = allPieces.length >= FILTER_MIN_PIECES;
55
+
56
+ const pieces = useMemo(() => {
57
+ const needle = filter.trim().toLowerCase();
58
+ if (!needle) return allPieces;
59
+ return allPieces.filter((piece) => (
60
+ piece.humanInfo.name.toLowerCase().includes(needle) || piece.humanInfo.author.toLowerCase().includes(needle)
61
+ ));
62
+ }, [allPieces, filter]);
63
+
64
+ // Narrowing the list renumbers everything under the cursor, so park it back
65
+ // at the top rather than leave it pointing at whatever now sits at that index.
66
+ useEffect(() => { setCursorIndex(0); }, [filter, pieceType]);
67
+
68
+ // Cursoring is useless if the card it lands on is below the fold of a
69
+ // height-capped grid.
26
70
  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]);
71
+ gridRef.current
72
+ ?.querySelector<HTMLElement>('[data-cursored="true"]')
73
+ ?.scrollIntoView({ block: "nearest", inline: "nearest" });
74
+ }, [cursorIndex]);
40
75
 
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);
76
+ useCursorInput({
77
+ source: inputSource,
78
+ enabled: pieces.length > 0,
79
+ onMoveColumn: (delta) => setCursorIndex((i) => (i + delta + pieces.length) % pieces.length),
80
+ // Rows don't wrap: wrapping left/right is how a select screen has always
81
+ // behaved, but wrapping "down" off the last row back to the first is
82
+ // disorienting once the grid is tall enough to scroll. Off either end the
83
+ // cursor simply stays where it is, rather than clamping to index 0/last
84
+ // and so sliding sideways to another column.
85
+ onMoveRow: (delta) => setCursorIndex((i) => {
86
+ const next = i + delta * columns;
87
+ if (next >= 0 && next < pieces.length) return next;
88
+ // The one exception: pressing down out of a full row into a shorter
89
+ // last row should still reach it, at its final card.
90
+ const lastRow = Math.floor((pieces.length - 1) / columns);
91
+ if (delta > 0 && Math.floor(i / columns) < lastRow) return pieces.length - 1;
92
+ return i;
93
+ }),
94
+ onConfirm: () => {
95
+ const piece = pieces[cursorIndex];
96
+ if (piece) onTogglePick(piece.id);
97
+ },
98
+ });
48
99
 
100
+ const atMax = picks.length >= plan.max;
49
101
  const countLabel = plan.min === plan.max
50
102
  ? `pick exactly ${plan.min}`
51
103
  : plan.max === Number.POSITIVE_INFINITY
52
104
  ? `pick ${plan.min}-any`
53
105
  : `pick ${plan.min}-${plan.max}`;
54
106
 
55
- const pieceById = new Map(pieces.map((piece) => [piece.id, piece]));
107
+ const pieceById = new Map(allPieces.map((piece) => [piece.id, piece]));
108
+
109
+ // Mouse hover wins over keyboard/gamepad cursor while active, but either
110
+ // one alone is enough to drive the preview panel beside the grid - a
111
+ // controller-only player never hovers anything, so falling back to
112
+ // cursorIndex is what gives them a live preview at all.
113
+ const activePiece = pieceById.get(hoveredId ?? "") ?? pieces[cursorIndex] ?? null;
56
114
 
57
115
  return (
58
- <div className="piece-type-section">
116
+ <div className="piece-type-section" data-density={density}>
59
117
  <div className="piece-type-header">
60
- <span className="piece-type-count">{countLabel} ({picks.length} picked)</span>
118
+ {showFilter && (
119
+ <input
120
+ className="piece-type-filter"
121
+ type="search"
122
+ value={filter}
123
+ placeholder={`Filter ${allPieces.length} ${pieceType}…`}
124
+ onChange={(e) => setFilter(e.target.value)}
125
+ aria-label={`Filter ${pieceType}`}
126
+ />
127
+ )}
128
+ <span className="piece-type-count">
129
+ {countLabel} ({picks.length} picked{filter ? `, ${pieces.length} shown` : ""})
130
+ </span>
61
131
  </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
- })}
132
+ <div className="piece-type-body">
133
+ <div className="card-grid" ref={gridRef}>
134
+ {pieces.map((piece, index) => {
135
+ const orderIndex = picks.indexOf(piece.id);
136
+ return (
137
+ <PieceCard
138
+ key={piece.id}
139
+ piece={piece}
140
+ pieceType={pieceType}
141
+ selected={orderIndex !== -1}
142
+ orderNumber={orderIndex === -1 ? undefined : orderIndex + 1}
143
+ downloaded={downloadedLogic ? downloadedLogic.has(piece.version.logic) : undefined}
144
+ cursored={index === cursorIndex}
145
+ disabled={atMax}
146
+ onClick={() => onTogglePick(piece.id)}
147
+ onHoverChange={(hovering) => setHoveredId(hovering ? piece.id : null)}
148
+ />
149
+ );
150
+ })}
151
+ {pieces.length === 0 && (
152
+ <span className="card-grid-empty">No {pieceType} match “{filter}”</span>
153
+ )}
154
+ </div>
155
+ <PiecePreviewPanel piece={activePiece} pieceType={pieceType} />
78
156
  </div>
79
157
  {picks.length > 0 && (
80
158
  <ol className="pick-order-list">
@@ -4,7 +4,7 @@ import { PieceTypePlan } from "./selectionPlan";
4
4
  import { PieceTypeSection } from "./PieceTypeSection";
5
5
 
6
6
  export function PlayerSelectionPanel({
7
- rosterConfig, slot, pieceType, plan, picks, onTogglePick, onReorderPick, matchAgentUrl, matchAgentAuth,
7
+ rosterConfig, slot, pieceType, plan, picks, onTogglePick, onReorderPick,
8
8
  }: {
9
9
  rosterConfig: RosterLockV1Config,
10
10
  slot: PlayerSlot,
@@ -13,8 +13,6 @@ export function PlayerSelectionPanel({
13
13
  picks: Array<string>,
14
14
  onTogglePick: (pieceId: string) => void,
15
15
  onReorderPick: (fromIndex: number, toIndex: number) => void,
16
- matchAgentUrl: string,
17
- matchAgentAuth: string,
18
16
  }) {
19
17
  return (
20
18
  <div className="player-selection-panel">
@@ -32,8 +30,6 @@ export function PlayerSelectionPanel({
32
30
  onTogglePick={onTogglePick}
33
31
  onReorderPick={onReorderPick}
34
32
  inputSource={slot.input}
35
- matchAgentUrl={matchAgentUrl}
36
- matchAgentAuth={matchAgentAuth}
37
33
  />
38
34
  </div>
39
35
  );
@@ -1,7 +1,9 @@
1
- import { useState, useMemo } from "react";
1
+ import { useState, useMemo, useEffect } from "react";
2
2
  import { RosterLockV1Config, UserSelection } from "@roster-lock/types";
3
3
  import { PlayerSlot } from "../../context/JoinSettingsContext";
4
4
  import { PlayerSelectionPanel } from "./PlayerSelectionPanel";
5
+ import { SelectionSourceProvider } from "../../context/SelectionSourceContext";
6
+ import { useGlobalNav } from "../../context/GlobalNavContext";
5
7
  import { PieceTypeTabs } from "./PieceTypeTabs";
6
8
  import { planForPieceType, buildUserSelection, PieceTypePlan } from "./selectionPlan";
7
9
 
@@ -14,16 +16,36 @@ type PickablePlan = Extract<PieceTypePlan, { kind: "pickable" }>;
14
16
  // inactive, so switching tabs never loses work. Used inline by
15
17
  // pages/MatchMaking/Rooms/[roomId] once a room is ready to select in.
16
18
  export function SelectionBoard({
17
- rosterConfig, playerSlots, matchAgentUrl, matchAgentAuth, onConfirm,
19
+ rosterConfig, playerSlots, pluginName, matchAgentUrl, matchAgentAuth, onConfirm, onCancel,
18
20
  }: {
19
21
  rosterConfig: RosterLockV1Config,
20
22
  playerSlots: Array<PlayerSlot>,
23
+ pluginName: string,
21
24
  matchAgentUrl: string,
22
25
  matchAgentAuth: string,
23
26
  onConfirm: (playerSelections: Record<number, UserSelection>) => void,
27
+ onCancel: () => void,
24
28
  }) {
25
29
  const [picksBySlot, setPicksBySlot] = useState<Record<string, Record<string, Array<string>>>>({});
26
30
 
31
+ // Each player slot's own useCursorInput already polls its assigned
32
+ // gamepad (and, for whichever slot is on the keyboard, its arrow keys)
33
+ // for d-pad/arrows + confirm - the global menu/roving-focus nav
34
+ // (GlobalNavContext) would otherwise read the same presses a second time.
35
+ const { setNavSuspended } = useGlobalNav();
36
+ useEffect(() => {
37
+ setNavSuspended(true);
38
+ return () => setNavSuspended(false);
39
+ }, [setNavSuspended]);
40
+
41
+ // Handed down by context rather than by prop: the deepest consumers are the
42
+ // per-piece download lookup and PieceCard's own preview, several layers and
43
+ // one card-per-roster-entry below here.
44
+ const selectionSource = useMemo(
45
+ () => ({ pluginName, engine: rosterConfig.engine, matchAgentUrl, matchAgentAuth }),
46
+ [pluginName, rosterConfig, matchAgentUrl, matchAgentAuth]
47
+ );
48
+
27
49
  const pieceTypePlans = useMemo(
28
50
  () => Object.keys(rosterConfig.engine.pieceDefinitions).map((t) => [t, planForPieceType(rosterConfig, t)] as const),
29
51
  [rosterConfig]
@@ -95,53 +117,56 @@ export function SelectionBoard({
95
117
  };
96
118
 
97
119
  return (
98
- <div className="selection-board">
99
- {infoTypes.length > 0 && (
100
- <div className="selection-board-info">
101
- {infoTypes.map(([pieceType, plan]) => (
102
- <span key={pieceType} className="piece-type-info-chip">
103
- {pieceType}: {plan.kind === "auto"
104
- ? (plan.reason === "mandatory" ? "included automatically" : plan.reason)
105
- : `${plan.configType} (not user-selectable)`}
106
- </span>
107
- ))}
108
- </div>
109
- )}
110
-
111
- <PieceTypeTabs
112
- types={pickableTypes.map(([pieceType]) => pieceType)}
113
- activeType={activeType}
114
- readyByType={readyByType}
115
- onSelect={setActiveType}
116
- />
117
-
118
- {activePlan && (
119
- <div className="selection-board-panels">
120
- {playerSlots.map((slot) => (
121
- <PlayerSelectionPanel
122
- key={slot.id}
123
- rosterConfig={rosterConfig}
124
- slot={slot}
125
- pieceType={activeType}
126
- plan={activePlan}
127
- picks={picksBySlot[slot.id]?.[activeType] ?? []}
128
- onTogglePick={(pieceId) => togglePick(slot.id, activeType, pieceId)}
129
- onReorderPick={(fromIndex, toIndex) => reorderPick(slot.id, activeType, fromIndex, toIndex)}
130
- matchAgentUrl={matchAgentUrl}
131
- matchAgentAuth={matchAgentAuth}
132
- />
133
- ))}
134
- </div>
135
- )}
120
+ <SelectionSourceProvider value={selectionSource}>
121
+ <div className="selection-board">
122
+ {infoTypes.length > 0 && (
123
+ <div className="selection-board-info">
124
+ {infoTypes.map(([pieceType, plan]) => (
125
+ <span key={pieceType} className="piece-type-info-chip">
126
+ {pieceType}: {plan.kind === "auto"
127
+ ? (plan.reason === "mandatory" ? "included automatically" : plan.reason)
128
+ : `${plan.configType} (not user-selectable)`}
129
+ </span>
130
+ ))}
131
+ </div>
132
+ )}
133
+
134
+ <PieceTypeTabs
135
+ types={pickableTypes.map(([pieceType]) => pieceType)}
136
+ activeType={activeType}
137
+ readyByType={readyByType}
138
+ onSelect={setActiveType}
139
+ />
136
140
 
137
- <div className="selection-board-footer">
138
- {!allValid && (
139
- <span className="selection-board-hint">Still needs: {pendingTypes.join(", ")}</span>
141
+ {activePlan && (
142
+ <div className="selection-board-panels">
143
+ {playerSlots.map((slot) => (
144
+ <PlayerSelectionPanel
145
+ key={slot.id}
146
+ rosterConfig={rosterConfig}
147
+ slot={slot}
148
+ pieceType={activeType}
149
+ plan={activePlan}
150
+ picks={picksBySlot[slot.id]?.[activeType] ?? []}
151
+ onTogglePick={(pieceId) => togglePick(slot.id, activeType, pieceId)}
152
+ onReorderPick={(fromIndex, toIndex) => reorderPick(slot.id, activeType, fromIndex, toIndex)}
153
+ />
154
+ ))}
155
+ </div>
140
156
  )}
141
- <button type="button" disabled={!allValid} onClick={handleConfirm}>
142
- Confirm Selection
143
- </button>
157
+
158
+ <div className="selection-board-footer">
159
+ {!allValid && (
160
+ <span className="selection-board-hint">Still needs: {pendingTypes.join(", ")}</span>
161
+ )}
162
+ <button type="button" onClick={onCancel}>
163
+ Cancel
164
+ </button>
165
+ <button type="button" disabled={!allValid} onClick={handleConfirm}>
166
+ Confirm Selection
167
+ </button>
168
+ </div>
144
169
  </div>
145
- </div>
170
+ </SelectionSourceProvider>
146
171
  );
147
172
  }