126 lines
3.9 KiB
JavaScript
126 lines
3.9 KiB
JavaScript
/*:
|
||
* @target MZ
|
||
* @plugindesc スイッチ・変数の変更をコンソールに出力(特定IDを強調+SE再生)
|
||
* @author 大江戸大五郎
|
||
*
|
||
* @param highlightSwitches
|
||
* @text 強調表示するスイッチID
|
||
* @type string
|
||
* @default 1,5,7
|
||
* @desc カンマ区切りでスイッチIDを入力(例:1,5,7)
|
||
|
||
* @param highlightVariables
|
||
* @text 強調表示する変数ID
|
||
* @type string
|
||
* @default 3,10
|
||
* @desc カンマ区切りで変数IDを入力(例:3,10)
|
||
|
||
* @param seName
|
||
* @text 強調時のSE名
|
||
* @type file
|
||
* @dir audio/se
|
||
* @default Switch1
|
||
* @desc 強調対象のIDが変更されたときに鳴らすSEファイル名
|
||
|
||
* @param seVolume
|
||
* @text SE音量
|
||
* @type number
|
||
* @default 90
|
||
* @desc SEの音量(0〜100)
|
||
|
||
* @param sePitch
|
||
* @text SEピッチ
|
||
* @type number
|
||
* @default 100
|
||
* @desc SEのピッチ(50〜150)
|
||
|
||
* @param sePan
|
||
* @text SEパン
|
||
* @type number
|
||
* @default 0
|
||
* @desc SEの左右パン(-100〜100)
|
||
|
||
*
|
||
* @help
|
||
* 【機能】
|
||
* - スイッチや変数が変更された際に内容をコンソールに出力
|
||
* - 指定IDの場合は強調スタイルでログ出力
|
||
* - 強調対象のIDが変更された場合はSEも再生
|
||
*
|
||
* 【注意】
|
||
* - SEは「audio/se」フォルダにあるファイルを指定してください。
|
||
*/
|
||
|
||
(() => {
|
||
const pluginName = document.currentScript.src.match(/\/([^\/]+)\.js$/)[1];
|
||
const params = PluginManager.parameters(pluginName);
|
||
|
||
const parseIdList = (str) =>
|
||
str.split(",").map(s => Number(s.trim())).filter(id => !isNaN(id) && id > 0);
|
||
|
||
const highlightSwitches = parseIdList(params["highlightSwitches"] || "");
|
||
const highlightVariables = parseIdList(params["highlightVariables"] || "");
|
||
|
||
const seParams = {
|
||
name: params["seName"] || "",
|
||
volume: Number(params["seVolume"] || 90),
|
||
pitch: Number(params["sePitch"] || 100),
|
||
pan: Number(params["sePan"] || 0)
|
||
};
|
||
|
||
const playHighlightSE = () => {
|
||
if (seParams.name) {
|
||
AudioManager.playSe({
|
||
name: seParams.name,
|
||
volume: seParams.volume,
|
||
pitch: seParams.pitch,
|
||
pan: seParams.pan
|
||
});
|
||
}
|
||
};
|
||
|
||
const _GameSwitches_setValue = Game_Switches.prototype.setValue;
|
||
Game_Switches.prototype.setValue = function(switchId, value) {
|
||
const oldValue = this.value(switchId);
|
||
if (oldValue !== value) {
|
||
const name = $dataSystem.switches[switchId] || "";
|
||
const before = oldValue ? "ON" : "OFF";
|
||
const after = value ? "ON" : "OFF";
|
||
const isHighlighted = highlightSwitches.includes(switchId);
|
||
const baseMsg = `スイッチ${switchId}「${name}」"${before}"→"`;
|
||
const afterColor = value ? "color: red;" : "color: deepskyblue;";
|
||
const msg = `%c${baseMsg}%c${after}%c"`;
|
||
|
||
const baseStyle = isHighlighted
|
||
? "color: black; background-color: yellow; font-weight: bold;"
|
||
: "color: white;";
|
||
const resetStyle = baseStyle;
|
||
|
||
console.log(msg, baseStyle, afterColor, resetStyle);
|
||
|
||
if (isHighlighted) {
|
||
playHighlightSE();
|
||
}
|
||
}
|
||
_GameSwitches_setValue.call(this, switchId, value);
|
||
};
|
||
|
||
const _GameVariables_setValue = Game_Variables.prototype.setValue;
|
||
Game_Variables.prototype.setValue = function(variableId, value) {
|
||
const oldValue = this.value(variableId);
|
||
if (oldValue !== value) {
|
||
const name = $dataSystem.variables[variableId] || "";
|
||
const isHighlighted = highlightVariables.includes(variableId);
|
||
const msg = `変数${variableId}「${name}」"${oldValue}"→"${value}"`;
|
||
const style = isHighlighted
|
||
? 'color: white; background-color: purple; font-weight: bold;'
|
||
: 'color: #d291ff;';
|
||
console.log(`%c${msg}`, style);
|
||
|
||
if (isHighlighted) {
|
||
playHighlightSE();
|
||
}
|
||
}
|
||
_GameVariables_setValue.call(this, variableId, value);
|
||
};
|
||
})();
|