@roster-lock/match-agent 0.2.0 → 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.
- package/client/dist/assets/index-D2395vmC.css +1 -0
- package/client/dist/assets/index-DcKsa72V.js +125 -0
- package/client/dist/index.html +2 -2
- package/client/e2e/lib/env.ts +50 -0
- package/client/e2e/lib/fileDialog.ts +31 -0
- package/client/e2e/lib/mockGamepad.ts +71 -0
- package/client/e2e/lib/onscreenKeyboard.ts +32 -0
- package/client/e2e/playwright.config.ts +48 -0
- package/client/e2e/tests/gamepad-only.spec.ts +274 -0
- package/client/e2e/tests/keyboard-only.spec.ts +67 -0
- package/client/e2e/tsconfig.json +15 -0
- package/client/node_modules/.bin/playwright +17 -0
- package/client/node_modules/.bin/roster-lock-plugin-manager +17 -0
- package/client/node_modules/.vite/deps/@rjsf_core.js +95 -95
- package/client/node_modules/.vite/deps/@rjsf_validator-ajv8.js +4 -3
- package/client/node_modules/.vite/deps/@roster-lock_ts-client.js +25 -25
- package/client/node_modules/.vite/deps/@roster-lock_types.js +2 -1
- package/client/node_modules/.vite/deps/@roster-lock_utils.js +2 -1
- package/client/node_modules/.vite/deps/_metadata.json +27 -27
- package/client/node_modules/.vite/deps/{chunk-NE7PXY4V.js → chunk-3HBL6DQ6.js} +99 -98
- package/client/node_modules/.vite/deps/{chunk-NE7PXY4V.js.map → chunk-3HBL6DQ6.js.map} +3 -3
- package/client/node_modules/.vite/deps/{chunk-4D2L7OBZ.js → chunk-3IRPLLFB.js} +498 -501
- package/client/node_modules/.vite/deps/{chunk-4D2L7OBZ.js.map → chunk-3IRPLLFB.js.map} +1 -1
- package/client/node_modules/.vite/deps/{chunk-I55GDNGV.js → chunk-7DRNB6P7.js} +5 -5
- package/client/node_modules/.vite/deps/{chunk-77TXW5ZT.js → chunk-FFVS6IUX.js} +6 -6
- package/client/node_modules/.vite/deps/{chunk-5KLROPUR.js → chunk-G44QLPFQ.js} +6 -6
- package/client/node_modules/.vite/deps/{chunk-IIDO6PKU.js → chunk-QTQN6EZX.js} +98 -98
- package/client/node_modules/.vite/deps/chunk-QTQN6EZX.js.map +7 -0
- package/client/node_modules/.vite/deps/chunk-WMTNK64S.js +1 -0
- package/client/node_modules/.vite/deps/react-dom.js +3 -2
- package/client/node_modules/.vite/deps/react-dom_client.js +12 -12
- package/client/node_modules/.vite/deps/react-dom_client.js.map +1 -1
- package/client/node_modules/.vite/deps/react-router-dom.js +42 -9
- package/client/node_modules/.vite/deps/react.js +2 -1
- package/client/node_modules/.vite/deps/react_jsx-dev-runtime.js +5 -5
- package/client/node_modules/.vite/deps/react_jsx-runtime.js +3 -2
- package/client/package.json +4 -1
- package/client/src/App.tsx +23 -14
- package/client/src/NavBar.tsx +15 -5
- package/client/src/api/matchAgent.ts +208 -5
- package/client/src/bridge/hostBridge.ts +39 -10
- package/client/src/components/FullScreenMenu.tsx +32 -0
- package/client/src/components/GameLauncherSettingsForm.tsx +80 -5
- package/client/src/components/InputHints.tsx +37 -0
- package/client/src/components/InstallGameLauncherLightbox.tsx +27 -14
- package/client/src/components/OnScreenFileDialog.tsx +83 -0
- package/client/src/components/OnScreenKeyboard.tsx +75 -0
- package/client/src/components/Selection/PieceCard.tsx +29 -4
- package/client/src/components/Selection/PiecePreviewPanel.tsx +48 -0
- package/client/src/components/Selection/PieceTypeSection.tsx +124 -46
- package/client/src/components/Selection/PlayerSelectionPanel.tsx +1 -5
- package/client/src/components/Selection/index.tsx +72 -47
- package/client/src/context/GlobalNavContext.tsx +340 -0
- package/client/src/context/SelectionSourceContext.tsx +26 -0
- package/client/src/hooks/useCursorInput.ts +66 -24
- package/client/src/hooks/useDownloadedPieceVersions.ts +39 -0
- package/client/src/hooks/useGridColumns.ts +29 -0
- package/client/src/hooks/useInView.ts +32 -0
- package/client/src/hooks/usePiecePreview.ts +124 -0
- package/client/src/pages/Controls/index.tsx +126 -0
- package/client/src/pages/Game/index.tsx +11 -15
- package/client/src/pages/MatchMaking/index.tsx +14 -7
- package/client/src/pages/PreviewRoster/index.tsx +118 -0
- package/client/src/styles/global.css +355 -6
- package/client/src/utils/inputLabels.ts +25 -0
- package/client/test-results/.last-run.json +4 -0
- package/client/tsconfig.tsbuildinfo +1 -1
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/inputBindings.js +40 -0
- package/dist/config/inputBindings.js.map +1 -0
- package/dist/config/manage.js +1 -0
- package/dist/config/manage.js.map +1 -1
- package/dist/handle-room/version-1/game-launcher/binaries.js +36 -0
- package/dist/handle-room/version-1/game-launcher/binaries.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/listing.js +24 -0
- package/dist/handle-room/version-1/game-launcher/listing.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/preview.js +38 -0
- package/dist/handle-room/version-1/game-launcher/preview.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/process.js +52 -0
- package/dist/handle-room/version-1/game-launcher/process.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/router.js +32 -0
- package/dist/handle-room/version-1/game-launcher/router.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/settings.js +49 -0
- package/dist/handle-room/version-1/game-launcher/settings.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/shared.js +28 -0
- package/dist/handle-room/version-1/game-launcher/shared.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/start.js +76 -0
- package/dist/handle-room/version-1/game-launcher/start.js.map +1 -0
- package/dist/handle-room/version-1/game-launcher/version.js +63 -0
- package/dist/handle-room/version-1/game-launcher/version.js.map +1 -0
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js +22 -9
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.js.map +1 -1
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js +50 -1
- package/dist/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.js.map +1 -1
- package/dist/handle-room/version-1/index.js +15 -15
- package/dist/handle-room/version-1/index.js.map +1 -1
- package/dist/handle-room/version-1/input-bindings.js +22 -0
- package/dist/handle-room/version-1/input-bindings.js.map +1 -0
- package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js +2 -1
- package/dist/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.js.map +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/http-handler.js +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/http-handler.js.map +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/steps.js +2 -1
- package/dist/handle-room/version-1/room-handler-bridge/steps.js.map +1 -1
- package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js +2 -2
- package/dist/handle-room/version-1/room-handler-bridge/ws-handler.js.map +1 -1
- package/dist/index.js +18 -4
- package/dist/index.js.map +1 -1
- package/dist/util-routers/file-system/env.js +3 -0
- package/dist/util-routers/file-system/env.js.map +1 -0
- package/dist/util-routers/file-system/index.js +31 -0
- package/dist/util-routers/file-system/index.js.map +1 -0
- package/dist/util-routers/file-system/list.js +50 -0
- package/dist/util-routers/file-system/list.js.map +1 -0
- package/dist/util-routers/file-system/resolve-within-root.js +18 -0
- package/dist/util-routers/file-system/resolve-within-root.js.map +1 -0
- package/dist/util-routers/file-system/roster-lock.js +56 -0
- package/dist/util-routers/file-system/roster-lock.js.map +1 -0
- package/dist/utils/pick-file.js +82 -0
- package/dist/utils/pick-file.js.map +1 -0
- package/dist/utils/pick-folder.js +84 -0
- package/dist/utils/pick-folder.js.map +1 -0
- package/package.json +10 -7
- package/src/config/index.ts +8 -3
- package/src/config/inputBindings.ts +56 -0
- package/src/config/manage.ts +7 -0
- package/src/handle-room/version-1/game-launcher/binaries.ts +52 -0
- package/src/handle-room/version-1/game-launcher/listing.ts +36 -0
- package/src/handle-room/version-1/game-launcher/preview.ts +54 -0
- package/src/handle-room/version-1/game-launcher/process.ts +75 -0
- package/src/handle-room/version-1/game-launcher/router.ts +42 -0
- package/src/handle-room/version-1/game-launcher/settings.ts +58 -0
- package/src/handle-room/version-1/game-launcher/shared.ts +34 -0
- package/src/handle-room/version-1/game-launcher/start.ts +113 -0
- package/src/handle-room/version-1/game-launcher/version.ts +85 -0
- package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/ensurePieceExists.ts +39 -14
- package/src/handle-room/version-1/globals/FolderDB/SQLFolderDB/schema.ts +83 -1
- package/src/handle-room/version-1/globals/FolderDB/types.ts +24 -0
- package/src/handle-room/version-1/globals/types.ts +24 -2
- package/src/handle-room/version-1/index.ts +27 -25
- package/src/handle-room/version-1/input-bindings.ts +19 -0
- package/src/handle-room/version-1/room-handler-bridge/exchange-and-download-selections.ts +4 -1
- package/src/handle-room/version-1/room-handler-bridge/http-handler.ts +4 -1
- package/src/handle-room/version-1/room-handler-bridge/steps.ts +8 -0
- package/src/handle-room/version-1/room-handler-bridge/ws-handler.ts +2 -2
- package/src/index.ts +42 -10
- package/src/util-routers/file-system/env.ts +7 -0
- package/src/util-routers/file-system/index.ts +23 -0
- package/src/util-routers/file-system/list.ts +62 -0
- package/src/util-routers/file-system/resolve-within-root.ts +25 -0
- package/src/util-routers/file-system/roster-lock.ts +74 -0
- package/src/utils/pick-file.ts +81 -0
- package/src/utils/pick-folder.ts +92 -0
- package/tests/integration/filesystem.test.ts +117 -0
- package/tests/integration/game-launcher-binaries.test.ts +263 -0
- package/tests/integration/game-launcher-game-complete.test.ts +111 -0
- package/tests/integration/game-launcher-preview.test.ts +107 -0
- package/tests/integration/game-launcher-settings.test.ts +123 -8
- package/tests/integration/game-processes-ws.test.ts +122 -0
- package/tests/integration/helpers/fakeFolderDB.ts +16 -0
- package/tests/integration/helpers/fakePluginRuntime.ts +10 -1
- package/tests/integration/helpers/relayHarness.ts +24 -0
- package/tests/integration/helpers/server.ts +23 -3
- package/tests/integration/input-bindings.test.ts +94 -0
- package/tests/integration/piece-ensure-ws.test.ts +1 -1
- package/tests/integration/piece-files.test.ts +1 -1
- package/tests/integration/relay-protocol.test.ts +100 -0
- package/tests/integration/roster-lock.test.ts +86 -0
- package/tests/integration/sync-dl.test.ts +1 -1
- package/vitest.config.ts +7 -1
- package/client/dist/assets/index-DeYshswm.js +0 -125
- package/client/dist/assets/index-gxAuIfGQ.css +0 -1
- package/client/node_modules/.vite/deps/chunk-IIDO6PKU.js.map +0 -7
- package/client/node_modules/.vite/deps_temp_ab51ebe9/package.json +0 -3
- package/dist/handle-room/version-1/game-launcher.js +0 -181
- package/dist/handle-room/version-1/game-launcher.js.map +0 -1
- package/src/handle-room/version-1/game-launcher.ts +0 -263
- /package/client/node_modules/.vite/deps/{chunk-I55GDNGV.js.map → chunk-7DRNB6P7.js.map} +0 -0
- /package/client/node_modules/.vite/deps/{chunk-77TXW5ZT.js.map → chunk-FFVS6IUX.js.map} +0 -0
- /package/client/node_modules/.vite/deps/{chunk-5KLROPUR.js.map → chunk-G44QLPFQ.js.map} +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import { NavLink } from "react-router-dom";
|
|
3
|
+
import { NAV_LINKS } from "../NavBar";
|
|
4
|
+
import { useGlobalNav } from "../context/GlobalNavContext";
|
|
5
|
+
import { backHint } from "../utils/inputLabels";
|
|
6
|
+
|
|
7
|
+
// Opened by Space / a gamepad's Start button - see GlobalNavContext. Lets
|
|
8
|
+
// either device reach NavBar's links in one press rather than
|
|
9
|
+
// roving-focusing all the way up to them from wherever the page scrolled.
|
|
10
|
+
export function FullScreenMenu({ containerRef, open, onClose }: {
|
|
11
|
+
containerRef: RefObject<HTMLDivElement | null>,
|
|
12
|
+
open: boolean,
|
|
13
|
+
onClose: () => void,
|
|
14
|
+
}) {
|
|
15
|
+
const { inputDevice, keyboardBindings, gamepadBindings } = useGlobalNav();
|
|
16
|
+
if (!open) return null;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div className="fullscreen-menu-backdrop" onClick={onClose}>
|
|
20
|
+
<div className="fullscreen-menu" ref={containerRef} onClick={(e) => e.stopPropagation()}>
|
|
21
|
+
{NAV_LINKS.map((link) => (
|
|
22
|
+
<NavLink key={link.to} to={link.to} className="fullscreen-menu-link" onClick={onClose}>
|
|
23
|
+
{link.label}
|
|
24
|
+
</NavLink>
|
|
25
|
+
))}
|
|
26
|
+
<button type="button" className="fullscreen-menu-close" onClick={onClose}>
|
|
27
|
+
Close ({backHint(inputDevice, keyboardBindings, gamepadBindings)})
|
|
28
|
+
</button>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -5,7 +5,8 @@ import type { RJSFSchema } from "@rjsf/utils";
|
|
|
5
5
|
import { useMatchAgent } from "../context/MatchAgentContext";
|
|
6
6
|
import {
|
|
7
7
|
getGameLauncherSettings, setGameLauncherSettings, getGameLauncherVersion, updateGameLauncherBinary,
|
|
8
|
-
validateGameLauncherBinaryLocation, listAvailableGameLaunchers,
|
|
8
|
+
validateGameLauncherBinaryLocation, listAvailableGameLaunchers, pickGameLauncherBinaryLocation,
|
|
9
|
+
listGameLauncherBinaries, removeGameLauncherBinary, DownloadedGameLauncherBinary,
|
|
9
10
|
} from "../api/matchAgent";
|
|
10
11
|
|
|
11
12
|
// A schema with no declared properties renders nothing useful in rjsf - most
|
|
@@ -41,6 +42,16 @@ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string })
|
|
|
41
42
|
const [localConfig, setLocalConfig] = useState<unknown>(undefined);
|
|
42
43
|
const [busy, setBusy] = useState(false);
|
|
43
44
|
const [error, setError] = useState<string | null>(null);
|
|
45
|
+
// Everything getBinary has put under this plugin's own dataDir so far -
|
|
46
|
+
// reloaded after every download/remove so the "hoarding old versions"
|
|
47
|
+
// list a player sees always matches what's actually on disk.
|
|
48
|
+
const [binaries, setBinaries] = useState<Array<DownloadedGameLauncherBinary>>([]);
|
|
49
|
+
|
|
50
|
+
const loadBinaries = () => {
|
|
51
|
+
listGameLauncherBinaries(settings.url, settings.authCode, pluginName)
|
|
52
|
+
.then(setBinaries)
|
|
53
|
+
.catch((e) => setError(e.message));
|
|
54
|
+
};
|
|
44
55
|
|
|
45
56
|
const validate = async (location: string) => {
|
|
46
57
|
if(!location){
|
|
@@ -70,13 +81,22 @@ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string })
|
|
|
70
81
|
};
|
|
71
82
|
|
|
72
83
|
useEffect(load, [pluginName, settings]);
|
|
84
|
+
useEffect(loadBinaries, [pluginName, settings]);
|
|
85
|
+
|
|
86
|
+
// validateGameLauncherBinaryLocation checks whatever is currently *saved*
|
|
87
|
+
// on the match-agent side, not a value the client merely holds in state -
|
|
88
|
+
// so any caller that wants a freshly-picked/edited location validated has
|
|
89
|
+
// to persist it first, otherwise it'd just re-validate the old one.
|
|
90
|
+
const persistAndValidate = async (location: string) => {
|
|
91
|
+
await setGameLauncherSettings(settings.url, settings.authCode, pluginName, { binaryLocation: location, localConfig });
|
|
92
|
+
await validate(location);
|
|
93
|
+
};
|
|
73
94
|
|
|
74
95
|
const save = async () => {
|
|
75
96
|
setBusy(true);
|
|
76
97
|
setError(null);
|
|
77
98
|
try {
|
|
78
|
-
await
|
|
79
|
-
await validate(binaryLocation);
|
|
99
|
+
await persistAndValidate(binaryLocation);
|
|
80
100
|
} catch (e) {
|
|
81
101
|
setError((e as Error).message);
|
|
82
102
|
} finally {
|
|
@@ -96,12 +116,49 @@ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string })
|
|
|
96
116
|
}
|
|
97
117
|
};
|
|
98
118
|
|
|
119
|
+
const browse = async () => {
|
|
120
|
+
setBusy(true);
|
|
121
|
+
setError(null);
|
|
122
|
+
try {
|
|
123
|
+
const result = await pickGameLauncherBinaryLocation(settings.url, settings.authCode, pluginName);
|
|
124
|
+
if ("path" in result) {
|
|
125
|
+
setBinaryLocation(result.path);
|
|
126
|
+
await persistAndValidate(result.path);
|
|
127
|
+
}
|
|
128
|
+
} catch (e) {
|
|
129
|
+
setError((e as Error).message);
|
|
130
|
+
} finally {
|
|
131
|
+
setBusy(false);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// Deliberately doesn't require binaryLocation to already be set (unlike
|
|
136
|
+
// checkVersion) - getBinary acquires one from scratch, so this is also
|
|
137
|
+
// how a plugin that supports it gets its *first* binaryLocation, not
|
|
138
|
+
// just later updates. The returned path is both displayed and validated
|
|
139
|
+
// immediately, same as a freshly Browse'd/typed one would be.
|
|
99
140
|
const download = async () => {
|
|
100
141
|
setBusy(true);
|
|
101
142
|
setError(null);
|
|
102
143
|
try {
|
|
103
|
-
await updateGameLauncherBinary(settings.url, settings.authCode, pluginName);
|
|
144
|
+
const { binaryLocation: newLocation } = await updateGameLauncherBinary(settings.url, settings.authCode, pluginName);
|
|
145
|
+
setBinaryLocation(newLocation);
|
|
146
|
+
await validate(newLocation);
|
|
104
147
|
await checkVersion();
|
|
148
|
+
loadBinaries();
|
|
149
|
+
} catch (e) {
|
|
150
|
+
setError((e as Error).message);
|
|
151
|
+
} finally {
|
|
152
|
+
setBusy(false);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const removeBinary = async (location: string) => {
|
|
157
|
+
setBusy(true);
|
|
158
|
+
setError(null);
|
|
159
|
+
try {
|
|
160
|
+
await removeGameLauncherBinary(settings.url, settings.authCode, pluginName, location);
|
|
161
|
+
loadBinaries();
|
|
105
162
|
} catch (e) {
|
|
106
163
|
setError((e as Error).message);
|
|
107
164
|
} finally {
|
|
@@ -115,6 +172,7 @@ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string })
|
|
|
115
172
|
Binary location
|
|
116
173
|
<input value={binaryLocation} onChange={(e) => setBinaryLocation(e.target.value)} />
|
|
117
174
|
</label>
|
|
175
|
+
<button type="button" disabled={busy} onClick={browse}>Browse...</button>
|
|
118
176
|
{hasProperties(localConfigSchema) && (
|
|
119
177
|
// Own submit button suppressed - localConfig just feeds into this
|
|
120
178
|
// component's own state via onChange, and goes out through the
|
|
@@ -129,11 +187,28 @@ export function GameLauncherSettingsForm({ pluginName }: { pluginName: string })
|
|
|
129
187
|
)}
|
|
130
188
|
<button type="button" disabled={busy} onClick={save}>Save</button>
|
|
131
189
|
<button type="button" disabled={busy || !binaryLocation} onClick={checkVersion}>Check version</button>
|
|
132
|
-
<button type="button" disabled={busy
|
|
190
|
+
<button type="button" disabled={busy} onClick={download}>Download / update</button>
|
|
133
191
|
{validation && !validation.valid && <p className="error">{validation.message}</p>}
|
|
134
192
|
{version && (
|
|
135
193
|
<p>Local: {version.local.title} - Supported: {version.supported.title}</p>
|
|
136
194
|
)}
|
|
195
|
+
{binaries.length > 0 && (
|
|
196
|
+
<ul className="game-launcher-binaries-list">
|
|
197
|
+
{binaries.map((binary) => (
|
|
198
|
+
<li key={binary.binaryLocation}>
|
|
199
|
+
<span>
|
|
200
|
+
{binary.version?.title ?? "(unrecognized install)"}
|
|
201
|
+
{binary.active && " - active"}
|
|
202
|
+
{binary.downloadedAt && ` - downloaded ${new Date(binary.downloadedAt).toLocaleString()}`}
|
|
203
|
+
{binary.lastUsedAt && ` - last used ${new Date(binary.lastUsedAt).toLocaleString()}`}
|
|
204
|
+
</span>
|
|
205
|
+
<button type="button" disabled={busy} onClick={() => removeBinary(binary.binaryLocation)}>
|
|
206
|
+
Remove
|
|
207
|
+
</button>
|
|
208
|
+
</li>
|
|
209
|
+
))}
|
|
210
|
+
</ul>
|
|
211
|
+
)}
|
|
137
212
|
{error && <p className="error">{error}</p>}
|
|
138
213
|
</div>
|
|
139
214
|
);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useGlobalNav } from "../context/GlobalNavContext";
|
|
2
|
+
import { gamepadButtonLabel, keyLabel } from "../utils/inputLabels";
|
|
3
|
+
|
|
4
|
+
// A persistent reminder of the four-action scheme GlobalNavContext drives
|
|
5
|
+
// the whole shell with, swapping key labels for button labels (and
|
|
6
|
+
// reflecting whatever the player has rebound on the Controls page)
|
|
7
|
+
// depending on whichever device was used most recently - so a player who
|
|
8
|
+
// just picked up a controller isn't stuck remembering a keyboard-labelled
|
|
9
|
+
// hint, and vice versa.
|
|
10
|
+
export function InputHints() {
|
|
11
|
+
const { inputDevice, keyboardBindings, gamepadBindings } = useGlobalNav();
|
|
12
|
+
|
|
13
|
+
const items = inputDevice === "gamepad"
|
|
14
|
+
? [
|
|
15
|
+
{ action: "Select", key: gamepadButtonLabel(gamepadBindings.select) },
|
|
16
|
+
{ action: "Back", key: gamepadButtonLabel(gamepadBindings.back) },
|
|
17
|
+
{ action: "Menu", key: gamepadButtonLabel(gamepadBindings.menu) },
|
|
18
|
+
{ action: "Move", key: "D-pad" },
|
|
19
|
+
]
|
|
20
|
+
: [
|
|
21
|
+
{ action: "Select", key: keyLabel(keyboardBindings.select) },
|
|
22
|
+
{ action: "Back", key: keyLabel(keyboardBindings.back) },
|
|
23
|
+
{ action: "Menu", key: keyLabel(keyboardBindings.menu) },
|
|
24
|
+
{ action: "Move", key: "Arrow keys" },
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className="input-hints">
|
|
29
|
+
{items.map((hint) => (
|
|
30
|
+
<span key={hint.action} className="input-hint">
|
|
31
|
+
<span className="input-hint-key">{hint.key}</span>
|
|
32
|
+
{hint.action}
|
|
33
|
+
</span>
|
|
34
|
+
))}
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -1,31 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState } from "react";
|
|
2
2
|
import { useMatchAgent } from "../context/MatchAgentContext";
|
|
3
3
|
import { installGameLauncherPlugin } from "../api/matchAgent";
|
|
4
4
|
import { GameLauncherSettingsForm } from "./GameLauncherSettingsForm";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
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
|
+
) {
|
|
11
17
|
const { settings } = useMatchAgent();
|
|
12
|
-
const [
|
|
18
|
+
const [phase, setPhase] = useState<Phase>("confirm");
|
|
13
19
|
const [error, setError] = useState<string | null>(null);
|
|
14
20
|
|
|
15
|
-
|
|
21
|
+
const confirmInstall = () => {
|
|
22
|
+
setPhase("installing");
|
|
16
23
|
installGameLauncherPlugin(settings.url, settings.authCode, pluginName)
|
|
17
24
|
.catch((e) => setError((e as Error).message))
|
|
18
|
-
.finally(() =>
|
|
19
|
-
|
|
20
|
-
}, [pluginName]);
|
|
25
|
+
.finally(() => setPhase("done"));
|
|
26
|
+
};
|
|
21
27
|
|
|
22
28
|
return (
|
|
23
29
|
<div className="page">
|
|
24
30
|
<h1>Install {pluginName}</h1>
|
|
25
|
-
{
|
|
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>}
|
|
26
39
|
{error && <p className="error">{error}</p>}
|
|
27
|
-
{
|
|
28
|
-
<button type="button" onClick={onDone}>Done</button>
|
|
40
|
+
{phase === "done" && <GameLauncherSettingsForm pluginName={pluginName} />}
|
|
41
|
+
{phase === "done" && <button type="button" onClick={onDone}>Done</button>}
|
|
29
42
|
</div>
|
|
30
43
|
);
|
|
31
44
|
}
|
|
@@ -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({
|
|
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
|
-
{
|
|
25
|
-
<img src={
|
|
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
|
+
}
|