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 $ node runner.js directory
To generate directory.json To generate directory.json
``` ```
``` bash
$ node runner.js charword
To generate the latest charword_table.json
```
### Webpage & JavaScript ### 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 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 { export default class CharwordTable {
#operatorIDs = Object.values(__config.operators).map(operator => { return operator.filename.replace(/^(dyn_illust_)(char_[\d]+)(_[\w]+)(|(_.+))$/g, '$2$3$4') }) #operatorIDs = Object.values(__config.operators).map(operator => { return this.#getOperatorId(operator) })
#charwordTable = { #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: { config: {
default_region: DEFAULT_REGION, default_region: DEFAULT_REGION,
regions: REGIONS, regions: REGIONS,
}, },
operators: {}, 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.#operatorIDs.forEach(id => {
this.#charwordTable.operators[id] = { this.#charwordTable.operators[id] = {
alternativeId: id.replace(/^(char_)([\d]+)(_[\w]+)(|(_.+))$/g, '$1$2$3'), 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 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') { if (region === 'zh_TW') {
return await this.#zhTWLoad() return await this.#zhTWLoad()
} }
const data = await this.#download(region) const data = await this.#download(region)
// put voice actor info into charword_table // put voice actor info into charword_table

View File

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

View File

@@ -23,6 +23,7 @@ async function main() {
const background = new Background() const background = new Background()
await background.process() await background.process()
const backgrounds = ['operator_bg.png', ...background.files] const backgrounds = ['operator_bg.png', ...background.files]
const charwordTable = new CharwordTable()
directory() directory()
@@ -38,10 +39,9 @@ async function main() {
for (const [key, _] of Object.entries(__config.operators)) { for (const [key, _] of Object.entries(__config.operators)) {
OPERATOR_NAMES.push(key) OPERATOR_NAMES.push(key)
} }
case 'test': case 'charword':
const charwordTable = new CharwordTable()
await charwordTable.process() await charwordTable.process()
return process.exit(0)
default: default:
break 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`)) 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 = [ const filesToCopy = [
...background.getFilesToCopy(SHOWCASE_PUBLIC_ASSSETS_FOLDER), ...background.getFilesToCopy(SHOWCASE_PUBLIC_ASSSETS_FOLDER),
{ {