@hadoku/game-ui 0.1.186 → 0.1.188
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/seats/SeatChip.js
CHANGED
|
@@ -4,8 +4,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
4
4
|
* (sit, bot on/off, close/open) — lifted from `games/magic/ui/src/screens/pod/PodSeats.tsx`
|
|
5
5
|
* (wave 119 §U). Platform: knows nothing of a draft pod, a Magic match or any other game's own
|
|
6
6
|
* seat semantics — the caller classifies each seat into a `SeatOccupant` first (Magic's own
|
|
7
|
-
* `PodSeats.tsx` still owns that classification, reading `isPodAi`/`
|
|
8
|
-
*
|
|
7
|
+
* `PodSeats.tsx` still owns that classification, reading `isPodAi`/`CLOSED_SEAT` from
|
|
8
|
+
* `@hadoku/shared`; a future game classifies its own seats the same way, into the same four shapes).
|
|
9
9
|
*
|
|
10
10
|
* `PodSeats.tsx` keeps its own markup's every class name and `data-testid` — `pod-seats`,
|
|
11
11
|
* `pod-seats__seat`, `pod-seat-<n>`, … — unchanged: cardtable's existing CSS (`PodSeats.css`) and
|
|
@@ -2,6 +2,7 @@ import { type ComponentType } from 'react';
|
|
|
2
2
|
import type { AppSettingsTab } from '@wolffm/task-ui-components';
|
|
3
3
|
import type { PrefsClient } from '@wolffm/prefs-client';
|
|
4
4
|
import { type MotionChoices } from '@wolffm/ui-shell/motion';
|
|
5
|
+
import { type KeyAction } from './keybinds.js';
|
|
5
6
|
import './settings.css';
|
|
6
7
|
/**
|
|
7
8
|
* What the Display tab saves in the game's own preferences: the UI scale, the motion switches
|
|
@@ -13,11 +14,14 @@ export interface DisplayPrefs extends MotionChoices {
|
|
|
13
14
|
[key: string]: unknown;
|
|
14
15
|
uiScale?: number;
|
|
15
16
|
frontMatch?: boolean;
|
|
17
|
+
/** The keys the player chose, by action (`./keybinds.ts`); an action not in it answers to its defaults. */
|
|
18
|
+
keys?: Record<string, readonly string[]>;
|
|
16
19
|
}
|
|
17
|
-
/** The game's own sections, where its UI scale is saved (and the scale before anything is), and what a new scale makes stale. */
|
|
20
|
+
/** The game's own sections, its key map's actions (none: no keys to choose), where its UI scale is saved (and the scale before anything is), and what a new scale makes stale. */
|
|
18
21
|
export interface SettingsParts {
|
|
19
22
|
Game: ComponentType;
|
|
20
23
|
Sound: ComponentType;
|
|
24
|
+
keys?: readonly KeyAction[];
|
|
21
25
|
prefs: () => PrefsClient<DisplayPrefs>;
|
|
22
26
|
defaultScale: number;
|
|
23
27
|
onScaled: () => void;
|
|
@@ -22,7 +22,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
22
22
|
* `../sound/mute.ts`), so whichever host draws a control, the board reads the change from the
|
|
23
23
|
* service and applies it. Only "This match" is not a preference: the board publishes it
|
|
24
24
|
* (`./liveMatch.ts`). The Gameplay and Sound tabs' sections are the game's own, handed in by `../composition.tsx`;
|
|
25
|
-
* Display (the UI scale and the motion switches) is drawn here, for every game
|
|
25
|
+
* Display (the UI scale and the motion switches) is drawn here, for every game, and so are the keys of a game
|
|
26
|
+
* that hands in a key map (`./keybinds.ts`), under its Gameplay.
|
|
26
27
|
*/
|
|
27
28
|
import { createContext, createElement, Fragment, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
28
29
|
import { Icon } from '@wolffm/themes';
|
|
@@ -32,6 +33,7 @@ import { appId } from '@wolffm/ui-shell/app-id';
|
|
|
32
33
|
import { applyMotion, clearMotion, motionState, rememberedMotion, rememberMotion, setMotionChoices, systemReducesMotion } from '@wolffm/ui-shell/motion';
|
|
33
34
|
import { Popover, usePopover } from "../components/Popover.js";
|
|
34
35
|
import { registered } from "../registered.js";
|
|
36
|
+
import { chordOf, keyMapOf, rebind } from "./keybinds.js";
|
|
35
37
|
import './settings.css';
|
|
36
38
|
const parts = registered('settings');
|
|
37
39
|
export const registerSettings = parts.set;
|
|
@@ -40,7 +42,11 @@ export const registerSettings = parts.set;
|
|
|
40
42
|
* how the page looks and moves, then sound.
|
|
41
43
|
*/
|
|
42
44
|
export const CARDTABLE_SETTINGS_TABS = [
|
|
43
|
-
{
|
|
45
|
+
{
|
|
46
|
+
id: 'game',
|
|
47
|
+
label: 'Gameplay',
|
|
48
|
+
render: () => (_jsxs("div", { className: "ct-settings__tab", children: [createElement(parts.get().Game), _jsx(KeySettings, {})] })),
|
|
49
|
+
},
|
|
44
50
|
{
|
|
45
51
|
id: 'display',
|
|
46
52
|
label: 'Display',
|
|
@@ -103,6 +109,34 @@ function DisplaySettings() {
|
|
|
103
109
|
setHeld(clampUiScale(Number(event.currentTarget.value) / 100));
|
|
104
110
|
} })] })] }));
|
|
105
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* The game's key map, one row an action: its keys, pressed to choose another (the next key pressed is its
|
|
114
|
+
* one key), and cleared to answer to none. Reset puts every action back on its defaults.
|
|
115
|
+
*/
|
|
116
|
+
function KeySettings() {
|
|
117
|
+
const { prefs: client, keys: actions } = parts.get();
|
|
118
|
+
const { prefs, save } = usePrefs(client());
|
|
119
|
+
const [choosing, setChoosing] = useState(null);
|
|
120
|
+
if (actions === undefined || actions.length === 0)
|
|
121
|
+
return null;
|
|
122
|
+
const map = keyMapOf(actions, prefs?.keys);
|
|
123
|
+
const choose = (id, chord) => {
|
|
124
|
+
setChoosing(null);
|
|
125
|
+
void save({ keys: rebind(map, id, chord) });
|
|
126
|
+
};
|
|
127
|
+
return (_jsxs("fieldset", { className: "ct-settings__section", "data-testid": "settings-keys", children: [_jsx("legend", { children: "Keys" }), _jsx("ul", { className: "ct-settings__triggers", children: actions.map((action) => (_jsxs("li", { className: "ct-settings__trigger", children: [_jsx("span", { children: action.label }), _jsxs("span", { className: "ct-settings__option", children: [_jsx("button", { type: "button", "data-testid": `settings-key-${action.id}`, "aria-pressed": choosing === action.id, onClick: () => setChoosing(choosing === action.id ? null : action.id), onBlur: () => setChoosing(null), onKeyDown: (event) => {
|
|
128
|
+
if (choosing !== action.id)
|
|
129
|
+
return;
|
|
130
|
+
const chord = chordOf(event);
|
|
131
|
+
// Tab still moves the focus on: leaving the row ends the choosing.
|
|
132
|
+
if (chord === null || event.key === 'Tab')
|
|
133
|
+
return;
|
|
134
|
+
// The key is this choice's: not the button's own press, and not the board's.
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
event.stopPropagation();
|
|
137
|
+
choose(action.id, chord);
|
|
138
|
+
}, children: choosing === action.id ? '…' : map[action.id]?.join(' · ') || '—' }), _jsx("button", { type: "button", className: "ct-settings__close", "aria-label": `Clear ${action.label}`, "data-testid": `settings-key-${action.id}-clear`, disabled: (map[action.id]?.length ?? 0) === 0, onClick: () => choose(action.id, null), children: _jsx(Icon, { name: "close", size: uiLength('0.875rem') }) })] })] }, action.id))) }), _jsx("button", { type: "button", "data-testid": "settings-keys-reset", onClick: () => void save({ keys: {} }), children: "Reset" })] }));
|
|
139
|
+
}
|
|
106
140
|
/** Whether the front page plays its featured match: the player's choice, else on unless the system asks for less motion. */
|
|
107
141
|
export function frontMatchShown(prefs) {
|
|
108
142
|
return prefs?.frontMatch ?? !systemReducesMotion();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** One thing a key can do, and the keys it answers to until the player chooses. */
|
|
2
|
+
export interface KeyAction<Id extends string = string> {
|
|
3
|
+
readonly id: Id;
|
|
4
|
+
readonly label: string;
|
|
5
|
+
readonly keys: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
/** Each action's keys. */
|
|
8
|
+
export type KeyMap<Id extends string = string> = Readonly<Record<Id, readonly string[]>>;
|
|
9
|
+
/** The chord a key press makes, or null for a press of a modifier alone. */
|
|
10
|
+
export declare function chordOf(event: Pick<KeyboardEvent, 'key' | 'ctrlKey' | 'altKey' | 'shiftKey' | 'metaKey'>): string | null;
|
|
11
|
+
/** Each action's defaults. */
|
|
12
|
+
export declare function defaultKeys<Id extends string>(actions: readonly KeyAction<Id>[]): KeyMap<Id>;
|
|
13
|
+
/**
|
|
14
|
+
* The key map a saved preference makes: each action the player chose keys for takes them, every other its
|
|
15
|
+
* defaults. Anything else saved (a retired action, a value that is no list of keys) is ignored, and a chord
|
|
16
|
+
* two actions claim stays with the first.
|
|
17
|
+
*/
|
|
18
|
+
export declare function keyMapOf<Id extends string>(actions: readonly KeyAction<Id>[], saved: unknown): KeyMap<Id>;
|
|
19
|
+
/** The action `chord` takes in `map`, or null. */
|
|
20
|
+
export declare function actionOf<Id extends string>(map: KeyMap<Id>, chord: string): Id | null;
|
|
21
|
+
/** `map` with `id` answering to `chord` alone (or to nothing, for null), and no other action answering to it. */
|
|
22
|
+
export declare function rebind<Id extends string>(map: KeyMap<Id>, id: NoInfer<Id>, chord: string | null): KeyMap<Id>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* A game's key map: the actions a key can take, the keys each one answers to, and the player's own
|
|
3
|
+
* choice of them, saved as a preference (`Settings.tsx`'s `KeySettings`).
|
|
4
|
+
*
|
|
5
|
+
* A key is named as a chord: its modifiers, then the key itself (`Ctrl+Z`, `Space`, `Enter`, `Shift+A`).
|
|
6
|
+
* One chord takes one action: binding it to an action takes it from any other that had it.
|
|
7
|
+
*/
|
|
8
|
+
/** Keys that are only ever a chord's modifier, or no key at all. */
|
|
9
|
+
const NOT_A_KEY = new Set(['Control', 'Shift', 'Alt', 'AltGraph', 'Meta', 'OS', 'CapsLock', 'NumLock', 'ScrollLock', 'Fn', 'Dead', 'Process', 'Unidentified']);
|
|
10
|
+
/** The chord a key press makes, or null for a press of a modifier alone. */
|
|
11
|
+
export function chordOf(event) {
|
|
12
|
+
if (event.key === '' || NOT_A_KEY.has(event.key))
|
|
13
|
+
return null;
|
|
14
|
+
const key = event.key === ' ' ? 'Space' : event.key.length === 1 ? event.key.toUpperCase() : event.key;
|
|
15
|
+
const held = [event.ctrlKey && 'Ctrl', event.altKey && 'Alt', event.shiftKey && 'Shift', event.metaKey && 'Meta'].filter((m) => m !== false);
|
|
16
|
+
return [...held, key].join('+');
|
|
17
|
+
}
|
|
18
|
+
/** Each action's defaults. */
|
|
19
|
+
export function defaultKeys(actions) {
|
|
20
|
+
return Object.fromEntries(actions.map((a) => [a.id, a.keys]));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The key map a saved preference makes: each action the player chose keys for takes them, every other its
|
|
24
|
+
* defaults. Anything else saved (a retired action, a value that is no list of keys) is ignored, and a chord
|
|
25
|
+
* two actions claim stays with the first.
|
|
26
|
+
*/
|
|
27
|
+
export function keyMapOf(actions, saved) {
|
|
28
|
+
const chosen = typeof saved === 'object' && saved !== null ? saved : {};
|
|
29
|
+
const taken = new Set();
|
|
30
|
+
const map = {};
|
|
31
|
+
for (const action of actions) {
|
|
32
|
+
const own = chosen[action.id];
|
|
33
|
+
const keys = Array.isArray(own) && own.every((k) => typeof k === 'string' && k !== '') ? own : action.keys;
|
|
34
|
+
const free = [...new Set(keys)].filter((k) => !taken.has(k));
|
|
35
|
+
for (const k of free)
|
|
36
|
+
taken.add(k);
|
|
37
|
+
map[action.id] = free;
|
|
38
|
+
}
|
|
39
|
+
return map;
|
|
40
|
+
}
|
|
41
|
+
/** The action `chord` takes in `map`, or null. */
|
|
42
|
+
export function actionOf(map, chord) {
|
|
43
|
+
for (const [id, keys] of Object.entries(map)) {
|
|
44
|
+
if (keys.includes(chord))
|
|
45
|
+
return id;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
/** `map` with `id` answering to `chord` alone (or to nothing, for null), and no other action answering to it. */
|
|
50
|
+
export function rebind(map, id, chord) {
|
|
51
|
+
const next = { ...map };
|
|
52
|
+
for (const other of Object.keys(next))
|
|
53
|
+
next[other] = next[other].filter((k) => k !== chord);
|
|
54
|
+
next[id] = chord === null ? [] : [chord];
|
|
55
|
+
return next;
|
|
56
|
+
}
|
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.188",
|
|
4
|
+
"gitHead": "457b94f52dad136822dba5d21e59e04fb4c6f2c7",
|
|
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.192",
|
|
57
|
+
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.192",
|
|
58
58
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.3",
|
|
59
59
|
"@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.149",
|
|
60
60
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.149",
|