prison-brave/js/plugins/MovieVolumeMZ.js
2025-08-28 10:38:20 -05:00

70 lines
2.7 KiB
JavaScript
Raw 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 ムービー再生開始時にBGMボリュームを適用Video.playをフック v1.0.0
* @author yuz-co-show
*
* @command InstallBgmHook
* @text BGM音量フックをインストール
* @desc 以後、ムービー再生開始時に BGM 音量AudioManager.bgmVolumeを適用。
*
* @command UninstallBgmHook
* @text BGM音量フックを解除
* @desc Video.play の上書きを解除して元に戻します。
*
* @help
* MZではムービーは静的クラス Video が扱いますVideo.play / Video.setVolume
* このプラグインはプラグインコマンドで Video.play を一度だけ上書きし、
* 再生のたびに「開始時点の BGM 音量」を 0..1 に換算して Video.setVolume へ渡します。
*
* 仕様:
* - 反映は「開始時だけ」。再生中にBGM音量を変えても追従しません。
* - 参照: AudioManager.bgmVolume0..100)。無ければ ConfigManager.volumeBgm を使用。
* - 他プラグインが後から Video.play を上書きした場合は、再度「インストール」を実行してください。
*/
(() => {
'use strict';
const PLUGIN_NAME = document.currentScript.src.split('/').pop().replace(/\.js$/, '');
function getBgmVol01() {
let v = 100;
if (typeof AudioManager !== 'undefined' && typeof AudioManager.bgmVolume === 'number') {
v = AudioManager.bgmVolume;
} else if (typeof ConfigManager !== 'undefined' && typeof ConfigManager.volumeBgm === 'number') {
v = ConfigManager.volumeBgm;
}
return Math.max(0, Math.min(1, v / 100));
}
function install() {
if (typeof Video === 'undefined' || typeof Video.play !== 'function' || typeof Video.setVolume !== 'function') {
console.warn('MovieBgmVolumeMZ: Video API が未準備のためフックできませんでした。');
return false;
}
if (Video.__mbv_hooked) return true;
Video.__mbv_originalPlay = Video.play.bind(Video);
Video.play = function(src) {
try {
Video.setVolume(getBgmVol01());
} catch (_) {}
return Video.__mbv_originalPlay(src);
};
Video.__mbv_hooked = true;
return true;
}
function uninstall() {
if (typeof Video === 'undefined') return false;
if (!Video.__mbv_hooked) return true;
if (typeof Video.__mbv_originalPlay === 'function') {
Video.play = Video.__mbv_originalPlay;
}
Video.__mbv_hooked = false;
return true;
}
PluginManager.registerCommand(PLUGIN_NAME, 'InstallBgmHook', install);
PluginManager.registerCommand(PLUGIN_NAME, 'UninstallBgmHook', uninstall);
})();