@hadoku/game-ui 0.1.37 → 0.1.39

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.
@@ -1,8 +1,11 @@
1
1
  import { type ReactNode } from 'react';
2
+ import type { Look } from '@wolffm/platform-wire/look';
2
3
  export interface RoomFrontMember {
3
4
  id: string;
4
5
  name: string;
5
6
  avatarId?: string;
7
+ /** Their picture and cosmetics: drawn instead of the character, as chat and the seats draw them. */
8
+ look?: Look;
6
9
  }
7
10
  /** 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
11
  export interface RoomFrontView {
@@ -107,7 +110,7 @@ export interface RoomFrontRowExtras {
107
110
  }
108
111
  export interface RoomFrontProps<V extends RoomFrontRoom> {
109
112
  rooms: RoomFrontClient<V>;
110
- /** The create form's own radio: every type a caller may make, id and label, at least one. */
113
+ /** The create form's own radio: every type a caller may make, id and label, at least one. With only one, no radio is drawn. */
111
114
  gameTypes: readonly RoomFrontGameType[];
112
115
  createFields?: (kind: string) => RoomFrontCreateSlot | null;
113
116
  rowExtras?: (room: V) => RoomFrontRowExtras;
@@ -310,7 +310,7 @@ function CreateRoomDialog({ client, gameTypes, createFields, onClose, onOpenRoom
310
310
  return (_jsx(OverPage, { children: _jsx("div", { className: "rooms__backdrop", "data-testid": "room-create-backdrop", onPointerDown: (e) => {
311
311
  if (e.target === e.currentTarget)
312
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) => {
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') }) })] }), kindOptions.length > 1 && (_jsxs(_Fragment, { children: [_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
314
  setTyped(e.target.value);
315
315
  setError(null);
316
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 }))] }) }) }));
@@ -0,0 +1,51 @@
1
+ /**
2
+ * A platform room's seats, read for `SeatList` and `SpectatorRow`: the one reading every game whose
3
+ * room is the platform's own (`@hadoku/game-server`'s `plainRoomType` with `markedSeats`) draws
4
+ * its lineup from, so no game classifies seats, names bots or picks faces of its own.
5
+ *
6
+ * - A member's face is their account's — `avatarId` AND `look` (the picture they chose, their
7
+ * cosmetics) — exactly as chat draws them, never a character drawn in their place.
8
+ * - A bot is the server's persona for its seat (`aiSeats`, `ai-faces.ts`'s `seatPersonas`): the
9
+ * character it plays as, by that character's name, the same on every page.
10
+ * - The "+1" slot is drawn only when every seat is taken (none open, none closed) and the room
11
+ * can still grow — Magic's pod rule. A room that keeps one seat open by itself (`keepOneOpen`) never draws it.
12
+ */
13
+ import type { Look } from '@wolffm/platform-wire/look';
14
+ import { type AiPersona } from '@wolffm/platform-wire/seats';
15
+ import type { SeatSlot } from './SeatChip.js';
16
+ /** What this reads of a room's view (`PlatformRoomView` and `PlainRoomView`). */
17
+ export interface PlatformSeatRoom {
18
+ leader: string;
19
+ /** As stored: a member id, `AI_SEAT`, `CLOSED_SEAT` or null. */
20
+ seats: readonly (string | null)[];
21
+ members: readonly {
22
+ id: string;
23
+ name: string;
24
+ ready?: boolean;
25
+ avatarId?: string;
26
+ look?: Look;
27
+ }[];
28
+ /** The bot at each seat, in seat order. Absent (an older server): a bot is drawn faceless, as "Bot". */
29
+ aiSeats?: readonly (AiPersona | null)[];
30
+ }
31
+ export interface PlatformSeats {
32
+ slots: SeatSlot[];
33
+ /** `SeatList`'s `realSeatCount`: the seats the room has, without the "+1" slot. */
34
+ realSeatCount: number;
35
+ /** The viewer's seat, or null while watching. */
36
+ mySeat: number | null;
37
+ /** Every member who holds no seat, as `SpectatorRow` takes them. */
38
+ spectators: {
39
+ id: string;
40
+ name: string;
41
+ avatarId?: string;
42
+ look?: Look;
43
+ }[];
44
+ }
45
+ export interface PlatformSeatsOptions {
46
+ /** The most seats the room can grow to: no "+1" slot at or past it. */
47
+ ceiling: number;
48
+ /** `false` for a game with no Ready step (its Start is a press, never a readiness gate): every member reads ready, so no ring says "not ready" for no reason. */
49
+ readiness?: boolean;
50
+ }
51
+ export declare function platformSeats(room: PlatformSeatRoom, myId: string | null, opts: PlatformSeatsOptions): PlatformSeats;
@@ -0,0 +1,41 @@
1
+ import { AI_SEAT, CLOSED_SEAT } from '@wolffm/platform-wire/seats';
2
+ export function platformSeats(room, myId, opts) {
3
+ const memberOf = (id) => room.members.find((m) => m.id === id);
4
+ const occupantOf = (holder, seat) => {
5
+ if (holder === null)
6
+ return { kind: 'open' };
7
+ if (holder === CLOSED_SEAT)
8
+ return { kind: 'closed' };
9
+ if (holder === AI_SEAT) {
10
+ const persona = room.aiSeats?.[seat] ?? null;
11
+ return persona === null ? { kind: 'bot', name: 'Bot' } : { kind: 'bot', name: persona.name, avatarId: persona.avatarId };
12
+ }
13
+ const member = memberOf(holder);
14
+ // A holder who is no longer a member is nobody's seat — the server's own reading of it.
15
+ if (member === undefined)
16
+ return { kind: 'open' };
17
+ return {
18
+ kind: 'member',
19
+ id: member.id,
20
+ name: member.name,
21
+ ...(member.avatarId === undefined ? {} : { avatarId: member.avatarId }),
22
+ ...(member.look === undefined ? {} : { look: member.look }),
23
+ ready: opts.readiness === false || member.ready === true,
24
+ leader: member.id === room.leader,
25
+ mine: member.id === myId,
26
+ };
27
+ };
28
+ const slots = room.seats.map((holder, seat) => ({ seat, occupant: occupantOf(holder, seat) }));
29
+ const seat = myId === null ? -1 : room.seats.indexOf(myId);
30
+ const mySeat = seat === -1 ? null : seat;
31
+ const realSeatCount = slots.length;
32
+ // Full: no open seat, and none closed either — a closed seat is the leader's to open, not grown past.
33
+ const full = slots.every((s) => s.occupant.kind !== 'open' && s.occupant.kind !== 'closed');
34
+ if (full && realSeatCount < opts.ceiling)
35
+ slots.push({ seat: realSeatCount, occupant: { kind: 'open' } });
36
+ const seated = new Set(room.seats);
37
+ const spectators = room.members
38
+ .filter((m) => !seated.has(m.id))
39
+ .map((m) => ({ id: m.id, name: m.name, ...(m.avatarId === undefined ? {} : { avatarId: m.avatarId }), ...(m.look === undefined ? {} : { look: m.look }) }));
40
+ return { slots, realSeatCount, mySeat, spectators };
41
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-ui",
3
- "version": "0.1.37",
4
- "gitHead": "f7fa1adf56787f42a175c5ddd4e290f0d1355068",
3
+ "version": "0.1.39",
4
+ "gitHead": "1f205041f6382de02221007ebda7bd1ba96e417d",
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.",
@@ -49,8 +49,8 @@
49
49
  "react-dom": "^19.2.8"
50
50
  },
51
51
  "dependencies": {
52
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.37",
53
- "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.37",
52
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.39",
53
+ "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.39",
54
54
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.27",
55
55
  "@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.109",
56
56
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.109",