23 lines
931 B
TypeScript
23 lines
931 B
TypeScript
import { z } from "zod";
|
|
import type { CatalogBaseStat } from "@/lib/translator/types";
|
|
|
|
const statValueSchema = z.union([z.number(), z.string()]);
|
|
const lunarisVersionSchema = z.object({ version: z.string().min(1) });
|
|
const lunarisWeaponListSchema = z.record(z.string(), z.object({
|
|
ascensionStats: z.record(z.string(), statValueSchema).optional(),
|
|
}).passthrough());
|
|
|
|
export function parseLunarisVersion(value: unknown): string {
|
|
return lunarisVersionSchema.parse(value).version;
|
|
}
|
|
|
|
export function weaponStatsFromLunaris(value: unknown): Map<string, CatalogBaseStat[]> {
|
|
const weapons = lunarisWeaponListSchema.parse(value);
|
|
return new Map(Object.entries(weapons).map(([id, weapon]) => [
|
|
id,
|
|
Object.entries(weapon.ascensionStats ?? {})
|
|
.map(([key, stat]) => ({ key, value: stat }))
|
|
.sort((left, right) => Number(right.key.toLowerCase() === "atk") - Number(left.key.toLowerCase() === "atk")),
|
|
]));
|
|
}
|