pure-full-lily/js/plugins/AutoPlayBgm.js
2025-09-16 10:12:44 -05:00

57 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*:
* @target MZ
* @plugindesc v1.0 指定秒後にBGMが鳴っていなければ自動再生します。 Author: IvI
* @command AutoPlayBgm
* @text 自動BGM再生
* @desc 指定時間経過後、まだBGMが再生されていなければ指定のBGMを再生します。
*
* @arg delay
* @type number
* @text 待ち秒数
* @min 0
* @default 1
*
* @arg bgmName
* @type file
* @dir audio/bgm
* @text BGMファイル名
*
* @arg volume
* @type number
* @default 90
* @min 0
* @max 100
* @text 音量
*
* @arg pitch
* @type number
* @default 100
* @text ピッチ
*
* @arg pan
* @type number
* @default 0
* @text 位相
*/
(() => {
const PLUGIN_NAME = document.currentScript.src.match(/([^\/]+)\.js$/i)[1];
PluginManager.registerCommand(PLUGIN_NAME, "AutoPlayBgm", args => {
const delay = Number(args.delay || 0); // 秒
const bgm = {
name: String(args.bgmName || ""),
volume: Number(args.volume || 90),
pitch: Number(args.pitch || 100),
pan: Number(args.pan || 0)
};
if (!bgm.name) return; // ファイル名未設定なら無視
// 指定秒後に判定→再生
setTimeout(() => {
if (!AudioManager._currentBgm) { // まだBGMが鳴っていない
AudioManager.playBgm(bgm);
}
}, delay * 1000);
});
})();