summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/menus/SpecialUnlocksMenu.svelte
blob: e565c331b960f24767e50d34e16f3b9bc21cfb3e (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
<!--
	Special Unlocks (the reference `SpecialUnlocksMenu`): toggles the special
	characters available in the add-character menu (`unlockSpecial`). Locked
	entries show as "???"; the icon is always visible.
-->
<script lang="ts">
	import type { GameSession } from '$lib/state/session';
	import { t } from '$lib/i18n';
	import Menu from '../Menu.svelte';

	/** The unlockable specials (the reference hard-codes this list). */
	const UNLOCKS: { id: string; icon: string }[] = [
		{ id: 'Demons', icon: '/images/demons.png' },
		{ id: 'Merchant-Guild', icon: '/images/merchant-guild.png' },
		{ id: 'Military', icon: '/images/military.png' },
		{ id: 'Bladeswarm', icon: '/images/class-icons/Bladeswarm.png' }
	];

	let {
		session,
		open = $bindable(true)
	}: {
		session: GameSession;
		open?: boolean;
	} = $props();

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

	const unlocked = $derived($gameState?.unlockedClasses ?? []);

	function isEnabled(id: string): boolean {
		return unlocked.includes(id);
	}

	function toggle(id: string) {
		if (!$player) return;
		session.command('unlockSpecial', { id });
	}
</script>

<Menu {open} title={t('specialUnlocks')}>
	<ul class="unlocklist">
		{#each UNLOCKS as u (u.id)}
			<li>
				<label class="unlocklist__item" class:unlocklist__item--disabled={!$player}>
					<input
						type="checkbox"
						checked={isEnabled(u.id)}
						disabled={!$player}
						onchange={() => toggle(u.id)}
					/>
					<img class="unlocklist__icon" src={u.icon} alt="" />
					<span>{isEnabled(u.id) ? u.id : '???'}</span>
				</label>
			</li>
		{/each}
	</ul>
</Menu>

<style>
	.unlocklist {
		list-style: none;
		margin: 0;
		padding: 0;
	}
	.unlocklist__item {
		display: flex;
		align-items: center;
		gap: 10px;
		padding: 8px 4px;
		font-size: 14px;
		cursor: pointer;
	}
	.unlocklist__item--disabled {
		cursor: default;
	}
	.unlocklist__icon {
		width: 40px;
		height: 40px;
		object-fit: contain;
	}
</style>