@hadoku/game-ui 0.1.255 → 0.1.256
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/rooms/screen/AskButton.d.ts +11 -0
- package/dist/rooms/screen/AskButton.js +35 -0
- package/dist/rooms/screen/CloseRoom.d.ts +8 -0
- package/dist/rooms/screen/CloseRoom.js +17 -0
- package/dist/rooms/screen/PlatformRoomScreen.d.ts +5 -2
- package/dist/rooms/screen/PlatformRoomScreen.js +13 -8
- package/dist/rooms/screen/RoomShell.d.ts +1 -2
- package/dist/rooms/screen/RoomShell.js +4 -39
- package/dist/rooms/screen/roomSounds.d.ts +13 -0
- package/dist/rooms/screen/roomSounds.js +41 -0
- package/package.json +4 -4
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import '../../components/Button.css';
|
|
2
|
+
export interface AskButtonProps {
|
|
3
|
+
className: string;
|
|
4
|
+
testId: string;
|
|
5
|
+
label: string;
|
|
6
|
+
confirm?: string;
|
|
7
|
+
act: () => Promise<string | null>;
|
|
8
|
+
/** Told as the ask opens and folds, so a row of asks can put one question at a time. */
|
|
9
|
+
onAsking?: (asking: boolean) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare function AskButton({ className, testId, label, confirm, act, onAsking }: AskButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* A press that asks once more before it acts (Leave when it costs an event, Close, Magic's Reset):
|
|
4
|
+
* Cancel, focused, and a danger confirm that runs `act`. `act` answers null once done (the ask folds)
|
|
5
|
+
* or the sentence to show while the ask stays. No `confirm`: the press acts at once. Testids are
|
|
6
|
+
* `<testId>` and `-ask|-no|-yes|-error`; the pair wears `<className>__ask`, the confirm
|
|
7
|
+
* `<className>--danger`, and nothing wraps them, so they sit directly in the caller's row.
|
|
8
|
+
*/
|
|
9
|
+
import { useState } from 'react';
|
|
10
|
+
import '../../components/Button.css';
|
|
11
|
+
export function AskButton({ className, testId, label, confirm, act, onAsking }) {
|
|
12
|
+
const [asking, setAsking] = useState(false);
|
|
13
|
+
const [busy, setBusy] = useState(false);
|
|
14
|
+
const [error, setError] = useState(null);
|
|
15
|
+
const ask = (next) => {
|
|
16
|
+
setAsking(next);
|
|
17
|
+
setError(null);
|
|
18
|
+
onAsking?.(next);
|
|
19
|
+
};
|
|
20
|
+
const run = () => {
|
|
21
|
+
setBusy(true);
|
|
22
|
+
setError(null);
|
|
23
|
+
void act().then((message) => {
|
|
24
|
+
setBusy(false);
|
|
25
|
+
if (message === null)
|
|
26
|
+
ask(false);
|
|
27
|
+
else
|
|
28
|
+
setError(message);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
const button = (id, words, onClick, danger = false, focus = false) => (_jsx("button", { type: "button", className: danger ? `${className} ${className}--danger ct-action ct-action--danger` : `${className} ct-action`, "data-testid": id, autoFocus: focus, disabled: busy, onClick: onClick, children: _jsx("span", { className: "ct-action__label", children: words }) }));
|
|
32
|
+
if (!asking)
|
|
33
|
+
return button(testId, label, () => (confirm === undefined ? run() : ask(true)));
|
|
34
|
+
return (_jsxs("span", { className: `${className}__ask`, "data-testid": `${testId}-ask`, children: [button(`${testId}-no`, 'Cancel', () => ask(false), false, true), button(`${testId}-yes`, confirm, run, true), error !== null && (_jsx("span", { className: "ct-error", role: "alert", "data-testid": `${testId}-error`, children: error }))] }));
|
|
35
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RoomEndOutcome } from '../room-core-client.js';
|
|
2
|
+
/** The game's close for a room. */
|
|
3
|
+
export type CloseRoomCall = (roomId: string) => Promise<RoomEndOutcome>;
|
|
4
|
+
export declare function CloseRoom({ roomId, close, onAsking }: {
|
|
5
|
+
roomId: string;
|
|
6
|
+
close: CloseRoomCall;
|
|
7
|
+
onAsking?: (asking: boolean) => void;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* The room leader's Close (the operator, 2026-10-19: *"lobby owner needs to be able to 'close' a
|
|
4
|
+
* tournament"*): asked once more, then the room ends for everyone and this screen goes to the lobby.
|
|
5
|
+
* A refusal stays asked, in the server's words. Its size is `.room-close`, in the app's one stylesheet.
|
|
6
|
+
*/
|
|
7
|
+
import { navigate } from "../../screens/route.js";
|
|
8
|
+
import { AskButton } from "./AskButton.js";
|
|
9
|
+
function closed(r) {
|
|
10
|
+
if (!r.ok)
|
|
11
|
+
return r.message;
|
|
12
|
+
navigate({ kind: 'lobby' });
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
export function CloseRoom({ roomId, close, onAsking }) {
|
|
16
|
+
return _jsx(AskButton, { className: "room-close", testId: "room-close", label: "Close", confirm: "Close room", act: () => close(roomId).then(closed), onAsking: onAsking });
|
|
17
|
+
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { type RoomViewBase } from '../game-setup.js';
|
|
3
|
+
import { type CloseRoomCall } from './CloseRoom.js';
|
|
3
4
|
import { type LeaveRoom } from './room-exit.js';
|
|
4
5
|
import type { RoomJoin } from './useRoomJoin.js';
|
|
5
6
|
export interface PlatformRoomScreenProps<R extends RoomViewBase> {
|
|
6
7
|
/** The host's read of the room. */
|
|
7
8
|
join: RoomJoin<R>;
|
|
8
|
-
/** What the host draws in the head row beside Leave
|
|
9
|
+
/** What the host draws in the head row beside Leave and Close: Settings. */
|
|
9
10
|
headerTools?: ReactNode;
|
|
11
|
+
/** The game's close for a room; given, the room's leader gets Close. */
|
|
12
|
+
close?: CloseRoomCall;
|
|
10
13
|
/** The game's `/leave` for this room; absent, the head row draws no Leave. */
|
|
11
14
|
leave?: LeaveRoom;
|
|
12
15
|
/** Told each time the game says a match is, or is no longer, live. */
|
|
13
16
|
onLive?: (live: boolean) => void;
|
|
14
17
|
}
|
|
15
|
-
export declare function PlatformRoomScreen<R extends RoomViewBase>({ join, headerTools, leave, onLive }: PlatformRoomScreenProps<R>): import("react").JSX.Element;
|
|
18
|
+
export declare function PlatformRoomScreen<R extends RoomViewBase>({ join, headerTools, close, leave, onLive }: PlatformRoomScreenProps<R>): import("react").JSX.Element;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/*
|
|
3
3
|
* The room screen for a game type the platform hosts: the shell every room has (`RoomShell`), drawn
|
|
4
4
|
* from the host's one read of the room (`useRoomJoin`), with the game type's own parts from the
|
|
5
5
|
* registry (`../game-setup.ts`) in its body.
|
|
6
6
|
*
|
|
7
|
-
* What it draws: the room's name, Leave (where the host has a way home), the
|
|
8
|
-
* password gate while the join is refused, the join's refusal
|
|
9
|
-
* and `game` for the room's `gameType`.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
7
|
+
* What it draws: the room's name, Leave (where the host has a way home), the leader's Close (where the
|
|
8
|
+
* host passes one), the host's tools, the password gate while the join is refused, the join's refusal
|
|
9
|
+
* in words, and the registered `setup` and `game` for the room's `gameType`. It plays the room's
|
|
10
|
+
* comings and goings (`./roomSounds.ts`) as its reads report them. Seats, spectators and options
|
|
11
|
+
* are the game's own, drawn in its `setup`. The host calls `useRoomJoin` itself and passes the
|
|
12
|
+
* result, so it can decide which screen to draw from the same read.
|
|
12
13
|
*
|
|
13
14
|
* While the game says a match is live (`GameSetupProps.onLive`), the head row steps aside; the game
|
|
14
15
|
* offers the way out itself (`GameSetupProps.leave`).
|
|
@@ -16,14 +17,18 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
16
17
|
import { useState } from 'react';
|
|
17
18
|
import { useChromeShell } from '@wolffm/ui-shell/chrome/shell';
|
|
18
19
|
import { gameRoomUiFor } from "../game-setup.js";
|
|
20
|
+
import { CloseRoom } from "./CloseRoom.js";
|
|
19
21
|
import { leaveRoomThen, useRoomHome } from "./room-exit.js";
|
|
22
|
+
import { useRoomSounds } from "./roomSounds.js";
|
|
20
23
|
import { RoomShell } from "./RoomShell.js";
|
|
21
|
-
export function PlatformRoomScreen({ join, headerTools, leave, onLive }) {
|
|
24
|
+
export function PlatformRoomScreen({ join, headerTools, close, leave, onLive }) {
|
|
22
25
|
const shellRef = useChromeShell('fit');
|
|
23
26
|
const home = useRoomHome();
|
|
24
27
|
const [live, setLive] = useState(false);
|
|
25
28
|
const { view } = join;
|
|
26
29
|
const ui = view === null ? null : gameRoomUiFor(view.gameType);
|
|
30
|
+
// The room's own record says who is in it, not who is ready: readiness is the game's.
|
|
31
|
+
useRoomSounds(view === null ? null : { others: view.members.filter((m) => m.id !== view.you.id).map((m) => m.id).sort(), ready: [], readySource: view.gameType });
|
|
27
32
|
const gameProps = {
|
|
28
33
|
view,
|
|
29
34
|
me: { userId: view?.you.id ?? '', seat: null, isLeader: view?.you.leader === true },
|
|
@@ -35,5 +40,5 @@ export function PlatformRoomScreen({ join, headerTools, leave, onLive }) {
|
|
|
35
40
|
},
|
|
36
41
|
...(home === null ? {} : { leave: () => void leaveRoomThen(home) }),
|
|
37
42
|
};
|
|
38
|
-
return (_jsxs(RoomShell, { shellRef: shellRef, dataMembers: view?.members.length, roomTitle: view?.name, settled: join.settled, leave: leave, headerTools: headerTools, resolved: join.resolved, pending: !join.resolved && !join.settled, locked: join.locked, password: join.password, onPasswordChange: join.setPassword, onPasswordSubmit: join.submitPassword, roomMissingMessage: join.joinError, live: live, children: [ui?.setup?.(gameProps), ui?.game(gameProps)] }));
|
|
43
|
+
return (_jsxs(RoomShell, { shellRef: shellRef, dataMembers: view?.members.length, roomTitle: view?.name, settled: join.settled, leave: leave, headerTools: _jsxs(_Fragment, { children: [close !== undefined && view?.you.leader === true && _jsx(CloseRoom, { roomId: view.id, close: close }), headerTools] }), resolved: join.resolved, pending: !join.resolved && !join.settled, locked: join.locked, password: join.password, onPasswordChange: join.setPassword, onPasswordSubmit: join.submitPassword, roomMissingMessage: join.joinError, live: live, children: [ui?.setup?.(gameProps), ui?.game(gameProps)] }));
|
|
39
44
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ReactNode, RefCallback } from 'react';
|
|
2
2
|
import { type LeaveRoom } from './room-exit.js';
|
|
3
|
-
import '../../components/Button.css';
|
|
4
3
|
import './RoomShell.css';
|
|
5
4
|
export interface RoomShellProps {
|
|
6
5
|
shellRef?: RefCallback<HTMLElement>;
|
|
@@ -1,28 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
* The room screen's own chrome: the shell, the title, the header's tool row, the streamed/builtin
|
|
4
|
-
* split, the password gate, and the one message a room that could not be read gets. Every room
|
|
5
|
-
* has this, whatever it plays — a game type's own content is a slot (`children`), never something
|
|
6
|
-
* this file knows the shape of.
|
|
7
|
-
*
|
|
8
|
-
* Nothing here is Magic's: no deck, no mode, no table. What a game type puts in the header
|
|
9
|
-
* (Magic's own settings panel, say) arrives already built, as `headerTools`; what it puts in the
|
|
10
|
-
* room's body arrives as `children`, rendered only once `resolved` is true and the room is not
|
|
11
|
-
* streamed — a streamed room draws `streamedBody` instead, and neither draws until the room record
|
|
12
|
-
* has answered.
|
|
13
|
-
*
|
|
14
|
-
* Only the member count, the title, `resolved` and the body are always given. Every other prop is
|
|
15
|
-
* off when absent: no tools, no streamed mode, no loading body, no password gate, no missing-room
|
|
16
|
-
* message. A game with none of those passes nothing for them.
|
|
17
|
-
*
|
|
18
|
-
* While the game in the body says a match is live (`live`), the head row is not drawn at all —
|
|
19
|
-
* no title, no Leave, no tools — so the game has the room to itself, and its own menu offers the
|
|
20
|
-
* way out (`GameSetupProps.leave`). It comes back the moment `live` is false again. The room's
|
|
21
|
-
* leave stays registered throughout, so the page's top bar still leaves through it.
|
|
22
|
-
*/
|
|
23
|
-
import { useState } from 'react';
|
|
2
|
+
import { AskButton } from "./AskButton.js";
|
|
24
3
|
import { leaveRoomThen, useRoomHome, useRoomLeave } from "./room-exit.js";
|
|
25
|
-
import '../../components/Button.css';
|
|
26
4
|
import './RoomShell.css';
|
|
27
5
|
export function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settled = false, leave, leaveAsks, headerTools = null, streamed = false, streamedSubLine = null, resolved, pending = false, pendingBody = null, streamedBody = null, locked = null, password = '', onPasswordChange, onPasswordSubmit, roomMissingMessage = null, live = false, children, }) {
|
|
28
6
|
useRoomLeave(leaveAsks === undefined ? (leave ?? null) : null);
|
|
@@ -34,20 +12,7 @@ export function RoomShell({ shellRef, dataMembers, roomTitle, titleAside, settle
|
|
|
34
12
|
}
|
|
35
13
|
/** The head row's Leave. A leave that costs an event (`asks`) is asked once more, by its name, before it leaves. */
|
|
36
14
|
function RoomLeave({ leave, asks, home }) {
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
return (_jsx("button", { type: "button", className: "room-leave ct-action", "data-testid": "room-leave", disabled: leaving, onClick: () => {
|
|
41
|
-
if (asks !== undefined) {
|
|
42
|
-
setAsking(true);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
setLeaving(true);
|
|
46
|
-
void leaveRoomThen(home);
|
|
47
|
-
}, children: _jsx("span", { className: "ct-action__label", children: asks ?? 'Leave' }) }));
|
|
48
|
-
}
|
|
49
|
-
return (_jsxs("span", { className: "room-leave__ask", "data-testid": "room-leave-ask", children: [_jsx("button", { type: "button", className: "room-leave ct-action", "data-testid": "room-leave-no", autoFocus: true, disabled: leaving, onClick: () => setAsking(false), children: _jsx("span", { className: "ct-action__label", children: "Cancel" }) }), _jsx("button", { type: "button", className: "room-leave ct-action ct-action--danger", "data-testid": "room-leave-yes", disabled: leaving, onClick: () => {
|
|
50
|
-
setLeaving(true);
|
|
51
|
-
void leave().finally(home);
|
|
52
|
-
}, children: _jsx("span", { className: "ct-action__label", children: asks }) })] }));
|
|
15
|
+
// Asked, it is this leave (the top bar only goes home); unasked, the one the shell registered.
|
|
16
|
+
const left = () => (asks === undefined ? leaveRoomThen(home) : leave().finally(home));
|
|
17
|
+
return (_jsx(AskButton, { className: "room-leave", testId: "room-leave", label: asks ?? 'Leave', confirm: asks, act: () => left().then(() => null) }));
|
|
53
18
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** What the room looks like for its sounds: who is in it besides you, and who is ready. */
|
|
2
|
+
export interface RoomPresence {
|
|
3
|
+
/** Every member's id except the viewer's own. */
|
|
4
|
+
others: readonly string[];
|
|
5
|
+
/** A key per ready member or seat. */
|
|
6
|
+
ready: readonly string[];
|
|
7
|
+
/** What the ready keys are read from; a change of source rebaselines readiness rather than sounding. */
|
|
8
|
+
readySource: string;
|
|
9
|
+
}
|
|
10
|
+
/** The roles one change of the room plays, in order: joins, leaves, then readies. */
|
|
11
|
+
export declare function presenceRoles(before: RoomPresence, after: RoomPresence): string[];
|
|
12
|
+
/** Sounds each change of `presence`; `null` while the room has not been read, which sounds nothing and resets the baseline. */
|
|
13
|
+
export declare function useRoomSounds(presence: RoomPresence | null): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The room's comings and goings (the operator, 2026-11-08: "a sound for when someone joins a card table
|
|
3
|
+
* room and also a sound for when they ready up", and one for leaving). Another member arriving plays
|
|
4
|
+
* `ui.room-join`, one going `ui.room-leave`, and anyone readying, you included, `ui.room-ready`. Every
|
|
5
|
+
* screen in the room hears the same changes, as the room's own reads report them.
|
|
6
|
+
*
|
|
7
|
+
* A screen hears only changes it saw happen: the first snapshot it reads is the baseline, and so is the
|
|
8
|
+
* first after the readiness it reads from changes source (a mode switch, the Gauntlet's state arriving).
|
|
9
|
+
* One update plays each role at most once, so a pod filling in one read is one join, not five.
|
|
10
|
+
* Each role is the game's to voice (Magic's falls back to a sound it already had until one is assigned).
|
|
11
|
+
*/
|
|
12
|
+
import { useEffect, useRef } from 'react';
|
|
13
|
+
import { playRole } from "../../sound/index.js";
|
|
14
|
+
/** The roles one change of the room plays, in order: joins, leaves, then readies. */
|
|
15
|
+
export function presenceRoles(before, after) {
|
|
16
|
+
const roles = [];
|
|
17
|
+
const was = new Set(before.others);
|
|
18
|
+
const is = new Set(after.others);
|
|
19
|
+
if (after.others.some((id) => !was.has(id)))
|
|
20
|
+
roles.push('ui.room-join');
|
|
21
|
+
if (before.others.some((id) => !is.has(id)))
|
|
22
|
+
roles.push('ui.room-leave');
|
|
23
|
+
if (before.readySource === after.readySource) {
|
|
24
|
+
const wasReady = new Set(before.ready);
|
|
25
|
+
if (after.ready.some((key) => !wasReady.has(key)))
|
|
26
|
+
roles.push('ui.room-ready');
|
|
27
|
+
}
|
|
28
|
+
return roles;
|
|
29
|
+
}
|
|
30
|
+
/** Sounds each change of `presence`; `null` while the room has not been read, which sounds nothing and resets the baseline. */
|
|
31
|
+
export function useRoomSounds(presence) {
|
|
32
|
+
const last = useRef(null);
|
|
33
|
+
const key = presence === null ? null : JSON.stringify(presence);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const now = key === null ? null : JSON.parse(key);
|
|
36
|
+
if (now !== null && last.current !== null)
|
|
37
|
+
for (const role of presenceRoles(last.current, now))
|
|
38
|
+
playRole(role);
|
|
39
|
+
last.current = now;
|
|
40
|
+
}, [key]);
|
|
41
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hadoku/game-ui",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "0.1.256",
|
|
4
|
+
"gitHead": "c702ab6e78d9e2f3bc68a89a9a28a3cf3396b6e5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "The browser parts any hosted game shares, above ui-shell: the room shell and session, seats and looks, the room route, the front page's generic pieces (gate, polls, gallery, patch notes), the bundle slot and relay channel a game's client mounts in, settings and trim screens, the HTTP and socket helpers, and the generic components (modal, popover, avatar, action button, radio cards). Knows no game; Magic's UI (games/magic/ui) plugs in, composed by the site (apps/ui). MIT; imports only react, react-dom, socket.io-client, @wolffm/* and the platform packages.",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"react-dom": "^19.2.8"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
57
|
-
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.
|
|
56
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.260",
|
|
57
|
+
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.260",
|
|
58
58
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.4",
|
|
59
59
|
"@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.158",
|
|
60
60
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.158",
|