do-disciplinary-committee-m.../www/js/plugins/Mihil_AudioCondition.js
2025-05-04 14:43:03 -05:00

249 lines
No EOL
8 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

//=============================================================================
// Mihil_AudioCondition.js
//
// Released under the MIT license
// http://opensource.org/licenses/mit-license.php
//=============================================================================
/*:
* @plugindesc 音声再生に条件を設定できます
*
* @author Mihiraghi
*
* @help つかいかた:
* 音声再生条件(文字列)にて、
* 制御する音声の種類(BGM, BGS, ME, SE)、
* 前方一致で検索する文字列、
* ON/OFFを制御するスイッチ番号、
* を指定します。
* 条件に一致した音声ファイルは、
* スイッチがONの時のみ演奏されるようになります
*
*
* Ver0.1.0 試作
*
* @param BGVVolumeName
* @text BGV音量の表示名
* @desc オプション画面に表示する「BGV音量」の項目名
* @type string
* @default BGV音量
*
* @param PrefixConditions
* @text 音声再生条件(文字列)
* @desc 文字列から前方一致で引っかかった
* ファイル名の音声再生をスイッチで制御します
* @type struct<PrefixCondition>[]
* @default []
*/
/*~struct~Condition:
*
*
* @param FileName
* @text ファイル名
* @desc
* @type file
* @dir audio
*
*
* @param Switch
* @text スイッチ
* @desc 複数の条件を入れた場合はANDで判定します
* @type switch
* @parent database
*/
/*~struct~PrefixCondition:
*
* @param AudioType
* @text 音声種類
* @desc 音声の種類です
* BGM, BGS, ME, SEから選択します
* @type select
* @option BGM
* @value BGM
* @option BGS
* @value BGS
* @option ME
* @value ME
* @option SE
* @value SE
*
* @param FileString
* @text ファイル検索文字列
* @desc 条件を前方一致したファイル名全てに含むことができます
* @type string
*
*
* @param Switch
* @text スイッチ
* @desc 条件に一致したファイルが、スイッチがOFFの場合演奏しないようにします
* @type switch
* @parent database
*/
//-----------------------------------------------------------------------------
(() => {
'use strict';
const pluginName = document.currentScript.src.replace(/^.*\/(.*).js$/, function () {
return arguments[1];
});
const pluginParameters = PluginManager.parameters(pluginName)
var param = JSON.parse(JSON.stringify(pluginParameters, function(key, value) {
try {
return JSON.parse(value);
} catch (e) {
try {
return eval(value);
} catch (e) {
return value;
}
}
}));
class AudioTypesDistributor{
constructor(){
this._bgm = [];
this._bgs = [];
this._me = [];
this._se = [];
//this.distributeCondition()
this.distributePrefixCondition()
}
distributePrefixCondition(){
for(const condition of param.PrefixConditions){
const list = this.audioListTable()[condition.AudioType]
list.push(condition)
}
}
audioListTable(){
return {
BGM: this._bgm,
BGS: this._bgs,
ME: this._me,
SE: this._se
}
}
get bgm(){ return this._bgm; }
get bgs(){ return this._bgs; }
get me(){ return this._me; }
get se(){ return this._se; }
}
const conditions = new AudioTypesDistributor()
function checkAudioCondition(typeName, audio){
if(!audio || !audio.name){ return true; }
for(const condition of conditions[typeName]){
if(!audio.name.startsWith(condition.FileString)){ continue; }
if(!condition.Switch){ console.error(`$gameSwitches key is falsy`, {key:condition.Switch}); continue; }
return $gameSwitches.value(condition.Switch)
}
return true;
}
const _AudioManager_playBgm = AudioManager.playBgm
AudioManager.playBgm = function(bgm, pos) {
//歓楽街BGM
if(arguments[0].name=="[MAP]NightTown"){
if($gameVariables.value(277)==1){
arguments[0].name = "[MAP]NightTown2" //2章敗北ルート時BGM
}
//神社BGM
}else if(arguments[0].name=="[MAP]Shrine_01"){
if($gameVariables.value(2)>=3){
arguments[0].name = "" //夜BGM
}
if($gameVariables.value(2)<=2 && $gameVariables.value(25)<=9 && $gameVariables.value(287)==0){
arguments[0].name = "[Scene]Serious05" //初期イベントBGM
}
//市街地BGM
}else if(arguments[0].name=="[MAP]Yumemi_town01"){
if($gameVariables.value(2)==2){
arguments[0].name = "[MAP]School_main2" //夕方BGM
}
if($gameVariables.value(2)>=3){
arguments[0].name = "" //夜BGM
}
//学園BGM
}else if(arguments[0].name=="[MAP]School_main"){
if($gameSwitches.value(752) && $gameVariables.value(589)<100){
arguments[0].name = "[Theme]Kitou" //生徒指導イベントBGM
}
if($gameVariables.value(167)==1){
arguments[0].name = "[MAP]School_Bad1" //敗北ルート時BGM
}
if($gameVariables.value(167)==2){
arguments[0].name = "[MAP]School_Hypno" //催眠時BGM
}
if($gameVariables.value(2)==2){
arguments[0].name = "[MAP]School_main2" //夕方BGM
}
if($gameVariables.value(2)>=3){
arguments[0].name = "" //夜BGM
}
//駅前BGM
}else if(arguments[0].name=="[MAP]Station_Rotary"){
if($gameVariables.value(2)==2){
arguments[0].name = "[MAP]School_main2" //夕方BGM
}
if($gameVariables.value(2)>=3){
arguments[0].name = "" //夜BGM
}
if($gameMap.mapId()==317 && $gameSwitches.value(649)){
arguments[0].name = "[Scene]Sukebe01" //ピアBGM
}
//アクアキングダムBGM
}else if(arguments[0].name=="[MAP]AquaKingdom_Front"){
if($gameVariables.value(23)>=81 && $gameVariables.value(23)<100){
arguments[0].name = "[MAP]AquaKingdom_Front2" //敗北期間BGM
}
}
if(!checkAudioCondition("bgm", bgm)){ return; }
_AudioManager_playBgm.apply(this, arguments)
}
const _AudioManager_playBgs = AudioManager.playBgs
AudioManager.playBgs = function(bgs, pos) {
//メモ BGSは対象マップでロードするとバグる
/*if(arguments[0].name=="Wood"){
if($gameVariables.value(2)>=2){
arguments[0].name = "" //夕方からは何も流さない
if($gameVariables.value(2)>=3){
AudioManager.playSe({"name":"Animal_Owl01","volume":90,"pitch":100,"pan":0})
}else{
AudioManager.playSe({"name":"Animal_Crow01","volume":90,"pitch":100,"pan":0})
}
}
}*/
if(!checkAudioCondition("bgs", bgs)){ return; }
if (bgs && !!bgs.name && bgs.name.includes("[BGV]")) {
bgs.volume = ConfigManager.bgvVolume; // オプション設定のBGV音量を適用
}
_AudioManager_playBgs.apply(this, arguments)
}
const _AudioManager_playMe = AudioManager.playMe
AudioManager.playMe = function(me) {
if(!checkAudioCondition("me", me)){ return; }
_AudioManager_playMe.apply(this, arguments)
}
const _AudioManager_playSe = AudioManager.playSe
AudioManager.playSe = function(se) {
if(!checkAudioCondition("se", se)){ return; }
if (se && !!se.name && se.name.includes("[BGV]")) {
se.volume = ConfigManager.bgvVolume; // オプション設定のBGV音量を適用
}
_AudioManager_playSe.apply(this, arguments)
}
// オプション画面にBGV音量を追加
ConfigManager.bgvVolume = 90; // 初期値を設定
const _Window_Options_addVolumeOptions = Window_Options.prototype.addVolumeOptions;
Window_Options.prototype.addVolumeOptions = function() {
_Window_Options_addVolumeOptions.apply(this, arguments);
this.addCommand(PluginManager.parameters('Mihil_AudioCondition')['BGVVolumeName'], "bgvVolume");
};
})();