mirror of
https://github.com/earthjasonlin/star-rail-warp-export.git
synced 2025-07-05 14:00:17 +08:00
feat: import srgf
This commit is contained in:
@ -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",
|
||||||
|
@ -81,15 +81,61 @@ const exportUIGF = async (uids) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseData(data, dataMap) {
|
||||||
|
const resultTemp = []
|
||||||
|
const isNew = !dataMap.has(data.uid)
|
||||||
|
|
||||||
|
let targetLang
|
||||||
|
if (!isNew) targetLang = dataMap.get(data.uid).lang
|
||||||
|
else targetLang = data.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]
|
||||||
|
|
||||||
|
data.list.forEach(recordEntry => {
|
||||||
|
resultTemp.push({
|
||||||
|
gacha_id: recordEntry.gacha_id,
|
||||||
|
gacha_type: recordEntry.gacha_type,
|
||||||
|
item_id: recordEntry.item_id,
|
||||||
|
count: recordEntry.count ?? "1",
|
||||||
|
time: recordEntry.time,
|
||||||
|
name: idTargetLangJson?.[recordEntry.item_id].name ?? recordEntry.name,
|
||||||
|
item_type: idTargetLangJson?.[recordEntry.item_id].item_type ?? recordEntry.item_type,
|
||||||
|
rank_type: recordEntry.rank_type,
|
||||||
|
id: recordEntry.id
|
||||||
|
})
|
||||||
|
})
|
||||||
|
const resultTempGrouped = resultTemp.reduce((acc, curr) => {
|
||||||
|
if (!acc[curr.gacha_type]) {
|
||||||
|
acc[curr.gacha_type] = []
|
||||||
|
}
|
||||||
|
acc[curr.gacha_type].push(curr)
|
||||||
|
return acc
|
||||||
|
}, {})
|
||||||
|
const resultTempMap = new Map(Object.entries(resultTempGrouped))
|
||||||
|
const resultMap = { result: resultTempMap, uid: data.uid}
|
||||||
|
let temp
|
||||||
|
const mergedData = mergeData(dataMap.get(data.uid), resultMap)
|
||||||
|
if (isNew) {
|
||||||
|
temp = { result: mergedData, time: Date.now(), uid: data.uid, lang: targetLang, region_time_zone: data.timezone, deleted: false }
|
||||||
|
} else {
|
||||||
|
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(temp)
|
||||||
|
changeCurrent(data.uid)
|
||||||
|
dataMap.set(data.uid, temp)
|
||||||
|
}
|
||||||
|
|
||||||
const importUIGF = async () => {
|
const importUIGF = async () => {
|
||||||
const filepath = await dialog.showOpenDialogSync({
|
const filepath = dialog.showOpenDialogSync({
|
||||||
properties: ['openFile'],
|
properties: ['openFile'],
|
||||||
filters: [
|
filters: [
|
||||||
{ name: i18n.uigf.fileType, extensions: ['json'] }
|
{ name: i18n.uigf.fileType, extensions: ['json'] }
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
if (!filepath) return
|
if (!filepath) return
|
||||||
const { dataMap, current } = await getData()
|
const { dataMap, current } = getData()
|
||||||
try {
|
try {
|
||||||
const jsonData = fs.readJsonSync(filepath[0])
|
const jsonData = fs.readJsonSync(filepath[0])
|
||||||
if('info' in jsonData && 'version' in jsonData.info) {
|
if('info' in jsonData && 'version' in jsonData.info) {
|
||||||
@ -98,63 +144,21 @@ const importUIGF = async () => {
|
|||||||
console.error('不支持此版本UIGF')
|
console.error('不支持此版本UIGF')
|
||||||
return
|
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 {
|
} else {
|
||||||
sendMsg('UIGF格式错误')
|
sendMsg('UIGF格式错误')
|
||||||
console.error('UIGF格式错误')
|
console.error('UIGF格式错误')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
jsonData.hkrpg.forEach(uidData => {
|
|
||||||
const resultTemp = []
|
|
||||||
const isNew = !Boolean(dataMap.has(uidData.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
|
|
||||||
if (!isNew) targetLang = dataMap.get(uidData.uid).lang
|
|
||||||
else targetLang = uidData.lang
|
|
||||||
if(!idJson[targetLang] && (!uidData.list[0].name || !uidData.list[0].item_type || !uidData.list[0].rank_type)) targetLang = config.lang
|
|
||||||
|
|
||||||
let idTargetLangJson = idJson[targetLang]
|
|
||||||
|
|
||||||
uidData.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({
|
|
||||||
gacha_id: recordEntry.gacha_id,
|
|
||||||
gacha_type: recordEntry.gacha_type,
|
|
||||||
item_id: recordEntry.item_id,
|
|
||||||
count: recordEntry.count ?? "1",
|
|
||||||
time: recordEntry.time,
|
|
||||||
name: idTargetLangJson?.[recordEntry.item_id].name ?? recordEntry.name,
|
|
||||||
item_type: idTargetLangJson?.[recordEntry.item_id].item_type ?? recordEntry.item_type,
|
|
||||||
rank_type: recordEntry.rank_type,
|
|
||||||
id: recordEntry.id
|
|
||||||
})
|
|
||||||
})
|
|
||||||
const resultTempGrouped = resultTemp.reduce((acc, curr) => {
|
|
||||||
if (!acc[curr.gacha_type]) {
|
|
||||||
acc[curr.gacha_type] = []
|
|
||||||
}
|
|
||||||
acc[curr.gacha_type].push(curr)
|
|
||||||
return acc;
|
|
||||||
}, {})
|
|
||||||
const resultTempMap = new Map(Object.entries(resultTempGrouped))
|
|
||||||
const resultMap = { result: resultTempMap, uid: uidData.uid}
|
|
||||||
let data
|
|
||||||
const mergedData = mergeData(dataMap.get(uidData.uid), resultMap)
|
|
||||||
if (isNew) {
|
|
||||||
data = { result: mergedData, time: Date.now(), uid: uidData.uid, lang: targetLang, region_time_zone: uidData.timezone, deleted: false }
|
|
||||||
} 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 }
|
|
||||||
}
|
|
||||||
|
|
||||||
saveData(data, '')
|
|
||||||
changeCurrent(uidData.uid)
|
|
||||||
dataMap.set(uidData.uid, data)
|
|
||||||
})
|
|
||||||
return {
|
return {
|
||||||
dataMap,
|
dataMap,
|
||||||
current: config.current
|
current: config.current
|
||||||
|
@ -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-')) {
|
||||||
|
@ -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
|
||||||
@ -545,4 +545,5 @@ exports.getUrl = getUrl
|
|||||||
exports.deleteData = deleteData
|
exports.deleteData = deleteData
|
||||||
exports.saveData = saveData
|
exports.saveData = saveData
|
||||||
exports.changeCurrent = changeCurrent
|
exports.changeCurrent = changeCurrent
|
||||||
exports.convertTimeZone = convertTimeZone
|
exports.convertTimeZone = convertTimeZone
|
||||||
|
exports.getGachaType = getGachaType
|
@ -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
|
||||||
|
Reference in New Issue
Block a user