feat: enhance asset management with weapon and relic stores, add fight property enums
This commit is contained in:
+103
-14
@@ -1,3 +1,4 @@
|
||||
import { feature } from "bun:bundle";
|
||||
import { ImageResponse } from "@takumi-rs/image-response";
|
||||
import { file, hash } from "bun";
|
||||
import { NotFoundError, status, t } from "elysia";
|
||||
@@ -16,8 +17,11 @@ import { ConstsSvg } from "@/assets/consts";
|
||||
import { featherImage } from "@/assets/feather";
|
||||
import shadeSvg from "@/assets/shade.svg" with { type: "file" };
|
||||
import fontFile from "@/assets/shinshin.woff2" with { type: "file" };
|
||||
import { star } from "@/assets/stars";
|
||||
import { TalentSvg } from "@/assets/talent";
|
||||
import { AssetManager, getEnkaAvatarStore } from "@/lib/assets";
|
||||
import { WeaponGlazeSvg } from "@/assets/weapon-glaze";
|
||||
import { AssetManager, getEnkaStores } from "@/lib/assets";
|
||||
import { mockData } from "@/lib/mock";
|
||||
|
||||
const assets = new AssetManager();
|
||||
const cache = new TTLCache();
|
||||
@@ -38,16 +42,19 @@ export function card(app: App) {
|
||||
async ({ params: { uid, char: charId }, store: { start } }) => {
|
||||
try {
|
||||
// const data = mockData;
|
||||
const [avatarStore, data] = await Promise.all([
|
||||
getEnkaAvatarStore().finally(() =>
|
||||
console.log(
|
||||
`\n${Date.now() - start}ms - Avatar store loaded`,
|
||||
const [[avatarStore, weaponStore, relicStore, locs], data] =
|
||||
await Promise.all([
|
||||
getEnkaStores().finally(() =>
|
||||
console.log(`\n${Date.now() - start}ms - Stores loaded`),
|
||||
),
|
||||
),
|
||||
fetchEnka(uid, false).finally(() =>
|
||||
console.log(`${Date.now() - start}ms - Enka data loaded`),
|
||||
),
|
||||
]);
|
||||
feature("API")
|
||||
? fetchEnka(uid, false).finally(() =>
|
||||
console.log(
|
||||
`${Date.now() - start}ms - Enka data loaded`,
|
||||
),
|
||||
)
|
||||
: mockData,
|
||||
]);
|
||||
if (typeof data.avatarInfoList === "undefined")
|
||||
return status(400, "The showcase for this UID is private");
|
||||
const char = data.avatarInfoList.find(
|
||||
@@ -62,11 +69,33 @@ export function card(app: App) {
|
||||
"Unsupported character, avatar store doesn't have this character",
|
||||
);
|
||||
|
||||
if (!char.equipList)
|
||||
return status(501, "INTERNAL: No equipList provided");
|
||||
const weapon = {
|
||||
data: char.equipList.find((e) => e.weapon)!.weapon!,
|
||||
store:
|
||||
weaponStore[
|
||||
char.equipList.find((e) => e.weapon)!.itemId ?? "Unknown"
|
||||
],
|
||||
};
|
||||
|
||||
const cacheKey = hash(JSON.stringify(data)).toString(36);
|
||||
const cached = cache.get<ImageResponse>(cacheKey);
|
||||
if (cached) return cached.clone();
|
||||
if (feature("API")) {
|
||||
const cached = cache.get<ImageResponse>(cacheKey);
|
||||
if (cached) return cached.clone();
|
||||
}
|
||||
|
||||
const resources = await Promise.all([
|
||||
assets
|
||||
.load(
|
||||
weapon.data.promoteLevel > 2
|
||||
? weapon.store.AwakenIcon
|
||||
: weapon.store.Icon,
|
||||
)
|
||||
.then((data) => ({
|
||||
src: "/weapon",
|
||||
data,
|
||||
})),
|
||||
...[...avatar.Consts, ...Object.values(avatar.Skills)].map(
|
||||
async (path) => ({
|
||||
src: path,
|
||||
@@ -97,7 +126,10 @@ export function card(app: App) {
|
||||
src: "/bg",
|
||||
data,
|
||||
})),
|
||||
]);
|
||||
] satisfies Promise<{
|
||||
src: string;
|
||||
data: ArrayBuffer | Buffer;
|
||||
}>[]);
|
||||
console.log(
|
||||
`${Date.now() - start}ms - Image resources loaded\n${resources.map((r) => `- ${r.src} ${(r.data.byteLength / 1000).toFixed(2)}Kb`).join("\n")}`,
|
||||
);
|
||||
@@ -232,7 +264,46 @@ export function card(app: App) {
|
||||
</div>
|
||||
</div>
|
||||
{/* middle section */}
|
||||
<div tw="absolute top-0 bottom-0 right-[23.1em] w-[21.5em] p-[1.4em_.7em_.7em]"></div>
|
||||
<div tw="absolute top-0 bottom-0 right-[23.1em] w-[21.5em] p-[1.4em_.7em_.7em] flex flex-col">
|
||||
{/* weapon */}
|
||||
<div tw="flex flex-start" className="Weapon">
|
||||
{/* display */}
|
||||
<div tw="w-[27%] leading-none shrink-0 min-h-[5.5em] relative">
|
||||
<img src="/weapon" alt="Weapon" tw="w-full" />
|
||||
<WeaponGlazeSvg
|
||||
tw="absolute top-[90%] -left-[15%] w-[130%]"
|
||||
style={{
|
||||
color: {
|
||||
1: "#868a82",
|
||||
2: "#70ca7a",
|
||||
3: "#5cabff",
|
||||
4: "#cc7bff",
|
||||
5: "#dd8637",
|
||||
}[weapon.store.Rarity],
|
||||
}}
|
||||
/>
|
||||
<div tw="absolute w-full top-[93%] flex justify-center">
|
||||
{Array.from({ length: weapon.store.Rarity }, (_, i) =>
|
||||
star(i),
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{/* caption */}
|
||||
<div tw="px-[5%] grow text-white self-center">
|
||||
<div
|
||||
tw="text-[108%] leading-[1.3]"
|
||||
style={{
|
||||
textShadow:
|
||||
"0 .08em .1em rgba(0,0,0,.4),0 .1em .3em rgba(0,0,0,.4)",
|
||||
}}
|
||||
>
|
||||
<span>{locs.en[weapon.store.NameTextMapHash]}</span>
|
||||
</div>
|
||||
{/* stats */}
|
||||
<div tw="pt-[3%] pb-[2%]"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/* right section */}
|
||||
<div tw="absolute top-0 bottom-0 right-0 w-[23.1em] p-[.7em]"></div>
|
||||
</div>,
|
||||
@@ -261,6 +332,24 @@ export function card(app: App) {
|
||||
.Talents.Fire { color: #541900!important }
|
||||
.Grass { color: #a5ffab; }
|
||||
.Talents.Grass { color: #134517!important }
|
||||
|
||||
.Substat {
|
||||
display: inline-block;
|
||||
background: rgba(255,255,255,.15);
|
||||
border-radius: .2em;
|
||||
padding: 2% 3%;
|
||||
box-sizing: content-box;
|
||||
margin-right: .5em;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.Weapon .Substat:before {
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
border-radius: .2em
|
||||
}
|
||||
`,
|
||||
],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user