feat: Support export as Star Rail Gacha Log Format file (#39)

This commit is contained in:
TremblingMoeNew
2023-06-29 15:02:36 +08:00
committed by GitHub
parent f2592040cb
commit 4ab2f60b53
11 changed files with 38 additions and 42 deletions

View File

@ -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()
})

View File

@ -76,7 +76,7 @@ const parseText = (text, data) => {
}
const mainProps = [
'symbol', 'ui', 'log', 'excel'
'symbol', 'ui', 'log', 'excel',"srgf"
]
const i18n = new Proxy(raw, {

View File

@ -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