@hadoku/game-ui 0.1.91 → 0.1.92
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,19 +1,32 @@
|
|
|
1
1
|
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
|
+
import { type MotionChoices } from '@wolffm/ui-shell/motion';
|
|
4
5
|
import './settings.css';
|
|
6
|
+
/**
|
|
7
|
+
* What the Display tab saves in the game's own preferences: the UI scale, the motion switches
|
|
8
|
+
* (`@hadoku/ui-shell/motion`, each unset until the player chooses, following the system until then) and
|
|
9
|
+
* whether the front page plays its featured match (unset, it follows card motion's default).
|
|
10
|
+
*/
|
|
11
|
+
export interface DisplayPrefs extends MotionChoices {
|
|
12
|
+
/** `usePrefs`'s own bound; nothing is read off it. */
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
uiScale?: number;
|
|
15
|
+
frontMatch?: boolean;
|
|
16
|
+
}
|
|
5
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. */
|
|
6
18
|
export interface SettingsParts {
|
|
7
19
|
Game: ComponentType;
|
|
8
20
|
Sound: ComponentType;
|
|
9
|
-
prefs: () => PrefsClient<
|
|
10
|
-
uiScale?: number;
|
|
11
|
-
}>;
|
|
21
|
+
prefs: () => PrefsClient<DisplayPrefs>;
|
|
12
22
|
defaultScale: number;
|
|
13
23
|
onScaled: () => void;
|
|
14
24
|
}
|
|
15
25
|
export declare const registerSettings: (value: SettingsParts) => void;
|
|
16
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* The settings as tabs, in the order a player looks for them (operator, 2026-11-21): how the game plays,
|
|
28
|
+
* how the page looks and moves, then sound.
|
|
29
|
+
*/
|
|
17
30
|
export declare const CARDTABLE_SETTINGS_TABS: AppSettingsTab[];
|
|
18
31
|
/** Every tab's sections one under another, for a popout with no tabs of its own. */
|
|
19
32
|
export declare function CardtableSettings(): import("react").JSX.Element;
|
|
@@ -27,6 +40,15 @@ export declare const HostDrawsSettingsProvider: import("react").Provider<boolean
|
|
|
27
40
|
* where the header held the only route to one.
|
|
28
41
|
*/
|
|
29
42
|
export declare function useHostDrawsSettings(): boolean;
|
|
43
|
+
/** Whether the front page plays its featured match: the player's choice, else on unless the system asks for less motion. */
|
|
44
|
+
export declare function frontMatchShown(prefs: DisplayPrefs | null): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The motion switches, applied: for every reader of `prefersReducedMotion()` / `screenShakeAllowed()`, and
|
|
47
|
+
* as attributes on `root`, where the sheets look for them (`@hadoku/ui-shell/motion`'s `css.ts`). Called once
|
|
48
|
+
* per app, as `useUiScale` is. Until prefs answer, the switches this browser applied last; a system that
|
|
49
|
+
* changes its mind mid-visit is followed by every switch the player has not set.
|
|
50
|
+
*/
|
|
51
|
+
export declare function useMotion(root: () => HTMLElement | null): void;
|
|
30
52
|
/**
|
|
31
53
|
* The saved UI scale, written where the stylesheet's tokens resolve (shell's `ui-scale.ts`). Called
|
|
32
54
|
* once per app — the standalone page's and the embed's — with the element that is. Until prefs
|
|
@@ -21,23 +21,30 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
21
21
|
* Every value is a preference in the fleet's service (`../play/live/prefs.ts`,
|
|
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
|
-
* (`./liveMatch.ts`). The
|
|
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
26
|
*/
|
|
26
27
|
import { createContext, createElement, Fragment, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
27
28
|
import { Icon } from '@wolffm/themes';
|
|
28
29
|
import { usePrefs } from '@wolffm/prefs-client/react';
|
|
29
30
|
import { applyUiScale, clampUiScale, rememberedUiScale, rememberUiScale, UI_SCALE, uiLength } from '@wolffm/ui-shell/settings';
|
|
31
|
+
import { appId } from '@wolffm/ui-shell/app-id';
|
|
32
|
+
import { applyMotion, clearMotion, motionState, rememberedMotion, rememberMotion, setMotionChoices, systemReducesMotion } from '@wolffm/ui-shell/motion';
|
|
30
33
|
import { Popover, usePopover } from "../components/Popover.js";
|
|
31
34
|
import { registered } from "../registered.js";
|
|
32
35
|
import './settings.css';
|
|
33
36
|
const parts = registered('settings');
|
|
34
37
|
export const registerSettings = parts.set;
|
|
35
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* The settings as tabs, in the order a player looks for them (operator, 2026-11-21): how the game plays,
|
|
40
|
+
* how the page looks and moves, then sound.
|
|
41
|
+
*/
|
|
36
42
|
export const CARDTABLE_SETTINGS_TABS = [
|
|
43
|
+
{ id: 'game', label: 'Gameplay', render: () => _jsx("div", { className: "ct-settings__tab", children: createElement(parts.get().Game) }) },
|
|
37
44
|
{
|
|
38
|
-
id: '
|
|
39
|
-
label: '
|
|
40
|
-
render: () => (_jsxs("div", { className: "ct-settings__tab", children: [
|
|
45
|
+
id: 'display',
|
|
46
|
+
label: 'Display',
|
|
47
|
+
render: () => (_jsxs("div", { className: "ct-settings__tab", children: [_jsx(DisplaySettings, {}), _jsx(MotionSettings, {})] })),
|
|
41
48
|
},
|
|
42
49
|
{ id: 'sound', label: 'Sound', render: () => _jsx("div", { className: "ct-settings__tab", children: createElement(parts.get().Sound) }) },
|
|
43
50
|
];
|
|
@@ -96,6 +103,59 @@ function DisplaySettings() {
|
|
|
96
103
|
setHeld(clampUiScale(Number(event.currentTarget.value) / 100));
|
|
97
104
|
} })] })] }));
|
|
98
105
|
}
|
|
106
|
+
/** Whether the front page plays its featured match: the player's choice, else on unless the system asks for less motion. */
|
|
107
|
+
export function frontMatchShown(prefs) {
|
|
108
|
+
return prefs?.frontMatch ?? !systemReducesMotion();
|
|
109
|
+
}
|
|
110
|
+
function MotionToggle({ testId, checked, label, onChange }) {
|
|
111
|
+
return (_jsxs("label", { className: "ct-settings__option", children: [_jsx("input", { type: "checkbox", "data-testid": testId, checked: checked, onChange: (event) => onChange(event.currentTarget.checked) }), label] }));
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Each motion switch on its own (operator, 2026-11-21: "make sure that each of them can be individually
|
|
115
|
+
* toggled"), each drawn as the page applies it now: a switch nobody set shows the system's answer.
|
|
116
|
+
*/
|
|
117
|
+
function MotionSettings() {
|
|
118
|
+
const { prefs: client } = parts.get();
|
|
119
|
+
const { prefs, save } = usePrefs(client());
|
|
120
|
+
const state = motionState(prefs ?? {});
|
|
121
|
+
return (_jsxs("fieldset", { className: "ct-settings__section", "data-testid": "settings-motion", children: [_jsx("legend", { children: "Motion" }), _jsx(MotionToggle, { testId: "settings-card-motion", checked: state.cardMotion, label: "Card animations", onChange: (on) => void save({ cardMotion: on }) }), _jsx(MotionToggle, { testId: "settings-screen-shake", checked: state.screenShake, label: "Screen shake", onChange: (on) => void save({ screenShake: on }) }), _jsx(MotionToggle, { testId: "settings-ambient-motion", checked: state.ambientMotion, label: "Looping animations", onChange: (on) => void save({ ambientMotion: on }) }), _jsx(MotionToggle, { testId: "settings-front-match", checked: frontMatchShown(prefs), label: "Front page match", onChange: (on) => void save({ frontMatch: on }) })] }));
|
|
122
|
+
}
|
|
123
|
+
/** Per game: the motion switches this browser applied last. */
|
|
124
|
+
const motionKey = () => `${appId()}:motion`;
|
|
125
|
+
/**
|
|
126
|
+
* The motion switches, applied: for every reader of `prefersReducedMotion()` / `screenShakeAllowed()`, and
|
|
127
|
+
* as attributes on `root`, where the sheets look for them (`@hadoku/ui-shell/motion`'s `css.ts`). Called once
|
|
128
|
+
* per app, as `useUiScale` is. Until prefs answer, the switches this browser applied last; a system that
|
|
129
|
+
* changes its mind mid-visit is followed by every switch the player has not set.
|
|
130
|
+
*/
|
|
131
|
+
export function useMotion(root) {
|
|
132
|
+
const { prefs: client } = parts.get();
|
|
133
|
+
const { prefs } = usePrefs(client());
|
|
134
|
+
const [remembered] = useState(() => rememberedMotion(motionKey()));
|
|
135
|
+
const [systemTick, setSystemTick] = useState(0);
|
|
136
|
+
const choices = prefs === null ? (remembered ?? {}) : { cardMotion: prefs.cardMotion, screenShake: prefs.screenShake, ambientMotion: prefs.ambientMotion };
|
|
137
|
+
const { cardMotion, screenShake, ambientMotion } = choices;
|
|
138
|
+
useLayoutEffect(() => {
|
|
139
|
+
const el = root();
|
|
140
|
+
setMotionChoices({ cardMotion, screenShake, ambientMotion });
|
|
141
|
+
if (el === null)
|
|
142
|
+
return undefined;
|
|
143
|
+
applyMotion(el);
|
|
144
|
+
return () => clearMotion(el);
|
|
145
|
+
}, [root, cardMotion, screenShake, ambientMotion, systemTick]);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
if (typeof matchMedia !== 'function')
|
|
148
|
+
return undefined;
|
|
149
|
+
const query = matchMedia('(prefers-reduced-motion: reduce)');
|
|
150
|
+
const changed = () => setSystemTick((t) => t + 1);
|
|
151
|
+
query.addEventListener?.('change', changed);
|
|
152
|
+
return () => query.removeEventListener?.('change', changed);
|
|
153
|
+
}, []);
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
if (prefs !== null)
|
|
156
|
+
rememberMotion(motionKey(), { cardMotion, screenShake, ambientMotion });
|
|
157
|
+
}, [prefs, cardMotion, screenShake, ambientMotion]);
|
|
158
|
+
}
|
|
99
159
|
/**
|
|
100
160
|
* The saved UI scale, written where the stylesheet's tokens resolve (shell's `ui-scale.ts`). Called
|
|
101
161
|
* once per app — the standalone page's and the embed's — with the element that is. Until prefs
|
|
@@ -91,6 +91,17 @@
|
|
|
91
91
|
gap: 4px;
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
/* One line of choices after its name: Game speed's three. */
|
|
95
|
+
.ct-settings__choices--row {
|
|
96
|
+
flex-flow: row wrap;
|
|
97
|
+
align-items: center;
|
|
98
|
+
column-gap: 12px;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.ct-settings__choices-label {
|
|
102
|
+
flex-basis: 100%;
|
|
103
|
+
}
|
|
104
|
+
|
|
94
105
|
.ct-settings__level {
|
|
95
106
|
display: grid;
|
|
96
107
|
grid-template-columns: 4rem 1fr;
|
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.92",
|
|
4
|
+
"gitHead": "e5f8a3ad2185e6524f982af947e6850dcf19134d",
|
|
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.
|
|
53
|
-
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.
|
|
52
|
+
"@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.96",
|
|
53
|
+
"@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.96",
|
|
54
54
|
"@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.1.31",
|
|
55
55
|
"@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.128",
|
|
56
56
|
"@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.128",
|