Skip to content

Commit

Permalink
refactor(helper): remove unused functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DuckySoLucky committed Jan 15, 2025
1 parent cd9536b commit ef44863
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 302 deletions.
32 changes: 18 additions & 14 deletions src/lib/sections/stats/misc/dragons.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,24 @@
<Items>
{#snippet text()}
<div>
<AdditionStat text="Most Damage" data={format(dragons.most_damage.best.toFixed(0))} asterisk={true}>
{#each Object.entries(dragons.most_damage) as [text, data]}
{#if text !== "best"}
<AdditionStat {text} data={format(data.toFixed(0))} />
{/if}
{/each}
</AdditionStat>
<AdditionStat text="Fastest Kill" data={formatTime(dragons.fastest_kill.best)} asterisk={true}>
{#each Object.entries(dragons.fastest_kill) as [text, data]}
{#if text !== "best"}
<AdditionStat {text} data={formatTime(data)} />
{/if}
{/each}
</AdditionStat>
{#if dragons.most_damage?.best}
<AdditionStat text="Most Damage" data={format(dragons.most_damage.best.toFixed(0))} asterisk={true}>
{#each Object.entries(dragons.most_damage) as [text, data]}
{#if text !== "best"}
<AdditionStat {text} data={format(data.toFixed(0))} />
{/if}
{/each}
</AdditionStat>
{/if}
{#if dragons.fastest_kill?.best}
<AdditionStat text="Fastest Kill" data={formatTime(dragons.fastest_kill.best)} asterisk={true}>
{#each Object.entries(dragons.fastest_kill) as [text, data]}
{#if text !== "best"}
<AdditionStat {text} data={formatTime(data)} />
{/if}
{/each}
</AdditionStat>
{/if}
{#if dragons.last_hits != null}
<AdditionStat text="Last Hits" data={format(dragons.last_hits.total)} asterisk={true}>
{#each Object.entries(dragons.last_hits) as [text, data]}
Expand Down
56 changes: 55 additions & 1 deletion src/lib/server/custom_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path from "path";
import RJSON from "relaxed-json";
import UPNG from "upng-js";
import util from "util";
import { getCacheFilePath, getCacheFolderPath, getFolderPath, getId, getPath, getTextureValue, hasPath } from "./helper";
import { getCacheFilePath, getCacheFolderPath, getFolderPath, getId, getTextureValue } from "./helper";
const mcData = minecraftData("1.8.9");

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down Expand Up @@ -44,6 +44,60 @@ const readyPromise = new Promise((resolve) => {
}, 1000);
});

function getKey(key: string): string | number {
const intKey = Number(key);

if (!isNaN(intKey)) {
return intKey;
}

return key;
}

function hasPath<T extends object>(obj: T, ...keys: (string | number)[]): boolean {
if (obj == null) {
return false;
}

let loc: unknown = obj;

for (let i = 0; i < keys.length; i++) {
if (typeof loc === "object" && loc !== null) {
loc = (loc as Record<string, unknown>)[getKey(keys[i] as string)];
} else {
return false;
}

if (loc === undefined) {
return false;
}
}

return true;
}

function getPath<T extends object, K = unknown>(obj: T, ...keys: (string | number)[]): K | undefined {
if (obj == null) {
return undefined;
}

let loc: unknown = obj;

for (let i = 0; i < keys.length; i++) {
if (typeof loc === "object" && loc !== null) {
loc = (loc as Record<string, unknown>)[getKey(keys[i] as string)];
} else {
return undefined;
}

if (loc === undefined) {
return undefined;
}
}

return loc as K;
}

async function getFiles(dir: string, fileList: string[]) {
const files = await fs.readdir(dir);

Expand Down
Loading

0 comments on commit ef44863

Please sign in to comment.