From eb8430633ff346b45a575c335d9a3c8eaa8a058a Mon Sep 17 00:00:00 2001 From: biuuu <10892119+biuuu@users.noreply.github.com> Date: Wed, 10 Jan 2024 11:22:02 +0800 Subject: [PATCH] Enhance the functionality for importing data. (#242) --- package.json | 3 +- src/gachaType.json | 210 ++++++++++ src/i18n/English.json | 11 +- ...\344\275\223\344\270\255\346\226\207.json" | 11 +- src/main/UIGFJson.js | 53 +-- src/main/gachaTypeMap.js | 18 + src/main/getData.js | 12 +- src/main/itemTypeMap.js | 395 ------------------ src/renderer/App.vue | 11 +- src/renderer/components/Setting.vue | 26 +- src/schema/local-data.json | 54 +++ yarn.lock | 2 +- 12 files changed, 354 insertions(+), 452 deletions(-) create mode 100644 src/gachaType.json create mode 100644 src/main/gachaTypeMap.js delete mode 100644 src/main/itemTypeMap.js create mode 100644 src/schema/local-data.json diff --git a/package.json b/package.json index 616afd8d..585c8241 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "genshin-wish-export", - "version": "0.10.1", + "version": "0.10.2", "main": "./dist/electron/main/main.js", "author": "biuuu ", "homepage": "https://github.com/biuuu/genshin-wish-export", @@ -80,6 +80,7 @@ "@vitejs/plugin-vue": "2.1.0", "@vue/compiler-sfc": "^3.2.29", "adm-zip": "^0.5.9", + "ajv": "6", "autoprefixer": "^10.4.2", "cfonts": "^2.10.0", "chalk": "^4.1.0", diff --git a/src/gachaType.json b/src/gachaType.json new file mode 100644 index 00000000..3ca52779 --- /dev/null +++ b/src/gachaType.json @@ -0,0 +1,210 @@ +{ + "en-us": [{ + "key": "200", + "name": "Permanent Wish" + }, { + "key": "100", + "name": "Novice Wishes" + }, { + "key": "301", + "name": "Character Event Wish" + }, { + "key": "302", + "name": "Weapon Event Wish" + }, { + "key": "400", + "name": "Character Event Wish-2" + }], + "fr-fr": [{ + "key": "200", + "name": "Vœux permanents" + }, { + "key": "100", + "name": "Vœux des débutants" + }, { + "key": "301", + "name": "Vœux événements de personnage" + }, { + "key": "302", + "name": "Vœux événements d'arme" + }, { + "key": "400", + "name": "Vœux événements de personnage - 2" + }], + "de-de": [{ + "key": "200", + "name": "Standardgebet" + }, { + "key": "100", + "name": "Neulingsgebete" + }, { + "key": "301", + "name": "Figurenaktionsgebet" + }, { + "key": "302", + "name": "Waffenaktionsgebet" + }, { + "key": "400", + "name": "Figurenaktionsgebet 2" + }], + "es-es": [{ + "key": "200", + "name": "Gachapón permanente" + }, { + "key": "100", + "name": "Gachapón de principiante" + }, { + "key": "301", + "name": "Gachapón promocional de personaje" + }, { + "key": "302", + "name": "Gachapón promocional de arma" + }, { + "key": "400", + "name": "Gachapón promocional de personaje 2" + }], + "pt-pt": [{ + "key": "200", + "name": "Desejo Comum" + }, { + "key": "100", + "name": "Desejos de Novato" + }, { + "key": "301", + "name": "Oração do Evento do Personagem" + }, { + "key": "302", + "name": "Oração do Evento de Arma" + }, { + "key": "400", + "name": "Oração de Evento de Personagem - 2" + }], + "ru-ru": [{ + "key": "200", + "name": "Стандартная молитва" + }, { + "key": "100", + "name": "Молитва новичка" + }, { + "key": "301", + "name": "Молитва события персонажа" + }, { + "key": "302", + "name": "Молитва события оружия" + }, { + "key": "400", + "name": "Молитва события персонажа II" + }], + "ja-jp": [{ + "key": "200", + "name": "通常祈願" + }, { + "key": "100", + "name": "初心者向け祈願" + }, { + "key": "301", + "name": "イベント祈願・キャラクター" + }, { + "key": "302", + "name": "イベント祈願・武器" + }, { + "key": "400", + "name": "イベント祈願・キャラクター 2" + }], + "ko-kr": [{ + "key": "200", + "name": "상주 기원" + }, { + "key": "100", + "name": "초심자 기원" + }, { + "key": "301", + "name": "캐릭터 이벤트 기원" + }, { + "key": "302", + "name": "무기 이벤트 기원" + }, { + "key": "400", + "name": "캐릭터 이벤트 기원-2" + }], + "th-th": [{ + "key": "200", + "name": "อธิษฐานถาวร" + }, { + "key": "100", + "name": "ผู้เริ่มอธิษฐาน" + }, { + "key": "301", + "name": "กิจกรรมอธิษฐานตัวละคร" + }, { + "key": "302", + "name": "กิจกรรมอธิษฐานอาวุธ" + }, { + "key": "400", + "name": "กิจกรรมอธิษฐานตัวละคร - 2" + }], + "vi-vn": [{ + "key": "200", + "name": "Cầu Nguyện Thường" + }, { + "key": "100", + "name": "Cầu Nguyện Tân Thủ" + }, { + "key": "301", + "name": "Cầu Nguyện Nhân Vật" + }, { + "key": "302", + "name": "Cầu Nguyện Vũ Khí" + }, { + "key": "400", + "name": "Cầu Nguyện Nhân Vật-2" + }], + "id-id": [{ + "key": "200", + "name": "Permohonan Standar" + }, { + "key": "100", + "name": "Permohonan Pemula" + }, { + "key": "301", + "name": "Event Permohonan Karakter" + }, { + "key": "302", + "name": "Event Permohonan Senjata" + }, { + "key": "400", + "name": "Event Permohonan Karakter - 2" + }], + "zh-cn": [{ + "key": "200", + "name": "常驻祈愿" + }, { + "key": "100", + "name": "新手祈愿" + }, { + "key": "301", + "name": "角色活动祈愿" + }, { + "key": "302", + "name": "武器活动祈愿" + }, { + "key": "400", + "name": "角色活动祈愿-2" + }], + "zh-tw": [{ + "key": "200", + "name": "常駐祈願" + }, { + "key": "100", + "name": "新手祈願" + }, { + "key": "301", + "name": "角色活動祈願" + }, { + "key": "302", + "name": "武器活動祈願" + }, { + "key": "400", + "name": "角色活動祈願-2" + }] +} \ No newline at end of file diff --git a/src/i18n/English.json b/src/i18n/English.json index d2c5d27d..d6323d05 100644 --- a/src/i18n/English.json +++ b/src/i18n/English.json @@ -50,13 +50,12 @@ "ui.setting.fetchFullHistoryHint": "When this option is enabled, click the \"Update Data\" button to get all the card draw records within 6 months. When there are incorrect data within 6 months, this function can be used to repair.", "ui.setting.closeProxy": "Disable system proxy", "ui.setting.closeProxyHint": "When you choose proxy mode, if the program crashes it can cause unwanted results that may affect your system. You can click this button to clear the system proxy settings.", - "ui.setting.UIGFHint": "This feature is used to export data to other wish history management tools (The first export may require a longer waiting time). For a list of supported tools, refer to this link:", - "ui.setting.UIGFImportButton": "Import JSON file", - "ui.setting.UIGFImportHint": "This feature is used to import data from other wish history management tools. For a list of supported tools, refer to this link:", - "ui.setting.UIGFImportLable": "Import from other tools", + "ui.setting.UIGFHint": "This feature is used for importing/exporting data (the first export may take some time). Refer to this link for supported tools:", + "ui.setting.UIGFImportButton": "Import data", + "ui.setting.UIGFImportSuccessed": "Data has been imported", "ui.setting.UIGFLink": "Uniformed Interchangeable GachaLog Format Standard", - "ui.setting.UIGFLable": "Export to other tools", - "ui.setting.UIGFButton": "Export JSON file", + "ui.setting.UIGFLable": "Import / Export", + "ui.setting.UIGFButton": "Export data", "ui.setting.UIGFReadable": "Readable", "ui.about.title": "About", "ui.about.license": "This software is opensource using MIT license.", diff --git "a/src/i18n/\347\256\200\344\275\223\344\270\255\346\226\207.json" "b/src/i18n/\347\256\200\344\275\223\344\270\255\346\226\207.json" index 65e40acc..9678998e 100644 --- "a/src/i18n/\347\256\200\344\275\223\344\270\255\346\226\207.json" +++ "b/src/i18n/\347\256\200\344\275\223\344\270\255\346\226\207.json" @@ -50,13 +50,12 @@ "ui.setting.fetchFullHistoryHint": "开启时点击“更新数据”按钮会完整获取6个月内所有的抽卡记录,当记录里有6个月范围以内的错误数据时可以通过这个功能修复。", "ui.setting.closeProxy": "关闭系统代理", "ui.setting.closeProxyHint": "如果使用过代理模式时工具非正常关闭,可能导致系统代理设置没能清除,可以通过这个按钮来清除设置过的系统代理。", - "ui.setting.UIGFHint": "该功能用于导出数据到其它抽卡记录管理工具(首次导出需要花费一点时间),支持的工具参考这个链接:", - "ui.setting.UIGFImportButton": "导入JSON文件", - "ui.setting.UIGFImportHint": "该功能用于从其它抽卡记录管理工具导入数据,支持的工具参考这个链接:", - "ui.setting.UIGFImportLable": "从其它工具导入", + "ui.setting.UIGFHint": "该功能用于导入/导出数据(首次导出需要花费一点时间),支持的工具参考这个链接:", + "ui.setting.UIGFImportButton": "导入数据", + "ui.setting.UIGFImportSuccessed": "数据已导入", "ui.setting.UIGFLink": "统一可交换抽卡记录标准", - "ui.setting.UIGFLable": "导出到其它工具", - "ui.setting.UIGFButton": "导出JSON文件", + "ui.setting.UIGFLable": "导入/导出", + "ui.setting.UIGFButton": "导出数据", "ui.setting.UIGFReadable": "可读", "ui.about.title": "关于", "ui.about.license": "本工具为开源软件,源代码使用 MIT 协议授权", diff --git a/src/main/UIGFJson.js b/src/main/UIGFJson.js index 0aa99516..7a2a824c 100644 --- a/src/main/UIGFJson.js +++ b/src/main/UIGFJson.js @@ -1,17 +1,18 @@ const { app, ipcMain, dialog } = require('electron') const fs = require('fs-extra') const path = require('path') -const getData = require('./getData').getData -const getItemTypeMap = require('./itemTypeMap').getItemTypeMap +const { getData, saveData, changeCurrent } = require('./getData') +const getItemTypeNameMap = require('./gachaTypeMap').getItemTypeNameMap const { version } = require('../../package.json') const config = require('./config') const fetch = require('electron-fetch').default -const { readJSON, saveJSON, existsFile } = require('./utils') -const Ajv = require("ajv") +const { readJSON, saveJSON, existsFile, userDataPath } = require('./utils') +const Ajv = require('ajv') // acquire uigf schema -const validateUigfJson = new Ajv().compile(require('../schema/uigf.json')); -const gachaListFileNamePattern = /^gacha-list-.*\.json$/; +const validateUigfJson = new Ajv().compile(require('../schema/uigf.json')) +const validateLocalJson = new Ajv().compile(require('../schema/local-data.json')) +const gachaListFileNamePattern = /^gacha-list-.*\.json$/ const uigfLangMap = new Map([ ['zh-cn', 'chs'], @@ -202,13 +203,14 @@ const start = async () => { } } -const readUigfJson = async (path) => { - fs.ensureFileSync(path) - const data = JSON.parse(fs.readFileSync(path, 'utf8')); - if (!validateUigfJson(data)) { - throw new Error(`UIGF Json Schema Validation Failed!`) +const saveAndBackup = async (data) => { + if (existsFile(`gacha-list-${data.uid}.json`)) { + const backupDir = path.join(userDataPath, 'backup', data.uid) + await fs.ensureDir(backupDir) + await fs.copyFile(path.join(userDataPath, `gacha-list-${data.uid}.json`), path.join(backupDir, `gacha-list-${data.uid}-${getTimeString()}.json`)) } - return data + await saveData(data) + await changeCurrent(data.uid) } const importJson = async () => { @@ -220,28 +222,29 @@ const importJson = async () => { }) if (filePathArr) { const filePath = filePathArr[0] - const fileBaseName = path.basename(filePath) - // if the imported json file is gacha-list-*.json file - if (gachaListFileNamePattern.test(fileBaseName)){ - fs.ensureFileSync(filePath) - await saveJSON(fileBaseName, JSON.parse(fs.readFileSync(filePath, 'utf8'))) - } - // else just assume the file is UIGF standard complaint - else { - const importData = await readUigfJson(filePath); + const jsonStr = await fs.readFile(filePath, 'utf8') + const importData = JSON.parse(jsonStr) + if (validateLocalJson(importData)) { + await saveAndBackup(importData) + } else if (validateUigfJson(importData)) { const gachaData = { result: new Map(), time: Date.now(), - typeMap: getItemTypeMap(importData.info.lang), + typeMap: getItemTypeNameMap(importData.info.lang), uid: importData.info.uid, lang: importData.info.lang } gachaData.typeMap.forEach((_, k) => gachaData.result.set(k, [])) + importData.list.sort((a, b) => parseInt(BigInt(a.id) - BigInt(b.id))) for (const item of importData.list) { - gachaData.result.get(item.uigf_gacha_type).push([item.time, item.name, item.item_type, Number(item.rank_type), item.gacha_type, item.id]) + gachaData.result.get(item.uigf_gacha_type).push([item.time, item.name, item.item_type, parseInt(item.rank_type), item.gacha_type, item.id]) } - await saveJSON(`gacha-list-${importData.info.uid}.json`, gachaData) + await saveAndBackup(gachaData) + } else { + throw new Error(`JSON format error`) } + } else { + return 'canceled' } } @@ -250,7 +253,7 @@ ipcMain.handle('EXPORT_UIGF_JSON', async () => { }) ipcMain.handle('IMPORT_UIGF_JSON', async () => { - await importJson() + return await importJson() }) module.exports = { uigfJson } \ No newline at end of file diff --git a/src/main/gachaTypeMap.js b/src/main/gachaTypeMap.js new file mode 100644 index 00000000..18dd071c --- /dev/null +++ b/src/main/gachaTypeMap.js @@ -0,0 +1,18 @@ + +const { order } = require('./getData') +const itemTypeNameMap = require('../gachaType.json') + +function convertItemTypeMap(mapObject) { + const convertedItemTypeMap = new Map() + order.forEach(id => { + const itemType = mapObject.find(item => { + return item.key === id + }) + convertedItemTypeMap.set(itemType.key, itemType.name) + }) + return convertedItemTypeMap +} + +exports.getItemTypeNameMap = function(lang) { + return convertItemTypeMap(itemTypeNameMap[lang]) +} \ No newline at end of file diff --git a/src/main/getData.js b/src/main/getData.js index 7151ab94..656b9159 100644 --- a/src/main/getData.js +++ b/src/main/getData.js @@ -16,8 +16,10 @@ const saveData = async (data, url) => { const obj = Object.assign({}, data) obj.result = [...obj.result] obj.typeMap = [...obj.typeMap] - config.urls.set(data.uid, url) - await config.save() + if (url) { + config.urls.set(data.uid, url) + await config.save() + } await saveJSON(`gacha-list-${data.uid}.json`, obj) } @@ -548,3 +550,9 @@ exports.getData = () => { current: config.current } } + +exports.order = order + +exports.saveData = saveData + +exports.changeCurrent = changeCurrent \ No newline at end of file diff --git a/src/main/itemTypeMap.js b/src/main/itemTypeMap.js deleted file mode 100644 index 5869fa3a..00000000 --- a/src/main/itemTypeMap.js +++ /dev/null @@ -1,395 +0,0 @@ -const itemTypeMap = { - "en-us": [{ - key: "200", - name: "Permanent Wish" - }, { - key: "100", - name: "Novice Wishes" - }, { - key: "301", - name: "Character Event Wish and Character Event Wish-2" - }, { - key: "302", - name: "Weapon Event Wish" - }], - "fr-fr": [{ - key: "200", - name: "Vœux permanents" - }, { - key: "100", - name: "Vœux des débutants" - }, { - key: "301", - name: "Vœux événements de personnage et Vœux événements de personnage - 2" - }, { - key: "302", - name: "Vœux événements d'arme" - }], - "de-de": [{ - key: "200", - name: "Standardgebet" - }, { - key: "100", - name: "Neulingsgebete" - }, { - key: "301", - name: "Figurenaktionsgebet und Figurenaktionsgebet 2" - }, { - key: "302", - name: "Waffenaktionsgebet" - }], - "es-es": [{ - key: "200", - name: "Gachapón permanente" - }, { - key: "100", - name: "Gachapón de principiante" - }, { - key: "301", - name: "Gachapón promocional de personaje y gachapón promocional de personaje 2" - }, { - key: "302", - name: "Gachapón promocional de arma" - }], - "pt-pt": [{ - key: "200", - name: "Desejo Comum" - }, { - key: "100", - name: "Desejos de Novato" - }, { - key: "301", - name: "Oração de Evento de Personagem e Oração de Evento de Personagem - 2" - }, { - key: "302", - name: "Oração do Evento de Arma" - }], - "ru-ru": [{ - key: "200", - name: "Стандартная молитва" - }, { - key: "100", - name: "Молитва новичка" - }, { - key: "301", - name: "Молитва события персонажа и Молитва события персонажа II" - }, { - key: "302", - name: "Молитва события оружия" - }], - "ja-jp": [{ - key: "200", - name: "通常祈願" - }, { - key: "100", - name: "初心者向け祈願" - }, { - key: "301", - name: "イベント祈願・キャラクターとイベント祈願・キャラクター 2" - }, { - key: "302", - name: "イベント祈願・武器" - }], - "ko-kr": [{ - key: "200", - name: "상주 기원" - }, { - key: "100", - name: "초심자 기원" - }, { - key: "301", - name: "캐릭터 이벤트 기원 및 캐릭터 이벤트 기원-2" - }, { - key: "302", - name: "무기 이벤트 기원" - }], - "th-th": [{ - key: "200", - name: "อธิษฐานถาวร" - }, { - key: "100", - name: "ผู้เริ่มอธิษฐาน" - }, { - key: "301", - name: "กิจกรรมอธิษฐานตัวละครและกิจกรรมอธิษฐานตัวละคร - 2" - }, { - key: "302", - name: "กิจกรรมอธิษฐานอาวุธ" - }], - "vi-vn": [{ - key: "200", - name: "Cầu Nguyện Thường" - }, { - key: "100", - name: "Cầu Nguyện Tân Thủ" - }, { - key: "301", - name: "Cầu Nguyện Nhân Vật và Cầu Nguyện Nhân Vật-2" - }, { - key: "302", - name: "Cầu Nguyện Vũ Khí" - }], - "id-id": [{ - key: "200", - name: "Permohonan Standar" - }, { - key: "100", - name: "Permohonan Pemula" - }, { - key: "301", - name: "Event Permohonan Karakter dan Event Permohonan Karakter - 2" - }, { - key: "302", - name: "Event Permohonan Senjata" - }], - "zh-cn": [{ - key: "200", - name: "常驻祈愿" - }, { - key: "100", - name: "新手祈愿" - }, { - key: "301", - name: "角色活动祈愿与角色活动祈愿-2" - }, { - key: "302", - name: "武器活动祈愿" - }], - "zh-tw": [{ - key: "200", - name: "常駐祈願" - }, { - key: "100", - name: "新手祈願" - }, { - key: "301", - name: "角色活動祈願與角色活動祈願-2" - }, { - key: "302", - name: "武器活動祈願" - }] -} -const itemTypeNameMap = { - "en-us": [{ - key: "200", - name: "Permanent Wish" - }, { - key: "100", - name: "Novice Wishes" - }, { - key: "301", - name: "Character Event Wish" - }, { - key: "302", - name: "Weapon Event Wish" - }, { - key: "400", - name: "Character Event Wish-2" - }], - "fr-fr": [{ - key: "200", - name: "Vœux permanents" - }, { - key: "100", - name: "Vœux des débutants" - }, { - key: "301", - name: "Vœux événements de personnage" - }, { - key: "302", - name: "Vœux événements d'arme" - }, { - key: "400", - name: "Vœux événements de personnage - 2" - }], - "de-de": [{ - key: "200", - name: "Standardgebet" - }, { - key: "100", - name: "Neulingsgebete" - }, { - key: "301", - name: "Figurenaktionsgebet" - }, { - key: "302", - name: "Waffenaktionsgebet" - }, { - key: "400", - name: "Figurenaktionsgebet 2" - }], - "es-es": [{ - key: "200", - name: "Gachapón permanente" - }, { - key: "100", - name: "Gachapón de principiante" - }, { - key: "301", - name: "Gachapón promocional de personaje" - }, { - key: "302", - name: "Gachapón promocional de arma" - }, { - key: "400", - name: "Gachapón promocional de personaje 2" - }], - "pt-pt": [{ - key: "200", - name: "Desejo Comum" - }, { - key: "100", - name: "Desejos de Novato" - }, { - key: "301", - name: "Oração do Evento do Personagem" - }, { - key: "302", - name: "Oração do Evento de Arma" - }, { - key: "400", - name: "Oração de Evento de Personagem - 2" - }], - "ru-ru": [{ - key: "200", - name: "Стандартная молитва" - }, { - key: "100", - name: "Молитва новичка" - }, { - key: "301", - name: "Молитва события персонажа" - }, { - key: "302", - name: "Молитва события оружия" - }, { - key: "400", - name: "Молитва события персонажа II" - }], - "ja-jp": [{ - key: "200", - name: "通常祈願" - }, { - key: "100", - name: "初心者向け祈願" - }, { - key: "301", - name: "イベント祈願・キャラクター" - }, { - key: "302", - name: "イベント祈願・武器" - }, { - key: "400", - name: "イベント祈願・キャラクター 2" - }], - "ko-kr": [{ - key: "200", - name: "상주 기원" - }, { - key: "100", - name: "초심자 기원" - }, { - key: "301", - name: "캐릭터 이벤트 기원" - }, { - key: "302", - name: "무기 이벤트 기원" - }, { - key: "400", - name: "캐릭터 이벤트 기원-2" - }], - "th-th": [{ - key: "200", - name: "อธิษฐานถาวร" - }, { - key: "100", - name: "ผู้เริ่มอธิษฐาน" - }, { - key: "301", - name: "กิจกรรมอธิษฐานตัวละคร" - }, { - key: "302", - name: "กิจกรรมอธิษฐานอาวุธ" - }, { - key: "400", - name: "กิจกรรมอธิษฐานตัวละคร - 2" - }], - "vi-vn": [{ - key: "200", - name: "Cầu Nguyện Thường" - }, { - key: "100", - name: "Cầu Nguyện Tân Thủ" - }, { - key: "301", - name: "Cầu Nguyện Nhân Vật" - }, { - key: "302", - name: "Cầu Nguyện Vũ Khí" - }, { - key: "400", - name: "Cầu Nguyện Nhân Vật-2" - }], - "id-id": [{ - key: "200", - name: "Permohonan Standar" - }, { - key: "100", - name: "Permohonan Pemula" - }, { - key: "301", - name: "Event Permohonan Karakter" - }, { - key: "302", - name: "Event Permohonan Senjata" - }, { - key: "400", - name: "Event Permohonan Karakter - 2" - }], - "zh-cn": [{ - key: "200", - name: "常驻祈愿" - }, { - key: "100", - name: "新手祈愿" - }, { - key: "301", - name: "角色活动祈愿" - }, { - key: "302", - name: "武器活动祈愿" - }, { - key: "400", - name: "角色活动祈愿-2" - }], - "zh-tw": [{ - key: "200", - name: "常駐祈願" - }, { - key: "100", - name: "新手祈願" - }, { - key: "301", - name: "角色活動祈願" - }, { - key: "302", - name: "武器活動祈願" - }, { - key: "400", - name: "角色活動祈願-2" - }] -} - -function convertItemTypeMap(mapObject) { - const convertedItemTypeMap = new Map() - Object.entries(mapObject).forEach(([_, itemType]) => convertedItemTypeMap.set(itemType.key, itemType.name)) - return convertedItemTypeMap -} - -export function getItemTypeMap(lang) { - return convertItemTypeMap(itemTypeMap[lang]) -} - -export function getItemTypeNameMap(lang) { - return convertItemTypeMap(itemTypeNameMap[lang]) -} \ No newline at end of file diff --git a/src/renderer/App.vue b/src/renderer/App.vue index d0c31697..6b12952d 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -78,6 +78,7 @@ import GachaDetail from './components/GachaDetail.vue' import Setting from './components/Setting.vue' import gachaDetail from './gachaDetail' import { version } from '../../package.json' +import gachaType from '../gachaType.json' import { ElMessage } from 'element-plus' const state = reactive({ @@ -148,8 +149,14 @@ const detail = computed(() => { }) const typeMap = computed(() => { - const data = state.dataMap.get(state.current) - return data.typeMap + const type = gachaType[state.config.lang] + const result = new Map() + if (type) { + for (let { key, name } of type) { + result.set(key, name) + } + } + return result }) const fetchData = async (url) => { diff --git a/src/renderer/components/Setting.vue b/src/renderer/components/Setting.vue index 40a950f2..297a1dc3 100644 --- a/src/renderer/components/Setting.vue +++ b/src/renderer/components/Setting.vue @@ -20,25 +20,15 @@

{{text.logTypeHint}}

- - {{ text.UIGFImportButton }} - -

{{ text.UIGFImportHint }} - {{ text.UIGFLink }} -

-
- {{ text.UIGFButton }} - + {{ text.UIGFImportButton }} + {{ text.UIGFButton }} {{ text.UIGFReadable }}

{{ text.UIGFHint }} {{ text.UIGFLink }} + @click="openLink(`https://uigf.org/${settingForm.lang.startsWith('zh-') ? 'zh/': 'en/'}`)">{{ text.UIGFLink }}

@@ -154,8 +144,16 @@ const exportUIGFJSON = async () => { const importUIGFJSON = async () => { data.loadingOfUIGFJSON = true try { - await ipcRenderer.invoke('IMPORT_UIGF_JSON') + const result = await ipcRenderer.invoke('IMPORT_UIGF_JSON') + if (result === 'canceled') { + return + } emit('dataUpdated') + closeSetting() + ElMessage({ + message: text.value.UIGFImportSuccessed, + type: 'success' + }) } catch (e) { ElMessage({ message: e.message || e, diff --git a/src/schema/local-data.json b/src/schema/local-data.json new file mode 100644 index 00000000..a1a03e5d --- /dev/null +++ b/src/schema/local-data.json @@ -0,0 +1,54 @@ +{ + "type": "object", + "properties": { + "time": { + "type": "number", + "title": "更新时间" + }, + "uid": { + "type": "string", + "title": "角色UID" + }, + "lang": { + "type": "string", + "title": "语言" + }, + "typeMap": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string", + "minItems": 2 + } + }, + "minItems": 4 + }, + "result": { + "type": "array", + "items": { + "type": "array", + "items": [ + { "type": "string" }, + { + "type": "array", + "items": { + "type": "array", + "items": [ + { "type": "string" }, + { "type": "string" }, + { "type": "string" }, + { "type": "integer" } + ], + "additionalItems": { + "type": "string" + } + } + } + ], + "additionalItems": false + } + } + }, + "required": ["uid", "lang", "typeMap", "result"] +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 4f8dd399..9906fb25 100644 --- a/yarn.lock +++ b/yarn.lock @@ -456,7 +456,7 @@ ajv-keywords@^3.4.1: resolved "https://registry.npmmirror.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d" integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ== -ajv@^6.10.0, ajv@^6.12.0: +ajv@6, ajv@^6.10.0, ajv@^6.12.0: version "6.12.6" resolved "https://registry.npmmirror.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==