Files
buzz-sheet/lib/catalog/lunaris.ts
T
gunshiz 22b09a6136
CI / Verify (push) Successful in 1m7s
CI / Build immutable images and deploy (push) Successful in 3m7s
feat(guides): add team loadouts and element icons
2026-08-30 05:39:54 +00:00

61 lines
1.6 KiB
TypeScript

import * as z from "zod";
export interface CatalogConstellation {
level: number;
name: string;
description: string;
iconKey: string | null;
}
const constellationSchema = z.object({
name: z.string(),
description: z.string(),
icon: z.string(),
});
export const characterDetailSchema = z.object({
info: z.object({
element: z.string().optional(),
weapon: z.string().optional(),
}).nullish(),
constellations: z.record(z.string(), constellationSchema).nullish(),
});
export function cleanLunarisText(value: string): string {
return value
.replace(/\{\/?LINK[^}]*\}/gu, "")
.replace(/<\/?color(?:=[^>]*)?>/gu, "")
.replace(/^"|"$/gu, "")
.trim();
}
export function avatarIconName(value: string): string {
return value.replace(/^UI_Gacha_AvatarIcon_/u, "UI_AvatarIcon_");
}
export function supportsWeaponType(
characterWeaponType: string | null | undefined,
weaponType: string | null | undefined,
): boolean {
return Boolean(characterWeaponType && characterWeaponType === weaponType);
}
export function constellationSnapshot(
value: z.infer<typeof characterDetailSchema>,
iconKey: (icon: string) => string,
): CatalogConstellation[] {
const result: CatalogConstellation[] = [];
for (const index of Array.from({ length: 6 }, (_, itemIndex) => itemIndex)) {
const level = index + 1;
const item = value.constellations?.[`const${level}`];
if (!item) continue;
result.push({
level,
name: cleanLunarisText(item.name),
description: cleanLunarisText(item.description),
iconKey: iconKey(item.icon),
});
}
return result;
}