feat: updated music and background handling to support _form_x type background

This commit is contained in:
Haoyu Xu
2025-10-05 20:26:10 +08:00
parent 49a49e5210
commit 33c7553506
8 changed files with 39 additions and 32 deletions

View File

@@ -1,6 +1,7 @@
import path from 'node:path'
import config from '@aklive2d/config'
import { githubDownload } from '@aklive2d/downloader'
import {files as backgroundFiles} from "@aklive2d/background"
import { file } from '@aklive2d/libs'
import type {
AudioDataTable,
@@ -85,6 +86,30 @@ const generateMapping = () => {
}
}
for (const e of musicFiles) {
const musicPath = path.join(e.source, e.filename)
if (!file.exists(musicPath)) {
throw new Error(`Music file ${e.filename} is not found in music folder.`)
}
}
for (const e of Object.keys(musicFileMapping)) {
if (!backgroundFiles.includes(e)) {
throw new Error(`Background file ${e} is not found in background folder.`)
}
}
for (const background of backgroundFiles) {
if (!musicFileMapping[background]) {
const alternativeMatch = background.replace(/_(form)(.*)(\.png)$/, "$3")
if (musicFileMapping[alternativeMatch]){
musicFileMapping[background] = structuredClone(musicFileMapping[alternativeMatch])
} else {
throw new Error(`Music mapping for background file ${background} is not found in music mapping.`)
}
}
}
return {
musicFiles,
musicFileMapping,