135 lines
5.1 KiB
JavaScript
135 lines
5.1 KiB
JavaScript
/*:ja
|
||
* @target MZ
|
||
* @author kurogoma knights
|
||
* @plugindesc 修正パッチ TorigoyaMZ_NotifyMessage(Shiftで透過+内部ログ管理)
|
||
* @help 修正パッチ TorigoyaMZ_NotifyMessage(Shiftで透過+内部ログ管理)
|
||
*
|
||
* @command CLEAR_LOGS
|
||
* @desc 内部保持ログをクリア
|
||
*
|
||
*/
|
||
|
||
(() => {
|
||
'use strict';
|
||
const script = document.currentScript;
|
||
const param = PluginManagerEx.createParameter(script);
|
||
|
||
const MAX_LINE = 100; // 最大ログ件数
|
||
const FADE_RATE = 0.2; // 透過率
|
||
|
||
/**
|
||
* ユーティリティ:メソッドラッパ
|
||
* 元のメソッドを保持したまま拡張する
|
||
*/
|
||
function wrap(target, methodName, func) {
|
||
const originalFunc = target[methodName] || function() { };
|
||
target[methodName] = function(...args) {
|
||
return func.apply(this, [this, originalFunc.bind(this), ...args]);
|
||
};
|
||
}
|
||
|
||
//============================================================
|
||
// ① Shiftキーで透過切替
|
||
//============================================================
|
||
let isLogFade = false;
|
||
wrap(Torigoya.NotifyMessage.Manager, 'update', function(self, originalFunc) {
|
||
originalFunc();
|
||
if (!self.isVisible()) return;
|
||
|
||
if (Input.isTriggered('alt')) {
|
||
isLogFade = !isLogFade;
|
||
}
|
||
|
||
for (const stack of self._stacks) {
|
||
const win = stack.window;
|
||
if (!win) continue;
|
||
|
||
win.contentsOpacity = isLogFade
|
||
? stack.notifyItem.openness * FADE_RATE
|
||
: stack.notifyItem.openness;
|
||
}
|
||
});
|
||
|
||
//============================================================
|
||
// ② 通知アニメーション初期化(そのまま)
|
||
//============================================================
|
||
Torigoya.NotifyMessage.Manager.startAppearAndExitAnimation = function(stack) {
|
||
const viewTime = Torigoya.NotifyMessage.parameter.baseViewTime;
|
||
const animationDirection = Torigoya.NotifyMessage.parameter.baseAnimationDirection;
|
||
const topPadding = Torigoya.NotifyMessage.parameter.advancedUiPaddingTop;
|
||
const bottomPadding = Torigoya.NotifyMessage.parameter.advancedUiPaddingBottom;
|
||
|
||
stack.y =
|
||
animationDirection === 'topToBottom'
|
||
? -stack.window.height + topPadding
|
||
: Graphics.height - bottomPadding;
|
||
|
||
stack.window.x = 0;
|
||
stack.window.y = stack.y;
|
||
stack.window.contentsOpacity = 0;
|
||
|
||
stack.appearAnimation = this.createAppearAnimation(stack).call(() =>
|
||
stack.waitAnimation ? stack.waitAnimation.start() : null,
|
||
);
|
||
|
||
stack.waitAnimation =
|
||
viewTime > 0
|
||
? this.createWaitAnimation(stack).call(() =>
|
||
stack.exitAnimation ? stack.exitAnimation.start() : null,
|
||
)
|
||
: null;
|
||
|
||
stack.exitAnimation = this.createExitAnimation(stack).call(() => this._destroyStack(stack));
|
||
stack.appearAnimation.start();
|
||
};
|
||
|
||
//============================================================
|
||
// ③ 内部ログ機構
|
||
//============================================================
|
||
|
||
// 内部ログストレージ追加(ゲーム起動中に保持)
|
||
Torigoya.NotifyMessage.Manager._logs = [];
|
||
|
||
// 通知発生時にログを追加
|
||
const _notify = Torigoya.NotifyMessage.Manager.notify;
|
||
Torigoya.NotifyMessage.Manager.notify = function(notifyItem) {
|
||
_notify.call(this, notifyItem);
|
||
|
||
// ログ文字列を整形
|
||
const line = `\\i[${notifyItem.icon || 0}]${notifyItem.message}`;
|
||
this._logs.push(line);
|
||
if (this._logs.length > MAX_LINE) this._logs.shift();
|
||
};
|
||
|
||
// ログ取得用ヘルパ
|
||
Torigoya.NotifyMessage.Manager.getLogs = function() {
|
||
return this._logs.slice(); // 安全にコピーを返す
|
||
};
|
||
|
||
// ログリセット用(任意で呼べる)
|
||
Torigoya.NotifyMessage.Manager.clearLogs = function() {
|
||
this._logs.length = 0;
|
||
};
|
||
|
||
// ログクリア
|
||
PluginManagerEx.registerCommand(script, "CLEAR_LOGS", function(args) {
|
||
Torigoya.NotifyMessage.Manager.clearLogs();
|
||
});
|
||
|
||
//============================================================
|
||
// ④ セーブデータ連動(再起動時もログを保持するようにする)
|
||
//============================================================
|
||
// const _makeSaveContents = DataManager.makeSaveContents;
|
||
// DataManager.makeSaveContents = function() {
|
||
// const contents = _makeSaveContents.call(this);
|
||
// contents.notifyLogs = Torigoya.NotifyMessage.Manager._logs;
|
||
// return contents;
|
||
// };
|
||
//
|
||
// const _extractSaveContents = DataManager.extractSaveContents;
|
||
// DataManager.extractSaveContents = function(contents) {
|
||
// _extractSaveContents.call(this, contents);
|
||
// Torigoya.NotifyMessage.Manager._logs = contents.notifyLogs || [];
|
||
// };
|
||
|
||
})();
|