feat(runner): add new charword command to runner

This commit is contained in:
Haoyu Xu
2023-02-05 16:56:08 -05:00
parent b32f07ccb3
commit 470e939a2a
5 changed files with 36 additions and 16 deletions

View File

@@ -38,6 +38,10 @@ To add operator info to README.md
$ node runner.js directory
To generate directory.json
```
``` bash
$ node runner.js charword
To generate the latest charword_table.json
```
### Webpage & JavaScript
Add query string `settings` to bring up the settings panel to adjust your settings. Then use appropriate JavaScript code to load your settings

View File

@@ -1 +1 @@
3.2.0
3.3.0

View File

@@ -14,17 +14,34 @@ const NICKNAME = {
}
export default class CharwordTable {
#operatorIDs = Object.values(__config.operators).map(operator => { return operator.filename.replace(/^(dyn_illust_)(char_[\d]+)(_[\w]+)(|(_.+))$/g, '$2$3$4') })
#charwordTable = {
#operatorIDs = Object.values(__config.operators).map(operator => { return this.#getOperatorId(operator) })
#charwordTablePath = path.join(__dirname, __config.folder.operator, __config.folder.share)
#charwordTableFile = path.join(this.#charwordTablePath, 'charword_table.json')
#charwordTable = JSON.parse(readSync(this.#charwordTableFile)) || {
config: {
default_region: DEFAULT_REGION,
regions: REGIONS,
},
operators: {},
}
#charwordTablePath = path.join(__dirname, __config.folder.operator, __config.folder.share)
constructor() {
async process() {
await Promise.all(REGIONS.map(async (region) => {await this.#load(region)}))
writeSync(JSON.stringify(this.#charwordTable), this.#charwordTableFile)
}
lookup(operatorName) {
return {
config: this.#charwordTable.config,
operator: this.#charwordTable.operators[this.#getOperatorId(__config.operators[operatorName])],
}
}
#getOperatorId(operatorConfig) {
return operatorConfig.filename.replace(/^(dyn_illust_)(char_[\d]+)(_[\w]+)(|(_.+))$/g, '$2$3$4')
}
async #load(region) {
this.#operatorIDs.forEach(id => {
this.#charwordTable.operators[id] = {
alternativeId: id.replace(/^(char_)([\d]+)(_[\w]+)(|(_.+))$/g, '$1$2$3'),
@@ -32,17 +49,11 @@ export default class CharwordTable {
info: REGIONS.reduce((acc, cur) => ({ ...acc, [cur]: {} }), {}), // use object to store voice actor info
}
})
}
async process() {
await Promise.all(REGIONS.map(async (region) => {await this.#load(region)}))
writeSync(JSON.stringify(this.#charwordTable), path.join(this.#charwordTablePath, 'charword_table.json'))
}
async #load(region) {
if (region === 'zh_TW') {
return await this.#zhTWLoad()
}
const data = await this.#download(region)
// put voice actor info into charword_table

View File

@@ -16,8 +16,11 @@ export async function read(filePath, encoding = 'utf8') {
}
export function readSync(filePath, encoding = 'utf8') {
if (exists(filePath)) {
return fs.readFileSync(filePath, encoding, { flag: 'r' })
}
return null
}
export function exists(filePath) {
return fs.existsSync(filePath)

View File

@@ -23,6 +23,7 @@ async function main() {
const background = new Background()
await background.process()
const backgrounds = ['operator_bg.png', ...background.files]
const charwordTable = new CharwordTable()
directory()
@@ -38,10 +39,9 @@ async function main() {
for (const [key, _] of Object.entries(__config.operators)) {
OPERATOR_NAMES.push(key)
}
case 'test':
const charwordTable = new CharwordTable()
case 'charword':
await charwordTable.process()
return
process.exit(0)
default:
break
}
@@ -85,6 +85,8 @@ async function main() {
write(JSON.stringify(content.assetsJson, null), path.join(OPERATOR_SOURCE_FOLDER, OPERATOR_NAME, `${__config.operators[OPERATOR_NAME].filename}.json`))
})
writeSync(JSON.stringify(charwordTable.lookup(OPERATOR_NAME)), path.join(OPERATOR_SOURCE_FOLDER, OPERATOR_NAME, 'charword_table.json'))
const filesToCopy = [
...background.getFilesToCopy(SHOWCASE_PUBLIC_ASSSETS_FOLDER),
{