@hadoku/game-ui 0.1.16 → 0.1.18
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.
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface RoomFrontMember {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
avatarId?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Every number and label a row draws besides its name, its lock and its roster — a game's own derivation, computed before the room reaches this file. */
|
|
8
|
+
export interface RoomFrontView {
|
|
9
|
+
seatsFilled: number;
|
|
10
|
+
seatsCapacity: number;
|
|
11
|
+
state: {
|
|
12
|
+
key: string;
|
|
13
|
+
label: string;
|
|
14
|
+
detail: string | null;
|
|
15
|
+
};
|
|
16
|
+
primaryAction: 'Join' | 'Watch';
|
|
17
|
+
/** A second, explicit Watch beside the primary action (the room is in progress, say). */
|
|
18
|
+
extraWatch: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface RoomFrontRoom {
|
|
21
|
+
id: string;
|
|
22
|
+
name: string;
|
|
23
|
+
gameType: string;
|
|
24
|
+
locked: boolean;
|
|
25
|
+
/** An admin-seeded testing room: its own section, folded by default preference, never sent to a non-admin at all. */
|
|
26
|
+
testing?: boolean;
|
|
27
|
+
members: readonly RoomFrontMember[];
|
|
28
|
+
you: {
|
|
29
|
+
id: string;
|
|
30
|
+
};
|
|
31
|
+
view: RoomFrontView;
|
|
32
|
+
}
|
|
33
|
+
export type RoomFrontJoinOutcome<V> = {
|
|
34
|
+
ok: true;
|
|
35
|
+
room: V;
|
|
36
|
+
} | {
|
|
37
|
+
ok: false;
|
|
38
|
+
reason: 'refused';
|
|
39
|
+
} | {
|
|
40
|
+
ok: false;
|
|
41
|
+
reason: 'rate-limited';
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
reason: 'error';
|
|
45
|
+
message: string;
|
|
46
|
+
};
|
|
47
|
+
export type RoomFrontCreateOutcome<V> = {
|
|
48
|
+
ok: true;
|
|
49
|
+
room: V;
|
|
50
|
+
} | {
|
|
51
|
+
ok: false;
|
|
52
|
+
message: string;
|
|
53
|
+
};
|
|
54
|
+
/** A client over game-server's generic room routes (`GET/POST /api/rooms`, the room view as `room-core.ts` answers it) — no Magic types. */
|
|
55
|
+
export interface RoomFrontClient<V extends RoomFrontRoom> {
|
|
56
|
+
list(): Promise<{
|
|
57
|
+
rooms: readonly V[];
|
|
58
|
+
}>;
|
|
59
|
+
create(body: Record<string, unknown> & {
|
|
60
|
+
name: string;
|
|
61
|
+
gameType: string;
|
|
62
|
+
}): Promise<RoomFrontCreateOutcome<V>>;
|
|
63
|
+
join(roomId: string, password?: string): Promise<RoomFrontJoinOutcome<V>>;
|
|
64
|
+
/** An admin's reset of a seeded testing room; omitted when a caller offers no testing rooms at all. */
|
|
65
|
+
reset?(roomId: string): Promise<{
|
|
66
|
+
ok: true;
|
|
67
|
+
} | {
|
|
68
|
+
ok: false;
|
|
69
|
+
message: string;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
/** What says the list changed, without polling it (`games/magic/ui/src/rooms/follow.ts`'s shape). Defaults to reading once and never again. */
|
|
73
|
+
export interface RoomFrontFeed {
|
|
74
|
+
follow(target: string, refresh: () => void): () => void;
|
|
75
|
+
}
|
|
76
|
+
export interface RoomFrontGameType {
|
|
77
|
+
id: string;
|
|
78
|
+
label: string;
|
|
79
|
+
}
|
|
80
|
+
export interface RoomFrontCreateSlot {
|
|
81
|
+
node?: ReactNode;
|
|
82
|
+
/**
|
|
83
|
+
* Takes over this kind's whole creation — a wholly different write than the generic
|
|
84
|
+
* `rooms.create()` (Magic's Challenge, say, which is whole-born from an event rather than named
|
|
85
|
+
* and typed). When set, the generic name field and the generic POST are both skipped for this kind.
|
|
86
|
+
*/
|
|
87
|
+
submit?: () => Promise<RoomFrontCreateOutcome<never>>;
|
|
88
|
+
/** No generic name field for this kind (set together with `submit` for a whole-born kind). */
|
|
89
|
+
nameless?: boolean;
|
|
90
|
+
/** The submit button stays disabled until this is true (default true — ready at once). */
|
|
91
|
+
ready?: boolean;
|
|
92
|
+
/** Extra fields merged into the generic POST body, alongside `name` and `gameType` (ignored when `submit` is set). */
|
|
93
|
+
body?: Record<string, unknown>;
|
|
94
|
+
}
|
|
95
|
+
export interface RoomFrontRowExtras {
|
|
96
|
+
/** The room's own background scene, large and faint behind the row's info. */
|
|
97
|
+
scene?: ReactNode;
|
|
98
|
+
/** The room's own type glyph, beside its name. */
|
|
99
|
+
typeIcon?: ReactNode;
|
|
100
|
+
trophy?: ReactNode;
|
|
101
|
+
modeChip?: ReactNode;
|
|
102
|
+
seriesChip?: ReactNode;
|
|
103
|
+
/** The row's trailing, screen-reader-mostly line (a streamed client's own label, say). */
|
|
104
|
+
legacyMeta?: ReactNode;
|
|
105
|
+
/** `data-family` on the row — which background gradient it draws (`rooms.css`). */
|
|
106
|
+
family?: string;
|
|
107
|
+
}
|
|
108
|
+
export interface RoomFrontProps<V extends RoomFrontRoom> {
|
|
109
|
+
rooms: RoomFrontClient<V>;
|
|
110
|
+
/** The create form's own radio: every type a caller may make, id and label, at least one. */
|
|
111
|
+
gameTypes: readonly RoomFrontGameType[];
|
|
112
|
+
createFields?: (kind: string) => RoomFrontCreateSlot | null;
|
|
113
|
+
rowExtras?: (room: V) => RoomFrontRowExtras;
|
|
114
|
+
/** A Twitch-like banner above the list — omitted draws none of its markup (no wrapper element). */
|
|
115
|
+
banner?: ReactNode;
|
|
116
|
+
/** The header's own tools row — omitted draws no `<nav>` at all. */
|
|
117
|
+
navTools?: ReactNode;
|
|
118
|
+
/** A slot beside `banner`, for a caller with no fused banner of its own — omitted draws nothing. */
|
|
119
|
+
featured?: ReactNode;
|
|
120
|
+
onOpenRoom: (id: string) => void;
|
|
121
|
+
/** Extra content in the list's own head row, beside the title and before Create room (a game's own filter bar, say). */
|
|
122
|
+
headExtras?: ReactNode;
|
|
123
|
+
/** Extra content beside Create room, in the same actions group (a game's own "Create event", say). */
|
|
124
|
+
actionsExtras?: ReactNode;
|
|
125
|
+
feed?: RoomFrontFeed;
|
|
126
|
+
/**
|
|
127
|
+
* Whether `room` matches every filter the caller is tracking that is currently ON — recomputed
|
|
128
|
+
* fresh every render (a filter toggle lives in the caller's own state, outside this list's own),
|
|
129
|
+
* never baked into a room at the time it was read. Rooms are never hidden by a filter, only
|
|
130
|
+
* sorted and dimmed: unset or always-true never dims anything.
|
|
131
|
+
*/
|
|
132
|
+
matches?: (room: V) => boolean;
|
|
133
|
+
/**
|
|
134
|
+
* A chance to do something other than `onOpenRoom` once a room is freshly joined or created (Magic
|
|
135
|
+
* starts a scenario room against the AI directly, say, rather than opening the room screen for it).
|
|
136
|
+
* `true`: handled, `onOpenRoom` is skipped for this one.
|
|
137
|
+
*/
|
|
138
|
+
beforeOpenRoom?: (room: V) => Promise<boolean> | boolean;
|
|
139
|
+
nameMaxLength?: number;
|
|
140
|
+
passwordMaxLength?: number;
|
|
141
|
+
/** The key `localStorage` remembers the Testing section's fold under. A caller with no testing rooms never reads it. */
|
|
142
|
+
testingStorageKey?: string;
|
|
143
|
+
/**
|
|
144
|
+
* The create form's name field starts prefilled with this (the viewer's own name, from the
|
|
145
|
+
* platform's own `useWhoami`, and a fresh random draw, so a word drawn once per opening) rather
|
|
146
|
+
* than empty. `viewerName` is `null` until the fleet has answered or has none for this viewer.
|
|
147
|
+
*/
|
|
148
|
+
defaultName?: (viewerName: string | null, random: () => number) => string;
|
|
149
|
+
/** The list's own `<section>`, the moment it mounts and again on unmount — a caller's own tooltip or scroll mechanism attaches here, same as it would to any other section it owns. */
|
|
150
|
+
onSectionRef?: (el: HTMLElement | null) => void;
|
|
151
|
+
/**
|
|
152
|
+
* The create dialog's own panel `className` (default: an unstyled block of this module's own,
|
|
153
|
+
* `room-front-create`). A caller with its own "raised surface" convention supplies its exact
|
|
154
|
+
* class string here rather than this file hard-coding one — Magic's `RoomList.tsx` passes
|
|
155
|
+
* `"rooms__create ct-surface ct-panel"`, the same classes base's own `CreateRoomDialog` always
|
|
156
|
+
* drew, from the one file (`RoomList.tsx`, through `CreateEventDialog.tsx`'s own import of
|
|
157
|
+
* `Modal.tsx`) `css-ownership.test.ts` already knows reaches the tree that owns `.ct-surface` —
|
|
158
|
+
* this module never does, and must not have to. Named exactly `className` (not, say,
|
|
159
|
+
* `createDialogClassName`): `css-ownership.test.ts`'s own "is this really a class list" check
|
|
160
|
+
* only recognises a literal that sits in a real `className=`/`class=` attribute position, which
|
|
161
|
+
* a camelCase prefix or suffix always breaks.
|
|
162
|
+
*/
|
|
163
|
+
className?: string;
|
|
164
|
+
}
|
|
165
|
+
export declare function RoomFront<V extends RoomFrontRoom>({ rooms: client, gameTypes, createFields, rowExtras, banner, navTools, featured, onOpenRoom, headExtras, actionsExtras, feed, matches: matchesFilter, beforeOpenRoom, nameMaxLength, passwordMaxLength, testingStorageKey, defaultName, onSectionRef, className: createSurfaceClassName, }: RoomFrontProps<V>): import("react").JSX.Element;
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/*
|
|
3
|
+
* The front-page module, settled for every game cardtable or another site hosts (wave 120 §F; the
|
|
4
|
+
* contract is frozen in `docs/planning/wave120-2026-11-17.md` — bomberman's own wave `bm1` consumes
|
|
5
|
+
* this from npmjs the moment it publishes, so its exported names and prop shapes may not drift
|
|
6
|
+
* without the tracker's say).
|
|
7
|
+
*
|
|
8
|
+
* This is the generic list/filter/sort/follow/create-dialog machinery that used to live, entangled
|
|
9
|
+
* with Magic's own fields, in `games/magic/ui/src/rooms/RoomList.tsx` (`RoomRow` and
|
|
10
|
+
* `CreateRoomDialog`). What is Magic's stays Magic's: the mode chip's icon, the room's background
|
|
11
|
+
* scene, the trophy, the series chip and the "legacy" streamed-client line are all drawn by
|
|
12
|
+
* `rowExtras`; a game's own create-form fields (and a wholly different creation, such as Magic's
|
|
13
|
+
* Challenge) are drawn and may be submitted by `createFields`. A room arrives here already carrying
|
|
14
|
+
* its own computed `view` (seats, state, the primary action) — that derivation is a game's own (a
|
|
15
|
+
* pod's phase, a table's series), never this file's.
|
|
16
|
+
*
|
|
17
|
+
* Platform: imports nothing from `@hadoku/magic-ui`, any `games/**` package, or `@hadoku/shared`
|
|
18
|
+
* (the layer ratchet resolves that package as Magic even through `/platform`, bar the handful of
|
|
19
|
+
* files it whitelists itself). No CSS is imported here either: a caller's own stylesheet draws these
|
|
20
|
+
* classes (cardtable's `games/magic/ui/src/rooms/rooms.css`, unmoved, still does for cardtable's own
|
|
21
|
+
* app) — the DOM this file emits is exactly the markup `rooms.css` was already written against.
|
|
22
|
+
*/
|
|
23
|
+
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
24
|
+
import { Icon } from '@wolffm/themes';
|
|
25
|
+
import { Avatar, faceOf } from "../components/Avatar.js";
|
|
26
|
+
import { OverPage } from "../components/OverPage.js";
|
|
27
|
+
import { RadioCards } from "../components/RadioCards.js";
|
|
28
|
+
import { TopLayer } from "../topLayer.js";
|
|
29
|
+
import { uiLength } from '@wolffm/ui-shell/settings';
|
|
30
|
+
import { Reveal } from '@wolffm/ui-shell/components';
|
|
31
|
+
import { FrontGateContext, usePartShown } from "./gate.js";
|
|
32
|
+
import { MAX_ROOM_GHOSTS } from "./shape.js";
|
|
33
|
+
import { ConstructedIcon, LockIcon, PersonIcon } from "./icons.js";
|
|
34
|
+
import { useWhoami } from "../room/whoami.js";
|
|
35
|
+
import { playRole } from "../sound/index.js";
|
|
36
|
+
const NEVER_FOLLOWED = {
|
|
37
|
+
follow(_target, refresh) {
|
|
38
|
+
refresh();
|
|
39
|
+
return () => undefined;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const DEFAULT_NAME_MAX = 60;
|
|
43
|
+
const DEFAULT_PASSWORD_MAX = 200;
|
|
44
|
+
const DEFAULT_TESTING_KEY = 'room-front.testingFolded';
|
|
45
|
+
/**
|
|
46
|
+
* Whether `node` is one of React's own "renders nothing" values — `null`, `undefined`, `false`,
|
|
47
|
+
* `''`, or an array holding only such values — rather than merely `!== undefined`. The settled
|
|
48
|
+
* contract's own words: "empty or absent renders nothing (no wrapper element)" for `banner`,
|
|
49
|
+
* `navTools` and `featured` — `undefined` is one way a caller omits a slot, but `null`, `false`
|
|
50
|
+
* and `[]` are the others a caller passes when it computes the slot conditionally (`cond && <X/>`,
|
|
51
|
+
* or `cond ? <X/> : null`), and each must draw no wrapper of its own either.
|
|
52
|
+
*/
|
|
53
|
+
function isRenderable(node) {
|
|
54
|
+
if (node === null || node === undefined || node === false || node === '')
|
|
55
|
+
return false;
|
|
56
|
+
if (Array.isArray(node))
|
|
57
|
+
return node.some(isRenderable);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
/** Whether the viewer is already a member — a room never hides its own occupant's name from them. */
|
|
61
|
+
const isMine = (room) => room.members.some((m) => m.id === room.you.id);
|
|
62
|
+
const normalRooms = (rooms) => rooms.filter((r) => r.testing !== true);
|
|
63
|
+
const testingRooms = (rooms) => rooms.filter((r) => r.testing === true);
|
|
64
|
+
/** `rooms`, with every matching one (by `matches`) moved ahead of every room that is not — a stable partition. */
|
|
65
|
+
function orderByMatch(rooms, matches) {
|
|
66
|
+
return [...rooms.filter(matches), ...rooms.filter((r) => !matches(r))];
|
|
67
|
+
}
|
|
68
|
+
function loadTestingFolded(key) {
|
|
69
|
+
try {
|
|
70
|
+
return globalThis.localStorage?.getItem(key) === '1';
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function saveTestingFolded(key, folded) {
|
|
77
|
+
try {
|
|
78
|
+
if (folded)
|
|
79
|
+
globalThis.localStorage?.setItem(key, '1');
|
|
80
|
+
else
|
|
81
|
+
globalThis.localStorage?.removeItem(key);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Unremembered is the whole fallback; nothing else to do.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export function RoomFront({ rooms: client, gameTypes, createFields, rowExtras, banner, navTools, featured, onOpenRoom, headExtras, actionsExtras, feed = NEVER_FOLLOWED, matches: matchesFilter, beforeOpenRoom, nameMaxLength = DEFAULT_NAME_MAX, passwordMaxLength = DEFAULT_PASSWORD_MAX, testingStorageKey = DEFAULT_TESTING_KEY, defaultName, onSectionRef, className: createSurfaceClassName = 'room-front-create', }) {
|
|
88
|
+
const [state, setState] = useState({ kind: 'loading' });
|
|
89
|
+
const [creating, setCreating] = useState(false);
|
|
90
|
+
const [testingFolded, setTestingFolded] = useState(() => loadTestingFolded(testingStorageKey));
|
|
91
|
+
const toggleTesting = () => {
|
|
92
|
+
playRole('ui.select');
|
|
93
|
+
setTestingFolded((was) => {
|
|
94
|
+
saveTestingFolded(testingStorageKey, !was);
|
|
95
|
+
return !was;
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
// Latest-wins: a read the server answers after a newer one has already landed changes nothing —
|
|
99
|
+
// never an older list overwriting a newer one, and never a late failure marking a fresh list stale.
|
|
100
|
+
const generation = useRef(0);
|
|
101
|
+
const refresh = useCallback(async () => {
|
|
102
|
+
const gen = ++generation.current;
|
|
103
|
+
try {
|
|
104
|
+
const { rooms: next } = await client.list();
|
|
105
|
+
if (gen !== generation.current)
|
|
106
|
+
return;
|
|
107
|
+
setState({ kind: 'ready', rooms: next, stale: null });
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
if (gen !== generation.current)
|
|
111
|
+
return;
|
|
112
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
113
|
+
setState((prev) => (prev.kind === 'ready' ? { ...prev, stale: message } : { kind: 'failed', message }));
|
|
114
|
+
}
|
|
115
|
+
}, [client]);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
let live = true;
|
|
118
|
+
const stop = feed.follow('list', () => {
|
|
119
|
+
if (live)
|
|
120
|
+
void refresh();
|
|
121
|
+
});
|
|
122
|
+
return () => {
|
|
123
|
+
live = false;
|
|
124
|
+
stop();
|
|
125
|
+
};
|
|
126
|
+
}, [refresh, feed]);
|
|
127
|
+
const retry = () => {
|
|
128
|
+
playRole('ui.select');
|
|
129
|
+
setState({ kind: 'loading' });
|
|
130
|
+
void refresh();
|
|
131
|
+
};
|
|
132
|
+
const normal = state.kind === 'ready' ? normalRooms(state.rooms) : [];
|
|
133
|
+
const testing = state.kind === 'ready' ? testingRooms(state.rooms) : [];
|
|
134
|
+
const matches = (room) => matchesFilter?.(room) ?? true;
|
|
135
|
+
const ordered = (list) => orderByMatch(orderByMatch(list, isMine), matches);
|
|
136
|
+
const orderedNormal = ordered(normal);
|
|
137
|
+
const orderedTesting = ordered(testing);
|
|
138
|
+
const { shape, remember } = useContext(FrontGateContext);
|
|
139
|
+
const shown = usePartShown('rooms', state.kind !== 'loading');
|
|
140
|
+
const drawnRooms = state.kind === 'ready' ? Math.min(normal.length, MAX_ROOM_GHOSTS) : null;
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (drawnRooms !== null)
|
|
143
|
+
remember({ rooms: drawnRooms });
|
|
144
|
+
}, [drawnRooms, remember]);
|
|
145
|
+
return (_jsxs(_Fragment, { children: [isRenderable(navTools) && _jsx("nav", { className: "shell__tools", children: navTools }), isRenderable(featured) && featured, isRenderable(banner) && banner, _jsxs("section", { className: "rooms ct-panel", "data-testid": "rooms", "aria-labelledby": "rooms-title", "aria-busy": !shown, ref: onSectionRef, children: [_jsxs("div", { className: "rooms__head", children: [_jsx("h2", { id: "rooms-title", className: "rooms__title ct-panel__title", children: "Rooms" }), headExtras, _jsxs("span", { className: "rooms__actions", children: [_jsx("button", { type: "button", className: "lobby__go", "data-testid": "room-create-open", "aria-haspopup": "dialog", onClick: () => {
|
|
146
|
+
playRole('ui.select');
|
|
147
|
+
setCreating(true);
|
|
148
|
+
}, children: "Create room" }), actionsExtras] })] }), _jsxs(Reveal, { name: "rooms", shown: shown, skeleton: _jsx(RoomGhosts, { count: shape.rooms }), layerClassName: "rooms__layer", children: [state.kind === 'failed' && (_jsxs("div", { className: "rooms__status rooms__status--bad", role: "alert", "data-testid": "rooms-error", children: [_jsx("p", { children: state.message }), _jsx("button", { type: "button", "data-testid": "rooms-retry", onClick: retry, children: "Retry" })] })), state.kind === 'ready' && normal.length === 0 && testing.length === 0 && (_jsx("p", { className: "rooms__status", "data-testid": "rooms-empty", children: "No rooms yet." })), state.kind === 'ready' && normal.length > 0 && (_jsx("ul", { className: "rooms__list", "data-testid": "room-list", children: orderedNormal.map((room) => (_jsx(RoomRow, { room: room, client: client, rowExtras: rowExtras, matches: matches, onGone: () => void refresh(), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, passwordMaxLength: passwordMaxLength }, room.id))) })), state.kind === 'ready' && testing.length > 0 && (_jsxs("div", { className: "rooms__testing", "data-testid": "rooms-testing", children: [_jsx("h3", { className: "rooms__title ct-panel__title", children: _jsxs("button", { type: "button", className: "rooms__fold", "aria-expanded": !testingFolded, "aria-controls": "room-list-testing", "data-testid": "rooms-testing-fold", onClick: toggleTesting, children: [_jsx("svg", { className: "rooms__fold-chevron", width: "14", height: "14", viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: "M9 5l7 7-7 7" }) }), "Testing"] }) }), !testingFolded && (_jsx("ul", { className: "rooms__list", id: "room-list-testing", "data-testid": "room-list-testing", children: orderedTesting.map((room) => (_jsx(RoomRow, { room: room, client: client, rowExtras: rowExtras, matches: matches, onGone: () => void refresh(), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, passwordMaxLength: passwordMaxLength }, room.id))) }))] })), state.kind === 'ready' && state.stale !== null && (_jsx("p", { className: "rooms__stale", "data-testid": "rooms-stale", children: "List may be out of date." }))] }), creating && (_jsx(CreateRoomDialog, { client: client, gameTypes: gameTypes, createFields: createFields, onClose: () => setCreating(false), onOpenRoom: onOpenRoom, beforeOpenRoom: beforeOpenRoom, nameMaxLength: nameMaxLength, defaultName: defaultName, surfaceClassName: createSurfaceClassName })), _jsx(TopLayer, { fixed: true })] })] }));
|
|
149
|
+
}
|
|
150
|
+
/* ── until the list arrives ─────────────────────────────────────────── */
|
|
151
|
+
function RoomGhosts({ count }) {
|
|
152
|
+
if (count === 0) {
|
|
153
|
+
return (_jsx("p", { className: "rooms__status", "data-testid": "rooms-loading", children: _jsx("span", { className: "ghost ghost--text", children: "No rooms yet." }) }));
|
|
154
|
+
}
|
|
155
|
+
return (_jsx("ul", { className: "rooms__list", "data-testid": "rooms-loading", children: Array.from({ length: count }, (_, i) => (_jsx("li", { className: "room-card", "data-skeleton": `room-${i}`, children: _jsxs("div", { className: "room-card__body", children: [_jsxs("div", { className: "room-card__row1", children: [_jsx("span", { className: "room-card__type-icon ghost", children: _jsx(ConstructedIcon, {}) }), _jsx("span", { className: "room-card__name", children: _jsx("span", { className: "ghost ghost--text", children: "A room's name" }) }), _jsxs("span", { className: "room-card__seats ghost", children: [_jsx(PersonIcon, {}), "0/2"] })] }), _jsxs("div", { className: "room-card__row2", children: [_jsx("span", { className: "room-card__mode-chip ghost", children: _jsx("span", { className: "room-card__mode-text", children: "Mode unset" }) }), _jsx("span", { className: "room-card__series-chip ghost", children: "Bo1" })] }), _jsxs("div", { className: "room-card__row3", children: [_jsx("span", { className: "room-card__state ghost", children: "Lobby" }), _jsx("span", { className: "room-card__state-detail", children: _jsx("span", { className: "ghost ghost--text", children: "Waiting for players" }) })] }), _jsx("div", { className: "room-card__row4", children: _jsx("button", { type: "button", className: "rooms__enter room-card__go ghost", tabIndex: -1, disabled: true, children: "Join" }) })] }) }, i))) }));
|
|
156
|
+
}
|
|
157
|
+
/* ── one row ─────────────────────────────────────────────────────────── */
|
|
158
|
+
function RoomRow({ room, client, rowExtras, matches, onGone, onOpenRoom, beforeOpenRoom, passwordMaxLength, }) {
|
|
159
|
+
const [asking, setAsking] = useState(false);
|
|
160
|
+
const [password, setPassword] = useState('');
|
|
161
|
+
const [busy, setBusy] = useState(false);
|
|
162
|
+
const [error, setError] = useState(null);
|
|
163
|
+
const nameRef = useRef(null);
|
|
164
|
+
const [nameTruncated, setNameTruncated] = useState(false);
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
const el = nameRef.current;
|
|
167
|
+
if (el === null || typeof ResizeObserver === 'undefined')
|
|
168
|
+
return undefined;
|
|
169
|
+
const check = () => setNameTruncated(el.scrollWidth > el.clientWidth);
|
|
170
|
+
check();
|
|
171
|
+
const ro = new ResizeObserver(check);
|
|
172
|
+
ro.observe(el);
|
|
173
|
+
return () => ro.disconnect();
|
|
174
|
+
}, [room.name]);
|
|
175
|
+
const enter = async (withPassword) => {
|
|
176
|
+
setBusy(true);
|
|
177
|
+
setError(null);
|
|
178
|
+
const outcome = await client.join(room.id, withPassword);
|
|
179
|
+
if (outcome.ok) {
|
|
180
|
+
// Still busy: the room is warmed (and a scenario's vs-bot start tried) before this row ever
|
|
181
|
+
// reconsiders it, so the button never flashes "not busy" between the join and leaving the page.
|
|
182
|
+
const handled = beforeOpenRoom === undefined ? false : await beforeOpenRoom(outcome.room);
|
|
183
|
+
setBusy(false);
|
|
184
|
+
if (!handled)
|
|
185
|
+
onOpenRoom(outcome.room.id);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
setBusy(false);
|
|
189
|
+
// Every arm below is a refusal, and `deny` is the cue for exactly that — raised once, here,
|
|
190
|
+
// rather than in each arm, so a new failure reason cannot arrive without it.
|
|
191
|
+
playRole('ui.deny');
|
|
192
|
+
switch (outcome.reason) {
|
|
193
|
+
case 'refused':
|
|
194
|
+
setError(room.locked ? 'No room with that name and password.' : 'No such room.');
|
|
195
|
+
onGone();
|
|
196
|
+
return;
|
|
197
|
+
case 'rate-limited':
|
|
198
|
+
setError('Too many attempts.');
|
|
199
|
+
return;
|
|
200
|
+
case 'error':
|
|
201
|
+
setError(outcome.message);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
const onEnterClick = () => {
|
|
205
|
+
// `select` for the press itself, whichever branch it takes.
|
|
206
|
+
playRole('ui.select');
|
|
207
|
+
if (room.locked && !isMine(room)) {
|
|
208
|
+
setAsking(true);
|
|
209
|
+
setError(null);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
void enter();
|
|
213
|
+
};
|
|
214
|
+
const onResetClick = async () => {
|
|
215
|
+
if (client.reset === undefined)
|
|
216
|
+
return;
|
|
217
|
+
playRole('ui.select');
|
|
218
|
+
setBusy(true);
|
|
219
|
+
setError(null);
|
|
220
|
+
const outcome = await client.reset(room.id);
|
|
221
|
+
setBusy(false);
|
|
222
|
+
if (!outcome.ok) {
|
|
223
|
+
playRole('ui.deny');
|
|
224
|
+
setError(outcome.message);
|
|
225
|
+
}
|
|
226
|
+
onGone();
|
|
227
|
+
};
|
|
228
|
+
const onPassword = (e) => {
|
|
229
|
+
e.preventDefault();
|
|
230
|
+
if (password === '') {
|
|
231
|
+
playRole('ui.deny');
|
|
232
|
+
setError('Password required.');
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
playRole('ui.select');
|
|
236
|
+
void enter(password);
|
|
237
|
+
};
|
|
238
|
+
const names = room.members.map((m) => m.name);
|
|
239
|
+
const view = room.view;
|
|
240
|
+
const extras = rowExtras?.(room) ?? {};
|
|
241
|
+
return (_jsxs("li", { className: "room-card", "data-testid": "room-row", "data-room-id": room.id, "data-mine": isMine(room) ? '' : undefined, "data-match": matches(room) ? undefined : 'false', "data-family": extras.family, children: [extras.scene !== undefined && (_jsx("span", { className: "room-card__mark", "aria-hidden": "true", children: extras.scene })), _jsxs("div", { className: "room-card__body", children: [_jsxs("div", { className: "room-card__row1", children: [extras.typeIcon !== undefined && (_jsx("span", { className: "room-card__type-icon", "aria-hidden": "true", children: extras.typeIcon })), _jsx("span", { ref: nameRef, className: "room-card__name", "data-testid": "room-name", "data-tip": nameTruncated ? room.name : undefined, tabIndex: nameTruncated ? 0 : undefined, children: room.name }), extras.trophy !== undefined && _jsx("span", { className: "room-card__trophy", children: extras.trophy }), _jsxs("span", { className: "room-card__seats", "data-testid": "room-seats", children: [_jsx(PersonIcon, {}), view.seatsFilled, "/", view.seatsCapacity] })] }), (extras.modeChip !== undefined || extras.seriesChip !== undefined) && (_jsxs("div", { className: "room-card__row2", children: [extras.modeChip, extras.seriesChip] })), _jsxs("div", { className: "room-card__row3", children: [_jsxs("span", { className: "room-card__state", "data-testid": "room-state", "data-state": view.state.key, children: [_jsx("span", { className: "room-card__dot", "aria-hidden": "true" }), view.state.label] }), view.state.detail !== null && _jsx("span", { className: "room-card__state-detail", children: view.state.detail })] }), _jsxs("span", { className: "rooms__members rooms__sr", "data-testid": "room-members", children: [room.members.map((m) => (_jsx(Avatar, { ...faceOf(m), fallback: "none", className: "rooms__face", "data-testid": "room-face", "data-avatar-id": m.avatarId, title: m.name, width: 18, height: 18, loading: "lazy" }, m.id))), names.join(', ')] }), _jsxs("div", { className: "room-card__row4", children: [!asking && (_jsxs("button", { type: "button", className: "rooms__enter room-card__go", "data-testid": "room-enter", "aria-label": `${view.primaryAction} ${room.name}`, disabled: busy, onClick: onEnterClick, children: [room.locked && (_jsx("span", { className: "room-card__lock", "data-testid": "room-locked", "aria-hidden": "true", children: _jsx(LockIcon, {}) })), view.primaryAction] })), !asking && view.extraWatch && (_jsx("button", { type: "button", className: "rooms__enter room-card__go room-card__go--watch", "data-testid": "room-watch", "aria-label": `Watch ${room.name}`, disabled: busy, onClick: onEnterClick, children: "Watch" })), !asking && room.testing === true && client.reset !== undefined && (_jsx("button", { type: "button", className: "rooms__enter", "data-testid": "room-reset", "aria-label": `Reset ${room.name}`, disabled: busy, onClick: () => void onResetClick(), children: "Reset" })), extras.legacyMeta !== undefined && _jsx("div", { className: "rooms__meta room-card__legacy", children: extras.legacyMeta })] })] }), asking && (_jsxs("form", { className: "rooms__password", onSubmit: onPassword, children: [_jsxs("label", { htmlFor: `room-password-${room.id}`, children: ["Password for ", room.name] }), _jsx("input", { id: `room-password-${room.id}`, "data-testid": "room-password", type: "password", maxLength: passwordMaxLength, autoComplete: "off", autoFocus: true, value: password, onChange: (e) => {
|
|
242
|
+
setPassword(e.target.value);
|
|
243
|
+
setError(null);
|
|
244
|
+
} }), _jsx("button", { type: "submit", "data-testid": "room-password-submit", "aria-label": `Enter ${room.name}`, disabled: busy, children: "Enter" }), _jsx("button", { type: "button", className: "rooms__cancel", onClick: () => {
|
|
245
|
+
setAsking(false);
|
|
246
|
+
setPassword('');
|
|
247
|
+
setError(null);
|
|
248
|
+
}, children: "Cancel" })] })), error !== null && (_jsx("p", { className: "ct-error rooms__error", role: "alert", "data-testid": "room-join-error", children: error }))] }));
|
|
249
|
+
}
|
|
250
|
+
/* ── create ──────────────────────────────────────────────────────────── */
|
|
251
|
+
function CreateRoomDialog({ client, gameTypes, createFields, onClose, onOpenRoom, beforeOpenRoom, nameMaxLength, defaultName, surfaceClassName, }) {
|
|
252
|
+
// The word half of the prefill is drawn once per opening (this component remounts fresh each
|
|
253
|
+
// time `creating` turns true) and stays put across re-renders; the viewer's own name half keeps
|
|
254
|
+
// tracking `who` until it resolves, same as the viewer's own name would if typed by hand — except
|
|
255
|
+
// nothing here has been typed yet.
|
|
256
|
+
const who = useWhoami();
|
|
257
|
+
const [draw] = useState(Math.random);
|
|
258
|
+
const [typed, setTyped] = useState(null);
|
|
259
|
+
const viewerName = who === 'pending' ? null : (who?.name ?? null);
|
|
260
|
+
const name = typed ?? (who === 'pending' || defaultName === undefined ? '' : defaultName(viewerName, () => draw));
|
|
261
|
+
const [kind, setKind] = useState(gameTypes[0]?.id ?? '');
|
|
262
|
+
const [busy, setBusy] = useState(false);
|
|
263
|
+
const [error, setError] = useState(null);
|
|
264
|
+
const slot = createFields?.(kind) ?? null;
|
|
265
|
+
const nameless = slot?.nameless === true;
|
|
266
|
+
const ready = slot?.ready ?? true;
|
|
267
|
+
// `RadioCards` wants `{ value, label }`; the settled contract wants `{ id, label }` — this is the
|
|
268
|
+
// one place the two meet.
|
|
269
|
+
const kindOptions = gameTypes.map((g) => ({ value: g.id, label: g.label }));
|
|
270
|
+
useEffect(() => {
|
|
271
|
+
const onKey = (event) => {
|
|
272
|
+
if (event.key === 'Escape')
|
|
273
|
+
onClose();
|
|
274
|
+
};
|
|
275
|
+
globalThis.document?.addEventListener('keydown', onKey);
|
|
276
|
+
return () => globalThis.document?.removeEventListener('keydown', onKey);
|
|
277
|
+
}, [onClose]);
|
|
278
|
+
const opened = async (outcome) => {
|
|
279
|
+
if (!outcome.ok) {
|
|
280
|
+
setBusy(false);
|
|
281
|
+
playRole('ui.deny');
|
|
282
|
+
setError(outcome.message);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const handled = beforeOpenRoom === undefined ? false : await beforeOpenRoom(outcome.room);
|
|
286
|
+
setBusy(false);
|
|
287
|
+
if (!handled)
|
|
288
|
+
onOpenRoom(outcome.room.id);
|
|
289
|
+
};
|
|
290
|
+
const submit = async (e) => {
|
|
291
|
+
e.preventDefault();
|
|
292
|
+
if (slot?.submit !== undefined) {
|
|
293
|
+
playRole('ui.select');
|
|
294
|
+
setBusy(true);
|
|
295
|
+
setError(null);
|
|
296
|
+
await opened(await slot.submit());
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const trimmed = name.trim();
|
|
300
|
+
if (!nameless && trimmed === '') {
|
|
301
|
+
playRole('ui.deny');
|
|
302
|
+
setError('Name required.');
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
playRole('ui.select');
|
|
306
|
+
setBusy(true);
|
|
307
|
+
setError(null);
|
|
308
|
+
await opened(await client.create({ name: trimmed, gameType: kind, ...(slot?.body ?? {}) }));
|
|
309
|
+
};
|
|
310
|
+
return (_jsx(OverPage, { children: _jsx("div", { className: "rooms__backdrop", "data-testid": "room-create-backdrop", onPointerDown: (e) => {
|
|
311
|
+
if (e.target === e.currentTarget)
|
|
312
|
+
onClose();
|
|
313
|
+
}, children: _jsxs("form", { className: surfaceClassName, "data-testid": "room-create", role: "dialog", "aria-modal": "true", "aria-labelledby": "room-create-title", autoComplete: "off", onSubmit: (e) => void submit(e), children: [_jsxs("div", { className: "rooms__create-head", children: [_jsx("h3", { id: "room-create-title", children: "Create a room" }), _jsx("button", { type: "button", className: "rooms__create-close", "aria-label": "Close", "data-testid": "room-create-close", onClick: onClose, children: _jsx(Icon, { name: "close", size: uiLength('1rem') }) })] }), _jsx("span", { className: "rooms__caption", children: "Game type" }), _jsx(RadioCards, { name: "room-create-type", label: "Game type", options: kindOptions, value: kind, onChange: setKind, testId: "room-create-type" }), !nameless && (_jsxs(_Fragment, { children: [_jsx("label", { htmlFor: "room-create-name", children: "Name" }), _jsx("input", { id: "room-create-name", "data-testid": "room-create-name", value: name, maxLength: nameMaxLength, placeholder: "Friday night", autoComplete: "nickname", autoFocus: true, onChange: (e) => {
|
|
314
|
+
setTyped(e.target.value);
|
|
315
|
+
setError(null);
|
|
316
|
+
} })] })), slot?.node, _jsx("button", { type: "submit", className: "lobby__go", "data-testid": "room-create-submit", disabled: busy || !ready, children: "Create room" }), error !== null && (_jsx("p", { className: "ct-error rooms__error", role: "alert", "data-testid": "room-create-error", children: error }))] }) }) }));
|
|
317
|
+
}
|
|
@@ -39,11 +39,21 @@ export interface ExternalGameConfig {
|
|
|
39
39
|
embedSrc: string;
|
|
40
40
|
/** How long a dropped seat is held for its player to come back (`relay-match.ts`'s `seatRejoinGraceMs`). */
|
|
41
41
|
seatRejoinGraceMs: number;
|
|
42
|
+
/**
|
|
43
|
+
* An entry that proves the GENERIC mechanism rather than any one real game (wave 120 §F:
|
|
44
|
+
* "deleting the `bomberman` entry deletes nothing else" — `e2e/external-game-room.spec.ts` rides
|
|
45
|
+
* on this one, never on `bomberman` by name). `apps/server/src/plugins/external-games.ts`'s
|
|
46
|
+
* `setup()` filters an `e2eOnly` entry out of its registration loop unless
|
|
47
|
+
* `CARDTABLE_E2E_TOY_GAMES=1` — a SECOND, dedicated gate on top of the shared
|
|
48
|
+
* `CARDTABLE_EXPERIMENTAL_GAMES` every entry already has, so this one stays unregistered even
|
|
49
|
+
* where a real external game is turned on. The e2e spec's own `startPlayStack` sets both.
|
|
50
|
+
*/
|
|
51
|
+
e2eOnly?: boolean;
|
|
42
52
|
}
|
|
43
53
|
/**
|
|
44
|
-
* One entry per external game cardtable may host
|
|
45
|
-
* repo serves `/bomberman/embed/bomberman-embed.js` same-origin, the same path watchparty loads
|
|
46
|
-
*
|
|
54
|
+
* One entry per external game cardtable may host, plus one e2e-only fixture entry. Bomberman's own
|
|
55
|
+
* repo serves `/bomberman/embed/bomberman-embed.js` same-origin, the same path watchparty loads it
|
|
56
|
+
* from.
|
|
47
57
|
*
|
|
48
58
|
* - `seats: {min:2, max:10}` — `hadoku-bomberman/game/src/consts.rs:54` (`MAX_PLAYERS = 10`) and
|
|
49
59
|
* `game/src/board.rs:136` (no 1-player map).
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
* `games/magic/server/src/plugins/relay.test.ts` and `games/magic/server/src/room/codec-generic.test.ts`.
|
|
22
22
|
*/
|
|
23
23
|
/**
|
|
24
|
-
* One entry per external game cardtable may host
|
|
25
|
-
* repo serves `/bomberman/embed/bomberman-embed.js` same-origin, the same path watchparty loads
|
|
26
|
-
*
|
|
24
|
+
* One entry per external game cardtable may host, plus one e2e-only fixture entry. Bomberman's own
|
|
25
|
+
* repo serves `/bomberman/embed/bomberman-embed.js` same-origin, the same path watchparty loads it
|
|
26
|
+
* from.
|
|
27
27
|
*
|
|
28
28
|
* - `seats: {min:2, max:10}` — `hadoku-bomberman/game/src/consts.rs:54` (`MAX_PLAYERS = 10`) and
|
|
29
29
|
* `game/src/board.rs:136` (no 1-player map).
|
|
@@ -39,4 +39,13 @@ export const EXTERNAL_GAMES = [
|
|
|
39
39
|
embedSrc: '/bomberman/embed/bomberman-embed.js',
|
|
40
40
|
seatRejoinGraceMs: 120_000,
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
id: 'e2e-toy-relay',
|
|
44
|
+
label: 'Toy Relay Game',
|
|
45
|
+
seats: { min: 2, max: 4 },
|
|
46
|
+
runtime: 'relay',
|
|
47
|
+
embedSrc: '/e2e/toy-relay-embed.js',
|
|
48
|
+
seatRejoinGraceMs: 120_000,
|
|
49
|
+
e2eOnly: true,
|
|
50
|
+
},
|
|
42
51
|
];
|
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.18",
|
|
4
|
+
"gitHead": "028a4236d9e2a79e34c820620c566e20c7174d5c",
|
|
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.",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"react-dom": "^19.2.8"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.
|
|
25
|
-
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.
|
|
24
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.18",
|
|
25
|
+
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.18",
|
|
26
26
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.27",
|
|
27
|
-
"@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.
|
|
28
|
-
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.
|
|
27
|
+
"@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.99",
|
|
28
|
+
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.99",
|
|
29
29
|
"@wolffm/task-ui-components": "npm:@hadoku/task-ui-components@^4.23.35",
|
|
30
30
|
"@wolffm/themes": "npm:@hadoku/themes@^5.14.4",
|
|
31
|
-
"@wolffm/watchparty-ui": "npm:@hadoku/watchparty-ui@^0.45.
|
|
31
|
+
"@wolffm/watchparty-ui": "npm:@hadoku/watchparty-ui@^0.45.99",
|
|
32
32
|
"socket.io-client": "^4.8.3",
|
|
33
33
|
"zod": "4.5.4"
|
|
34
34
|
},
|