diff --git a/src/lib/components/Hall.svelte b/src/lib/components/Hall.svelte index 7a6e7eb..3d46b6f 100644 --- a/src/lib/components/Hall.svelte +++ b/src/lib/components/Hall.svelte @@ -16,13 +16,10 @@ let name = $state(playerName()); let code = $state(''); /** The host's choices for the next table, from the game's declared options. */ - // The host's last choices come back as the defaults; a regular does not re-pick them each visit. - let options = $state>( + // A new table starts from the preferences' table defaults; the hall's selectors set the same keys. + const options = $derived>( Object.fromEntries((game.options ?? []).map((o) => [o.key, o.choices.some((c) => c.value === prefs[`table.${o.key}`]) ? String(prefs[`table.${o.key}`]) : o.default])) ); - $effect(() => { - for (const o of game.options ?? []) if (prefs[`table.${o.key}`] !== options[o.key]) setPref(`table.${o.key}`, options[o.key]); - }); let prefsOpen = $state(false); /** The hall's still of the opening position, on whichever board the selector names. */ @@ -192,7 +189,7 @@
diff --git a/src/lib/prefs.svelte.ts b/src/lib/prefs.svelte.ts index 6c126cf..6d2ba50 100644 --- a/src/lib/prefs.svelte.ts +++ b/src/lib/prefs.svelte.ts @@ -21,7 +21,16 @@ export const KIT_PREFERENCES: Preference[] = [ { key: 'confirmMoves', label: 'Confirm a move before it is sent', kind: 'toggle', default: false } ]; -export const PREFERENCES: Preference[] = [...KIT_PREFERENCES, ...(game.preferences ?? [])]; +/** Every table option is also a preference: the choice a new table starts with. The hall reads and writes the same keys. */ +const TABLE_DEFAULTS: Preference[] = (game.options ?? []).map((o) => ({ + key: `table.${o.key}`, + label: `${o.label}, for a new table`, + kind: 'choice', + choices: o.choices.map((c) => ({ value: c.value, label: c.label })), + default: o.default +})); + +export const PREFERENCES: Preference[] = [...KIT_PREFERENCES, ...TABLE_DEFAULTS, ...(game.preferences ?? [])]; const KEY = 'hnefatafl:prefs'; @@ -38,8 +47,6 @@ function load(): Record { if (p.kind === 'toggle' && typeof v === 'boolean') base[p.key] = v; if (p.kind === 'choice' && typeof v === 'string' && p.choices?.some((c) => c.value === v)) base[p.key] = v; } - // The hall's last table options ride along under table., undeclared. - for (const [k, v] of Object.entries(saved)) if (k.startsWith('table.') && typeof v === 'string') base[k] = v; } catch { // Without storage the defaults apply for this visit. }