summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/menus
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-19 08:53:51 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-19 08:53:51 +0100
commitb884441ba0d10bdd3559748507a0991888f66194 (patch)
tree074321d353c1153e8d95191eecf5a61b2eec1096 /web/src/lib/ui/menus
parentd64cf3514e5ff1ddb1c7f3ddac9a769db3e7dde0 (diff)
Phase 6: settings, saves, localization parity (M6)
Diffstat (limited to 'web/src/lib/ui/menus')
-rw-r--r--web/src/lib/ui/menus/AddCharacterMenu.svelte31
-rw-r--r--web/src/lib/ui/menus/RemoveCharacterMenu.svelte30
-rw-r--r--web/src/lib/ui/menus/SaveCharacterMenu.svelte177
-rw-r--r--web/src/lib/ui/menus/SaveCharacterModalMenu.svelte148
-rw-r--r--web/src/lib/ui/menus/SaveMenu.svelte127
-rw-r--r--web/src/lib/ui/menus/SaveModalMenu.svelte146
-rw-r--r--web/src/lib/ui/menus/SelectScenarioMenu.svelte20
-rw-r--r--web/src/lib/ui/menus/SettingsMenu.svelte417
8 files changed, 1066 insertions, 30 deletions
diff --git a/web/src/lib/ui/menus/AddCharacterMenu.svelte b/web/src/lib/ui/menus/AddCharacterMenu.svelte
index 20a5ca7..8383f13 100644
--- a/web/src/lib/ui/menus/AddCharacterMenu.svelte
+++ b/web/src/lib/ui/menus/AddCharacterMenu.svelte
@@ -10,6 +10,7 @@
import { classColor, classIcon } from '$lib/game/art';
import { t } from '$lib/i18n';
import Menu from '../Menu.svelte';
+ import SaveCharacterMenu from './SaveCharacterMenu.svelte';
let {
session,
@@ -56,6 +57,8 @@
(campaignData ?? []).filter((c) => !c.hidden || q.includes(c.name.toLowerCase()))
);
+ let charsOpen = $state(false);
+
function pick(cls: ClassData) {
if (!$player) return;
session.command('addCharacter', { id: cls.id, edition: cls.edition, level });
@@ -93,4 +96,32 @@
</ul>
{/if}
{/if}
+
+ <!-- Character saves (the reference `SaveCharacterMenu` entry). -->
+ <button class="saveentry" onclick={() => (charsOpen = true)}>
+ {t('loadOrSaveCharacters')}
+ </button>
</Menu>
+
+{#if charsOpen}
+ <SaveCharacterMenu {session} bind:open={charsOpen} />
+{/if}
+
+<style>
+ .saveentry {
+ display: block;
+ width: calc(100% - 24px);
+ margin: 8px 12px 4px;
+ padding: 6px 12px;
+ font-size: 13px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.12);
+ color: inherit;
+ cursor: pointer;
+ text-align: left;
+ }
+ .saveentry:hover {
+ background: rgba(255, 255, 255, 0.25);
+ }
+</style>
diff --git a/web/src/lib/ui/menus/RemoveCharacterMenu.svelte b/web/src/lib/ui/menus/RemoveCharacterMenu.svelte
index bb7e970..bdd9b8b 100644
--- a/web/src/lib/ui/menus/RemoveCharacterMenu.svelte
+++ b/web/src/lib/ui/menus/RemoveCharacterMenu.svelte
@@ -7,6 +7,7 @@
import { isCharacter } from '$lib/protocol/types';
import { t } from '$lib/i18n';
import Menu from '../Menu.svelte';
+ import SaveCharacterMenu from './SaveCharacterMenu.svelte';
let {
session,
@@ -20,6 +21,7 @@
const player = session.player;
let selected = $state<Set<string>>(new Set());
+ let charsOpen = $state(false);
// Default to selecting every current character.
$effect(() => {
@@ -83,4 +85,32 @@
</button>
</div>
{/if}
+
+ <!-- Character saves (the reference `SaveCharacterMenu` entry). -->
+ <button class="saveentry" onclick={() => (charsOpen = true)}>
+ {t('loadOrSaveCharacters')}
+ </button>
</Menu>
+
+{#if charsOpen}
+ <SaveCharacterMenu {session} bind:open={charsOpen} />
+{/if}
+
+<style>
+ .saveentry {
+ display: block;
+ width: calc(100% - 24px);
+ margin: 8px 12px 4px;
+ padding: 6px 12px;
+ font-size: 13px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.12);
+ color: inherit;
+ cursor: pointer;
+ text-align: left;
+ }
+ .saveentry:hover {
+ background: rgba(255, 255, 255, 0.25);
+ }
+</style>
diff --git a/web/src/lib/ui/menus/SaveCharacterMenu.svelte b/web/src/lib/ui/menus/SaveCharacterMenu.svelte
new file mode 100644
index 0000000..c237b8a
--- /dev/null
+++ b/web/src/lib/ui/menus/SaveCharacterMenu.svelte
@@ -0,0 +1,177 @@
+<!--
+ Character saves (the reference `SaveCharacterMenu`, Phase 6):
+
+ - "Add new Save:" — one class icon per character in the current list;
+ tapping opens the modal in save-only mode with a suggested name
+ (display name + the next free number, the reference numbering).
+ - "Load Character:" — the stored character saves, each with its class
+ icon; tapping opens the modal with Load / Delete.
+
+ As with game-state saves, the content lives on the server only; the
+ messages are `saveCharacter` / `loadCharacterSave` / `deleteCharacterSave`
+ (player-gated). Loading restores the character's identity (level /
+ display / perks) with a fresh battle state — the reference
+ `CharacterState.fromSave`.
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import { t } from '$lib/i18n';
+ import { serverSettings } from '$lib/settings';
+ import { isCharacter, type CharacterItem } from '$lib/protocol/types';
+ import { classIcon } from '$lib/game/art';
+ import Menu from '../Menu.svelte';
+ import SaveCharacterModalMenu from './SaveCharacterModalMenu.svelte';
+
+ let {
+ session,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ open?: boolean;
+ } = $props();
+
+ const gameState = session.state;
+ const player = session.player;
+ const ss = serverSettings;
+
+ /** The characters in the current list. */
+ const characters = $derived.by((): CharacterItem[] =>
+ ($gameState?.currentList ?? []).filter((i): i is CharacterItem => isCharacter(i))
+ );
+
+ /**
+ * The suggested name for a character (the reference `SaveCharacterMenu`):
+ * its display name plus the next number among the existing saves whose
+ * name starts with that display name (no number when it is the first).
+ */
+ function suggestedName(char: CharacterItem): string {
+ const display = char.characterState.display || char.characterClass;
+ let nr = 1;
+ for (const s of $ss?.characterSaves ?? []) {
+ if (s.name.startsWith(display)) nr++;
+ }
+ return display + (nr > 1 ? nr.toString() : '');
+ }
+
+ let modal = $state<{ name: string; saveId: string; characterId: string | null } | null>(
+ null
+ );
+ let modalOpen = $state(false);
+
+ function openFor(char: CharacterItem) {
+ const name = suggestedName(char);
+ modal = { name, saveId: `${name}\n${char.id}`, characterId: char.id };
+ modalOpen = true;
+ }
+
+ function openExisting(name: string, characterId: string) {
+ modal = { name, saveId: `${name}\n${characterId}`, characterId: null };
+ modalOpen = true;
+ }
+</script>
+
+<Menu open={open} title={t('loadSaveDeleteCharacters')}>
+ <div class="sect">{t('addNewSaveLabel')}</div>
+ {#if characters.length > 0}
+ <div class="icons">
+ {#each characters as char (char.id)}
+ <button
+ class="iconbtn"
+ disabled={!$player}
+ aria-label={char.characterState.display || char.characterClass}
+ onclick={() => openFor(char)}
+ >
+ <img src={classIcon(char.characterClass)} alt="" loading="lazy" />
+ </button>
+ {/each}
+ </div>
+ {:else}
+ <p class="empty">{t('noResultsFound')}</p>
+ {/if}
+
+ <div class="sect">{t('loadCharacter')}</div>
+ {#each $ss?.characterSaves ?? [] as s (s.name + s.characterId)}
+ <button class="savebtn" disabled={!$player} onclick={() => openExisting(s.name, s.characterId)}>
+ <img src={classIcon(s.characterId)} alt="" loading="lazy" />
+ {s.name}
+ </button>
+ {/each}
+ {#if $ss != null && ($ss?.characterSaves?.length ?? 0) === 0}
+ <p class="empty">{t('noResultsFound')}</p>
+ {/if}
+</Menu>
+
+{#if modalOpen && modal}
+ {@const m = modal}
+ <SaveCharacterModalMenu
+ {session}
+ name={m.name}
+ saveId={m.saveId}
+ characterId={m.characterId}
+ bind:open={modalOpen}
+ />
+{/if}
+
+<style>
+ .sect {
+ padding: 8px 12px 4px;
+ font-size: 14px;
+ font-weight: 600;
+ }
+ .icons {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 4px;
+ padding: 0 12px 4px;
+ }
+ .iconbtn {
+ width: 36px;
+ height: 36px;
+ padding: 0;
+ border: none;
+ border-radius: 4px;
+ background: none;
+ cursor: pointer;
+ }
+ .iconbtn:disabled {
+ opacity: 0.4;
+ cursor: default;
+ }
+ .iconbtn img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+ }
+ .savebtn {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ width: calc(100% - 24px);
+ margin: 4px 12px;
+ padding: 6px 8px;
+ font-size: 14px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(127, 127, 127, 0.15);
+ color: inherit;
+ cursor: pointer;
+ text-align: left;
+ }
+ .savebtn:hover:not(:disabled) {
+ background: rgba(127, 127, 127, 0.3);
+ }
+ .savebtn:disabled {
+ opacity: 0.4;
+ cursor: default;
+ }
+ .savebtn img {
+ width: 24px;
+ height: 24px;
+ object-fit: contain;
+ }
+ .empty {
+ padding: 4px 12px;
+ opacity: 0.7;
+ font-size: 13px;
+ }
+</style>
diff --git a/web/src/lib/ui/menus/SaveCharacterModalMenu.svelte b/web/src/lib/ui/menus/SaveCharacterModalMenu.svelte
new file mode 100644
index 0000000..2e74606
--- /dev/null
+++ b/web/src/lib/ui/menus/SaveCharacterModalMenu.svelte
@@ -0,0 +1,148 @@
+<!--
+ The character-save modal (the reference `SaveCharacterModalMenu`,
+ Phase 6). Button visibility follows the reference:
+ - **Load** — from an existing entry: `loadCharacterSave(saveId)`.
+ - **Save** — only from the "Add new Save" path (a live character was
+ passed in): when the name changed, the old slot is deleted first
+ (`deleteCharacterSave`) before `saveCharacter` stores the character
+ (the reference does `deleteCharacterSave + saveCharacterState`).
+ - **Delete** — from an existing entry: `deleteCharacterSave(saveId)`.
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import { t } from '$lib/i18n';
+
+ let {
+ session,
+ name,
+ saveId,
+ characterId = null,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ /** The original (list) name of the save. */
+ name: string;
+ /** The full save id `"$name\n$characterId"`. */
+ saveId: string;
+ /** The live character to save (the "Add new Save" path); null from a list entry. */
+ characterId?: string | null;
+ open?: boolean;
+ } = $props();
+
+ let newName = $state(name);
+
+ function finish() {
+ open = false;
+ }
+
+ function doLoad() {
+ session.loadCharacterSave(saveId);
+ finish();
+ }
+
+ function doSave() {
+ const trimmed = newName.trim();
+ if (!trimmed || characterId == null) return;
+ if (trimmed !== name) session.deleteCharacterSave(saveId);
+ session.saveCharacter(trimmed, characterId);
+ finish();
+ }
+
+ function doDelete() {
+ session.deleteCharacterSave(saveId);
+ finish();
+ }
+</script>
+
+<svelte:window
+ onkeydown={(e) => {
+ // Only acts while the modal is open.
+ if (open && e.key === 'Escape') finish();
+ }}
+/>
+{#if open}
+ <div class="modal" role="dialog" aria-modal="true" aria-label={t('setSaveName')}>
+ <div class="modal__scrim" aria-hidden="true" onclick={finish}></div>
+ <div class="modal__card">
+ <div class="modal__buttons">
+ {#if characterId == null}
+ <button onclick={doLoad}>{t('loadButton')}</button>
+ {/if}
+ {#if characterId != null}
+ <button class="modal__save" disabled={!newName.trim()} onclick={doSave}>
+ {t('saveButton')}
+ </button>
+ {/if}
+ {#if characterId == null}
+ <button class="modal__delete" onclick={doDelete}>{t('deleteButton')}</button>
+ {/if}
+ </div>
+ <div class="modal__name">
+ <label for="charsavename">{t('setSaveName')}</label>
+ <input id="charsavename" type="text" bind:value={newName} />
+ </div>
+ </div>
+ </div>
+{/if}
+
+<style>
+ .modal {
+ position: fixed;
+ inset: 0;
+ z-index: 200;
+ display: grid;
+ place-items: center;
+ }
+ .modal__scrim {
+ position: absolute;
+ inset: 0;
+ background: #000000aa;
+ }
+ .modal__card {
+ position: relative;
+ width: min(320px, calc(100vw - 24px));
+ padding: 14px;
+ background: var(--dialog-bg);
+ color: var(--fg);
+ border-radius: 8px;
+ box-shadow: 0 4px 24px #00000080;
+ }
+ .modal__buttons {
+ display: flex;
+ justify-content: center;
+ gap: 10px;
+ }
+ .modal__buttons button {
+ flex: 1;
+ padding: 8px 4px;
+ font-size: 14px;
+ border: 2px solid #4a7dff;
+ border-radius: 4px;
+ background: none;
+ color: inherit;
+ cursor: pointer;
+ }
+ .modal__buttons button:hover:not(:disabled) {
+ background: rgba(74, 125, 255, 0.2);
+ }
+ .modal__buttons button:disabled {
+ opacity: 0.4;
+ cursor: default;
+ }
+ .modal__name {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 6px;
+ margin-top: 20px;
+ }
+ .modal__name input {
+ width: 200px;
+ padding: 6px 8px;
+ font-size: 14px;
+ border: 1px solid currentColor;
+ border-radius: 4px;
+ background: transparent;
+ color: inherit;
+ }
+</style>
diff --git a/web/src/lib/ui/menus/SaveMenu.svelte b/web/src/lib/ui/menus/SaveMenu.svelte
new file mode 100644
index 0000000..94d1cc1
--- /dev/null
+++ b/web/src/lib/ui/menus/SaveMenu.svelte
@@ -0,0 +1,127 @@
+<!--
+ Save states (the reference `SaveMenu`, Phase 6): the named game-state
+ saves plus "Add new Save". Tapping an entry opens the
+ {@link SaveModalMenu} with Load / Save / Delete and a rename field.
+
+ The save *content* lives on the server only (PLAN.md section 4 — it never
+ crosses the wire); this menu works with names via the `save` /
+ `loadSave` / `deleteSave` messages, which are player-gated on the server
+ (loading a save is an undoable action, so it advances the command index).
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import { t } from '$lib/i18n';
+ import { serverSettings } from '$lib/settings';
+ import Menu from '../Menu.svelte';
+ import SaveModalMenu from './SaveModalMenu.svelte';
+
+ let {
+ session,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ open?: boolean;
+ } = $props();
+
+ const gameState = session.state;
+ const player = session.player;
+ const ss = serverSettings;
+
+ /**
+ * The suggested name (the reference `getSuggestedSaveName`): the campaign
+ * name plus the next free number (no space, as in the reference).
+ */
+ const suggestedName = $derived.by(() => {
+ const saves = $ss?.saves ?? [];
+ const campaign = $gameState?.currentCampaign ?? '';
+ let nr = saves.length + 1;
+ while (saves.includes(campaign + nr.toString())) nr++;
+ return campaign + nr.toString();
+ });
+
+ let modalName = $state<string | null>(null);
+ let modalSaveOnly = $state(false);
+ let modalOpen = $state(false);
+
+ function openModal(name: string, saveOnly: boolean) {
+ modalName = name;
+ modalSaveOnly = saveOnly;
+ modalOpen = true;
+ }
+</script>
+
+<Menu open={open} title={t('loadAddDeleteSaves')}>
+ <p class="note">{t('saveStateNote')}</p>
+
+ {#if $player}
+ <button class="pill" onclick={() => openModal(suggestedName, true)}>
+ {t('addNewSave')}
+ </button>
+ {/if}
+
+ {#each $ss?.saves ?? [] as name (name)}
+ <button class="savebtn" disabled={!$player} onclick={() => openModal(name, false)}>
+ {name}
+ </button>
+ {/each}
+ {#if $ss != null && ($ss?.saves?.length ?? 0) === 0}
+ <p class="empty">{t('noResultsFound')}</p>
+ {/if}
+</Menu>
+
+{#if modalOpen && modalName != null}
+ <SaveModalMenu
+ {session}
+ name={modalName}
+ saveOnly={modalSaveOnly}
+ bind:open={modalOpen}
+ />
+{/if}
+
+<style>
+ .note {
+ margin: 0 0 12px;
+ padding: 0 12px;
+ font-size: 13px;
+ opacity: 0.85;
+ }
+ .pill {
+ margin: 0 12px 8px;
+ padding: 6px 12px;
+ font-size: 13px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.12);
+ color: inherit;
+ cursor: pointer;
+ text-align: left;
+ }
+ .pill:hover {
+ background: rgba(255, 255, 255, 0.25);
+ }
+ .savebtn {
+ display: block;
+ width: calc(100% - 24px);
+ margin: 0 12px 4px;
+ padding: 8px 12px;
+ font-size: 14px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(127, 127, 127, 0.15);
+ color: inherit;
+ cursor: pointer;
+ text-align: left;
+ }
+ .savebtn:hover:not(:disabled) {
+ background: rgba(127, 127, 127, 0.3);
+ }
+ .savebtn:disabled {
+ opacity: 0.4;
+ cursor: default;
+ }
+ .empty {
+ padding: 12px;
+ opacity: 0.7;
+ font-size: 13px;
+ }
+</style>
diff --git a/web/src/lib/ui/menus/SaveModalMenu.svelte b/web/src/lib/ui/menus/SaveModalMenu.svelte
new file mode 100644
index 0000000..07d9f1e
--- /dev/null
+++ b/web/src/lib/ui/menus/SaveModalMenu.svelte
@@ -0,0 +1,146 @@
+<!--
+ The save-state modal (the reference `SaveModalMenu`, Phase 6): Load /
+ Save / Delete for one named save plus a rename field.
+
+ Reference button behaviour, ported:
+ - **Load** — `loadSave` (the server runs `LoadSaveCommand`, an undoable
+ action).
+ - **Save** — when the name was changed, the old slot is deleted first
+ (`deleteSave`) before `save` stores the state under the new name (the
+ reference does `deleteSave(old) + saveState(new)`; same end state, one
+ fewer round-trip when the name is unchanged).
+ - **Delete** — `deleteSave`.
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import { t } from '$lib/i18n';
+
+ let {
+ session,
+ name,
+ saveOnly = false,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ /** The original (list) name of the save. */
+ name: string;
+ /** True from "Add new Save": only Save (no Load/Delete yet). */
+ saveOnly?: boolean;
+ open?: boolean;
+ } = $props();
+
+ let newName = $state(name);
+
+ function finish() {
+ open = false;
+ }
+
+ function doLoad() {
+ session.loadSave(name);
+ finish();
+ }
+
+ function doSave() {
+ const trimmed = newName.trim();
+ if (!trimmed) return;
+ if (trimmed !== name) session.deleteSave(name);
+ session.save(trimmed);
+ finish();
+ }
+
+ function doDelete() {
+ session.deleteSave(name);
+ finish();
+ }
+</script>
+
+<svelte:window
+ onkeydown={(e) => {
+ // Only acts while the modal is open.
+ if (open && e.key === 'Escape') finish();
+ }}
+/>
+{#if open}
+ <div class="modal" role="dialog" aria-modal="true" aria-label={t('setSaveName')}>
+ <div class="modal__scrim" aria-hidden="true" onclick={finish}></div>
+ <div class="modal__card">
+ <div class="modal__buttons">
+ {#if !saveOnly}
+ <button onclick={doLoad}>{t('loadButton')}</button>
+ {/if}
+ <button class="modal__save" disabled={!newName.trim()} onclick={doSave}>
+ {t('saveButton')}
+ </button>
+ {#if !saveOnly}
+ <button class="modal__delete" onclick={doDelete}>{t('deleteButton')}</button>
+ {/if}
+ </div>
+ <div class="modal__name">
+ <label for="savename">{t('setSaveName')}</label>
+ <input id="savename" type="text" bind:value={newName} />
+ </div>
+ </div>
+ </div>
+{/if}
+
+<style>
+ .modal {
+ position: fixed;
+ inset: 0;
+ z-index: 200;
+ display: grid;
+ place-items: center;
+ }
+ .modal__scrim {
+ position: absolute;
+ inset: 0;
+ background: #000000aa;
+ }
+ .modal__card {
+ position: relative;
+ width: min(320px, calc(100vw - 24px));
+ padding: 14px;
+ background: var(--dialog-bg);
+ color: var(--fg);
+ border-radius: 8px;
+ box-shadow: 0 4px 24px #00000080;
+ }
+ .modal__buttons {
+ display: flex;
+ justify-content: center;
+ gap: 10px;
+ }
+ .modal__buttons button {
+ flex: 1;
+ padding: 8px 4px;
+ font-size: 14px;
+ border: 2px solid #4a7dff;
+ border-radius: 4px;
+ background: none;
+ color: inherit;
+ cursor: pointer;
+ }
+ .modal__buttons button:hover:not(:disabled) {
+ background: rgba(74, 125, 255, 0.2);
+ }
+ .modal__buttons button:disabled {
+ opacity: 0.4;
+ cursor: default;
+ }
+ .modal__name {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 6px;
+ margin-top: 20px;
+ }
+ .modal__name input {
+ width: 200px;
+ padding: 6px 8px;
+ font-size: 14px;
+ border: 1px solid currentColor;
+ border-radius: 4px;
+ background: transparent;
+ color: inherit;
+ }
+</style>
diff --git a/web/src/lib/ui/menus/SelectScenarioMenu.svelte b/web/src/lib/ui/menus/SelectScenarioMenu.svelte
index 14add41..3c0d6cd 100644
--- a/web/src/lib/ui/menus/SelectScenarioMenu.svelte
+++ b/web/src/lib/ui/menus/SelectScenarioMenu.svelte
@@ -6,7 +6,9 @@
<script lang="ts">
import type { GameSession } from '$lib/state/session';
import { gameData, type CampaignData } from '$lib/data/gameData';
+ import { isCustomCampaign } from '$lib/game/rules';
import { t } from '$lib/i18n';
+ import { clientSettings } from '$lib/settings';
import Menu from '../Menu.svelte';
let {
@@ -75,6 +77,20 @@
session.command('setScenario', { scenario, section: false });
open = false;
}
+
+ // Phase 6 display gates (the reference `scenario_tile` / campaign list):
+ // `showScenarioNames` — full name vs. the first word; `showCustomContent`
+ // — custom campaigns are hidden from the picker.
+ const visibleCampaigns = $derived(
+ (campaigns ?? []).filter(
+ (c) => $clientSettings.showCustomContent || !isCustomCampaign(c)
+ )
+ );
+
+ /** The scenario tile's label (the reference `scenario_tile`). */
+ function scenarioTitle(name: string): string {
+ return $clientSettings.showScenarioNames ? name : name.split(' ')[0];
+ }
</script>
<Menu open={open} title={t('menuSetScenario')}>
@@ -82,7 +98,7 @@
<p style="padding: 12px; opacity: 0.8">{error}</p>
{:else if campaigns}
<div class="campaignbtns">
- {#each campaigns as c (c)}
+ {#each visibleCampaigns as c (c)}
<button class:button--active={c === campaign} onclick={() => (campaign = c)}>
{c}
</button>
@@ -96,7 +112,7 @@
{#each data.scenarios as s (s.name)}
<li>
<button class="menulist__item" disabled={!$player} onclick={() => pickScenario(s.name)}>
- {s.name}
+ {scenarioTitle(s.name)}
</button>
</li>
{/each}
diff --git a/web/src/lib/ui/menus/SettingsMenu.svelte b/web/src/lib/ui/menus/SettingsMenu.svelte
index 4a6699a..07dc1c3 100644
--- a/web/src/lib/ui/menus/SettingsMenu.svelte
+++ b/web/src/lib/ui/menus/SettingsMenu.svelte
@@ -1,16 +1,40 @@
<!--
- Settings (the reference `SettingsMenu`): the visual style theme and the
- UI language (client-only preferences), plus the special-unlock controls
- (the reference `settingsClearUnlocked` / `settingsUnlockSpecials`
- entries, which are game commands).
+ Settings (the reference `SettingsMenu`, Phase 6 rebuild).
+
+ The reference keeps one big settings list; the web version splits it per
+ PLAN.md section 4:
+ - **server-side** settings (game-relevant) live on the server and are
+ edited with `session.setSetting(...)` — the server validates, stores,
+ persists and *broadcasts* the change, so every screen updates. They are
+ disabled on this screen unless the session is a player (the server
+ forbids them for spectators).
+ - **client-side** settings (pure UI per browser) live in localStorage
+ (`$lib/settings.ts` → `clientSettings`) and are always editable.
+
+ Reference entries without a web counterpart (documented, omitted):
+ `settingsDarkMode` (the style themes replace dark mode),
+ `settingsSoftNumpad` (browsers have keyboards), `settingsShowSections`
+ (no section rendering in the web main view), `settingsHealthWheel`
+ (no health wheel in the web status menu) and the network section
+ (no ad-hoc network UI — the server is the session).
-->
<script lang="ts">
import type { GameSession } from '$lib/state/session';
import { availableLocales, locale, type Locale } from '$lib/i18n';
- import { styleTheme, type StyleTheme } from '$lib/settings';
import { t } from '$lib/i18n';
+ import {
+ clientSettings,
+ setClientSetting,
+ serverSettings,
+ styleTheme,
+ styleIndex,
+ type ClientSettings,
+ type PowerMode,
+ type StyleTheme
+ } from '$lib/settings';
import Menu from '../Menu.svelte';
import SpecialUnlocksMenu from './SpecialUnlocksMenu.svelte';
+ import SaveMenu from './SaveMenu.svelte';
let {
session,
@@ -23,45 +47,340 @@
const player = session.player;
const gameState = session.state;
- const THEMES: { id: StyleTheme; label: string }[] = [
- { id: 'frosthaven', label: 'Frosthaven' },
- { id: 'gloomhaven', label: 'Gloomhaven' },
- { id: 'original', label: 'Original' }
+ // Native language names (the reference `SettingsMenu._kLocales`).
+ const LOCALES: { code: Locale; native: string }[] = [
+ { code: 'en', native: 'English' },
+ { code: 'de', native: 'Deutsch' },
+ { code: 'fr', native: 'Français' },
+ { code: 'es', native: 'Español' },
+ { code: 'pl', native: 'Polski' },
+ { code: 'ko', native: '한국어' },
+ { code: 'ru', native: 'Русский' },
+ { code: 'zh', native: '中文' },
+ { code: 'zh_Hant', native: '中文 (繁體)' },
+ { code: 'th', native: 'ภาษาไทย' }
+ ];
+
+ // The reference menu shows two style radios; the shared `Style` enum (and
+ // the Phase 3 web themes) has three, so the web offers all three.
+ const STYLES: { id: StyleTheme; label: string }[] = [
+ { id: 'frosthaven', label: 'styleFrosthaven' },
+ { id: 'gloomhaven', label: 'styleGloomhaven' },
+ { id: 'original', label: 'styleOriginal' }
];
let unlocksOpen = $state(false);
+ let saveOpen = $state(false);
+ let powerInfoOpen = $state(false);
+
+ /** The server settings payload (null before the first welcome). */
+ const ss = serverSettings;
+
+ /** Change a server-side setting (players only — the server enforces it). */
+ function srv(name: string, value: boolean | number | string) {
+ if (!$player) return;
+ session.setSetting(name, value);
+ }
+
+ /** Toggle a server-side boolean from its current value. */
+ function srvToggle(name: string, current: boolean) {
+ srv(name, !current);
+ }
+
+ /** Change a client-side (this browser's) setting. */
+ function cli<K extends keyof ClientSettings>(name: K, value: ClientSettings[K]) {
+ setClientSetting(name, value);
+ }
+
+ function pickLocale(l: Locale) {
+ locale.set(l); // this browser's UI strings
+ srv('locale', l); // the shared command-description locale
+ }
+
+ function toggleFullscreen(v: boolean) {
+ cli('fullScreen', v);
+ // The browser only honours fullscreen changes from a user gesture —
+ // this checkbox is one (the reference `settings.setFullscreen`).
+ const el = document.documentElement;
+ if (v) {
+ el.requestFullscreen?.().catch(() => {});
+ } else if (document.fullscreenElement) {
+ document.exitFullscreen().catch(() => {});
+ }
+ }
+
+ function pickStyle(theme: StyleTheme) {
+ srv('style', styleIndex(theme));
+ }
</script>
<Menu open={open} title={t('menuSettings')}>
<div class="settingsrow">
- <label for="theme">{t('menuSettings')}</label>
+ <label for="settings-language">{t('settingsLanguage')}</label>
<select
- id="theme"
+ id="settings-language"
class="search"
style="margin: 0; width: auto"
- value={$styleTheme}
- onchange={(e) => styleTheme.set(e.currentTarget.value as StyleTheme)}
+ value={$locale}
+ onchange={(e) => pickLocale(e.currentTarget.value as Locale)}
>
- {#each THEMES as th (th.id)}
- <option value={th.id}>{th.label}</option>
+ {#each LOCALES as l (l.code)}
+ <option value={l.code}>{l.native}</option>
{/each}
</select>
</div>
- <div class="settingsrow">
- <label for="locale">Language</label>
- <select
- id="locale"
- class="search"
- style="margin: 0; width: auto"
- value={$locale}
- onchange={(e) => locale.set(e.currentTarget.value as Locale)}
- >
- {#each availableLocales as l (l)}
- <option value={l}>{l}</option>
- {/each}
- </select>
+ {#if $player}
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$ss?.noInit ?? false}
+ onchange={() => srvToggle('noInit', $ss?.noInit ?? false)}
+ />
+ {t('settingsNoInit')}
+ </label>
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$ss?.expireConditions ?? false}
+ onchange={() => srvToggle('expireConditions', $ss?.expireConditions ?? false)}
+ />
+ {t('settingsExpireConditions')}
+ </label>
+ <label class="settingsrow">
+ <!-- The server runs `TrackStandeesCommand` for this one (reference). -->
+ <input
+ type="checkbox"
+ checked={$ss?.noStandees ?? false}
+ onchange={() => srvToggle('noStandees', $ss?.noStandees ?? false)}
+ />
+ {t('settingsNoStandees')}
+ </label>
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$ss?.autoAddStandees ?? true}
+ onchange={() => srvToggle('autoAddStandees', $ss?.autoAddStandees ?? true)}
+ />
+ {t('settingsAutoAddStandees')}
+ </label>
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$ss?.autoAddSpawns ?? true}
+ onchange={() => srvToggle('autoAddSpawns', $ss?.autoAddSpawns ?? true)}
+ />
+ {t('settingsAutoAddSpawns')}
+ </label>
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$ss?.randomStandees ?? false}
+ onchange={() => srvToggle('randomStandees', $ss?.randomStandees ?? false)}
+ />
+ {t('settingsRandomStandees')}
+ </label>
+ {/if}
+
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$clientSettings.noCalculation}
+ onchange={(e) => cli('noCalculation', e.currentTarget.checked)}
+ />
+ {t('settingsNoCalculations')}
+ </label>
+
+ {#if $player}
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$ss?.hideLootDeck ?? false}
+ onchange={() => srvToggle('hideLootDeck', $ss?.hideLootDeck ?? false)}
+ />
+ {t('settingsHideLootDeck')}
+ </label>
+ {/if}
+
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$clientSettings.shimmer}
+ onchange={(e) => cli('shimmer', e.currentTarget.checked)}
+ />
+ {t('settingsShimmer')}
+ </label>
+
+ <div class="settingsrow settingsrow--title">
+ {t('settingsPowerModeLabel')}
+ <button class="info" aria-label="Info" onclick={() => (powerInfoOpen = !powerInfoOpen)}>
+ ⓘ
+ </button>
</div>
+ {#if powerInfoOpen}
+ <p class="note">{t('settingsPowerModeInfo')}</p>
+ {/if}
+ <label class="settingsrow">
+ <input
+ type="radio"
+ name="powerMode"
+ checked={$clientSettings.powerMode === 'normal'}
+ onchange={() => cli('powerMode', 'normal' as PowerMode)}
+ />
+ {t('powerModeNormal')}
+ </label>
+ <label class="settingsrow">
+ <input
+ type="radio"
+ name="powerMode"
+ checked={$clientSettings.powerMode === 'dimWhenIdle'}
+ onchange={() => cli('powerMode', 'dimWhenIdle' as PowerMode)}
+ />
+ {t('powerModeDimWhenIdle')}
+ </label>
+ <label class="settingsrow">
+ <input
+ type="radio"
+ name="powerMode"
+ checked={$clientSettings.powerMode === 'reducePower'}
+ onchange={() => cli('powerMode', 'reducePower' as PowerMode)}
+ />
+ {t('settingsReducePower')}
+ </label>
+
+ {#if $player}
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$ss?.fhHazTerrainCalcInOGGloom ?? true}
+ onchange={() => srvToggle('fhHazTerrainCalcInOGGloom', $ss?.fhHazTerrainCalcInOGGloom ?? true)}
+ />
+ {t('settingsFhHazTerrainCalc')}
+ </label>
+ {/if}
+
+ {#if $player}
+ <label class="settingsrow">
+ <!-- A game command (`setAllyDeckInOgGloom`), like the reference. -->
+ <input
+ type="checkbox"
+ checked={$gameState?.allyDeckInOGGloom ?? false}
+ onchange={() =>
+ session.command('setAllyDeckInOgGloom', {
+ set: !($gameState?.allyDeckInOGGloom ?? false)
+ })}
+ />
+ {t('settingsAllyDeckOGGloom')}
+ </label>
+ {/if}
+
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$clientSettings.showScenarioNames}
+ onchange={(e) => cli('showScenarioNames', e.currentTarget.checked)}
+ />
+ {t('settingsShowScenarioNames')}
+ </label>
+
+ {#if $player}
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$ss?.showBattleGoalReminder ?? true}
+ onchange={() => srvToggle('showBattleGoalReminder', $ss?.showBattleGoalReminder ?? true)}
+ />
+ {t('settingsShowBattleGoalReminder')}
+ </label>
+ {/if}
+
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$clientSettings.showCustomContent}
+ onchange={(e) => cli('showCustomContent', e.currentTarget.checked)}
+ />
+ {t('settingsShowCustomContent')}
+ </label>
+
+ {#if $player}
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$ss?.showReminders ?? true}
+ onchange={() => srvToggle('showReminders', $ss?.showReminders ?? true)}
+ />
+ {t('settingsShowReminders')}
+ </label>
+ <label class="settingsrow">
+ <!-- Turning the shared decks off also hides the character AMDs
+ (reference mutual gating). -->
+ <input
+ type="checkbox"
+ checked={$ss?.showAmdDeck ?? true}
+ onchange={(e) => {
+ srv('showAmdDeck', e.currentTarget.checked);
+ if (!e.currentTarget.checked) cli('showCharacterAMD', false);
+ }}
+ />
+ {t('settingsShowAmdDeck')}
+ </label>
+ {/if}
+
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$clientSettings.showCharacterAMD}
+ onchange={(e) => {
+ cli('showCharacterAMD', e.currentTarget.checked);
+ if (e.currentTarget.checked && $player) srv('showAmdDeck', true);
+ }}
+ />
+ {t('settingsShowCharacterAmd')}
+ </label>
+
+ <label class="settingsrow">
+ <input
+ type="checkbox"
+ checked={$clientSettings.fullScreen}
+ onchange={(e) => toggleFullscreen(e.currentTarget.checked)}
+ />
+ {t('settingsFullscreen')}
+ </label>
+
+ <div class="settingsrow settingsrow--label">{t('settingsMainListScaling')}</div>
+ <input
+ type="range"
+ min={0.2}
+ max={3.0}
+ step={0.05}
+ value={$clientSettings.mainListScaling}
+ onchange={(e) => cli('mainListScaling', Number(e.currentTarget.value))}
+ />
+ <div class="settingsrow settingsrow--label">{t('settingsAppBarScaling')}</div>
+ <input
+ type="range"
+ min={0.8}
+ max={3.0}
+ step={0.05}
+ value={$clientSettings.barScaling}
+ onchange={(e) => cli('barScaling', Number(e.currentTarget.value))}
+ />
+
+ {#if $player}
+ <div class="settingsrow settingsrow--title">{t('settingsStyleLabel')}</div>
+ {#each STYLES as st (st.id)}
+ <label class="settingsrow">
+ <input
+ type="radio"
+ name="style"
+ checked={$styleTheme === st.id}
+ onchange={() => pickStyle(st.id)}
+ />
+ {t(st.label)}
+ </label>
+ {/each}
+ {/if}
<div class="settingsrow settingsrow--btn">
<button
@@ -77,16 +396,58 @@
{t('settingsUnlockSpecials')}
</button>
</div>
+ <div class="settingsrow settingsrow--btn">
+ {#if $player}
+ <button class="pill" onclick={() => (saveOpen = true)}>
+ {t('settingsLoadSaveState')}
+ </button>
+ {/if}
+ </div>
</Menu>
{#if unlocksOpen}
<SpecialUnlocksMenu {session} bind:open={unlocksOpen} />
{/if}
+{#if saveOpen}
+ <SaveMenu {session} bind:open={saveOpen} />
+{/if}
+
<style>
+ /* The shared .settingsrow is space-between; this menu packs its rows
+ left (label + control together). */
+ .settingsrow {
+ justify-content: flex-start;
+ gap: 8px;
+ }
+ .settingsrow--title {
+ font-weight: 600;
+ }
+ .settingsrow--label {
+ padding-left: 16px;
+ margin-top: 10px;
+ }
.settingsrow--btn {
justify-content: flex-start;
}
+ .info {
+ margin-left: 8px;
+ padding: 2px 8px;
+ font-size: 12px;
+ border: 1px solid currentColor;
+ border-radius: 50%;
+ background: none;
+ color: inherit;
+ cursor: pointer;
+ }
+ .note {
+ margin: 0 0 8px;
+ padding: 8px 12px;
+ font-size: 13px;
+ opacity: 0.85;
+ background: rgba(127, 127, 127, 0.15);
+ border-radius: 4px;
+ }
.pill {
padding: 6px 12px;
font-size: 13px;