100 lines
3.5 KiB
JavaScript
100 lines
3.5 KiB
JavaScript
/*:
|
|
* @target MZ
|
|
* @plugindesc 通知メッセージアドオン: スイッチ開放通知(中央固定版) v1.0.0
|
|
* @author IvI
|
|
*
|
|
* TorigoyaMZ_NotifyMessage_AddonVariableChangeCenter と併用し、
|
|
* 指定スイッチが OFF → ON になった瞬間に
|
|
* 『「スイッチ名」が開放されました』というメッセージを
|
|
* まったく同じ演出でポップアップ表示します。
|
|
*
|
|
* ▼ 使用手順
|
|
* 1. プラグイン管理で本ファイルを『変数通知アドオン』の下に追加してください。
|
|
* 2. 「監視スイッチリスト」に対象スイッチを登録します。
|
|
* ・{name} … スイッチ名に置換
|
|
*
|
|
* @param watchSwitchList
|
|
* @text 監視スイッチリスト
|
|
* @type struct<SwitchWatchItem>[]
|
|
* @default []
|
|
*/
|
|
/*~struct~SwitchWatchItem:
|
|
* @param switchId
|
|
* @text スイッチID
|
|
* @type switch
|
|
* @default 1
|
|
*
|
|
* @param messageTemplate
|
|
* @text メッセージ
|
|
* @desc {name} がスイッチ名に置換されます
|
|
* @default \\c[1]「{name}」が開放されました
|
|
* @type string
|
|
*
|
|
* @param iconId
|
|
* @text アイコンID
|
|
* @type number
|
|
* @default 0
|
|
*/
|
|
|
|
(() => {
|
|
'use strict';
|
|
|
|
const PLUGIN_NAME = 'TorigoyaMZ_NotifyMessage_AddonSwitchUnlockCenter';
|
|
const params = PluginManager.parameters(PLUGIN_NAME);
|
|
|
|
// -------------------------------------------------------------------------
|
|
// 依存チェック
|
|
const Torigoya = window.Torigoya || {};
|
|
if (!Torigoya.NotifyMessage || !Torigoya.NotifyMessage.Manager) {
|
|
console.error('[%s] TorigoyaMZ_NotifyMessage が読み込まれていません。', PLUGIN_NAME);
|
|
return;
|
|
}
|
|
const Manager = Torigoya.NotifyMessage.Manager;
|
|
|
|
// -------------------------------------------------------------------------
|
|
// パラメータ読み込み
|
|
const rawList = JSON.parse(params.watchSwitchList || '[]');
|
|
/** @type {{switchId:number,messageTemplate:string,iconId:number}[]} */
|
|
const WATCHERS = rawList
|
|
.map((raw) => {
|
|
const o = JSON.parse(raw);
|
|
return {
|
|
switchId: Number(o.switchId || 0),
|
|
messageTemplate: String(o.messageTemplate || '\\c[1]「{name}」が開放されました'),
|
|
iconId: Number(o.iconId || 0),
|
|
};
|
|
})
|
|
.filter((w) => w.switchId > 0);
|
|
|
|
const WATCH_TABLE = {};
|
|
for (const w of WATCHERS) WATCH_TABLE[w.switchId] = w;
|
|
|
|
// -------------------------------------------------------------------------
|
|
// ユーティリティ
|
|
const buildMessage = (template, name) => template.replace('{name}', name);
|
|
|
|
function notifyUnlock(watcher) {
|
|
const name = $dataSystem.switches[watcher.switchId] || `スイッチ${watcher.switchId}`;
|
|
const notifyItem = new Torigoya.NotifyMessage.NotifyItem({
|
|
message: buildMessage(watcher.messageTemplate, name),
|
|
icon: watcher.iconId,
|
|
// 既存の中央固定処理に乗せるため同じ note を使う
|
|
note: '<type:variableChange>',
|
|
});
|
|
Manager.notify(notifyItem);
|
|
}
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Game_Switches 拡張
|
|
const _setValue = Game_Switches.prototype.setValue;
|
|
Game_Switches.prototype.setValue = function (switchId, value) {
|
|
const old = this.value(switchId);
|
|
_setValue.apply(this, arguments);
|
|
|
|
const watcher = WATCH_TABLE[switchId];
|
|
if (!watcher) return;
|
|
|
|
// OFF → ON になった瞬間だけ通知
|
|
if (!old && value) notifyUnlock(watcher);
|
|
};
|
|
})();
|