fix(aklive2d): fixed regional game data repo
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/* eslint-disable no-undef */
|
/* eslint-disable no-undef */
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import dotenv from "dotenv"
|
import dotenv from "dotenv"
|
||||||
import { exists, writeSync, readdirSync, rm, readSync } from "./file.js"
|
import { writeSync, readSync } from "./file.js"
|
||||||
import Downloader from "./downloader.js"
|
import Downloader from "./downloader.js"
|
||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
@@ -9,6 +9,12 @@ dotenv.config()
|
|||||||
// zh_TW uses an older version of charword_table.json
|
// zh_TW uses an older version of charword_table.json
|
||||||
// zh_TW is removed
|
// zh_TW is removed
|
||||||
const REGIONS = ["zh_CN", "en_US", "ja_JP", "ko_KR"]
|
const REGIONS = ["zh_CN", "en_US", "ja_JP", "ko_KR"]
|
||||||
|
const REGION_URLS = {
|
||||||
|
"zh_CN": "Kengxxiao/ArknightsGameData",
|
||||||
|
"en_US": "Kengxxiao/ArknightsGameData_YoStar",
|
||||||
|
"ja_JP": "Kengxxiao/ArknightsGameData_YoStar",
|
||||||
|
"ko_KR": "Kengxxiao/ArknightsGameData_YoStar",
|
||||||
|
}
|
||||||
const DEFAULT_REGION = REGIONS[0]
|
const DEFAULT_REGION = REGIONS[0]
|
||||||
const NICKNAME = {
|
const NICKNAME = {
|
||||||
"zh_CN": "博士",
|
"zh_CN": "博士",
|
||||||
@@ -58,11 +64,6 @@ export default class CharwordTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async #load(region) {
|
async #load(region) {
|
||||||
// if (region === 'zh_TW') {
|
|
||||||
// return await this.#zhTWLoad()
|
|
||||||
// } else if (region === DEFAULT_REGION) {
|
|
||||||
// return await this.#zhCNLoad()
|
|
||||||
// }
|
|
||||||
|
|
||||||
const data = await this.#download(region)
|
const data = await this.#download(region)
|
||||||
|
|
||||||
@@ -121,158 +122,7 @@ export default class CharwordTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async #download(region) {
|
async #download(region) {
|
||||||
return await (new Downloader()).github(`https://api.github.com/repos/Kengxxiao/ArknightsGameData/commits?path=${region}/gamedata/excel/charword_table.json`, `https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master/${region}/gamedata/excel/charword_table.json`, path.join(this.#charwordTablePath, `charword_table_${region}.json`))
|
return await (new Downloader()).github(`https://api.github.com/repos/${REGION_URLS[region]}/commits?path=${region}/gamedata/excel/charword_table.json`, `https://raw.githubusercontent.com/${REGION_URLS[region]}/master/${region}/gamedata/excel/charword_table.json`, path.join(this.#charwordTablePath, `charword_table_${region}.json`))
|
||||||
}
|
}
|
||||||
|
|
||||||
async #zhCNLoad() {
|
|
||||||
const region = DEFAULT_REGION
|
|
||||||
|
|
||||||
const data = await this.#download(region)
|
|
||||||
|
|
||||||
// put voice actor info into charword_table
|
|
||||||
for (const [id, element] of Object.entries(this.#charwordTable.operators)) {
|
|
||||||
let operatorId = id
|
|
||||||
let useAlternativeId = false
|
|
||||||
if (typeof data.voiceLangDict.find(e => e.key === operatorId) === 'undefined') {
|
|
||||||
operatorId = element.alternativeId
|
|
||||||
useAlternativeId = true
|
|
||||||
}
|
|
||||||
element.infile = this.#operatorIDs.includes(operatorId);
|
|
||||||
element.ref = useAlternativeId && element.infile;
|
|
||||||
|
|
||||||
if (element.infile && useAlternativeId) {
|
|
||||||
// if using alternative id and infile is true, means data can be
|
|
||||||
// refered inside the file
|
|
||||||
// if infile is false, useAlternativeId is always true
|
|
||||||
// if useAlternativeId is false, infile is always true
|
|
||||||
// | case | infile | useAlternativeId | Note |
|
|
||||||
// | ------------------- | ------ | ---------------- | --------------- |
|
|
||||||
// | lee_trust_your_eyes | false | true | skin only |
|
|
||||||
// | nearl_relight | true | true | skin, operator, no voice |
|
|
||||||
// | nearl | true | false | operator only |
|
|
||||||
// | w_fugue | true | false | skin, operator, voice |
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
Object.values(data.voiceLangDict.find(e => e.key === operatorId).value.voiceLangInfoDataDict).forEach(item => {
|
|
||||||
if (typeof element.info[region][item.value.wordkey] === 'undefined') {
|
|
||||||
element.info[region][item.value.wordkey] = {}
|
|
||||||
}
|
|
||||||
element.info[region][item.value.wordkey][item.value.voiceLangType] = [...(typeof item.value.cvName === 'string' ? [item.value.cvName] : item.value.cvName)]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// put voice lines into charword_table
|
|
||||||
data.charWords.forEach(item => {
|
|
||||||
const operatorInfo = Object.values(this.#charwordTable.operators).filter(element => element.info[region][item.value.wordKey])
|
|
||||||
if (operatorInfo.length > 0) {
|
|
||||||
if (typeof operatorInfo[0].voice[region][item.value.wordKey] === 'undefined') {
|
|
||||||
operatorInfo[0].voice[region][item.value.wordKey] = {}
|
|
||||||
}
|
|
||||||
operatorInfo[0].voice[region][item.value.wordKey][item.value.voiceId] = {
|
|
||||||
title: item.value.voiceTitle,
|
|
||||||
text: item.value.voiceText.replace(/{@nickname}/g, NICKNAME[region]),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async #zhTWLoad() {
|
|
||||||
const region = 'zh_TW'
|
|
||||||
const downloaded = await this.#zhTWDownload()
|
|
||||||
const data = downloaded.data
|
|
||||||
const handbook = downloaded.handbook
|
|
||||||
|
|
||||||
// put voice actor info into charword_table
|
|
||||||
for (const [id, element] of Object.entries(this.#charwordTable.operators)) {
|
|
||||||
let operatorId = id
|
|
||||||
let useAlternativeId = false
|
|
||||||
if (typeof handbook.handbookDict[operatorId] === 'undefined') {
|
|
||||||
operatorId = element.alternativeId
|
|
||||||
useAlternativeId = true
|
|
||||||
}
|
|
||||||
// not available in other region
|
|
||||||
if (typeof handbook.handbookDict[operatorId] === 'undefined') {
|
|
||||||
console.log(`Voice actor info of ${id} is not available in ${region}.`)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (element.infile && useAlternativeId) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
const charId = handbook.handbookDict[operatorId].charID
|
|
||||||
if (typeof element.info[region][charId] === 'undefined') {
|
|
||||||
element.info[region][charId] = {}
|
|
||||||
}
|
|
||||||
element.info[region][charId].JP = [...[handbook.handbookDict[operatorId].infoName]]
|
|
||||||
}
|
|
||||||
|
|
||||||
// put voice lines into charword_table
|
|
||||||
Object.values(data).forEach(item => {
|
|
||||||
const operatorInfo = Object.values(this.#charwordTable.operators).filter(element => element.info[region][item.wordKey])
|
|
||||||
if (operatorInfo.length > 0) {
|
|
||||||
if (typeof operatorInfo[0].voice[region][item.wordKey] === 'undefined') {
|
|
||||||
operatorInfo[0].voice[region][item.wordKey] = {}
|
|
||||||
}
|
|
||||||
operatorInfo[0].voice[region][item.wordKey][item.voiceId] = {
|
|
||||||
title: item.voiceTitle,
|
|
||||||
text: item.voiceText.replace(/{@nickname}/g, NICKNAME[region]),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async #zhTWDownload() {
|
|
||||||
const output = {}
|
|
||||||
const region = 'zh_TW'
|
|
||||||
const historyResponse = await fetch(`https://api.github.com/repos/Kengxxiao/ArknightsGameData/commits?path=${region}/gamedata/excel/charword_table.json`)
|
|
||||||
const handbookHistoryResponse = await fetch(`https://api.github.com/repos/Kengxxiao/ArknightsGameData/commits?path=${region}/gamedata/excel/handbook_info_table.json`)
|
|
||||||
const historyData = await historyResponse.json()
|
|
||||||
const handbookHistoryData = await handbookHistoryResponse.json()
|
|
||||||
const lastCommit = historyData[0]
|
|
||||||
const handboookLastCommit = handbookHistoryData[0]
|
|
||||||
const lastCommitDate = new Date(lastCommit.commit.committer.date)
|
|
||||||
const handbookLastCommitDate = new Date(handboookLastCommit.commit.committer.date)
|
|
||||||
const filepath = path.join(this.#charwordTablePath, `charword_table_${region}_${lastCommitDate.getTime()}.json`)
|
|
||||||
const handbookFilepath = path.join(this.#charwordTablePath, `handbook_info_table_${region}_${handbookLastCommitDate.getTime()}.json`)
|
|
||||||
console.log(`Last commit date: ${lastCommitDate.getTime()}`)
|
|
||||||
console.log(`Handbook last commit date: ${handbookLastCommitDate.getTime()}`)
|
|
||||||
|
|
||||||
if (exists(filepath)) {
|
|
||||||
console.log(`charword_table_${region}.json is the latest version.`)
|
|
||||||
output.data = JSON.parse(readSync(filepath))
|
|
||||||
} else {
|
|
||||||
const response = await fetch(`https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master/${region}/gamedata/excel/charword_table.json`)
|
|
||||||
const data = await response.json()
|
|
||||||
writeSync(JSON.stringify(data), filepath)
|
|
||||||
console.log(`charword_table_${region}.json is updated.`)
|
|
||||||
|
|
||||||
// remove old file
|
|
||||||
const files = readdirSync(path.join(__projectRoot, __config.folder.operator, __config.folder.share))
|
|
||||||
for (const file of files) {
|
|
||||||
if (file.startsWith(`charword_table_${region}`) && file !== path.basename(filepath)) {
|
|
||||||
rm(path.join(__projectRoot, __config.folder.operator, __config.folder.share, file))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output.data = data
|
|
||||||
}
|
|
||||||
if (exists(handbookFilepath)) {
|
|
||||||
console.log(`handbook_info_table_${region}.json is the latest version.`)
|
|
||||||
output.handbook = JSON.parse(readSync(handbookFilepath))
|
|
||||||
} else {
|
|
||||||
const response = await fetch(`https://raw.githubusercontent.com/Kengxxiao/ArknightsGameData/master/${region}/gamedata/excel/handbook_info_table.json`)
|
|
||||||
const data = await response.json()
|
|
||||||
writeSync(JSON.stringify(data), handbookFilepath)
|
|
||||||
console.log(`handbook_info_table_${region}.json is updated.`)
|
|
||||||
|
|
||||||
// remove old file
|
|
||||||
const files = readdirSync(path.join(__projectRoot, __config.folder.operator, __config.folder.share))
|
|
||||||
for (const file of files) {
|
|
||||||
if (file.startsWith(`handbook_info_table_${region}`) && file !== path.basename(handbookFilepath)) {
|
|
||||||
rm(path.join(__projectRoot, __config.folder.operator, __config.folder.share, file))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
output.handbook = data
|
|
||||||
}
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user