//============================================================================= // RPG Maker MZ - Debug Switch // // Copyright 2024 Panzer-IV. All rights reserved. // This source code or any portion thereof must not be // reproduced or used without licensed in any manner whatsoever. //============================================================================= /*: * @target MZ * @plugindesc デバッグスイッチプラグイン * @author 四号戦車 * @base PluginCommonBase * @orderAfter PluginCommonBase * * @param debug * @text デバッグモード * @desc デバッグの有効/無効を切り換えます * @type boolean * @default false * @on 有効 * @off 無効 * */ (() => { "use strict"; const pluginName = "DebugSwitch"; const script = document.currentScript; const param = PluginManagerEx.createParameter(script); class DebugSwitch { static isEnable() { return param.debug && Utils.isOptionValid("test"); } } window.DebugSwitch = DebugSwitch; let _debugLebel = 2; // debug class Logger { static ERROR = 'error'; static WORN = 'worn'; static DEBUG = 'debug'; static VERBOSE = 'verbose'; static DEBUG_LEVELS = { 'error': 4, 'worn': 3, 'debug': 2, 'verbose': 1, }; static setLevel(level) { Logger.log(`level changed: ${level}`); const num = Logger.DEBUG_LEVELS[level]; _debugLebel = !!num ? num : 0; } static e(text) { if (_debugLebel <= Logger.DEBUG_LEVELS[Logger.ERROR]) { Logger.log(text) } } static w(text) { if (_debugLebel <= Logger.DEBUG_LEVELS[Logger.WORN]) { Logger.log(text) } } static d(text) { if (_debugLebel <= Logger.DEBUG_LEVELS[Logger.DEBUG]) { Logger.log(text) } } static v(text) { if (_debugLebel <= Logger.DEBUG_LEVELS[Logger.VERBOSE]) { Logger.log(text) } } static log(text) { if (DebugSwitch.isEnable()) { console.log(text); } } constructor() { } } window.Logger = Logger; })();