fix: fixed background and music order in project.json

This commit is contained in:
Haoyu Xu
2025-02-23 22:18:32 +08:00
parent 4a1b901f25
commit 1fd7b61ab1
3 changed files with 28 additions and 4 deletions

View File

@@ -16,7 +16,16 @@ const DEFAULT_BACKGROUND_FILE = path.join(
)
const getFiles = () => {
return file.readdirSync(DIST_DIR)
const ret = file.readdirSync(DIST_DIR)
ret.unshift(
ret.splice(
ret.findIndex(
(e) => e === config.module.background.operator_bg_png
),
1
)[0]
)
return ret
}
export let files = getFiles()

View File

@@ -10,15 +10,27 @@ import { getLangs } from '@aklive2d/charword-table'
const DIST_DIR = path.join(import.meta.dirname, config.dir_name.dist)
export const build = (namesToBuild) => {
const err = []
const names = !namesToBuild.length ? Object.keys(operators) : namesToBuild
console.log('Generating assets for', names.length, 'operators')
const musicMapping = []
// sort music mapping based on background file order
for (const item of backgrounds) {
if (musics.musicFileMapping[item]) {
musicMapping.push(item)
} else {
err.push(
`Music folder doesn't contain music for ${item} background.`
)
}
}
for (const name of names) {
const { voiceLangs, subtitleLangs } = getLangs(name)
load(name, {
backgrounds,
voiceLangs,
subtitleLangs,
music: Object.keys(musics.musicFileMapping),
music: musicMapping,
})
file.symlink(
path.join(
@@ -28,6 +40,7 @@ export const build = (namesToBuild) => {
path.join(getDistDir(name), config.module.project_json.preview_jpg)
)
}
return err
}
const getDistDir = (name) => {

View File

@@ -1,7 +1,8 @@
import { envParser } from '@aklive2d/libs'
import { envParser, error } from '@aklive2d/libs'
import { build } from './index.js'
async function main() {
let err = []
const { mode, name } = envParser.parse({
mode: {
type: 'string',
@@ -16,11 +17,12 @@ async function main() {
})
switch (mode) {
case 'build':
build(name)
err = build(name)
break
default:
throw new Error(`Unknown mode: ${mode}`)
}
error.handle(err)
}
main()