From 13e5974114f759bae73f3bfd68c62ce9cfaf785e Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 20 Feb 2022 21:38:14 -0600 Subject: add more stuff to profile and fix bugs --- src/lib/APITypes.d.ts | 96 ++++++++++++++ src/lib/Collapsible.svelte | 40 ++++++ src/lib/Emoji.svelte | 11 +- src/lib/GlobalTooltip.svelte | 94 ++------------ src/lib/GlobalTooltip.ts | 76 ++++++++++++ src/lib/minecraft/Inventory.svelte | 14 ++- src/lib/minecraft/Item.svelte | 21 ++-- src/lib/minecraft/MinecraftTooltip.svelte | 18 ++- src/lib/minecraft/Username.svelte | 9 +- src/lib/minecraft/heads/Head2d.svelte | 6 +- src/lib/minecraft/heads/Head3d.svelte | 6 +- src/lib/minecraft/inventory.ts | 5 +- src/lib/profile.ts | 61 ++++----- src/lib/sections/Infobox.svelte | 36 ++---- src/lib/sections/Inventories.svelte | 2 +- src/lib/sections/Skills.svelte | 1 + src/lib/sections/StatList.svelte | 42 +++++++ src/lib/utils.ts | 8 +- src/routes/player/[player]/[profile].svelte | 73 ++++++----- src/routes/player/[player]/index.svelte | 39 +++--- src/routes/todos/_api.ts | 22 ---- src/routes/todos/index.svelte | 186 ---------------------------- src/routes/todos/index.ts | 52 -------- 23 files changed, 433 insertions(+), 485 deletions(-) create mode 100644 src/lib/APITypes.d.ts create mode 100644 src/lib/Collapsible.svelte create mode 100644 src/lib/GlobalTooltip.ts create mode 100644 src/lib/sections/StatList.svelte delete mode 100644 src/routes/todos/_api.ts delete mode 100644 src/routes/todos/index.svelte delete mode 100644 src/routes/todos/index.ts (limited to 'src') diff --git a/src/lib/APITypes.d.ts b/src/lib/APITypes.d.ts new file mode 100644 index 0000000..04f9220 --- /dev/null +++ b/src/lib/APITypes.d.ts @@ -0,0 +1,96 @@ +export interface CleanMemberProfile { + member: CleanMemberProfilePlayer + profile: CleanFullProfileBasicMembers + customization?: AccountCustomization +} + +export interface CleanMemberProfilePlayer extends CleanPlayer { + profileName: string + first_join: number + last_save: number + bank?: Bank + purse?: number + stats?: StatItem[] + rawHypixelStats?: { + [key: string]: number + } + minions?: CleanMinion[] + fairy_souls?: FairySouls + inventories?: Inventories + objectives?: Objective[] + skills?: Skill[] + visited_zones?: Zone[] + collections?: Collection[] + slayers?: SlayerData +} + +export interface CleanBasicPlayer { + uuid: string + username: string +} + +export interface CleanPlayer extends CleanBasicPlayer { + rank: CleanRank + socials: CleanSocialMedia + profiles?: CleanBasicProfile[] +} + +export interface StatItem { + rawName: string + value: number + categorizedName: string + category: string | null + unit: string | null +} + +interface Item { + id: string + count: number + vanillaId: string + display: { + name: string + lore: string[] + glint: boolean + } + reforge?: string + anvil_uses?: number + timestamp?: string + enchantments?: { + [name: string]: number + } + head_texture?: string +} +export declare type Inventory = Item[] +export declare const INVENTORIES: { + armor: string + inventory: string + ender_chest: string + talisman_bag: string + potion_bag: string + fishing_bag: string + quiver: string + trick_or_treat_bag: string + wardrobe: string +} +export declare type Inventories = { + [name in keyof typeof INVENTORIES]: Item[] +} + + +export interface CleanUser { + player: CleanPlayer | null + profiles?: CleanProfile[] + activeProfile?: string + online?: boolean + customization?: AccountCustomization +} + +export interface CleanProfile extends CleanBasicProfile { + members?: CleanBasicMember[] +} + +/** A basic profile that only includes the profile uuid and name */ +export interface CleanBasicProfile { + uuid: string + name?: string +} diff --git a/src/lib/Collapsible.svelte b/src/lib/Collapsible.svelte new file mode 100644 index 0000000..f3a28d2 --- /dev/null +++ b/src/lib/Collapsible.svelte @@ -0,0 +1,40 @@ + + +
+ + +

Details

+
+
+
+ +
+
+ + diff --git a/src/lib/Emoji.svelte b/src/lib/Emoji.svelte index 0e8f4a7..1869f37 100644 --- a/src/lib/Emoji.svelte +++ b/src/lib/Emoji.svelte @@ -1,17 +1,20 @@ - - {@html twemojiHtml(value)} - +{@html twemojiHtml(value)} diff --git a/src/lib/minecraft/heads/Head3d.svelte b/src/lib/minecraft/heads/Head3d.svelte index f8d2657..2400f4b 100644 --- a/src/lib/minecraft/heads/Head3d.svelte +++ b/src/lib/minecraft/heads/Head3d.svelte @@ -6,7 +6,7 @@ {player.username}'s head @@ -24,4 +24,8 @@ height: 1em; width: 1em; } + + .player-head { + margin-right: 0.2em; + } diff --git a/src/lib/minecraft/inventory.ts b/src/lib/minecraft/inventory.ts index cb926b4..faaea85 100644 --- a/src/lib/minecraft/inventory.ts +++ b/src/lib/minecraft/inventory.ts @@ -1,6 +1,7 @@ import * as skyblockAssets from 'skyblock-assets' import vanilla from 'skyblock-assets/matchers/vanilla.json' import packshq from 'skyblock-assets/matchers/vanilla.json' +import furfsky_reborn from 'skyblock-assets/matchers/furfsky_reborn.json' interface Item { @@ -52,10 +53,8 @@ export function itemToUrl(item: Item, packName?: string): string { textureUrl = skyblockAssets.getTextureUrl({ id: item.vanillaId, nbt: itemNbt, - packs: [packshq, vanilla] + packs: [furfsky_reborn, vanilla] }) - if (!textureUrl) - console.log('no texture', item) return textureUrl } diff --git a/src/lib/profile.ts b/src/lib/profile.ts index 320a5dc..c2c945e 100644 --- a/src/lib/profile.ts +++ b/src/lib/profile.ts @@ -1,3 +1,4 @@ +import type { CleanMemberProfile, StatItem } from './APITypes' import { cleanId, millisecondsToTime } from './utils' /** @@ -10,7 +11,7 @@ export function prettyTimestamp(ms: number) { return timeAsString } -export function generateInfobox(data, opts: { meta: boolean }): string[] { +export function generateInfobox(data: CleanMemberProfile): string[] { const result: string[] = [] result.push(`๐Ÿ’พ Last save: ${prettyTimestamp(data.member.last_save * 1000)}`) @@ -22,35 +23,37 @@ export function generateInfobox(data, opts: { meta: boolean }): string[] { if (data.profile.minion_count >= data.profile.maxUniqueMinions) result.push(`๐Ÿค– Minion count: ${data.profile.minion_count}`) - let mostSignificantKillsStat = null - let mostSignificantDeathsStat = null - - for (const stat of data.member.stats) { - if ( - stat.category === 'kills' - && stat.rawName != 'kills' - && stat.value >= 200_000 - && stat.value > (mostSignificantKillsStat?.value ?? 0) - ) - mostSignificantKillsStat = stat - if ( - stat.category === 'deaths' - && stat.rawName != 'deaths' - && stat.value > 1_000_000 - && stat.value > (mostSignificantDeathsStat?.value ?? 0) - ) - mostSignificantDeathsStat = stat + if (data.member.stats) { + let mostSignificantKillsStat: StatItem | null = null + let mostSignificantDeathsStat: StatItem | null = null + + for (const stat of data.member.stats) { + if ( + stat.category === 'kills' + && stat.rawName != 'kills' + && stat.value >= 200_000 + && stat.value > (mostSignificantKillsStat?.value ?? 0) + ) + mostSignificantKillsStat = stat + if ( + stat.category === 'deaths' + && stat.rawName != 'deaths' + && stat.value > 1_000_000 + && stat.value > (mostSignificantDeathsStat?.value ?? 0) + ) + mostSignificantDeathsStat = stat + } + + if (mostSignificantKillsStat) + result.push( + `โš”๏ธ ${mostSignificantKillsStat.value.toLocaleString()} ${mostSignificantKillsStat.unit || cleanId(mostSignificantKillsStat.rawName).toLowerCase()}` + ) + + if (mostSignificantDeathsStat) + result.push( + `โ˜  ${mostSignificantDeathsStat.value.toLocaleString()} ${mostSignificantDeathsStat.unit || cleanId(mostSignificantDeathsStat.rawName).toLowerCase()}` + ) } - if (mostSignificantKillsStat) - result.push( - `โš”๏ธ ${mostSignificantKillsStat.value.toLocaleString()} ${mostSignificantKillsStat.unit || cleanId(mostSignificantKillsStat.rawName).toLowerCase()}` - ) - - if (mostSignificantDeathsStat) - result.push( - `โ˜  ${mostSignificantDeathsStat.value.toLocaleString()} ${mostSignificantDeathsStat.unit || cleanId(mostSignificantDeathsStat.rawName).toLowerCase()}` - ) - return result } \ No newline at end of file diff --git a/src/lib/sections/Infobox.svelte b/src/lib/sections/Infobox.svelte index 756987d..7670dec 100644 --- a/src/lib/sections/Infobox.svelte +++ b/src/lib/sections/Infobox.svelte @@ -2,37 +2,23 @@ import { generateInfobox } from '$lib/profile' import Username from '$lib/minecraft/Username.svelte' import Emoji from '$lib/Emoji.svelte' + import { onMount } from 'svelte' export let data - - + // onMount(() => { + // // reload the data every second so the infobox updates + // const interval = setInterval(() => { + // data = data + // }, 1000) + + // return () => clearInterval(interval) + // }) +

({data.member.profileName})

- {#each generateInfobox(data, { meta: false }) as item} + {#each generateInfobox(data) as item}

{/each}
diff --git a/src/lib/sections/Inventories.svelte b/src/lib/sections/Inventories.svelte index 49a00c2..42607b6 100644 --- a/src/lib/sections/Inventories.svelte +++ b/src/lib/sections/Inventories.svelte @@ -27,7 +27,7 @@ {#each displayingInventories as inventoryName} {#if inventoryName === selectedInventoryName}
- +
{/if} {/each} diff --git a/src/lib/sections/Skills.svelte b/src/lib/sections/Skills.svelte index 7111c43..6e1efdb 100644 --- a/src/lib/sections/Skills.svelte +++ b/src/lib/sections/Skills.svelte @@ -70,5 +70,6 @@ } ul > li { width: 10em; + margin: 0.25em 0.25em 0 0; } diff --git a/src/lib/sections/StatList.svelte b/src/lib/sections/StatList.svelte new file mode 100644 index 0000000..266ceb3 --- /dev/null +++ b/src/lib/sections/StatList.svelte @@ -0,0 +1,42 @@ + + + + + + diff --git a/src/lib/utils.ts b/src/lib/utils.ts index f16021d..197bf6b 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -26,7 +26,7 @@ const colorCodeCharacter = 'ยง' export function formattingCodeToHtml(formatted: string): string { let htmlOutput = '' // we store the hex code, not the formatting code - let currentColor = null + let currentColor: null | string = null // we store the css code, not the formatting code const activeSpecialCodes: string[] = [] function reset() { @@ -50,7 +50,7 @@ export function formattingCodeToHtml(formatted: string): string { // if there's already a color, close that tag if (currentColor) htmlOutput += '' currentColor = colorCodes[colorCharacter] - htmlOutput += `` + htmlOutput += `` } } else if (specialCodes[colorCharacter]) { if (!activeSpecialCodes.includes(specialCodes[colorCharacter])) { @@ -133,7 +133,7 @@ export function twemojiHtml(s: string) { const htmlEncoded = s.replace('<', '<').replace('>', '>').replace('&', '&') // replace unicode emojis with const asTwemoji = htmlEncoded.replace(emojiRegex, (match) => { - return `` + return `` }) return asTwemoji } @@ -150,5 +150,5 @@ export function formatNumber(n: number, digits = 3) { { value: 1e18, symbol: 'E' }, ] const item = numberSymbolsLookup.slice().reverse().find(item => n >= item.value) - return (n / item.value).toPrecision(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + item.symbol + return (n / (item?.value ?? 1)).toPrecision(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + (item?.symbol ?? '') } \ No newline at end of file diff --git a/src/routes/player/[player]/[profile].svelte b/src/routes/player/[player]/[profile].svelte index e28dae7..1fed489 100644 --- a/src/routes/player/[player]/[profile].svelte +++ b/src/routes/player/[player]/[profile].svelte @@ -23,6 +23,7 @@ - - - Todos - - -
-

Todos

- -
{ - form.reset() - }, - }} - > - -
- - {#each todos as todo (todo.uid)} -
-
{ - todo.done = !!data.get('done') - }, - }} - > - - -
- {/each} -
- - diff --git a/src/routes/todos/index.ts b/src/routes/todos/index.ts deleted file mode 100644 index 129b60a..0000000 --- a/src/routes/todos/index.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { api } from './_api'; -import type { RequestHandler } from '@sveltejs/kit'; - -export const get: RequestHandler = async ({ request, locals }) => { - // locals.userid comes from src/hooks.js - const response = await api(request, `todos/${locals.userid}`); - - if (response.status === 404) { - // user hasn't created a todo list. - // start with an empty array - return { - body: { - todos: [] - } - }; - } - - if (response.ok) { - return { - body: { - todos: await response.json() - } - }; - } - - return { - status: response.status - }; -}; - -export const post: RequestHandler = async ({ request, locals }) => { - const form = await request.formData(); - - return api(request, `todos/${locals.userid}`, { - text: form.get('text') - }); -}; - -export const patch: RequestHandler = async ({ request, locals }) => { - const form = await request.formData(); - - return api(request, `todos/${locals.userid}/${form.get('uid')}`, { - text: form.has('text') ? form.get('text') : undefined, - done: form.has('done') ? !!form.get('done') : undefined - }); -}; - -export const del: RequestHandler = async ({ request, locals }) => { - const form = await request.formData(); - - return api(request, `todos/${locals.userid}/${form.get('uid')}`); -}; -- cgit