FIX: Monster bar
All checks were successful
Gitea Auto Deploy / Deploy-Container (push) Successful in 1m38s

This commit is contained in:
2025-07-25 11:30:19 +07:00
parent 13d27bb014
commit a649ec14ac
19 changed files with 159 additions and 38 deletions

View File

@@ -1,4 +1,5 @@
import useSocketStore from "@/stores/socketSettingStore";
import { EnemyHakushiRawType, EnemyHakushiType } from "@/types";
import { AvatarHakushiType, AvatarHakushiRawType } from "@/types/avatar";
import axios from 'axios';
@@ -46,6 +47,29 @@ export async function getCharacterListApi(): Promise<AvatarHakushiType[]> {
}
}
export async function getEnemyListApi(): Promise<EnemyHakushiType[]> {
try {
const res = await axios.get<Record<string, EnemyHakushiRawType>>(
'https://api.hakush.in/hsr/data/monster.json',
{
headers: {
'Content-Type': 'application/json',
},
}
);
const data = new Map(Object.entries(res.data));
return Array.from(data.entries()).map(([id, it]) => convertMonster(id, it));
} catch (error: unknown) {
if (axios.isAxiosError(error)) {
console.log(`Error: ${error.response?.status} - ${error.message}`);
} else {
console.log(`Unexpected error: ${String(error)}`);
}
return [];
}
}
function convertAvatar(id: string, item: AvatarHakushiRawType): AvatarHakushiType {
const lang = new Map<string, string>([
@@ -66,5 +90,26 @@ function convertAvatar(id: string, item: AvatarHakushiRawType): AvatarHakushiTyp
id: id
};
return result;
}
export function convertMonster(id: string, item: EnemyHakushiRawType): EnemyHakushiType {
const lang = new Map<string, string>([
['en', item.en],
['kr', item.kr],
['cn', item.cn],
['jp', item.jp]
]);
const result: EnemyHakushiType = {
id: id,
rank: item.rank,
camp: item.camp,
icon: item.icon,
child: item.child,
weak: item.weak,
desc: item.desc,
lang: lang
};
return result;
}