Files
asphyxia_plugins/gitadora@asphyxia/handlers/MusicList.ts
T
Thome Valentin 2ad1769b78 Added several player profile stats to the web UI.
Refactored and cleaned up several functions.
MDB loader now logs the number of loaded songs available to GF and DM.
MDB: Fixed "is_secret" field being ignored (always set to false)
2022-05-04 06:58:17 +02:00

40 lines
1.0 KiB
TypeScript

import { getVersion } from "../utils";
import { CommonMusicDataField, findMDBFile, readMDBFile, loadSongsForGameVersion } from "../data/mdb";
import Logger from "../utils/logger"
const logger = new Logger("MusicList")
export const playableMusic: EPR = async (info, data, send) => {
const version = getVersion(info);
let music: CommonMusicDataField[] = [];
try {
if (U.GetConfig("enable_custom_mdb")) {
let customMdb = findMDBFile("custom")
music = (await readMDBFile(customMdb)).music
}
} catch (e) {
logger.warn("Read Custom MDB failed. Using default MDB as a fallback.")
logger.debugWarn(e.stack);
music = [];
}
if (music.length == 0) {
music = (await loadSongsForGameVersion(version)).music
}
let response = getPlayableMusicResponse(music)
await send.object(response)
};
function getPlayableMusicResponse(music) {
return {
hot: {
major: K.ITEM('s32', 1),
minor: K.ITEM('s32', 1),
},
musicinfo: K.ATTR({ nr: `${music.length}` }, {
music,
}),
}
}