@air-jam/sdk 0.1.0 → 0.1.2
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/dist/{chunk-XSXI3RIS.js → chunk-B5DURUWT.js} +11 -3
- package/dist/chunk-B5DURUWT.js.map +1 -0
- package/dist/index.cjs +2346 -1931
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +97 -41
- package/dist/index.d.ts +97 -41
- package/dist/index.js +2401 -2001
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs +10 -0
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +42 -1
- package/dist/protocol.d.ts +42 -1
- package/dist/protocol.js +1 -1
- package/package.json +5 -1
- package/src/AirJamClient.ts +1 -552
- package/src/audio/audio-manager.ts +12 -1
- package/src/audio/volume-store.ts +47 -0
- package/src/components/air-jam-debug.tsx +77 -0
- package/src/components/air-jam-overlay.tsx +243 -186
- package/src/components/controller-shell.tsx +174 -182
- package/src/components/debug-state-dialog.tsx +83 -0
- package/src/components/player-avatar.tsx +64 -0
- package/src/components/qr-scanner-dialog.tsx +2 -2
- package/src/components/ui/button.tsx +1 -1
- package/src/components/ui/dialog.tsx +122 -0
- package/src/constants.ts +3 -2
- package/src/context/air-jam-context.tsx +3 -14
- package/src/hooks/use-air-jam-controller.ts +1 -1
- package/src/hooks/use-air-jam-host.ts +94 -49
- package/src/hooks/use-air-jam-shell.ts +36 -0
- package/src/index.ts +6 -0
- package/src/internal/input-manager.ts +28 -14
- package/src/protocol.ts +55 -0
- package/src/store/create-air-jam-store.ts +274 -0
- package/src/store/index.ts +1 -0
- package/src/utils/url-builder.ts +3 -3
- package/dist/chunk-XSXI3RIS.js.map +0 -1
|
@@ -15,26 +15,15 @@ import { useFullscreen } from "../hooks/use-fullscreen";
|
|
|
15
15
|
import type { ConnectionStatus, PlayerProfile } from "../protocol";
|
|
16
16
|
import { cn } from "../utils/cn";
|
|
17
17
|
import { detectRunMode } from "../utils/mode";
|
|
18
|
+
import { PlayerAvatar } from "./player-avatar";
|
|
18
19
|
import { QRScannerDialog } from "./qr-scanner-dialog";
|
|
19
|
-
import { Avatar, AvatarImage } from "./ui/avatar";
|
|
20
20
|
import { Button } from "./ui/button";
|
|
21
|
-
import { VolumeControls } from "./volume-controls";
|
|
22
|
-
|
|
23
|
-
type OrientationRequirement = "portrait" | "landscape" | "any";
|
|
24
|
-
|
|
25
|
-
// Generate a consistent avatar URL for a player based on their ID
|
|
26
|
-
const getPlayerAvatarUrl = (playerId: string): string => {
|
|
27
|
-
// Use DiceBear API with identicon style for GitHub-like avatars
|
|
28
|
-
// The seed ensures the same player ID always gets the same avatar
|
|
29
|
-
return `https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=${encodeURIComponent(
|
|
30
|
-
playerId,
|
|
31
|
-
)}`;
|
|
32
|
-
};
|
|
33
21
|
|
|
34
22
|
interface ControllerShellProps {
|
|
35
23
|
roomId?: string | null;
|
|
36
24
|
connectionStatus: ConnectionStatus;
|
|
37
|
-
|
|
25
|
+
/** Optional forced orientation. If not set, no orientation enforcement is applied. */
|
|
26
|
+
forceOrientation?: "portrait" | "landscape";
|
|
38
27
|
children: ReactNode;
|
|
39
28
|
gameState?: "paused" | "playing";
|
|
40
29
|
onTogglePlayPause?: () => void;
|
|
@@ -59,8 +48,10 @@ const describeStatus = (status: ConnectionStatus): string => {
|
|
|
59
48
|
}
|
|
60
49
|
};
|
|
61
50
|
|
|
62
|
-
const orientationMatches = (
|
|
63
|
-
|
|
51
|
+
const orientationMatches = (
|
|
52
|
+
required: "portrait" | "landscape" | undefined,
|
|
53
|
+
): boolean => {
|
|
54
|
+
if (!required) return true;
|
|
64
55
|
if (typeof window === "undefined" || !window.matchMedia) return true;
|
|
65
56
|
const matcher = window.matchMedia(`(orientation: ${required})`);
|
|
66
57
|
return matcher.matches;
|
|
@@ -69,7 +60,7 @@ const orientationMatches = (required: OrientationRequirement): boolean => {
|
|
|
69
60
|
export const ControllerShell = ({
|
|
70
61
|
roomId,
|
|
71
62
|
connectionStatus,
|
|
72
|
-
|
|
63
|
+
forceOrientation,
|
|
73
64
|
children,
|
|
74
65
|
gameState = "paused",
|
|
75
66
|
onTogglePlayPause,
|
|
@@ -79,7 +70,7 @@ export const ControllerShell = ({
|
|
|
79
70
|
}: ControllerShellProps): JSX.Element => {
|
|
80
71
|
const isChildMode = useMemo(() => detectRunMode() === "platform", []);
|
|
81
72
|
const [isOrientationOk, setOrientationOk] = useState(() =>
|
|
82
|
-
orientationMatches(
|
|
73
|
+
orientationMatches(forceOrientation),
|
|
83
74
|
);
|
|
84
75
|
const [isScannerOpen, setIsScannerOpen] = useState(false);
|
|
85
76
|
const { isFullscreen, toggleFullscreen } = useFullscreen();
|
|
@@ -112,18 +103,20 @@ export const ControllerShell = ({
|
|
|
112
103
|
}, [controllerId, players, connectionStatus]);
|
|
113
104
|
|
|
114
105
|
useEffect(() => {
|
|
115
|
-
if (
|
|
106
|
+
if (!forceOrientation) {
|
|
107
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
108
|
+
setOrientationOk(true);
|
|
116
109
|
return;
|
|
117
110
|
}
|
|
118
111
|
|
|
119
|
-
const media = window.matchMedia(`(orientation: ${
|
|
112
|
+
const media = window.matchMedia(`(orientation: ${forceOrientation})`);
|
|
120
113
|
const handleChange = (): void => setOrientationOk(media.matches);
|
|
121
114
|
handleChange();
|
|
122
115
|
media.addEventListener("change", handleChange);
|
|
123
116
|
return () => media.removeEventListener("change", handleChange);
|
|
124
|
-
}, [
|
|
117
|
+
}, [forceOrientation]);
|
|
125
118
|
|
|
126
|
-
const orientationOk =
|
|
119
|
+
const orientationOk = !forceOrientation ? true : isOrientationOk;
|
|
127
120
|
|
|
128
121
|
const statusDotColor = useMemo(() => {
|
|
129
122
|
switch (connectionStatus) {
|
|
@@ -142,188 +135,187 @@ export const ControllerShell = ({
|
|
|
142
135
|
// The parent frame provides the shell (header, volume, etc).
|
|
143
136
|
if (isChildMode) {
|
|
144
137
|
return (
|
|
145
|
-
<div className="
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
<
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
<div
|
|
159
|
-
className={cn(
|
|
160
|
-
"h-full w-full select-none",
|
|
161
|
-
!orientationOk && "pointer-events-none opacity-30",
|
|
138
|
+
<div className="dark">
|
|
139
|
+
<div className="text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden bg-transparent select-none">
|
|
140
|
+
<main className="relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4">
|
|
141
|
+
{!orientationOk && (
|
|
142
|
+
<div className="bg-background/95 absolute inset-0 z-50 flex flex-col items-center justify-center p-6 text-center shadow-lg backdrop-blur-sm">
|
|
143
|
+
<p className="text-card-foreground text-xl font-semibold">
|
|
144
|
+
Rotate your device
|
|
145
|
+
</p>
|
|
146
|
+
<p className="text-muted-foreground mt-2 text-sm">
|
|
147
|
+
This game is best experienced in {forceOrientation}{" "}
|
|
148
|
+
orientation.
|
|
149
|
+
</p>
|
|
150
|
+
</div>
|
|
162
151
|
)}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
152
|
+
<div
|
|
153
|
+
className={cn(
|
|
154
|
+
"h-full w-full select-none",
|
|
155
|
+
!orientationOk && "pointer-events-none opacity-30",
|
|
156
|
+
)}
|
|
157
|
+
>
|
|
158
|
+
{children}
|
|
159
|
+
</div>
|
|
160
|
+
</main>
|
|
161
|
+
</div>
|
|
167
162
|
</div>
|
|
168
163
|
);
|
|
169
164
|
}
|
|
170
165
|
|
|
171
166
|
return (
|
|
172
|
-
<div className="
|
|
173
|
-
<
|
|
174
|
-
<
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
167
|
+
<div className="dark">
|
|
168
|
+
<div className="bg-background text-foreground relative flex h-dvh w-dvw touch-none flex-col overflow-hidden select-none">
|
|
169
|
+
<header className="pointer-events-none sticky top-0 z-50 flex items-center justify-between border-b px-6 py-2">
|
|
170
|
+
<div className="pointer-events-auto flex items-center gap-3">
|
|
171
|
+
{typeof window !== "undefined" &&
|
|
172
|
+
(currentPlayer || controllerId) && (
|
|
173
|
+
<div
|
|
174
|
+
className="relative"
|
|
175
|
+
title={describeStatus(connectionStatus)}
|
|
176
|
+
>
|
|
177
|
+
{currentPlayer ? (
|
|
178
|
+
<PlayerAvatar player={currentPlayer} size="sm" />
|
|
179
|
+
) : controllerId ? (
|
|
180
|
+
<PlayerAvatar
|
|
181
|
+
player={{
|
|
182
|
+
id: controllerId,
|
|
183
|
+
label: "Player",
|
|
184
|
+
}}
|
|
185
|
+
size="sm"
|
|
186
|
+
/>
|
|
187
|
+
) : null}
|
|
188
|
+
{/* Black border circle - always visible behind */}
|
|
189
|
+
<span
|
|
190
|
+
className="absolute right-0 bottom-0 h-3 w-3 rounded-full bg-black"
|
|
191
|
+
aria-hidden="true"
|
|
192
|
+
/>
|
|
193
|
+
{/* Colored status dot - on top */}
|
|
194
|
+
<span
|
|
195
|
+
className={cn(
|
|
196
|
+
"absolute right-0.5 bottom-0.5 h-2 w-2 rounded-full",
|
|
197
|
+
statusDotColor,
|
|
198
|
+
connectionStatus === "connected" && "animate-pulse",
|
|
199
|
+
)}
|
|
200
|
+
aria-label={describeStatus(connectionStatus)}
|
|
201
|
+
/>
|
|
202
|
+
</div>
|
|
203
|
+
)}
|
|
204
|
+
<div>
|
|
205
|
+
<p className="text-muted-foreground text-xs tracking-[0.24em] uppercase">
|
|
206
|
+
Room
|
|
207
|
+
</p>
|
|
208
|
+
<p className="text-foreground text-lg font-semibold">
|
|
209
|
+
{typeof window !== "undefined" ? (roomId ?? "N/A") : "N/A"}
|
|
210
|
+
</p>
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
<div className="pointer-events-auto flex items-center gap-3">
|
|
214
|
+
{customActions}
|
|
215
|
+
{onRefresh && roomId && (
|
|
216
|
+
<Button
|
|
217
|
+
type="button"
|
|
218
|
+
variant="outline"
|
|
219
|
+
size="icon"
|
|
220
|
+
onClick={onRefresh}
|
|
221
|
+
disabled={
|
|
222
|
+
connectionStatus === "connecting" ||
|
|
223
|
+
connectionStatus === "reconnecting"
|
|
224
|
+
}
|
|
225
|
+
aria-label="Reconnect"
|
|
226
|
+
title="Reconnect to room"
|
|
182
227
|
>
|
|
183
|
-
<
|
|
184
|
-
|
|
185
|
-
|
|
228
|
+
<RefreshCw
|
|
229
|
+
className={cn(
|
|
230
|
+
"h-5 w-5",
|
|
231
|
+
(connectionStatus === "connecting" ||
|
|
232
|
+
connectionStatus === "reconnecting") &&
|
|
233
|
+
"animate-spin",
|
|
186
234
|
)}
|
|
187
|
-
alt={currentPlayer?.label || "Player"}
|
|
188
235
|
/>
|
|
189
|
-
</
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
{customActions}
|
|
217
|
-
{onRefresh && roomId && (
|
|
218
|
-
<Button
|
|
219
|
-
type="button"
|
|
220
|
-
variant="outline"
|
|
221
|
-
size="icon"
|
|
222
|
-
onClick={onRefresh}
|
|
223
|
-
disabled={
|
|
224
|
-
connectionStatus === "connecting" ||
|
|
225
|
-
connectionStatus === "reconnecting"
|
|
226
|
-
}
|
|
227
|
-
aria-label="Reconnect"
|
|
228
|
-
title="Reconnect to room"
|
|
229
|
-
>
|
|
230
|
-
<RefreshCw
|
|
231
|
-
className={cn(
|
|
232
|
-
"h-5 w-5",
|
|
233
|
-
(connectionStatus === "connecting" ||
|
|
234
|
-
connectionStatus === "reconnecting") &&
|
|
235
|
-
"animate-spin",
|
|
236
|
+
</Button>
|
|
237
|
+
)}
|
|
238
|
+
{onReconnect && (
|
|
239
|
+
<Button
|
|
240
|
+
type="button"
|
|
241
|
+
variant="outline"
|
|
242
|
+
size="icon"
|
|
243
|
+
onClick={() => setIsScannerOpen(true)}
|
|
244
|
+
aria-label="Scan QR code to reconnect"
|
|
245
|
+
title="Scan QR code to reconnect"
|
|
246
|
+
>
|
|
247
|
+
<QrCode className="h-5 w-5" />
|
|
248
|
+
</Button>
|
|
249
|
+
)}
|
|
250
|
+
{onTogglePlayPause && (
|
|
251
|
+
<Button
|
|
252
|
+
type="button"
|
|
253
|
+
variant="outline"
|
|
254
|
+
size="icon"
|
|
255
|
+
onClick={onTogglePlayPause}
|
|
256
|
+
aria-label={gameState === "playing" ? "Pause" : "Play"}
|
|
257
|
+
title={gameState === "playing" ? "Pause" : "Play"}
|
|
258
|
+
>
|
|
259
|
+
{gameState === "playing" ? (
|
|
260
|
+
<Pause className="h-5 w-5" />
|
|
261
|
+
) : (
|
|
262
|
+
<Play className="h-5 w-5" />
|
|
236
263
|
)}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
)}
|
|
240
|
-
{onReconnect && (
|
|
241
|
-
<Button
|
|
242
|
-
type="button"
|
|
243
|
-
variant="outline"
|
|
244
|
-
size="icon"
|
|
245
|
-
onClick={() => setIsScannerOpen(true)}
|
|
246
|
-
aria-label="Scan QR code to reconnect"
|
|
247
|
-
title="Scan QR code to reconnect"
|
|
248
|
-
>
|
|
249
|
-
<QrCode className="h-5 w-5" />
|
|
250
|
-
</Button>
|
|
251
|
-
)}
|
|
252
|
-
{onTogglePlayPause && (
|
|
264
|
+
</Button>
|
|
265
|
+
)}
|
|
253
266
|
<Button
|
|
254
267
|
type="button"
|
|
255
268
|
variant="outline"
|
|
256
269
|
size="icon"
|
|
257
|
-
onClick={
|
|
258
|
-
aria-label={
|
|
259
|
-
title={
|
|
270
|
+
onClick={() => toggleFullscreen()}
|
|
271
|
+
aria-label={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
272
|
+
title={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
260
273
|
>
|
|
261
|
-
{
|
|
262
|
-
<
|
|
274
|
+
{isFullscreen ? (
|
|
275
|
+
<Minimize className="h-5 w-5" />
|
|
263
276
|
) : (
|
|
264
|
-
<
|
|
277
|
+
<Maximize className="h-5 w-5" />
|
|
265
278
|
)}
|
|
266
279
|
</Button>
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
type="button"
|
|
270
|
-
variant="outline"
|
|
271
|
-
size="icon"
|
|
272
|
-
onClick={() => toggleFullscreen()}
|
|
273
|
-
aria-label={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
274
|
-
title={isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
|
|
275
|
-
>
|
|
276
|
-
{isFullscreen ? (
|
|
277
|
-
<Minimize className="h-5 w-5" />
|
|
278
|
-
) : (
|
|
279
|
-
<Maximize className="h-5 w-5" />
|
|
280
|
-
)}
|
|
281
|
-
</Button>
|
|
282
|
-
</div>
|
|
283
|
-
</header>
|
|
284
|
-
|
|
285
|
-
{/* Volume Controls - positioned absolutely for mobile */}
|
|
286
|
-
<div className="pointer-events-none fixed right-4 bottom-4 z-50">
|
|
287
|
-
<div className="pointer-events-auto">
|
|
288
|
-
<VolumeControls compact={true} />
|
|
289
|
-
</div>
|
|
290
|
-
</div>
|
|
280
|
+
</div>
|
|
281
|
+
</header>
|
|
291
282
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
)}
|
|
305
|
-
<div
|
|
306
|
-
className={cn(
|
|
307
|
-
"h-full w-full select-none",
|
|
308
|
-
!orientationOk && "pointer-events-none opacity-30",
|
|
283
|
+
<main className="relative flex min-h-0 flex-1 items-center justify-center overflow-hidden p-2 select-none sm:p-4">
|
|
284
|
+
<div className="bg-card/95 absolute inset-0 z-10 flex flex-col items-center justify-center p-6 text-center shadow-lg backdrop-blur-sm">
|
|
285
|
+
{!orientationOk && forceOrientation && (
|
|
286
|
+
<div className="bg-background/95 absolute inset-0 z-10 flex flex-col items-center justify-center p-6 text-center shadow-lg backdrop-blur-sm">
|
|
287
|
+
<p className="text-card-foreground text-xl font-semibold">
|
|
288
|
+
Rotate your device
|
|
289
|
+
</p>
|
|
290
|
+
<p className="text-muted-foreground mt-2 text-sm">
|
|
291
|
+
This game is best experienced in {forceOrientation}{" "}
|
|
292
|
+
orientation.
|
|
293
|
+
</p>
|
|
294
|
+
</div>
|
|
309
295
|
)}
|
|
310
|
-
|
|
311
|
-
|
|
296
|
+
<div
|
|
297
|
+
className={cn(
|
|
298
|
+
"h-full w-full select-none",
|
|
299
|
+
!orientationOk && "pointer-events-none opacity-30",
|
|
300
|
+
)}
|
|
301
|
+
>
|
|
302
|
+
{children}
|
|
303
|
+
</div>
|
|
312
304
|
</div>
|
|
313
|
-
</
|
|
314
|
-
</main>
|
|
305
|
+
</main>
|
|
315
306
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
307
|
+
{onReconnect && (
|
|
308
|
+
<QRScannerDialog
|
|
309
|
+
isOpen={isScannerOpen}
|
|
310
|
+
onClose={() => setIsScannerOpen(false)}
|
|
311
|
+
onScan={(roomCode) => {
|
|
312
|
+
onReconnect(roomCode);
|
|
313
|
+
setIsScannerOpen(false);
|
|
314
|
+
}}
|
|
315
|
+
currentRoomId={roomId}
|
|
316
|
+
/>
|
|
317
|
+
)}
|
|
318
|
+
</div>
|
|
327
319
|
</div>
|
|
328
320
|
);
|
|
329
321
|
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { Check, Copy } from "lucide-react";
|
|
2
|
+
import type { JSX } from "react";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { Button } from "./ui/button";
|
|
5
|
+
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "./ui/dialog";
|
|
6
|
+
|
|
7
|
+
interface DebugStateDialogProps {
|
|
8
|
+
isOpen: boolean;
|
|
9
|
+
onClose: () => void;
|
|
10
|
+
getState: () => unknown;
|
|
11
|
+
title?: string;
|
|
12
|
+
updateInterval?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const DebugStateDialog = ({
|
|
16
|
+
isOpen,
|
|
17
|
+
onClose,
|
|
18
|
+
getState,
|
|
19
|
+
title = "Debug State",
|
|
20
|
+
updateInterval = 100,
|
|
21
|
+
}: DebugStateDialogProps): JSX.Element => {
|
|
22
|
+
const [state, setState] = useState<unknown>(() => getState());
|
|
23
|
+
const [copied, setCopied] = useState(false);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!isOpen) return;
|
|
27
|
+
|
|
28
|
+
// Update state periodically to see changes
|
|
29
|
+
const interval = setInterval(() => {
|
|
30
|
+
setState(getState());
|
|
31
|
+
}, updateInterval);
|
|
32
|
+
|
|
33
|
+
// Update immediately on mount
|
|
34
|
+
const timeoutId = setTimeout(() => {
|
|
35
|
+
setState(getState());
|
|
36
|
+
}, 0);
|
|
37
|
+
|
|
38
|
+
return () => {
|
|
39
|
+
clearInterval(interval);
|
|
40
|
+
clearTimeout(timeoutId);
|
|
41
|
+
};
|
|
42
|
+
}, [isOpen, getState, updateInterval]);
|
|
43
|
+
|
|
44
|
+
const jsonString = JSON.stringify(state, null, 2);
|
|
45
|
+
|
|
46
|
+
const handleCopy = async () => {
|
|
47
|
+
try {
|
|
48
|
+
await navigator.clipboard.writeText(jsonString);
|
|
49
|
+
setCopied(true);
|
|
50
|
+
setTimeout(() => setCopied(false), 2000);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("Failed to copy:", error);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Dialog open={isOpen} onOpenChange={onClose}>
|
|
58
|
+
<DialogContent className="dark max-h-[90vh] max-w-2xl flex-col">
|
|
59
|
+
<DialogHeader>
|
|
60
|
+
<DialogTitle className="text-foreground">{title}</DialogTitle>
|
|
61
|
+
</DialogHeader>
|
|
62
|
+
<div className="relative flex-1 overflow-auto pt-4">
|
|
63
|
+
<Button
|
|
64
|
+
variant="ghost"
|
|
65
|
+
size="icon-sm"
|
|
66
|
+
onClick={handleCopy}
|
|
67
|
+
className="text-muted-foreground hover:text-foreground absolute top-6 right-2 z-10"
|
|
68
|
+
aria-label="Copy state"
|
|
69
|
+
>
|
|
70
|
+
{copied ? (
|
|
71
|
+
<Check className="h-4 w-4" />
|
|
72
|
+
) : (
|
|
73
|
+
<Copy className="h-4 w-4" />
|
|
74
|
+
)}
|
|
75
|
+
</Button>
|
|
76
|
+
<pre className="bg-muted text-muted-foreground overflow-auto rounded-lg border p-4 font-mono text-xs">
|
|
77
|
+
{jsonString}
|
|
78
|
+
</pre>
|
|
79
|
+
</div>
|
|
80
|
+
</DialogContent>
|
|
81
|
+
</Dialog>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { JSX } from "react";
|
|
2
|
+
import type { PlayerProfile } from "../protocol";
|
|
3
|
+
|
|
4
|
+
// Generate a consistent avatar URL for a player based on their ID
|
|
5
|
+
const getPlayerAvatarUrl = (playerId: string): string => {
|
|
6
|
+
// Use DiceBear API with identicon style for GitHub-like avatars
|
|
7
|
+
// The seed ensures the same player ID always gets the same avatar
|
|
8
|
+
return `https://api.dicebear.com/9.x/adventurer-neutral/svg?seed=${encodeURIComponent(
|
|
9
|
+
playerId,
|
|
10
|
+
)}`;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Convert hex color to rgba with opacity
|
|
14
|
+
const hexToRgba = (hex: string, opacity: number): string => {
|
|
15
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
16
|
+
if (!result) return `rgba(0, 0, 0, ${opacity})`;
|
|
17
|
+
const r = parseInt(result[1], 16);
|
|
18
|
+
const g = parseInt(result[2], 16);
|
|
19
|
+
const b = parseInt(result[3], 16);
|
|
20
|
+
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
interface PlayerAvatarProps {
|
|
24
|
+
player: PlayerProfile;
|
|
25
|
+
size?: "sm" | "md" | "lg";
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const PlayerAvatar = ({
|
|
30
|
+
player,
|
|
31
|
+
size = "md",
|
|
32
|
+
className = "",
|
|
33
|
+
}: PlayerAvatarProps): JSX.Element => {
|
|
34
|
+
const sizeClasses = {
|
|
35
|
+
sm: "h-8 w-8 border-2",
|
|
36
|
+
md: "h-12 w-12 border-4",
|
|
37
|
+
lg: "h-16 w-16 border-4",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const shadowStyles = {
|
|
41
|
+
sm: player.color
|
|
42
|
+
? `inset 0 0 4px rgba(0, 0, 0, 0.2), 0 0 8px ${hexToRgba(player.color, 0.4)}`
|
|
43
|
+
: "inset 0 0 4px rgba(0, 0, 0, 0.2)",
|
|
44
|
+
md: player.color
|
|
45
|
+
? `inset 0 0 10px rgba(0, 0, 0, 0.4), 0 0 20px ${hexToRgba(player.color, 0.6)}, 0 0 10px ${hexToRgba(player.color, 0.8)}`
|
|
46
|
+
: "inset 0 0 10px rgba(0, 0, 0, 0.4), 0 0 20px hsl(var(--border) / 0.5)",
|
|
47
|
+
lg: player.color
|
|
48
|
+
? `inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px ${hexToRgba(player.color, 0.6)}, 0 0 12px ${hexToRgba(player.color, 0.8)}`
|
|
49
|
+
: "inset 0 0 12px rgba(0, 0, 0, 0.4), 0 0 24px hsl(var(--border) / 0.5)",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<img
|
|
54
|
+
src={getPlayerAvatarUrl(player.id)}
|
|
55
|
+
alt={player.label}
|
|
56
|
+
className={`bg-secondary/30 shrink-0 rounded-full shadow-lg ${sizeClasses[size]} ${className}`}
|
|
57
|
+
style={{
|
|
58
|
+
borderColor: player.color || "hsl(var(--border))",
|
|
59
|
+
boxShadow: shadowStyles[size],
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
@@ -15,8 +15,8 @@ interface QRScannerDialogProps {
|
|
|
15
15
|
/**
|
|
16
16
|
* Extracts room code from a scanned URL or text.
|
|
17
17
|
* Supports formats like:
|
|
18
|
-
* - http://host/
|
|
19
|
-
* - https://host/
|
|
18
|
+
* - http://host/controller?room=CODE
|
|
19
|
+
* - https://host/controller?room=CODE
|
|
20
20
|
* - Just the room code itself
|
|
21
21
|
*/
|
|
22
22
|
const extractRoomCode = (text: string): string | null => {
|
|
@@ -18,7 +18,7 @@ const buttonVariants = cva(
|
|
|
18
18
|
secondary:
|
|
19
19
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
20
20
|
ghost:
|
|
21
|
-
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
21
|
+
"text-foreground hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
22
22
|
link: "text-primary underline-offset-4 hover:underline",
|
|
23
23
|
},
|
|
24
24
|
size: {
|