diff options
Diffstat (limited to 'web/src/lib/ui/menus/SaveCharacterModalMenu.svelte')
| -rw-r--r-- | web/src/lib/ui/menus/SaveCharacterModalMenu.svelte | 148 |
1 files changed, 148 insertions, 0 deletions
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> |
