summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/menus/SaveMenu.svelte
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/SaveMenu.svelte
parentd64cf3514e5ff1ddb1c7f3ddac9a769db3e7dde0 (diff)
Phase 6: settings, saves, localization parity (M6)
Diffstat (limited to 'web/src/lib/ui/menus/SaveMenu.svelte')
-rw-r--r--web/src/lib/ui/menus/SaveMenu.svelte127
1 files changed, 127 insertions, 0 deletions
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>