I know, I know, yet another audio attempt by me... but what can I say? Except "Help", of course, as I'm currently swamped and have no idea how to make it work.
EDIT: it's broken... let me fix it.
EDIT nth: good lord, this is a nightmare!
EDIT nNth: ok so, I am at my wit's end and have no idea how to make it work the way it is meant to. It doesn't crash, but it doesn't work properly either.
JavaScript:
/*:
* @plugindesc BGM Palette Plugin - Play a palette of audio files as map BGM in random or sequential order using notetags
* @target MZ
* @url TBC
* @author Dark_Ansem
*
* @help
* To use this plugin, add the following notetag in the map's "Note" field:
* <BGM_Palette: folder_name, file1, file2, file3, ..., mode>
* - folder_name: The folder within audio/bgm where your palette audio files are located.
* - file1, file2, file3, ...: A comma-separated list of audio file names without file extensions.
* - mode: The playback mode for audio files: 'random' or 'sequential'.
*/
(() => {
const pluginName = "BGM_Palette";
let currentIndex = 0;
let audioFolder = '';
let audioFiles = [];
let playbackMode = '';
const playNext = () => {
let nextIndex;
if (playbackMode === "random") {
nextIndex = Math.floor(Math.random() * audioFiles.length);
} else {
nextIndex = (currentIndex + 1) % audioFiles.length;
}
const audioFile = {
name: `${audioFolder}/${audioFiles[nextIndex]}`,
volume: 100,
pitch: 100,
pan: 0,
};
AudioManager.playBgm(audioFile);
currentIndex = nextIndex;
};
const _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
_Scene_Map_update.call(this);
if (audioFiles.length > 0 && AudioManager._bgmBuffer && AudioManager._bgmBuffer.isPlaying() && AudioManager._bgmBuffer._audioNode && AudioManager._bgmBuffer._audioNode.ended) {
playNext();
}
};
const _Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function (mapId) {
_Game_Map_setup.call(this, mapId);
this.setupBgmPalette();
};
Game_Map.prototype.setupBgmPalette = function () {
const mapNote = $dataMap.note;
const notetagRegex = /<BGM_Palette:\s*([^,]+)((?:,\s*[^,]+)+),\s*(random|sequential)\s*>/i;
if (mapNote.match(notetagRegex)) {
audioFolder = RegExp.$1.trim();
audioFiles = RegExp.$2.trim().split(',').map(file => file.trim()).filter(file => file);
playbackMode = RegExp.$3.trim();
playNext();
} else {
// Stop BGM when leaving the map with the BGM_Palette notetag
AudioManager.stopBgm();
audioFiles = [];
}
};
})();
EDIT: it's broken... let me fix it.
EDIT nth: good lord, this is a nightmare!
EDIT nNth: ok so, I am at my wit's end and have no idea how to make it work the way it is meant to. It doesn't crash, but it doesn't work properly either.