128 lines
4.1 KiB
JavaScript
128 lines
4.1 KiB
JavaScript
//=============================================================================
|
|
// RPG Maker MZ - ButtonEventTrigger
|
|
//
|
|
// Copyright 2025 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 PluginUtils
|
|
* @base InputExtension
|
|
* @orderAfter PluginUtils
|
|
* @orderAfter InputExtension
|
|
*
|
|
* @param triggers
|
|
* @text トリガー一覧
|
|
* @desc トリガーのリストです。
|
|
* @type struct<EventTrigger>[]
|
|
* @default []
|
|
*
|
|
* @param comment
|
|
* @text 備考欄
|
|
* @desc プラグイン側では使用しません。
|
|
* メモ欄としてお使いください。
|
|
* @type multiline_string
|
|
* @default
|
|
*
|
|
* @help ButtonEventTrigger.js
|
|
*
|
|
* Version: 0.0.1
|
|
*
|
|
* ボタン/キーでのイベントトリガー
|
|
*
|
|
* 指定のボタンを押した時に指定のイベントを実行します。
|
|
* スイッチを指定して有効/無効を切り替えることができます。
|
|
* マップ中のみ有効です。(戦闘中は使用できません)
|
|
*
|
|
*/
|
|
|
|
/*~struct~EventTrigger:
|
|
*
|
|
* @param trigger
|
|
* @text トリガーとなるキー
|
|
* @desc トリガーとなるキー/ボタンを指定します。
|
|
* @type select
|
|
* @default select
|
|
* @option SHIFT
|
|
* @value shift
|
|
* @option START
|
|
* @value start
|
|
* @option SELECT
|
|
* @value select
|
|
*
|
|
* @param switch
|
|
* @text 制御スイッチ
|
|
* @desc ONの時のみ有効になるスイッチです。
|
|
* 未指定の場合無条件で有効になります。
|
|
* @type switch
|
|
* @default 0
|
|
*
|
|
* @param event
|
|
* @text イベント
|
|
* @desc 実行するイベントです。
|
|
* @type common_event
|
|
* @default 0
|
|
*
|
|
*/
|
|
(() => {
|
|
"use strict";
|
|
|
|
//========================================================================
|
|
// プラグイン定義
|
|
//========================================================================
|
|
const pluginName = "ButtonEventTrigger";
|
|
const script = document.currentScript;
|
|
const param = PluginUtils.reparseParameter(script);
|
|
|
|
//========================================================================
|
|
// 定数定義
|
|
//========================================================================
|
|
const convertTriggerToKey = (trigger) => {
|
|
const key = trigger.trigger;
|
|
switch (key) {
|
|
case 'shift':
|
|
return InputClass.INPUT_CLASS_SHIFT;
|
|
case 'select':
|
|
return InputClass.INPUT_CLASS_SELECT;
|
|
case 'start':
|
|
return InputClass.INPUT_CLASS_START;
|
|
default:
|
|
return null;
|
|
} // switch
|
|
};
|
|
|
|
//========================================================================
|
|
// コアスクリプト変更部 (Game_Map)
|
|
//========================================================================
|
|
const _Scene_Map_prototype_updateMain = Scene_Map.prototype.updateMain;
|
|
Scene_Map.prototype.updateMain = function() {
|
|
_Scene_Map_prototype_updateMain.apply(this, arguments);
|
|
if (this.isPlayerActive()) {
|
|
param.triggers.forEach(trigger => {
|
|
const key = convertTriggerToKey(trigger);
|
|
if (!key) {
|
|
// キー指定が不正
|
|
return;
|
|
}
|
|
|
|
if (!!trigger.event && trigger.event === 0) {
|
|
// イベント指定が無い
|
|
return;
|
|
}
|
|
|
|
const flag = (trigger.switch === 0) || $gameSwitches.value(trigger.switch);
|
|
if (flag === false) {
|
|
// 制御スイッチがOFF
|
|
return;
|
|
}
|
|
|
|
if (Input.isTriggered(key)) {
|
|
PluginUtils.fireCommonEvent(trigger.event);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
})();
|