feat: enhance asset management with weapon and relic stores, add fight property enums
This commit is contained in:
+55
-6
@@ -2,7 +2,7 @@ import { mkdir, readdir } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { file, hash, write } from "bun";
|
||||
import { TTLCache } from "enka.ts";
|
||||
import { AvatarStore } from "@/type/enka";
|
||||
import { AvatarStore, EnkaLocs, RelicStore, WeaponStore } from "@/type/enka";
|
||||
|
||||
export const cache = new TTLCache();
|
||||
|
||||
@@ -10,17 +10,21 @@ export class AssetManager {
|
||||
private cache = new Map<string, ArrayBuffer>();
|
||||
|
||||
async getMissingAssets() {
|
||||
const store = await getEnkaAvatarStore();
|
||||
const avatars = await getEnkaAvatarStore();
|
||||
const weapons = await getEnkaWeaponStore();
|
||||
const relics = await getEnkaRelicStore();
|
||||
await mkdir("store").catch(() => {});
|
||||
const existing = await readdir("store");
|
||||
const missing = new Set<string>();
|
||||
Object.values(store)
|
||||
.flatMap((a) => [
|
||||
[
|
||||
...Object.values(avatars).flatMap((a) => [
|
||||
...a.Consts,
|
||||
...Object.values(a.Skills),
|
||||
a.SideIconName.replace("AvatarIcon_Side", "Gacha_AvatarImg"),
|
||||
])
|
||||
.map((n) => existing.includes(hash(n).toString(36)) || missing.add(n));
|
||||
]),
|
||||
...Object.values(weapons).flatMap((w) => [w.Icon, w.AwakenIcon]),
|
||||
...Object.values(relics.Items).map((r) => r.Icon),
|
||||
].map((n) => existing.includes(hash(n).toString(36)) || missing.add(n));
|
||||
|
||||
console.log(
|
||||
`${missing.size} assets missing, ${existing.length} assets in store`,
|
||||
@@ -89,6 +93,15 @@ export class AssetManager {
|
||||
}
|
||||
}
|
||||
|
||||
export async function getEnkaStores() {
|
||||
return Promise.all([
|
||||
getEnkaAvatarStore(),
|
||||
getEnkaWeaponStore(),
|
||||
getEnkaRelicStore(),
|
||||
getEnkaLocs(),
|
||||
]);
|
||||
}
|
||||
|
||||
export async function getEnkaAvatarStore(): Promise<AvatarStore> {
|
||||
const cached = cache.get("enkaAvatarStore");
|
||||
if (cached) return cached as AvatarStore;
|
||||
@@ -100,3 +113,39 @@ export async function getEnkaAvatarStore(): Promise<AvatarStore> {
|
||||
cache.set("enkaAvatarStore", data, 86400); // 24 hours
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getEnkaWeaponStore(): Promise<WeaponStore> {
|
||||
const cached = cache.get("enkaWeaponStore");
|
||||
if (cached) return cached as WeaponStore;
|
||||
|
||||
const response = await fetch(
|
||||
"https://github.com/EnkaNetwork/API-docs/raw/refs/heads/master/store/gi/weapons.json",
|
||||
);
|
||||
const data = await response.json();
|
||||
cache.set("enkaWeaponStore", data, 86400); // 24 hours
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getEnkaRelicStore(): Promise<RelicStore> {
|
||||
const cached = cache.get("enkaRelicStore");
|
||||
if (cached) return cached as RelicStore;
|
||||
|
||||
const response = await fetch(
|
||||
"https://github.com/EnkaNetwork/API-docs/raw/refs/heads/master/store/gi/relics.json",
|
||||
);
|
||||
const data = await response.json();
|
||||
cache.set("enkaRelicStore", data, 86400); // 24 hours
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getEnkaLocs(): Promise<EnkaLocs> {
|
||||
const cached = cache.get("enkaLocs");
|
||||
if (cached) return cached as EnkaLocs;
|
||||
|
||||
const response = await fetch(
|
||||
"https://github.com/EnkaNetwork/API-docs/raw/refs/heads/master/store/gi/locs.json",
|
||||
);
|
||||
const data = await response.json();
|
||||
cache.set("enkaLocs", data, 86400); // 24 hours
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user