feat: import srgf

This commit is contained in:
mio
2024-08-08 21:58:24 +08:00
parent acd7b66761
commit f6d0a18d5c
5 changed files with 67 additions and 59 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "star-rail-warp-export", "name": "star-rail-warp-export",
"version": "0.1.9", "version": "0.1.10",
"main": "./dist/electron/main/main.js", "main": "./dist/electron/main/main.js",
"author": "biuuu <https://github.com/biuuu>", "author": "biuuu <https://github.com/biuuu>",
"homepage": "https://github.com/biuuu/star-rail-warp-export", "homepage": "https://github.com/biuuu/star-rail-warp-export",

View File

@ -81,47 +81,18 @@ const exportUIGF = async (uids) => {
} }
} }
const importUIGF = async () => { function parseData(data, dataMap) {
const filepath = await dialog.showOpenDialogSync({
properties: ['openFile'],
filters: [
{ name: i18n.uigf.fileType, extensions: ['json'] }
]
})
if (!filepath) return
const { dataMap, current } = await getData()
try {
const jsonData = fs.readJsonSync(filepath[0])
if('info' in jsonData && 'version' in jsonData.info) {
if (jsonData.info.version !== 'v4.0') {
sendMsg('不支持此版本UIGF')
console.error('不支持此版本UIGF')
return
}
} else {
sendMsg('UIGF格式错误')
console.error('UIGF格式错误')
return
}
jsonData.hkrpg.forEach(uidData => {
const resultTemp = [] const resultTemp = []
const isNew = !Boolean(dataMap.has(uidData.uid)) const isNew = !dataMap.has(data.uid)
let region_time_zone
if (!isNew) region_time_zone = dataMap.get(uidData.uid).region_time_zone
else region_time_zone = uidData.timezone
let targetLang let targetLang
if (!isNew) targetLang = dataMap.get(uidData.uid).lang if (!isNew) targetLang = dataMap.get(data.uid).lang
else targetLang = uidData.lang else targetLang = data.lang
if(!idJson[targetLang] && (!uidData.list[0].name || !uidData.list[0].item_type || !uidData.list[0].rank_type)) targetLang = config.lang if(!idJson[targetLang] && (!data.list[0].name || !data.list[0].item_type || !data.list[0].rank_type)) targetLang = config.lang
let idTargetLangJson = idJson[targetLang] let idTargetLangJson = idJson[targetLang]
uidData.list.forEach(recordEntry => { data.list.forEach(recordEntry => {
let rank_type
if (idTargetLangJson?.[recordEntry.item_id].rank_type) rank_type = String(idTargetLangJson[recordEntry.item_id].rank_type)
else rank_type = recordEntry.rank_type
resultTemp.push({ resultTemp.push({
gacha_id: recordEntry.gacha_id, gacha_id: recordEntry.gacha_id,
gacha_type: recordEntry.gacha_type, gacha_type: recordEntry.gacha_type,
@ -139,22 +110,55 @@ const importUIGF = async () => {
acc[curr.gacha_type] = [] acc[curr.gacha_type] = []
} }
acc[curr.gacha_type].push(curr) acc[curr.gacha_type].push(curr)
return acc; return acc
}, {}) }, {})
const resultTempMap = new Map(Object.entries(resultTempGrouped)) const resultTempMap = new Map(Object.entries(resultTempGrouped))
const resultMap = { result: resultTempMap, uid: uidData.uid} const resultMap = { result: resultTempMap, uid: data.uid}
let data let temp
const mergedData = mergeData(dataMap.get(uidData.uid), resultMap) const mergedData = mergeData(dataMap.get(data.uid), resultMap)
if (isNew) { if (isNew) {
data = { result: mergedData, time: Date.now(), uid: uidData.uid, lang: targetLang, region_time_zone: uidData.timezone, deleted: false } temp = { result: mergedData, time: Date.now(), uid: data.uid, lang: targetLang, region_time_zone: data.timezone, deleted: false }
} else { } else {
data = { result: mergedData, time: Date.now(), uid: dataMap.get(uidData.uid).uid, lang: targetLang, region_time_zone: dataMap.get(uidData.uid).region_time_zone, deleted: dataMap.get(uidData.uid).deleted } temp = { result: mergedData, time: Date.now(), uid: dataMap.get(data.uid).uid, lang: targetLang, region_time_zone: dataMap.get(data.uid).region_time_zone, deleted: dataMap.get(data.uid).deleted }
} }
saveData(data, '') saveData(temp)
changeCurrent(uidData.uid) changeCurrent(data.uid)
dataMap.set(uidData.uid, data) dataMap.set(data.uid, temp)
}
const importUIGF = async () => {
const filepath = dialog.showOpenDialogSync({
properties: ['openFile'],
filters: [
{ name: i18n.uigf.fileType, extensions: ['json'] }
]
}) })
if (!filepath) return
const { dataMap, current } = getData()
try {
const jsonData = fs.readJsonSync(filepath[0])
if('info' in jsonData && 'version' in jsonData.info) {
if (jsonData.info.version !== 'v4.0') {
sendMsg('不支持此版本UIGF')
console.error('不支持此版本UIGF')
return
}
jsonData.hkrpg.forEach(uidData => {
parseData(uidData, dataMap)
})
} else if (jsonData?.info?.srgf_version) {
parseData({
uid: jsonData.info.uid,
lang: jsonData.info.lang,
timezone: jsonData.info.region_time_zone,
...jsonData
}, dataMap)
} else {
sendMsg('UIGF格式错误')
console.error('UIGF格式错误')
return
}
return { return {
dataMap, dataMap,
current: config.current current: config.current

View File

@ -4,6 +4,7 @@ const { app, ipcMain, dialog } = require('electron')
const fs = require('fs-extra') const fs = require('fs-extra')
const path = require('path') const path = require('path')
const i18n = require('./i18n') const i18n = require('./i18n')
const { getGachaType } = require('./getData')
function pad(num) { function pad(num) {
return `${num}`.padStart(2, "0"); return `${num}`.padStart(2, "0");
@ -53,10 +54,11 @@ const start = async () => {
const { header, customFont, filePrefix, fileType, wish2 } = i18n.excel const { header, customFont, filePrefix, fileType, wish2 } = i18n.excel
const { dataMap, current } = await getData() const { dataMap, current } = await getData()
const data = dataMap.get(current) const data = dataMap.get(current)
const typeMap = getGachaType(data.lang)
// https://github.com/sunfkny/genshin-gacha-export-js/blob/main/index.js // https://github.com/sunfkny/genshin-gacha-export-js/blob/main/index.js
const workbook = new ExcelJS.Workbook() const workbook = new ExcelJS.Workbook()
for (let [key, value] of data.result) { for (let [key, value] of data.result) {
const name = data.typeMap.get(key) const name = typeMap.find(item => item.key === key)?.name
const sheet = workbook.addWorksheet(name.replace(/[*?:\/\\]/g, ' '), {views: [{state: 'frozen', ySplit: 1}]}) const sheet = workbook.addWorksheet(name.replace(/[*?:\/\\]/g, ' '), {views: [{state: 'frozen', ySplit: 1}]})
let width = [24, 14, 8, 8, 8, 8, 8] let width = [24, 14, 8, 8, 8, 8, 8]
if (!data.lang.includes('zh-')) { if (!data.lang.includes('zh-')) {

View File

@ -15,7 +15,7 @@ const dataMap = new Map()
const order = ['11', '12', '1', '2'] const order = ['11', '12', '1', '2']
let apiDomain = 'https://api-takumi.mihoyo.com' let apiDomain = 'https://api-takumi.mihoyo.com'
const saveData = async (data, url) => { const saveData = async (data) => {
const obj = Object.assign({}, data) const obj = Object.assign({}, data)
obj.result = [...obj.result] obj.result = [...obj.result]
await config.save() await config.save()
@ -466,7 +466,7 @@ const fetchData = async (urlOverride) => {
data.result = mergedResult data.result = mergedResult
dataMap.set(originUid, data) dataMap.set(originUid, data)
await changeCurrent(originUid) await changeCurrent(originUid)
await saveData(data, url) await saveData(data)
} }
let proxyStarted = false let proxyStarted = false
@ -546,3 +546,4 @@ exports.deleteData = deleteData
exports.saveData = saveData exports.saveData = saveData
exports.changeCurrent = changeCurrent exports.changeCurrent = changeCurrent
exports.convertTimeZone = convertTimeZone exports.convertTimeZone = convertTimeZone
exports.getGachaType = getGachaType

View File

@ -11,6 +11,7 @@ const itemCount = (map, name) => {
const order = ['11', '12', '1', '2'] const order = ['11', '12', '1', '2']
const gachaDetail = (data) => { const gachaDetail = (data) => {
if (!data) return
const detailMap = new Map() const detailMap = new Map()
for (let key of order) { for (let key of order) {
if (!data.has(key)) return if (!data.has(key)) return