From 582409e7cb1598b65bee6d1023b77620bb3791af Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 20 Feb 2022 02:16:09 -0600 Subject: add inventories --- .gitignore | 3 +- .vscode/settings.json | 3 + package.json | 5 +- src/lib/minecraft/Inventory.svelte | 22 +- src/lib/minecraft/Item.svelte | 21 +- src/lib/minecraft/inventory.ts | 54 +- src/lib/sections/Armor.svelte | 4 +- src/lib/sections/Inventories.svelte | 55 ++ src/routes/about.svelte | 50 -- src/routes/index.svelte | 52 +- src/routes/player/[player]/[profile].svelte | 22 +- static/backgrounds/67.jpg | Bin 43436 -> 16140 bytes static/emoji/1f6b6.svg | 2 +- static/style.css | 855 ---------------------------- svelte.config.js | 36 +- yarn.lock | 142 ++++- 16 files changed, 269 insertions(+), 1057 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/lib/sections/Inventories.svelte delete mode 100644 src/routes/about.svelte delete mode 100644 static/style.css diff --git a/.gitignore b/.gitignore index 5b11e81..09319ad 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ node_modules !.env.example .vercel .output -.yarn \ No newline at end of file +.yarn +/.vercel_build_output \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..3b61434 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.formatOnSave": true +} \ No newline at end of file diff --git a/package.json b/package.json index 3b9bcfd..d4f22e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "skyblock-stats-svelte", "version": "0.0.1", + "license": "MIT", "scripts": { "dev": "svelte-kit dev", "build": "svelte-kit build", @@ -33,8 +34,10 @@ "type": "module", "dependencies": { "@lukeed/uuid": "^2.0.0", + "@sveltejs/adapter-node": "^1.0.0-next.68", + "@sveltejs/adapter-vercel": "^1.0.0-next.43", "cookie": "^0.4.1", - "skyblock-assets": "^1.1.12" + "skyblock-assets": "^2.0.3" }, "packageManager": "yarn@3.1.1" } diff --git a/src/lib/minecraft/Inventory.svelte b/src/lib/minecraft/Inventory.svelte index 3d3b9c0..d29b1e0 100644 --- a/src/lib/minecraft/Inventory.svelte +++ b/src/lib/minecraft/Inventory.svelte @@ -4,6 +4,7 @@ export let items export let name = '' export let pack = '' + export let groupLimit = 9 if (name === 'inventory') // in the inventory, the first 9 items are the hotbar and should be at the end @@ -13,14 +14,14 @@ let itemGroups = [] $: { itemGroups = [] - for (let i = 0; i < items.length; i += 9) { - itemGroups.push(items.slice(i, i + 9)) + for (let i = 0; i < items.length; i += groupLimit) { + itemGroups.push(items.slice(i, i + groupLimit)) } }
- {#each itemGroups as itemGroup, groupIndex} + {#each itemGroups as itemGroup}
{#each itemGroup as item} @@ -28,18 +29,3 @@
{/each}
- - diff --git a/src/lib/minecraft/Item.svelte b/src/lib/minecraft/Item.svelte index 8ddc4a8..c944f1b 100644 --- a/src/lib/minecraft/Item.svelte +++ b/src/lib/minecraft/Item.svelte @@ -1,22 +1,26 @@ {@html itemNameHtml} {@html itemLoreHtml} - + {#if item} {#if imageUrl} @@ -60,6 +64,13 @@ image-rendering: pixelated; } + img.item-custom-head { + width: 0.75em; + height: 0.75em; + margin-top: 0.1875em; + margin-left: 0.1875em; + } + .item-slot { margin: 0.05em; } diff --git a/src/lib/minecraft/inventory.ts b/src/lib/minecraft/inventory.ts index fa75887..cb926b4 100644 --- a/src/lib/minecraft/inventory.ts +++ b/src/lib/minecraft/inventory.ts @@ -1,7 +1,7 @@ -import vanillaDamages from 'skyblock-assets/data/vanilla_damages.json' import * as skyblockAssets from 'skyblock-assets' +import vanilla from 'skyblock-assets/matchers/vanilla.json' +import packshq from 'skyblock-assets/matchers/vanilla.json' -const itemToUrlCache: Record = {} interface Item { id?: string @@ -36,10 +36,7 @@ const INVENTORIES = { export type Inventories = { [name in keyof typeof INVENTORIES]: Item[] } -export async function itemToUrl(item: Item, packName?: string): Promise { - const stringifiedItem = (packName ?? 'packshq') + JSON.stringify(item) - if (stringifiedItem in itemToUrlCache) - return itemToUrlCache[stringifiedItem] +export function itemToUrl(item: Item, packName?: string): string { const itemNbt: skyblockAssets.NBT = { display: { Name: item.display?.name @@ -52,21 +49,22 @@ export async function itemToUrl(item: Item, packName?: string): Promise if (item.head_texture) textureUrl = `https://mc-heads.net/head/${item.head_texture}` else - textureUrl = await skyblockAssets.getTextureUrl({ + textureUrl = skyblockAssets.getTextureUrl({ id: item.vanillaId, nbt: itemNbt, - pack: packName ?? 'packshq' + packs: [packshq, vanilla] }) if (!textureUrl) console.log('no texture', item) - itemToUrlCache[stringifiedItem] = textureUrl return textureUrl } + export async function skyblockItemToUrl(skyblockItemName: string) { const item = skyblockItemNameToItem(skyblockItemName) const itemTextureUrl = await itemToUrl(item, 'packshq') return itemTextureUrl } + export function skyblockItemNameToItem(skyblockItemName: string): Item { let item: Item if (Object.keys(skyblockItems).includes(skyblockItemName)) { @@ -78,6 +76,7 @@ export function skyblockItemNameToItem(skyblockItemName: string): Item { } return item } + const skyblockItems: { [itemName: string]: Item } = { ink_sac: { vanillaId: 'minecraft:dye' }, cocoa_beans: { vanillaId: 'minecraft:dye:3' }, @@ -102,41 +101,4 @@ const skyblockItems: { [itemName: string]: Item } = { head_texture: '39b6e047d3b2bca85e8cc49e5480f9774d8a0eafe6dfa9559530590283715142' }, hard_stone: { vanillaId: 'minecraft:stone' }, -} - -export function itemToUrlCached(item: Item, packName?: string): string { - if (!item) return null - if (typeof item === 'string') { - let itemId: string = vanillaDamages[item] ?? item - let damage: number = null - // remove the minecraft: namespace since we already know it's all vanilla - if (itemId.startsWith('minecraft:')) itemId = itemId.slice('minecraft:'.length) - // split the damage into its own variable - if (itemId.includes(':')) { - damage = parseInt(itemId.split(':')[1]) - itemId = itemId.split(':')[0] - } - item = { - count: 1, - display: { - glint: false, - lore: null, - name: null - }, - id: null, - // vanillaId: damage === null ? `minecraft:${itemId}` : `minecraft:${itemId}:${damage}` - vanillaId: `minecraft:${itemId}` - } - } - const stringifiedItem = (packName ?? 'packshq') + JSON.stringify(item) - return itemToUrlCache[stringifiedItem] -} -/** Get all the items in an inventories object to cache them */ -export async function cacheInventories(inventories: Inventories, packName?: string) { - const promises: Promise[] = [] - for (const inventoryItems of Object.values(inventories ?? {})) - for (const inventoryItem of inventoryItems) - if (inventoryItem) - promises.push(itemToUrl(inventoryItem, packName)) - await Promise.all(promises) } \ No newline at end of file diff --git a/src/lib/sections/Armor.svelte b/src/lib/sections/Armor.svelte index c4e7950..ab0e73b 100644 --- a/src/lib/sections/Armor.svelte +++ b/src/lib/sections/Armor.svelte @@ -4,4 +4,6 @@ export let pack - + + + diff --git a/src/lib/sections/Inventories.svelte b/src/lib/sections/Inventories.svelte new file mode 100644 index 0000000..49a00c2 --- /dev/null +++ b/src/lib/sections/Inventories.svelte @@ -0,0 +1,55 @@ + + +
+ {#each displayingInventories as inventoryName} + + {/each} +
+{#each displayingInventories as inventoryName} + {#if inventoryName === selectedInventoryName} +
+ +
+ {/if} +{/each} + + diff --git a/src/routes/about.svelte b/src/routes/about.svelte deleted file mode 100644 index 569d3e1..0000000 --- a/src/routes/about.svelte +++ /dev/null @@ -1,50 +0,0 @@ - - - - About - - -
-

About this app

- -

- This is a SvelteKit app. You can make your own by typing the - following into your command line and following the prompts: -

- - -
npm init svelte@next
- -

- The page you're looking at is purely static HTML, with no client-side interactivity needed. - Because of that, we don't need to load any JavaScript. Try viewing the page's source, or opening - the devtools network panel and reloading. -

- -

- The TODOs page illustrates SvelteKit's data loading and form handling. Try using - it with JavaScript disabled! -

-
- - diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 68311dd..524df13 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -1,9 +1,5 @@ - - @@ -11,49 +7,5 @@
-

-
- - - Welcome - -
- - to your new
SvelteKit app -

- -

- try editing src/routes/index.svelte -

- - +

SkyBlock Stats

- - diff --git a/src/routes/player/[player]/[profile].svelte b/src/routes/player/[player]/[profile].svelte index bd9402d..e28dae7 100644 --- a/src/routes/player/[player]/[profile].svelte +++ b/src/routes/player/[player]/[profile].svelte @@ -1,5 +1,4 @@