moon-red-goddess-cornelia/js/plugins/consolelog.js
2025-10-06 13:25:53 -05:00

126 lines
3.9 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 スイッチ・変数の変更をコンソールに出力特定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);
};
})();