109 lines
3.2 KiB
JavaScript
109 lines
3.2 KiB
JavaScript
/*:
|
||
* @target MZ
|
||
* @plugindesc [究極安定版] スイッチ113がONのときマウスオーバー選択+左クリック決定(完全リセット対応)
|
||
* @author you
|
||
*
|
||
* @help
|
||
* ■ 概要
|
||
* バトル中のみ動作。
|
||
* スイッチ113がONの間、以下の挙動を行います。
|
||
*
|
||
* ・右半分(x >= 641)にマウスがある → 右キー入力中と同じ
|
||
* ・左半分(x <= 640)にマウスがある → 左キー入力中と同じ
|
||
* ・左クリック → 決定キー(OK)入力1フレーム+スイッチ113をOFF
|
||
*
|
||
* ■ 安定化仕様
|
||
* ・戦闘開始/終了の両方で全Input状態をリセット(左右残留防止)
|
||
* ・スイッチOFF時は完全停止
|
||
* ・再ONで再動作可能
|
||
*/
|
||
|
||
(() => {
|
||
const SWITCH_ID = 113;
|
||
const CENTER_X = 640;
|
||
let okTriggered = false;
|
||
let processing = false;
|
||
|
||
// 入力を完全リセット(全状態と履歴)
|
||
function resetAllInput() {
|
||
Input._currentState = {};
|
||
Input._previousState = {};
|
||
Input._latestButton = null;
|
||
Input._pressedTime = 0;
|
||
if (Input.clear) Input.clear();
|
||
}
|
||
|
||
// スイッチON&バトル中チェック
|
||
function isReady() {
|
||
return (
|
||
typeof $gameSwitches !== "undefined" &&
|
||
$gameSwitches &&
|
||
typeof $gameParty !== "undefined" &&
|
||
$gameParty &&
|
||
$gameParty.inBattle &&
|
||
$gameParty.inBattle() &&
|
||
$gameSwitches.value(SWITCH_ID)
|
||
);
|
||
}
|
||
|
||
// メイン更新
|
||
const _updateMain = SceneManager.updateMain;
|
||
SceneManager.updateMain = function() {
|
||
_updateMain.call(this);
|
||
|
||
if (!isReady()) {
|
||
processing = false;
|
||
return;
|
||
}
|
||
|
||
if (processing) return;
|
||
processing = true;
|
||
|
||
const x = TouchInput.x;
|
||
Input._currentState.left = false;
|
||
Input._currentState.right = false;
|
||
|
||
if (x >= CENTER_X + 1) {
|
||
Input._currentState.right = true;
|
||
} else if (x <= CENTER_X) {
|
||
Input._currentState.left = true;
|
||
}
|
||
|
||
if (TouchInput.isTriggered() && !TouchInput.isCancelled()) {
|
||
okTriggered = true;
|
||
}
|
||
};
|
||
|
||
// OK入力とOFF処理
|
||
const _Input_update = Input.update;
|
||
Input.update = function() {
|
||
_Input_update.call(this);
|
||
if (okTriggered) {
|
||
this._currentState.ok = true;
|
||
okTriggered = false;
|
||
|
||
setTimeout(() => {
|
||
this._currentState.ok = false;
|
||
if ($gameSwitches) $gameSwitches.setValue(SWITCH_ID, false);
|
||
processing = false;
|
||
}, 16);
|
||
}
|
||
};
|
||
|
||
// 🧩【追加】戦闘開始時にも全入力を初期化
|
||
const _BattleManager_setup = BattleManager.setup;
|
||
BattleManager.setup = function(troopId, canEscape, canLose) {
|
||
resetAllInput(); // ← 戦闘に入る瞬間にリセット
|
||
_BattleManager_setup.call(this, troopId, canEscape, canLose);
|
||
};
|
||
|
||
// 🧩【追加】戦闘終了時にも全入力を初期化
|
||
const _BattleManager_endBattle = BattleManager.endBattle;
|
||
BattleManager.endBattle = function(result) {
|
||
_BattleManager_endBattle.call(this, result);
|
||
setTimeout(() => {
|
||
resetAllInput(); // ← 1フレーム後に完全クリア
|
||
processing = false;
|
||
}, 16);
|
||
};
|
||
})();
|