aboutsummaryrefslogtreecommitdiff
path: root/src/lib/sections/Inventories.svelte
blob: 8be68537e05c627dcfe942ec56a96d52461a3780 (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
<script lang="ts">
	import Inventory from '$lib/minecraft/Inventory.svelte'
	import { fade } from 'svelte/transition'
	import { cleanId } from '$lib/utils'
	import { skyblockItemToUrl, type Item } from '$lib/minecraft/inventory'

	export let data
	export let pack

	let displayingInventories: string[] = []
	for (const inventoryName in data.member.inventories)
		if (inventoryName !== 'armor') displayingInventories.push(inventoryName)

	let selectedInventoryName: string = displayingInventories[0]

	const inventoryIconMap: Record<string, string | Item> = {
		inventory: {
			id: 'SKYBLOCK_MENU',
			vanillaId: 'nether_star',
			display: { name: 'SkyBlock Menu' },
		},
		ender_chest: 'ender_chest',
		potion_bag: 'potion',
		fishing_bag: 'fishing_rod',
		quiver: 'arrow',
		wardrobe: 'leather_chestplate',
	}
</script>

<div id="inventory-tabs">
	{#each displayingInventories as inventoryName}
		<button
			class="inventory-tab"
			class:inventory-tab-active={inventoryName === selectedInventoryName}
			on:click={() => (selectedInventoryName = inventoryName)}
		>
			{#if inventoryName in inventoryIconMap}
				<img
					class="inventory-tab-icon"
					loading="lazy"
					src={skyblockItemToUrl(inventoryIconMap[inventoryName])}
					alt={cleanId(inventoryName)}
				/>
			{/if}
			<span class="inventory-tab-name">{cleanId(inventoryName)}</span>
		</button>
	{/each}
</div>
{#each displayingInventories as inventoryName}
	{#if inventoryName === selectedInventoryName}
		<div id={inventoryName} class="inventory-content">
			<Inventory items={data.member.inventories[inventoryName]} {pack} name={inventoryName} />
		</div>
	{/if}
{/each}

<style>
	#inventory-tabs {
		margin-bottom: 1em;
		overflow: hidden;
		border-radius: 1em;
		max-width: 40em;
		/* box-shadow: 0 0 1em #000; */
	}
	.inventory-tab {
		/* background-color: var(--theme-lighter-background); */
		background-color: rgba(20, 20, 20, 0.4);
		color: var(--theme-main-text);
		border: none;
		border-radius: 0;
		/* padding: 0.8em; */
		cursor: pointer;
		transition-duration: 200ms;
		height: 2.5em;
		vertical-align: middle;
	}
	.inventory-tab-icon {
		height: 1.5em;
		width: 1.5em;
		vertical-align: text-bottom;
		position: relative;
		top: 0.1em;
		image-rendering: crisp-edges;
		image-rendering: pixelated;
	}
	.inventory-tab-name {
		vertical-align: text-top;
	}
	.inventory-tab:hover,
	.inventory-tab-active {
		background-color: rgba(40, 40, 40, 0.9);
	}
</style>