diff options
Diffstat (limited to 'src/lib/minecraft')
-rw-r--r-- | src/lib/minecraft/Item.svelte | 35 | ||||
-rw-r--r-- | src/lib/minecraft/MinecraftTooltip.svelte | 2 | ||||
-rw-r--r-- | src/lib/minecraft/inventory.ts | 21 |
3 files changed, 51 insertions, 7 deletions
diff --git a/src/lib/minecraft/Item.svelte b/src/lib/minecraft/Item.svelte index 4d0997c..cfcc219 100644 --- a/src/lib/minecraft/Item.svelte +++ b/src/lib/minecraft/Item.svelte @@ -1,5 +1,5 @@ <script lang="ts"> - import { formattingCodeToHtml, removeFormattingCode } from '$lib/utils' + import { cleanId, formattingCodeToHtml, removeFormattingCode, TIER_COLORS } from '$lib/utils' import MinecraftTooltip from './MinecraftTooltip.svelte' import type { MatcherFile } from 'skyblock-assets' import { itemToUrl } from './inventory' @@ -13,8 +13,35 @@ let itemNameHtml: string | null let imageUrl: string | null - $: itemLoreHtml = item ? item.display.lore.map(l => formattingCodeToHtml(l)).join('<br>') : null - $: itemNameHtml = item ? formattingCodeToHtml(item.display.name) : null + let extraLore: string[] = [] + if (!item?.display?.lore && item?.tier) { + // ☠ &cRequires &5Enderman Slayer 7 + if (item.requirements.slayer) + extraLore.push( + `§4☠ §cRequires §5${cleanId(item.requirements.slayer.boss)} Slayer ${ + item.requirements.slayer.level + }` + ) + extraLore.push(`§l§${TIER_COLORS[item.tier] ?? 'c'}${item.tier}`) + } + if (item?.id) { + extraLore.push(`\n§8ID: ${item.id}`) + } + + $: itemLoreHtml = item + ? (item.display?.lore ?? []) + .concat(extraLore) + .map(l => formattingCodeToHtml(l)) + .join('<br>') + : null + $: { + let itemDisplayName = item?.display?.name + if (itemDisplayName) { + if (!itemDisplayName.includes('§') && item.tier) + itemDisplayName = `§${TIER_COLORS[item.tier] ?? 'c'}${itemDisplayName}` + } + itemNameHtml = itemDisplayName ? formattingCodeToHtml(itemDisplayName) : null + } $: imageUrl = item ? itemToUrl(item, pack, headSize) : null </script> @@ -33,7 +60,7 @@ class:item-custom-head={imageUrl.startsWith('https://mc-heads.net/head/')} /> {/if} - {#if item.count !== 1} + {#if item.count !== undefined && item.count !== 1} <span class="item-count">{item.count}</span> {/if} </span> diff --git a/src/lib/minecraft/MinecraftTooltip.svelte b/src/lib/minecraft/MinecraftTooltip.svelte index 0cdb237..7149626 100644 --- a/src/lib/minecraft/MinecraftTooltip.svelte +++ b/src/lib/minecraft/MinecraftTooltip.svelte @@ -26,6 +26,8 @@ .minecraft-tooltip { /* this makes it be less dumb about the height so it doesn't add extra or anything */ display: grid; + /* this is so it doesn't change width to fill the container in the item list page */ + max-width: fit-content; } /* these elements exist so we can copy them later from GlobalTooltip */ .tooltip-name, diff --git a/src/lib/minecraft/inventory.ts b/src/lib/minecraft/inventory.ts index 871af93..ec0e193 100644 --- a/src/lib/minecraft/inventory.ts +++ b/src/lib/minecraft/inventory.ts @@ -1,6 +1,6 @@ import * as skyblockAssets from 'skyblock-assets' import { vanilla } from '$lib/packs' - +import { browser } from '$app/env' export interface Item { id?: string @@ -97,6 +97,13 @@ export const inventoryIconMap: Record<string, string | Item> = { export type Inventories = { [name in keyof typeof INVENTORIES]: Item[] } +// we cache the item urls because it takes a bit of time to get them usually +// { "<pack> <item id>": "https://..." } +let itemUrlCache: Record<string, string> = {} +// clear the cache every 120 seconds, this number is arbitrary +setInterval(() => { + itemUrlCache = {} +}, 120 * 1000) export function itemToUrl(item: Item, pack?: skyblockAssets.MatcherFile, headSize?: number): string { const itemNbt: skyblockAssets.NBT = { display: { @@ -107,6 +114,11 @@ export function itemToUrl(item: Item, pack?: skyblockAssets.MatcherFile, headSiz }, } let textureUrl: string + + const itemCacheIdentifier = `${pack?.dir ?? 'v'} ${JSON.stringify(itemNbt)}` + if (itemCacheIdentifier in itemUrlCache) + return itemUrlCache[itemCacheIdentifier] + if (item.headTexture) { // if it's a head, try without vanilla and if it fails just use the mc-heads url textureUrl = skyblockAssets.getTextureUrl({ @@ -120,21 +132,24 @@ export function itemToUrl(item: Item, pack?: skyblockAssets.MatcherFile, headSiz if (headSize) textureUrl += `/${headSize}` } - } else + } else { textureUrl = skyblockAssets.getTextureUrl({ id: item.vanillaId, nbt: itemNbt, packs: pack ? [pack, vanilla as skyblockAssets.MatcherFile] : [vanilla as skyblockAssets.MatcherFile], }) + } + itemUrlCache[itemCacheIdentifier] = textureUrl return textureUrl } export function skyblockItemToUrl(skyblockItem: string | Item, pack?: skyblockAssets.MatcherFile, headSize?: number) { - const item: Item = typeof skyblockItem === 'string' ? skyblockItemNameToItem(skyblockItem) : skyblockItem + const item = typeof skyblockItem === 'string' ? skyblockItemNameToItem(skyblockItem) : skyblockItem const itemTextureUrl = itemToUrl(item, pack, headSize) return itemTextureUrl } + export function skyblockItemNameToItem(skyblockItemName: string): Item { let item: Item if (Object.keys(skyblockItems).includes(skyblockItemName)) { |