Rewrite MDB loading code to support loading .xml, .json or .b64 files. This applies to the default MDB (determined by the version of the game requesting it), or custom MDB if that setting is enabled. To use a custom MDB, enable it in Web UI, then place a custom.json, custom.xml or custom.b64 file in the data/mdb subfolder.

This commit is contained in:
Thome Valentin
2022-05-01 12:24:17 +02:00
parent 5c612929e2
commit 89be828ef8
3 changed files with 80 additions and 35 deletions
+5 -4
View File
@@ -1,6 +1,5 @@
import { getVersion } from "../utils";
import { defaultProcessRawData, processDataBuilder } from "../data/mdb"
import { CommonMusicDataField, readJSONOrXML, readXML } from "../data/mdb";
import { CommonMusicDataField, findMDBFile, readMDBFile, loadSongsForGameVersion } from "../data/mdb";
import Logger from "../utils/logger"
const logger = new Logger("MusicList")
@@ -10,7 +9,9 @@ export const playableMusic: EPR = async (info, data, send) => {
let music: CommonMusicDataField[] = [];
try {
if (U.GetConfig("enable_custom_mdb")) {
music = (await defaultProcessRawData('data/mdb/custom.xml')).music
let customMdb = findMDBFile("custom")
music = (await readMDBFile(customMdb)).music
}
} catch (e) {
logger.warn("Read Custom MDB failed. Using default MDB as a fallback.")
@@ -19,7 +20,7 @@ export const playableMusic: EPR = async (info, data, send) => {
}
if (music.length == 0) {
music = _.get(await processDataBuilder(version), 'music', []);
music = (await loadSongsForGameVersion(version)).music
}
await send.object({