Skip to content

Commit 8e8680f

Browse files
DuckySoLuckyHydoxlCopilot
authored
prod (#132)
* fix: hex colors * fix: some minor bug fixes * update info header to refer to new repository (#129) * fix: wth * fix: do not fetch garden unless unlocked * fix: enrichments * fix: garden * feat: cache /api/item endpoint * Update src/lib/server/stats/missing.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update src/lib/server/helper/renderer.ts Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * feat(items): add back backpack networth * fix: ironman logo * fix: do not show dungeon fllors that aren't unlocked * fix: get enchantment glint if colored armor --------- Co-authored-by: Niko <107579333+Hydoxl@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent bd75e6a commit 8e8680f

15 files changed

Lines changed: 94 additions & 78 deletions

File tree

src/lib/components/Item.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
const skyblockItem = $derived(piece as ProcessedSkyBlockItem);
3232
const bgColor = $derived(getRarityClass(piece.rarity ?? ("common".toLowerCase() as string), "bg"));
3333
const recombobulated = $derived(showRecombobulated && (skyblockItem.recombobulated ?? false));
34-
const enchanted = $derived(skyblockItem.shiny);
34+
const enchanted = $derived(skyblockItem.texture_path.includes("/api/leather/") ? false : skyblockItem.shiny);
3535
const shine = $derived(enchanted || skyblockItem.shiny);
3636
const showNumbers = $derived(showCount && (skyblockItem.Count ?? 0) > 1);
3737

src/lib/components/item/item-content.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
const itemNameHtml = $derived(renderLore(itemName));
2626
const isMulticolor = $derived((itemNameHtml.match(/<\/span>/g) || []).length > 1);
2727
const bgColor = $derived(getRarityClass(piece.rarity ?? ("common".toLowerCase() as string), "bg"));
28-
const enchanted = $derived(skyblockItem.shiny);
28+
const enchanted = $derived(skyblockItem.texture_path.includes("/api/leather/") ? false : skyblockItem.shiny);
2929
const packData = $derived(packConfigs.find((pack) => pack.id === skyblockItem.texture_pack));
3030
3131
// Get the wiki link for the item

src/lib/layouts/stats/PlayerProfile.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
🎲
9898
{/if}
9999
{#if otherProfile.game_mode === "ironman"}
100-
🥋
100+
♻️
101101
{/if}
102102
{#if otherProfile.game_mode === "island"}
103103
🌴

src/lib/sections/stats/Accessories.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
<p class="text-text/60 space-x-0.5 leading-6 font-bold capitalize">
149149
<span>Enrichments: </span>
150150
{#each Object.entries(accessories.enrichments) as [key, value], index (index)}
151-
{#if key !== "missing"}
151+
{#if key !== "missing" && STATS_DATA[key.toLowerCase()]}
152152
<span class={STATS_DATA[key.toLowerCase()].color}>
153153
{value
154154
{STATS_DATA[key.toLowerCase()].name}

src/lib/sections/stats/Dungeons.svelte

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -87,63 +87,65 @@
8787
{#if catacombs}
8888
<ScrollItems>
8989
{#each catacombs as catacomb, index (index)}
90-
<div class="bg-background/30 flex min-w-80 basis-[calc((100%/3)-1.25rem)] flex-col gap-1 rounded-lg">
91-
<div class="border-icon flex w-full items-center justify-center gap-1.5 border-b-2 py-2 text-center font-semibold uppercase">
92-
<Avatar.Root>
93-
<Avatar.Image loading="lazy" src={catacomb.texture} class="size-8 object-contain" />
94-
<Avatar.Fallback>
95-
<Image class="size-8" />
96-
</Avatar.Fallback>
97-
</Avatar.Root>
98-
{catacomb.name}
99-
</div>
100-
101-
<Collapsible.Root class="p-5">
102-
<Collapsible.Trigger class="group flex items-center gap-0.5">
103-
<ChevronDown class="size-5 transition-all duration-300 group-data-[state=open]:-rotate-180" />
104-
<SectionSubtitle class="my-0">Floor Stats</SectionSubtitle>
105-
</Collapsible.Trigger>
106-
<Collapsible.Content>
107-
{#each Object.entries(catacomb.stats) as [key, value], index (index)}
108-
{#if typeof value === "object"}
109-
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatNumber(value.damage)} subData="({value.type})" />
110-
{:else if key.includes("time") && key !== "times_played"}
111-
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatDuration(value)} />
112-
{:else}
113-
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatNumber(value)} />
114-
{/if}
115-
{/each}
116-
</Collapsible.Content>
117-
</Collapsible.Root>
90+
{#if catacomb.stats.tier_completions > 0}
91+
<div class="bg-background/30 flex min-w-80 basis-[calc((100%/3)-1.25rem)] flex-col gap-1 rounded-lg">
92+
<div class="border-icon flex w-full items-center justify-center gap-1.5 border-b-2 py-2 text-center font-semibold uppercase">
93+
<Avatar.Root>
94+
<Avatar.Image loading="lazy" src={catacomb.texture} class="size-8 object-contain" />
95+
<Avatar.Fallback>
96+
<Image class="size-8" />
97+
</Avatar.Fallback>
98+
</Avatar.Root>
99+
{catacomb.name}
100+
</div>
118101

119-
{#if catacomb.best_run}
120-
<Collapsible.Root class="px-5 pb-[2.5rem]">
102+
<Collapsible.Root class="p-5">
121103
<Collapsible.Trigger class="group flex items-center gap-0.5">
122104
<ChevronDown class="size-5 transition-all duration-300 group-data-[state=open]:-rotate-180" />
123-
<SectionSubtitle class="my-0">Best run</SectionSubtitle>
105+
<SectionSubtitle class="my-0">Floor Stats</SectionSubtitle>
124106
</Collapsible.Trigger>
125107
<Collapsible.Content>
126-
{#each Object.entries(catacomb.best_run) as [key, value], index (index)}
127-
{#if typeof value === "number"}
128-
{#if key === "timestamp"}
129-
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatDistanceToNowStrict(value, { addSuffix: true })} asterisk={true}>
130-
{formatDate(value, "dd MMMM yyyy 'at' HH:mm")}
131-
</AdditionStat>
132-
{:else if key.includes("time")}
133-
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatDuration(value)} />
134-
{:else}
135-
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatNumber(value)} />
136-
{/if}
108+
{#each Object.entries(catacomb.stats) as [key, value], index (index)}
109+
{#if typeof value === "object"}
110+
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatNumber(value.damage)} subData="({value.type})" />
111+
{:else if key.includes("time") && key !== "times_played"}
112+
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatDuration(value)} />
137113
{:else}
138-
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={value} />
114+
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatNumber(value)} />
139115
{/if}
140116
{/each}
141117
</Collapsible.Content>
142118
</Collapsible.Root>
143-
{:else}
144-
<div class="p-5 text-center">This player has not completed this floor.</div>
145-
{/if}
146-
</div>
119+
120+
{#if catacomb.best_run}
121+
<Collapsible.Root class="px-5 pb-[2.5rem]">
122+
<Collapsible.Trigger class="group flex items-center gap-0.5">
123+
<ChevronDown class="size-5 transition-all duration-300 group-data-[state=open]:-rotate-180" />
124+
<SectionSubtitle class="my-0">Best run</SectionSubtitle>
125+
</Collapsible.Trigger>
126+
<Collapsible.Content>
127+
{#each Object.entries(catacomb.best_run) as [key, value], index (index)}
128+
{#if typeof value === "number"}
129+
{#if key === "timestamp"}
130+
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatDistanceToNowStrict(value, { addSuffix: true })} asterisk={true}>
131+
{formatDate(value, "dd MMMM yyyy 'at' HH:mm")}
132+
</AdditionStat>
133+
{:else if key.includes("time")}
134+
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatDuration(value)} />
135+
{:else}
136+
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={formatNumber(value)} />
137+
{/if}
138+
{:else}
139+
<AdditionStat class="capitalize" text={key.toLowerCase().replaceAll("_", " ")} data={value} />
140+
{/if}
141+
{/each}
142+
</Collapsible.Content>
143+
</Collapsible.Root>
144+
{:else}
145+
<div class="p-5 text-center">This player has not completed this floor.</div>
146+
{/if}
147+
</div>
148+
{/if}
147149
{/each}
148150
</ScrollItems>
149151
{:else}

src/lib/server/constants/accessories.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ export const MAGICAL_POWER = {
212212
very_special: 5
213213
} as Record<string, number>;
214214

215+
export const ENRICHMENT_TO_STAT = {
216+
walk_speed: "speed"
217+
} as Record<string, string>;
218+
215219
export const RECOMBABLE_ACCESSORIES_COUNT = new Set(
216220
getMaxAccessories()
217221
.filter((a) => SPECIAL_ACCESSORIES[a.id]?.allowsRecomb !== false)

src/lib/server/constants/update-collections.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export async function updateCollectionConstants() {
99

1010
const collections = await MONGO.collection("collections").findOne({});
1111
if (collections?.collections == null) {
12-
console.log(collections);
1312
return;
1413
}
1514

src/lib/server/helper/renderer.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ Modified and Improved by @DuckySoLucky
1010
export const CACHE_PATH = helper.getCacheFolderPath();
1111

1212
import { base } from "$app/paths";
13+
import { REDIS } from "$lib/server/db/redis";
14+
import type { ItemQuery } from "$types/global";
1315
import { createCanvas, loadImage } from "@napi-rs/canvas";
1416
import fs from "fs-extra";
17+
import minecraftData from "minecraft-data";
1518
import sanitize from "mongo-sanitize";
1619
import path from "path";
17-
18-
import type { ItemQuery } from "$types/global";
19-
import minecraftData from "minecraft-data";
2020
import * as helper from "../helper";
2121
import { getItemData } from "./item";
2222
const mcData = minecraftData("1.8.9");
@@ -443,6 +443,12 @@ async function renderPotion(type: string, color: string) {
443443
* @returns Image of an item
444444
*/
445445
export async function renderItem(skyblockId: string | undefined, query: ItemQuery): Promise<RenderItemOutput> {
446+
const cacheId = `ITEM:${skyblockId}:${JSON.stringify(query)}`;
447+
const cache = await REDIS.get(cacheId);
448+
if (cache) {
449+
return JSON.parse(cache);
450+
}
451+
446452
query = sanitize(query);
447453
let itemQuery = query ?? {};
448454

@@ -501,5 +507,8 @@ export async function renderItem(skyblockId: string | undefined, query: ItemQuer
501507
console.error("Error processing static image:", error);
502508
}
503509
}
510+
511+
REDIS.SETEX(cacheId, 60 * 30, JSON.stringify(outputTexture));
512+
504513
return outputTexture;
505514
}

src/lib/server/stats.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ async function processStats<T>(player: Player, profile: Profile, stats: Array<[s
3131
}
3232

3333
export async function getStats(profile: Profile, player: Player, extra: { museum?: MuseumRawResponse; packs?: string[] } = {}) {
34-
const timeNow = Date.now();
3534
const cacheId = `STATS:${profile.uuid}:${profile.profile_id}:${extra.packs?.join(",") ?? "NONE"}`;
3635
const cache = await REDIS.get(cacheId);
3736
if (cache && !dev) {
38-
console.log(`[CACHE] Found cache for ${profile.uuid}:${profile.profile_id} in ${Date.now() - timeNow}ms`);
3937
return JSON.parse(cache);
4038
}
4139

src/lib/server/stats/garden.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getLevelByXp, getSkillExperience } from "./leveling/leveling";
66

77
function getVisitorRarities(gardenData: GardenResponse) {
88
const output = {} as Record<string, { visited?: number; completed?: number; unique: string[]; maxUnique: number }>;
9-
for (const [key, value] of Object.entries(gardenData.commission_data.visits ?? {})) {
9+
for (const [key, value] of Object.entries(gardenData.commission_data?.visits ?? {})) {
1010
const rarity = NEU_CONSTANTS.get("garden").visitors[key] ?? "unknown";
1111

1212
const visited = output[rarity]?.visited ?? 0;
@@ -15,7 +15,7 @@ function getVisitorRarities(gardenData: GardenResponse) {
1515

1616
output[rarity] = {
1717
visited: visited + value,
18-
completed: completed + (gardenData.commission_data.completed?.[key] ?? 0),
18+
completed: completed + (gardenData.commission_data?.completed?.[key] ?? 0),
1919
unique: unique.includes(key) ? unique : [...unique, key],
2020
maxUnique: NEU_CONSTANTS.get("garden").maxVisitors[rarity]
2121
};
@@ -26,9 +26,9 @@ function getVisitorRarities(gardenData: GardenResponse) {
2626

2727
function getVisitors(gardenData: GardenResponse) {
2828
const output = {
29-
visited: Object.values(gardenData.commission_data.visits ?? {}).reduce((a, b) => a + b, 0),
30-
completed: gardenData.commission_data.total_completed ?? 0,
31-
uniqueVisitors: gardenData.commission_data.unique_npcs_served ?? 0,
29+
visited: Object.values(gardenData.commission_data?.visits ?? {}).reduce((a, b) => a + b, 0),
30+
completed: gardenData.commission_data?.total_completed ?? 0,
31+
uniqueVisitors: gardenData.commission_data?.unique_npcs_served ?? 0,
3232
visitors: getVisitorRarities(gardenData)
3333
};
3434

@@ -67,7 +67,7 @@ function getCropUpgrades(gardenData: GardenResponse) {
6767
function getComposterUpgrades(gardenData: GardenResponse) {
6868
const output = {} as Record<string, number>;
6969
for (const key in NEU_CONSTANTS.get("garden").composterUpgrades) {
70-
output[key] = gardenData.composter_data.upgrades?.[key] ?? 0;
70+
output[key] = gardenData.composter_data?.upgrades?.[key] ?? 0;
7171
}
7272

7373
return output;

0 commit comments

Comments
 (0)