diff --git a/src/pages/User/Gacha.vue b/src/pages/User/Gacha.vue index 953d0f58..2a65c427 100644 --- a/src/pages/User/Gacha.vue +++ b/src/pages/User/Gacha.vue @@ -162,10 +162,10 @@ import useHutaoStore from "@store/hutao.js"; import useUserStore from "@store/user.js"; import { path } from "@tauri-apps/api"; import { open, save } from "@tauri-apps/plugin-dialog"; -import Hakushi from "@utils/Hakushi.js"; import TGLogger from "@utils/TGLogger.js"; import { str2timeStr, timeStr2str } from "@utils/toolFunc.js"; import { exportUigfData } from "@utils/UIGF.js"; +import fetchYattaJson from "@utils/Yatta.js"; import { storeToRefs } from "pinia"; import { onMounted, ref, shallowRef, watch } from "vue"; import { useRouter } from "vue-router"; @@ -190,7 +190,7 @@ const hutaoShow = ref(false); const htMode = ref("download"); const selectItem = shallowRef>([]); const gachaListCur = shallowRef>([]); -const hakushiData = shallowRef>([]); +const yattaData = shallowRef>([]); onMounted(async () => { await showLoading.start("正在加载祈愿数据", "正在获取祈愿 UID 列表"); @@ -386,13 +386,11 @@ async function handleHutaoDownload(uids: Array): Promise { tempItem.item_type = find.itemType; tempItem.rank_type = find.star.toString(); } else { - if (hakushiData.value.length === 0) { - await showLoading.update( - `未查找到 ${tempItem.item_id} 的 信息,正在获取 Hakushi 数据`, - ); - await loadHakushi(); + if (yattaData.value.length === 0) { + await showLoading.update(`未查找到 ${tempItem.item_id} 的 信息,正在获取 Yatta 数据`); + await loadYatta(); } - const findH = hakushiData.value.find((i) => i.id.toString() === item.ItemId.toString()); + const findH = yattaData.value.find((i) => i.id.toString() === item.ItemId.toString()); if (findH) { tempItem.name = findH.name; tempItem.item_type = findH.type; @@ -566,13 +564,11 @@ async function refreshGachaPool( const find = AppCalendarData.find((i) => i.name === item.name); if (find) tempItem.item_id = find.id.toString(); if (tempItem.item_id === "") { - if (hakushiData.value.length === 0) { - await showLoading.update(`未查找到 ${tempItem.name} 的 ItemId,正在获取 Hakushi 数据`); - await loadHakushi(); + if (yattaData.value.length === 0) { + await showLoading.update(`未查找到 ${tempItem.name} 的 ItemId,正在获取 Yatta 数据`); + await loadYatta(); } - const find = hakushiData.value.find( - (i) => i.type === item.item_type && i.name === item.name, - ); + const find = yattaData.value.find((i) => i.type === item.item_type && i.name === item.name); if (find) tempItem.item_id = find.id.toString(); else { showSnackbar.warn(`无法搜索到 ${item.item_type} ${item.name} 的ID,请等待元数据更新`); @@ -593,13 +589,13 @@ async function refreshGachaPool( } } -async function loadHakushi(): Promise { +async function loadYatta(): Promise { try { - hakushiData.value = await Hakushi.fetch(); + yattaData.value = await fetchYattaJson(); } catch (e) { console.error(e); - showSnackbar.warn(`获取Hakushi元数据失败`); - await TGLogger.Error(`[UserGacha][onMounted]获取Hakushi元数据失败`); + showSnackbar.warn(`获取 Yatta 元数据失败`); + await TGLogger.Error(`[UserGacha][onMounted]获取 Yatta 元数据失败`); await TGLogger.Error(`${e}`); } } @@ -713,12 +709,12 @@ async function checkData(): Promise { cnt++; continue; } - if (hakushiData.value.length === 0) { - await showLoading.update(`尝试获取Hakushi数据`); - await loadHakushi(); + if (yattaData.value.length === 0) { + await showLoading.update(`尝试获取 Yatta 数据`); + await loadYatta(); } // TODO: 如果有名字重复的需要注意 - const find2 = hakushiData.value.find((i) => i.name === data.name); + const find2 = yattaData.value.find((i) => i.name === data.name); if (find2) { await showLoading.update(`${data.name} -> ${find2.id}`); await TSUserGacha.update.itemId(data, find2.id); diff --git a/src/types/Plugins/Hakushi.d.ts b/src/types/Plugins/Hakushi.d.ts deleted file mode 100644 index ee6ee87a..00000000 --- a/src/types/Plugins/Hakushi.d.ts +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Hakushi插件相关类型 - * @since Beta v0.9.0 - */ - -declare namespace TGApp.Plugins.Hakushi { - /** - * 武器JSON返回 - * @since Beta v0.9.0 - * @see https://api.hakush.in/gi/data/weapon.json - */ - type WeaponResp = Record; - - /** - * 角色JSON返回 - * @since Beta v0.9.0 - * @see https://api.hakush.in/gi/data/character.json - */ - type AvatarResp = Record; - - /** - * 武器信息 - * @since Beta v0.9.0 - */ - type WeaponBrief = { - /** 图标 */ - icon: string; - /** 稀有度 */ - rank: number; - /** - * 类型 - * @remarks 枚举 - * @example - * - WEAPON_BOW 弓 - */ - type: string; - /** 英文译名 */ - EN: string; - /** 描述(英文) */ - desc: string; - /** 韩文译名 */ - KR: string; - /** 中文译名 */ - CHS: string; - /** 日文译名 */ - JP: string; - }; - - /** - * 角色信息 - * @since Beta v0.9.0 - */ - type AvatarBrief = { - /** 生日 */ - birth: Array; - /** 图标 */ - icon: string; - /** 稀有度 */ - rank: number; - /** - * 武器类型 - * @remarks 枚举 - * @example - * - WEAPON_BOW 弓 - */ - weapon: string; - /** 上线时间 */ - release: string; - /** 元素 */ - element: string; - /** 英文译名 */ - EN: string; - /** 描述(英文) */ - desc: string; - /** 韩文译名 */ - KR: string; - /** 中文译名 */ - CHS: string; - /** 日文译名 */ - JP: string; - }; - - /** - * 转换后的数据 - * @since Beta v0.9.1 - */ - type ConvertData = { - /** ID */ - id: string; - /** 名称 */ - name: string; - /** 类型 */ - type: "武器" | "角色"; - /** 星级 */ - star: number; - }; -} diff --git a/src/types/Plugins/Yatta.d.ts b/src/types/Plugins/Yatta.d.ts new file mode 100644 index 00000000..89e6f623 --- /dev/null +++ b/src/types/Plugins/Yatta.d.ts @@ -0,0 +1,157 @@ +/** + * Yatta 插件相关类型 + * @since Beta v0.9.6 + */ + +declare namespace TGApp.Plugins.Yatta { + /** + * 通用 Yatta 接口返回响应 + * @since Beta v0.9.6 + */ + type Resp = { + /** 回复码 */ + response: number; + /** 数据 */ + data: T; + }; + + /** + * 角色 JSON 返回 + * @since Beta v0.9.6 + * @see https://gi.yatta.moe/api/v2/chs/avatar + */ + type AvatarResp = Resp; + + /** + * 武器 JSON 返回 + * @since Beta v0.9.6 + * @see https://gi.yatta.moe/api/v2/chs/weapon + */ + type WeaponResp = Resp; + + /** + * 角色返回数据 + * @since Beta v0.9.6 + */ + type AvatarRes = { + /** + * 属性 + * @remarks 未使用 + */ + props: unknown; + /** + * 类型 + * @remarks 未使用 + */ + types: unknown; + /** 角色列表 */ + items: Record; + }; + + /** + * 角色数据 + * @since Beta v0.9.6 + */ + type Avatar = { + /** ID */ + id: number; + /** 星级 */ + rank: number; + /** 名称 */ + name: string; + /** + * 元素类型 + * @example Fire + */ + element: string; + /** + * 武器类型 + * @example WEAPON_CLAYMORE + */ + weaponType: string; + /** + * 区域 + * @example MONDSTAT + */ + region: string; + /** + * 特殊属性 + * @example FIGHT_PROP_CRITICAL + */ + specialProp: string; + /** + * 体型 + * @example MALE + */ + bodyType: string; + /** 图标 */ + icon: string; + /** 生日 */ + birthday: Array & { length: 2 }; + /** 发行时间戳(秒) */ + release: number; + /** 路由 */ + route: string; + }; + + /** + * 武器返回数据 + * @since Beta v0.9.6 + */ + type WeaponRes = { + /** + * 属性 + * @remarks 未使用 + */ + props: unknown; + /** + * 类型 + * @remarks 未使用 + */ + types: unknown; + /** 武器列表 */ + items: Record; + }; + + /** + * 武器数据 + * @since Beta v0.9.6 + */ + type Weapon = { + /** ID */ + id: number; + /** 星级 */ + rank: number; + /** + * 武器类型 + * @example WEAPON_SWORD_ONE_HAND + */ + type: string; + /** 名称 */ + name: string; + /** + * 特殊属性 + * @example FIGHT_PROP_ELEMENT_MASTERY + */ + specialProp: string; + /** 图标 */ + icon: string; + /** 路由 */ + route: string; + }; + + /** + * 转换后的数据 + * @since Beta v0.9.6 + */ + type ConvertData = { + /** ID */ + id: string; + /** 名称 */ + name: string; + /** 类型 */ + type: "武器" | "角色"; + /** 星级 */ + star: number; + }; +} diff --git a/src/utils/Hakushi.ts b/src/utils/Hakushi.ts deleted file mode 100644 index 1b444636..00000000 --- a/src/utils/Hakushi.ts +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Hakushi 插件入口 - * @since Beta v0.9.0 - */ -import TGHttp from "@utils/TGHttp.js"; - -const HAKUSHI_API = "https://api.hakush.in/gi/data/"; - -/** - * 请求角色数据 - * @since Beta v0.9.0 - * @returns 角色数据 - */ -async function fetchAvatar(): Promise { - return await TGHttp(`${HAKUSHI_API}character.json`, { - method: "GET", - }); -} - -/** - * 请求武器数据 - * @since Beta v0.9.0 - * @returns 武器数据 - */ -async function fetchWeapon(): Promise { - return await TGHttp(`${HAKUSHI_API}weapon.json`, { - method: "GET", - }); -} - -/** - * 转换数据 - * @since Beta v0.9.1 - */ -async function fetchJson(): Promise> { - const jsonW = await fetchWeapon(); - const jsonA = await fetchAvatar(); - const res: Array = []; - for (const [id, data] of Object.entries(jsonW)) { - res.push({ id: id.toString(), name: data.CHS, type: "武器", star: data.rank }); - } - for (const [id, data] of Object.entries(jsonA)) { - res.push({ id: id.toString(), name: data.CHS, type: "角色", star: data.rank }); - } - return res; -} - -const Hakushi = { - fetch: fetchJson, -}; - -export default Hakushi; diff --git a/src/utils/Yatta.ts b/src/utils/Yatta.ts new file mode 100644 index 00000000..5a776866 --- /dev/null +++ b/src/utils/Yatta.ts @@ -0,0 +1,48 @@ +/** + * Yatta 插件入口 + * @since Beta v0.9.6 + */ +import TGHttp from "@utils/TGHttp.js"; + +const YATTA_API = "https://gi.yatta.moe/api/v2/"; + +/** + * 请求角色数据 + * @since Beta v0.9.6 + * @returns 角色数据 + */ +async function fetchAvatar(): Promise { + return await TGHttp(`${YATTA_API}avatar`, { + method: "GET", + }); +} + +/** + * 请求武器数据 + * @since Beta v0.9.6 + * @returns 武器数据 + */ +async function fetchWeapon(): Promise { + return await TGHttp(`${YATTA_API}weapon`, { + method: "GET", + }); +} + +/** + * 转换数据 + * @since Beta v0.9.6 + */ +async function fetchYattaJson(): Promise> { + const jsonW = await fetchWeapon(); + const jsonA = await fetchAvatar(); + const res: Array = []; + for (const weapon of Object.values(jsonW.data.items)) { + res.push({ id: weapon.id.toString(), name: weapon.name, type: "武器", star: weapon.rank }); + } + for (const avatar of Object.values(jsonA.data.items)) { + res.push({ id: avatar.id.toString(), name: avatar.name, type: "角色", star: avatar.rank }); + } + return res; +} + +export default fetchYattaJson;