summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/MainMenu.svelte
blob: 59386a299debdee484f45b09001c222a0a84950a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!--
	The slide-out main menu (the reference app's menu drawer): undo/redo,
	action log, scenario setup, character/monster management, and settings.
	Every entry either acts directly (undo/redo) or opens one of the menu
	dialogs owned by the App.
-->
<script lang="ts">
	import type { GameSession } from '$lib/state/session';
	import { shouldShowAlliesDeck } from '$lib/game/rules';
	import { t } from '$lib/i18n';

	export type MenuName =
		| 'scenario'
		| 'section'
		| 'addChar'
		| 'removeChar'
		| 'setLevel'
		| 'addMon'
		| 'removeMon'
		| 'noteRow'
		| 'actionLog'
		| 'settings';

	let {
		session,
		open = $bindable(false),
		onOpenMenu
	}: {
		session: GameSession;
		open?: boolean;
		onOpenMenu: (menu: MenuName) => void;
	} = $props();

	const gameState = session.state;
	const index = session.index;
	const player = session.player;

	function pick(menu: MenuName) {
		open = false;
		onOpenMenu(menu);
	}

	// The ally deck (the reference `MainMenuViewModel.showShowAllyDeck` /
	// `showHideAllyDeck`; the web always shows the AMD deck, so that gate
	// is dropped).
	const showShowAllyDeck = $derived.by(() => {
		const gs = $gameState;
		return gs != null && !gs.showAllyDeck && !shouldShowAlliesDeck(gs);
	});
	const showHideAllyDeck = $derived.by(() => {
		const gs = $gameState;
		return gs != null && gs.showAllyDeck;
	});

	function toggleAllyDeck(show: boolean) {
		if (!$player) return;
		session.command(show ? 'showAllyDeck' : 'hideAllyDeck');
	}
</script>

{#if open}
	<!-- Click-to-close scrim (Escape also closes; not a real control). -->
	<div
		class="scrim"
		aria-hidden="true"
		style="position: fixed; inset: 0; z-index: 39; background: #00000066"
		onclick={() => (open = false)}
	></div>
	<nav class="drawer drawer--open" aria-label="Main menu">
		<div class="drawer__header"></div>
		<div style="padding: 8px 0">
			<div class="statrow" style="padding: 4px 16px">
				<span class="statrow__label" style="opacity: 0.8; font-size: 13px">
					{t('currentCampaign', { campaign: $gameState?.currentCampaign ?? '—' })}
				</span>
			</div>
		</div>

		<button class="drawer__item" disabled={$index <= 0} onclick={() => { open = false; session.undo(); }}>
			{t('undo')}
		</button>
		<button class="drawer__item" onclick={() => { open = false; session.redo(); }}>
			{t('redo')}
		</button>
		<button class="drawer__item" onclick={() => pick('actionLog')}>{t('menuActionLog')}</button>

		<hr class="drawer__divider" />

		<button class="drawer__item" onclick={() => pick('scenario')}>{t('menuSetScenario')}</button>
		<button class="drawer__item" onclick={() => pick('section')}>{t('menuAddSection')}</button>

		<hr class="drawer__divider" />

		<button class="drawer__item" onclick={() => pick('addChar')}>{t('menuAddCharacter')}</button>
		<button class="drawer__item" onclick={() => pick('removeChar')}>{t('menuRemoveCharacters')}</button>
		<button class="drawer__item" onclick={() => pick('setLevel')}>{t('menuSetLevel')}</button>

		<hr class="drawer__divider" />

		<button class="drawer__item" onclick={() => pick('addMon')}>{t('menuAddMonsters')}</button>
		<button class="drawer__item" onclick={() => pick('removeMon')}>{t('menuRemoveMonsters')}</button>
		<button class="drawer__item" onclick={() => pick('noteRow')}>{t('menuAddNoteRow')}</button>
		{#if showShowAllyDeck}
			<button class="drawer__item" disabled={!$player} onclick={() => toggleAllyDeck(true)}>
				{t('menuShowAllyDeck')}
			</button>
		{/if}
		{#if showHideAllyDeck}
			<button class="drawer__item" disabled={!$player} onclick={() => toggleAllyDeck(false)}>
				{t('menuHideAllyDeck')}
			</button>
		{/if}

		<hr class="drawer__divider" />

		<button class="drawer__item" onclick={() => pick('settings')}>{t('menuSettings')}</button>
	</nav>
{/if}