mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2026-03-26 05:39:45 +08:00
👽️ 替换祈愿数据源为yatta
This commit is contained in:
@@ -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<boolean>(false);
|
||||
const htMode = ref<UgoHutaoMode>("download");
|
||||
const selectItem = shallowRef<Array<string>>([]);
|
||||
const gachaListCur = shallowRef<Array<TGApp.Sqlite.Gacha.Gacha>>([]);
|
||||
const hakushiData = shallowRef<Array<TGApp.Plugins.Hakushi.ConvertData>>([]);
|
||||
const yattaData = shallowRef<Array<TGApp.Plugins.Yatta.ConvertData>>([]);
|
||||
|
||||
onMounted(async () => {
|
||||
await showLoading.start("正在加载祈愿数据", "正在获取祈愿 UID 列表");
|
||||
@@ -386,13 +386,11 @@ async function handleHutaoDownload(uids: Array<string>): Promise<void> {
|
||||
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<void> {
|
||||
async function loadYatta(): Promise<void> {
|
||||
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<void> {
|
||||
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);
|
||||
|
||||
97
src/types/Plugins/Hakushi.d.ts
vendored
97
src/types/Plugins/Hakushi.d.ts
vendored
@@ -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<string, WeaponBrief>;
|
||||
|
||||
/**
|
||||
* 角色JSON返回
|
||||
* @since Beta v0.9.0
|
||||
* @see https://api.hakush.in/gi/data/character.json
|
||||
*/
|
||||
type AvatarResp = Record<string, AvatarBrief>;
|
||||
|
||||
/**
|
||||
* 武器信息
|
||||
* @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<number>;
|
||||
/** 图标 */
|
||||
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;
|
||||
};
|
||||
}
|
||||
157
src/types/Plugins/Yatta.d.ts
vendored
Normal file
157
src/types/Plugins/Yatta.d.ts
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
/**
|
||||
* Yatta 插件相关类型
|
||||
* @since Beta v0.9.6
|
||||
*/
|
||||
|
||||
declare namespace TGApp.Plugins.Yatta {
|
||||
/**
|
||||
* 通用 Yatta 接口返回响应
|
||||
* @since Beta v0.9.6
|
||||
*/
|
||||
type Resp<T = unknown> = {
|
||||
/** 回复码 */
|
||||
response: number;
|
||||
/** 数据 */
|
||||
data: T;
|
||||
};
|
||||
|
||||
/**
|
||||
* 角色 JSON 返回
|
||||
* @since Beta v0.9.6
|
||||
* @see https://gi.yatta.moe/api/v2/chs/avatar
|
||||
*/
|
||||
type AvatarResp = Resp<AvatarRes>;
|
||||
|
||||
/**
|
||||
* 武器 JSON 返回
|
||||
* @since Beta v0.9.6
|
||||
* @see https://gi.yatta.moe/api/v2/chs/weapon
|
||||
*/
|
||||
type WeaponResp = Resp<WeaponRes>;
|
||||
|
||||
/**
|
||||
* 角色返回数据
|
||||
* @since Beta v0.9.6
|
||||
*/
|
||||
type AvatarRes = {
|
||||
/**
|
||||
* 属性
|
||||
* @remarks 未使用
|
||||
*/
|
||||
props: unknown;
|
||||
/**
|
||||
* 类型
|
||||
* @remarks 未使用
|
||||
*/
|
||||
types: unknown;
|
||||
/** 角色列表 */
|
||||
items: Record<string, Avatar>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 角色数据
|
||||
* @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<number> & { length: 2 };
|
||||
/** 发行时间戳(秒) */
|
||||
release: number;
|
||||
/** 路由 */
|
||||
route: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* 武器返回数据
|
||||
* @since Beta v0.9.6
|
||||
*/
|
||||
type WeaponRes = {
|
||||
/**
|
||||
* 属性
|
||||
* @remarks 未使用
|
||||
*/
|
||||
props: unknown;
|
||||
/**
|
||||
* 类型
|
||||
* @remarks 未使用
|
||||
*/
|
||||
types: unknown;
|
||||
/** 武器列表 */
|
||||
items: Record<string, Weapon>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 武器数据
|
||||
* @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;
|
||||
};
|
||||
}
|
||||
@@ -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<TGApp.Plugins.Hakushi.AvatarResp> {
|
||||
return await TGHttp<TGApp.Plugins.Hakushi.AvatarResp>(`${HAKUSHI_API}character.json`, {
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求武器数据
|
||||
* @since Beta v0.9.0
|
||||
* @returns 武器数据
|
||||
*/
|
||||
async function fetchWeapon(): Promise<TGApp.Plugins.Hakushi.WeaponResp> {
|
||||
return await TGHttp<TGApp.Plugins.Hakushi.WeaponResp>(`${HAKUSHI_API}weapon.json`, {
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换数据
|
||||
* @since Beta v0.9.1
|
||||
*/
|
||||
async function fetchJson(): Promise<Array<TGApp.Plugins.Hakushi.ConvertData>> {
|
||||
const jsonW = await fetchWeapon();
|
||||
const jsonA = await fetchAvatar();
|
||||
const res: Array<TGApp.Plugins.Hakushi.ConvertData> = [];
|
||||
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;
|
||||
48
src/utils/Yatta.ts
Normal file
48
src/utils/Yatta.ts
Normal file
@@ -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<TGApp.Plugins.Yatta.AvatarResp> {
|
||||
return await TGHttp<TGApp.Plugins.Yatta.AvatarResp>(`${YATTA_API}avatar`, {
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求武器数据
|
||||
* @since Beta v0.9.6
|
||||
* @returns 武器数据
|
||||
*/
|
||||
async function fetchWeapon(): Promise<TGApp.Plugins.Yatta.WeaponResp> {
|
||||
return await TGHttp<TGApp.Plugins.Yatta.WeaponResp>(`${YATTA_API}weapon`, {
|
||||
method: "GET",
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换数据
|
||||
* @since Beta v0.9.6
|
||||
*/
|
||||
async function fetchYattaJson(): Promise<Array<TGApp.Plugins.Yatta.ConvertData>> {
|
||||
const jsonW = await fetchWeapon();
|
||||
const jsonA = await fetchAvatar();
|
||||
const res: Array<TGApp.Plugins.Yatta.ConvertData> = [];
|
||||
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;
|
||||
Reference in New Issue
Block a user