From 4ab2f60b5356e51fba14477e7a598652c202ada5 Mon Sep 17 00:00:00 2001 From: TremblingMoeNew <39522864+TremblingMoeNew@users.noreply.github.com> Date: Thu, 29 Jun 2023 15:02:36 +0800 Subject: [PATCH] feat: Support export as Star Rail Gacha Log Format file (#39) --- src/i18n/Deutsch.json | 4 +- src/i18n/English.json | 2 + src/i18n/Français.json | 1 + src/i18n/日本語.json | 1 + src/i18n/简体中文.json | 2 + src/i18n/繁體中文.json | 2 + src/main/{UIGFJson.js => SRGFJson.js} | 55 ++++++++++----------------- src/main/i18n.js | 2 +- src/main/main.js | 2 +- src/renderer/App.vue | 5 +++ src/renderer/components/Setting.vue | 4 -- 11 files changed, 38 insertions(+), 42 deletions(-) rename src/main/{UIGFJson.js => SRGFJson.js} (58%) diff --git a/src/i18n/Deutsch.json b/src/i18n/Deutsch.json index 1f20ac9..b106a43 100644 --- a/src/i18n/Deutsch.json +++ b/src/i18n/Deutsch.json @@ -3,6 +3,7 @@ "ui.button.load": "Lade Daten", "ui.button.update": "Aktualisieren", "ui.button.excel": "In Excel exportieren", + "ui.button.srgf": "In SRGF exportieren", "ui.button.url": "Eingabe URL", "ui.button.setting": "Einstellungen", "ui.button.option": "Optionen", @@ -75,5 +76,6 @@ "excel.wish2": "Wunsch 2", "excel.customFont": "Arial", "excel.filePrefix": "", - "excel.fileType": "Excel Datei" + "excel.fileType": "Excel Datei", + "srgf.fileType": "Star Rail Gacha Log Format Datei" } diff --git a/src/i18n/English.json b/src/i18n/English.json index a41f446..2dee8ef 100644 --- a/src/i18n/English.json +++ b/src/i18n/English.json @@ -4,6 +4,7 @@ "ui.button.update": "Update", "ui.button.directUpdate": "Direct update", "ui.button.excel": "Export Excel", + "ui.button.srgf": "Export SRGF", "ui.button.url": "Input URL", "ui.button.setting": "Settings", "ui.button.option": "Option", @@ -94,6 +95,7 @@ "excel.customFont": "Arial", "excel.filePrefix": "Star Rail Warp logger", "excel.fileType": "Excel file", + "srgf.fileType": "Star Rail Gacha Log Format file", "ui.extra.cacheClean": "1. Confirm whether the warp history in the game has been opened, and if the error \"User authentication expired\" still appears, try the following steps \n2. Close the game window of Star Rail \n3. Click the \"Open Web Cache Folder\" button above to open the \"Cache\" folder \n4. Delete the \"Cache_ Data\" folder \n5. Start the Star Rail game and open the warp history page in the game \n6. Close this dialog and click the \"Update Data\" button", "ui.extra.findCacheFolder": "If the \"Open cache folder\" button does not respond, you can manually find the game's web cache folder. The directory is \"Your game installation path/Star Rail/Games/StarRail_Data/webCaches/Cache/\"", "ui.extra.urlCopied": "URL Copied" diff --git a/src/i18n/Français.json b/src/i18n/Français.json index f81050d..92e696a 100644 --- a/src/i18n/Français.json +++ b/src/i18n/Français.json @@ -4,6 +4,7 @@ "ui.button.update": "Mettre à jour", "ui.button.directUpdate": "Mise à jour directe", "ui.button.excel": "Exporter vers Excel", + "ui.button.srgf": "Exporter vers SRGF", "ui.button.url": "URL d'import", "ui.button.setting": "Paramètres", "ui.button.option": "Options", diff --git a/src/i18n/日本語.json b/src/i18n/日本語.json index 3ca4799..aa5f734 100644 --- a/src/i18n/日本語.json +++ b/src/i18n/日本語.json @@ -3,6 +3,7 @@ "ui.button.load": "データの読み込み", "ui.button.update": "更新データ", "ui.button.excel": "Excelにエクスポート", + "ui.button.srgf": "SRGFにエクスポート", "ui.button.url": "URL入力", "ui.button.setting": "設定", "ui.button.option": "オプション", diff --git a/src/i18n/简体中文.json b/src/i18n/简体中文.json index f404cca..294fdf4 100644 --- a/src/i18n/简体中文.json +++ b/src/i18n/简体中文.json @@ -4,6 +4,7 @@ "ui.button.update": "更新数据", "ui.button.directUpdate": "直接更新", "ui.button.excel": "导出Excel", + "ui.button.srgf":"导出SRGF", "ui.button.url": "输入URL", "ui.button.setting": "设置", "ui.button.option": "选项", @@ -94,6 +95,7 @@ "excel.customFont": "微软雅黑", "excel.filePrefix": "星穹铁道跃迁记录", "excel.fileType": "Excel文件", + "srgf.fileType":"星穹铁道跃迁记录格式文件", "ui.extra.cacheClean": "1. 确认是否已经打开游戏内的抽卡历史记录,如果仍然出现“身份认证已过期”的错误,再尝试下面的步骤\n2. 关闭星穹铁道的游戏窗口\n3. 点击上方的“打开缓存文件夹”按钮,打开Cache文件夹\n4. 删除Cache_Data文件夹\n5. 启动星穹铁道游戏,打开游戏内抽卡历史记录页面\n6. 关闭这个对话框,再点击“更新数据”按钮", "ui.extra.findCacheFolder": "如果点“打开缓存文件夹”按钮没有反应,可以手动找到游戏的网页缓存文件夹,目录为“你的游戏安装路径/Star Rail/Game/StarRail_Data/webCaches/Cache/”", "ui.extra.urlCopied": "URL已复制" diff --git a/src/i18n/繁體中文.json b/src/i18n/繁體中文.json index f45f0be..52a4763 100644 --- a/src/i18n/繁體中文.json +++ b/src/i18n/繁體中文.json @@ -4,6 +4,7 @@ "ui.button.update": "更新資料", "ui.button.directUpdate": "直接更新", "ui.button.excel": "匯出 Excel", + "ui.button.srgf": "匯出 SRGF", "ui.button.url": "輸入 URL", "ui.button.setting": "設定", "ui.button.option": "選項", @@ -83,6 +84,7 @@ "excel.customFont": "微軟正黑體", "excel.filePrefix": "星穹鐵道躍遷紀錄", "excel.fileType": "Excel 檔案", + "srgf.fileType":"星穹鐵道躍遷紀錄格式檔案", "ui.extra.cacheClean": "1. 確認是否已經開啟遊戲內的躍遷歷史紀錄,如果仍然出現「身分驗證已過期」的錯誤,再嘗試下面的步驟\n2. 關閉「崩壞:星穹鐵道」的遊戲視窗\n3. 按一下上方的「開啟快取資料夾」按鈕,開啟「Cache」資料夾\n4. 刪除「Cache_Data」資料夾\n5. 啟動「崩壞:星穹鐵道」遊戲,開啟遊戲內躍遷歷史紀錄頁面\n6. 關閉這個對話方塊,再按下「更新資料」按鈕", "ui.extra.findCacheFolder": "如果按下「開啟快取資料夾」按鈕沒有回應,可以手動找到遊戲的網頁快取資料夾,目錄為「您的遊戲安裝路徑/Star Rail/Games/StarRail_Data/webCaches/Cache/」" } diff --git a/src/main/UIGFJson.js b/src/main/SRGFJson.js similarity index 58% rename from src/main/UIGFJson.js rename to src/main/SRGFJson.js index 786ea9c..4c33f7b 100644 --- a/src/main/UIGFJson.js +++ b/src/main/SRGFJson.js @@ -3,6 +3,7 @@ const fs = require('fs-extra') const path = require('path') const getData = require('./getData').getData const { version } = require('../../package.json') +const i18n = require('./i18n') const getTimeString = () => { return new Date().toLocaleString('sv').replace(/[- :]/g, '').slice(0, -2) @@ -15,67 +16,51 @@ const formatDate = (date) => { return `${y}-${m}-${d} ${date.toLocaleString('zh-cn', { hour12: false }).slice(-8)}` } -const fakeIdFn = () => { - let id = 1000000000000000000n - return () => { - id = id + 1n - return id.toString() - } -} - -const shouldBeString = (value) => { - if (typeof value !== 'string') { - return '' - } - return value -} - const start = async () => { const { dataMap, current } = await getData() const data = dataMap.get(current) if (!data.result.size) { throw new Error('数据为空') } - const fakeId = fakeIdFn() const result = { info: { uid: data.uid, lang: data.lang, export_time: formatDate(new Date()), - export_timestamp: Date.now(), - export_app: 'genshin-wish-export', + export_timestamp: Math.ceil(Date.now()/1000), + export_app: 'star-rail-warp-export', export_app_version: `v${version}`, - uigf_version: 'v2.2' + region_time_zone: data.region_time_zone, + srgf_version: 'v1.0' }, list: [] } const listTemp = [] for (let [type, arr] of data.result) { - arr.forEach(item => { + arr.forEach(log => { listTemp.push({ - gacha_type: shouldBeString(item[4]) || type, - time: item[0], - timestamp: new Date(item[0]).getTime(), - name: item[1], - item_type: item[2], - rank_type: `${item[3]}`, - id: shouldBeString(item[5]) || '', - uigf_gacha_type: type + gacha_id:log.gacha_id, + gacha_type: log.gacha_type, + item_id:log.item_id, + count:"1", + time:log.time, + name:log.name, + item_type:log.item_type, + rank_type:log.rank_type, + id:log.id }) }) } - listTemp.sort((a, b) => a.timestamp - b.timestamp) + listTemp.sort((a, b) => BigInt(a.id) - BigInt(b.id)) listTemp.forEach(item => { - delete item.timestamp result.list.push({ - ...item, - id: item.id || fakeId() + ...item }) }) const filePath = dialog.showSaveDialogSync({ - defaultPath: path.join(app.getPath('downloads'), `UIGF_${data.uid}_${getTimeString()}`), + defaultPath: path.join(app.getPath('downloads'), `SRGF_${data.uid}_${getTimeString()}`), filters: [ - { name: 'JSON文件', extensions: ['json'] } + { name: i18n.srgf.fileType, extensions: ['json'] } ] }) if (filePath) { @@ -84,6 +69,6 @@ const start = async () => { } } -ipcMain.handle('EXPORT_UIGF_JSON', async () => { +ipcMain.handle('EXPORT_SRGF_JSON', async () => { await start() }) diff --git a/src/main/i18n.js b/src/main/i18n.js index b33c751..e8ed7b3 100644 --- a/src/main/i18n.js +++ b/src/main/i18n.js @@ -76,7 +76,7 @@ const parseText = (text, data) => { } const mainProps = [ - 'symbol', 'ui', 'log', 'excel' + 'symbol', 'ui', 'log', 'excel',"srgf" ] const i18n = new Proxy(raw, { diff --git a/src/main/main.js b/src/main/main.js index adf307d..fb5d17f 100644 --- a/src/main/main.js +++ b/src/main/main.js @@ -4,7 +4,7 @@ const { disableProxy, proxyStatus } = require('./module/system-proxy') require('./getData') require('./bridge') require('./excel') -require('./UIGFJson') +require('./SRGFJson') const { getUpdateInfo } = require('./update/index') const isDev = !app.isPackaged diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 80c6480..d31c30c 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -4,6 +4,7 @@
{{state.status === 'init' ? ui.button.load: ui.button.update}} {{ui.button.excel}} + {{ui.button.srgf}} @@ -227,6 +228,10 @@ const saveExcel = async () => { await ipcRenderer.invoke('SAVE_EXCEL') } +const exportSRGFJSON = () => { + ipcRenderer.invoke('EXPORT_SRGF_JSON') +} + const openCacheFolder = async () => { await ipcRenderer.invoke('OPEN_CACHE_FOLDER') } diff --git a/src/renderer/components/Setting.vue b/src/renderer/components/Setting.vue index 157c7d1..60edf7e 100644 --- a/src/renderer/components/Setting.vue +++ b/src/renderer/components/Setting.vue @@ -139,10 +139,6 @@ const disableProxy = async () => { const openGithub = () => shell.openExternal('https://github.com/biuuu/star-rail-warp-export') const openLink = (link) => shell.openExternal(link) -const exportUIGFJSON = () => { - ipcRenderer.invoke('EXPORT_UIGF_JSON') -} - const deleteData = async (uid, action) => { state.dataActionLoading = true await ipcRenderer.invoke('DELETE_DATA', uid, action)