From 77b40185df23940eeec4a4f0d0916a62bfd921aa Mon Sep 17 00:00:00 2001 From: BTMuli Date: Wed, 19 Apr 2023 15:07:55 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20feat(UIGF):=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=20Uigf=20=E7=B1=BB=E5=9E=8B=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4=20Uiaf=20=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Achievements.vue | 13 ++--- src/types/Gacha.d.ts | 107 +++++++++++++++++++++++++++++++++++++ src/utils/UIAF.ts | 24 ++++----- 3 files changed, 123 insertions(+), 21 deletions(-) create mode 100644 src/types/Gacha.d.ts diff --git a/src/pages/Achievements.vue b/src/pages/Achievements.vue index ecc9df45..aa2c232b 100644 --- a/src/pages/Achievements.vue +++ b/src/pages/Achievements.vue @@ -113,7 +113,7 @@ import { useAchievementsStore } from "../store/modules/achievements"; import { TGAppData } from "../data"; import { createTGWindow } from "../utils/TGWindow"; import { ReadAllTGData, ReadTGDataByIndex, ReadTGDataByKey, UpdateTGDataByKey } from "../utils/TGIndex"; -import { getHeader, readUIAF, verifyUIAF } from "../utils/UIAF"; +import { getUiafHeader, readUiafData, verifyUiafData } from "../utils/UIAF"; // Store const achievementsStore = useAchievementsStore(); @@ -147,11 +147,9 @@ async function loadData () { loadingTitle.value = "正在获取成就系列数据"; const seriesDB: BTMuli.Genshin.AchievementSeries[] = await ReadAllTGData("AchievementSeries"); CardsInfo.value = TGAppData.nameCards[1]; - loadingTitle.value = "对成就系列数据进行排序"; seriesList.value = seriesDB.sort((a, b) => a.order - b.order); loadingTitle.value = "正在获取成就数据"; const getAchievements = await ReadAllTGData("Achievements"); - loadingTitle.value = "正在对成就数据进行排序"; getAchievements.sort((a, b) => { if (a.completed === b.completed) { return a.id - b.id; @@ -159,7 +157,6 @@ async function loadData () { return a.completed ? 1 : -1; } }); - loadingTitle.value = "正在渲染成就数据"; selectedAchievement.value = getAchievements; title.value = achievementsStore.title; loading.value = false; @@ -184,7 +181,6 @@ async function selectSeries (index: number) { } else { getCard = {} as BTMuli.Genshin.NameCard; } - loadingTitle.value = "正在对成就数据进行排序"; getAchievements.sort((a, b) => { if (a.completed === b.completed) { return a.id - b.id; @@ -192,7 +188,6 @@ async function selectSeries (index: number) { return a.completed ? 1 : -1; } }); - loadingTitle.value = "正在渲染成就数据"; selectedAchievement.value = getAchievements; getCardInfo.value = getCard; loading.value = false; @@ -252,8 +247,8 @@ async function importJson () { }, ], }); - if (selectedFile && (await verifyUIAF(selectedFile))) { - const remoteRaw: string | false = await readUIAF(selectedFile); + if (selectedFile && (await verifyUiafData(selectedFile))) { + const remoteRaw: string | false = await readUiafData(selectedFile); if (remoteRaw === false) { snackbarText.value = "读取 UIAF 数据失败,请检查文件是否符合规范"; snackbar.value = true; @@ -339,7 +334,7 @@ async function exportJson () { return data.progress !== 0 || data.completed === true; }); const UiafData = { - info: await getHeader(), + info: await getUiafHeader(), list: [] as TGPlugin.UIAF.Achievement[], }; // 转换数据 diff --git a/src/types/Gacha.d.ts b/src/types/Gacha.d.ts new file mode 100644 index 00000000..7a0351ca --- /dev/null +++ b/src/types/Gacha.d.ts @@ -0,0 +1,107 @@ +/** + * @file types Gacha.d.ts + * @description 卡池祈愿类型定义 + * @author BTMuli + * @since Alpha v0.1.3 + */ + +declare namespace TGPlugin.UIGF { + /** + * @description UIGF 数据 + * @since Alpha v1.3.0 + * @interface BaseData + * @property {UigfInfo} info - UIGF 头部信息 + * @property {UigfGacha[]} list - UIGF 祈愿列表 + * @return BaseData + */ + export interface BaseData { + info: UigfInfo + list: UigfInfo[] + } + + /** + * @description UIGF 头部信息 + * @since Alpha v1.3.0 + * @interface UigfInfo + * @property {string} uid - UID + * @property {string} lang - 语言 + * @property {string} uigf_version - UIGF 版本 + * @property {number} export_timestamp - 导出时间戳(秒) + * @property {string} export_time - 导出时间 yyyy-MM-dd HH:mm:ss + * @property {string} export_app - 导出应用 + * @property {string} export_app_version - 导出应用版本 + * @return UIGF_Info + */ + export interface UigfInfo { + uid: string + lang: string + uigf_version: string + export_timestamp?: number + export_time?: string + export_app?: string + export_app_version?: string + } + + /** + * @description 祈愿类型 + * @since Alpha v1.3.0 + * @enum EnumGachaType + * @property {string} CharacterUp - 角色活动祈愿 + * @property {string} CharacterUp2 - 角色活动祈愿2 + * @property {string} WeaponUp - 武器活动祈愿 + * @property {string} Normal - 普通祈愿 + * @property {string} Newbie - 新手祈愿 + * @return EnumGachaType + */ + export enum EnumGachaType { + CharacterUp = "301", + CharacterUp2 = "400", + WeaponUp = "302", + Normal = "200", + Newbie = "100", + } + + /** + * @description UIGF 祈愿类型 + * @since Alpha v1.3.0 + * @enum EnumUigfGachaType + * @property {string} CharacterUp - 角色活动祈愿&角色活动祈愿2 + * @property {string} WeaponUp - 武器活动祈愿 + * @property {string} Normal - 普通祈愿 + * @property {string} Newbie - 新手祈愿 + * @return EnumUigfGachaType + */ + export enum EnumUigfGachaType { + CharacterUp = "301", + WeaponUp = "302", + Normal = "200", + Newbie = "100", + } + + /** + * @description UIGF 祈愿列表 + * @since Alpha v1.3.0 + * @interface UigfGacha + * @property {EnumGachaType} gacha_type - 祈愿类型 + * @property {string} item_id - 物品ID + * @property {string} count - 数量 + * @property {string} time - 时间 yyyy-MM-dd HH:mm:ss + * @property {string} name - 名称 + * @property {string} item_type - 物品类型 + * @property {string} rank_type - 稀有度 + * @property {string} id - ID + * @property {EnumUigfGachaType} uigf_gacha_type - UIGF 祈愿类型 + * @return UIGF_Gacha + */ + export interface UigfGacha { + gacha_type: string + item_id?: string + count?: string + time: string + name: string + item_type?: string + rank_type?: string + id: string + uigf_gacha_type: string + } +} diff --git a/src/utils/UIAF.ts b/src/utils/UIAF.ts index 59cba826..a483f209 100644 --- a/src/utils/UIAF.ts +++ b/src/utils/UIAF.ts @@ -1,18 +1,18 @@ /** - * @description 获取 UIAF 头部信息 - * @since Alpha v0.1.2 - * @returns {Promise} + * @file utils UIAF.ts + * @description UIAF工具类 + * @author BTMuli + * @since Alpha v0.1.3 */ import { app, fs } from "@tauri-apps/api"; /** * @description 获取 UIAF 头部信息 - * @since Alpha v0.1.2 + * @since Alpha v0.1.3 * @returns {Promise} */ - -export async function getHeader (): Promise { +export async function getUiafHeader (): Promise { return { // eslint-disable-next-line camelcase export_app: "Tauri.Genshin", @@ -28,23 +28,23 @@ export async function getHeader (): Promise { /** * @description 检测是否存在 UIAF 数据 * @description 粗略检测,不保证数据完整性 - * @since Alpha v0.1.2 + * @since Alpha v0.1.3 * @param {string} path - UIAF 数据路径 * @returns {Promise} 是否存在 UIAF 数据 */ -export async function verifyUIAF (path: string): Promise { +export async function verifyUiafData (path: string): Promise { const fileData: string = await fs.readTextFile(path); - const UIAFData: TGPlugin.UIAF.Header = JSON.parse(fileData).info; - return UIAFData.uiaf_version !== undefined; + const UiafData: TGPlugin.UIAF.Header = JSON.parse(fileData).info; + return UiafData.uiaf_version !== undefined; } /** * @description 读取 UIAF 数据 - * @since Alpha v0.1.2 + * @since Alpha v0.1.3 * @param {string} userPath - UIAF 数据路径 * @returns {Promise} UIAF 数据 */ -export async function readUIAF (userPath: string): Promise { +export async function readUiafData (userPath: string): Promise { if (await fs.exists(userPath)) { const fileData = await fs.readTextFile(userPath); if (fileData !== undefined && fileData !== null && fileData !== "" && fileData !== "{}") {