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/*
|
| 4 |
+
These are the gamepad keys that MV has available.
|
| 5 |
+
So, we're going to add the missing keys.
|
| 6 |
+
Input.gamepadMapper = {
|
| 7 |
+
0: 'ok', // A
|
| 8 |
+
1: 'cancel', // B
|
| 9 |
+
2: 'shift', // X
|
| 10 |
+
3: 'menu', // Y
|
| 11 |
+
4: 'pageup', // LB
|
| 12 |
+
5: 'pagedown', // RB
|
| 13 |
+
12: 'up', // D-pad up
|
| 14 |
+
13: 'down', // D-pad down
|
| 15 |
+
14: 'left', // D-pad left
|
| 16 |
+
15: 'right', // D-pad right
|
| 17 |
+
};
|
| 18 |
+
|
| 19 |
+
To use them, simply determine how you want the button to be pressed.
|
| 20 |
+
Input.isTriggered('key') means the action will be done upon the button press.
|
| 21 |
+
Input.isPressed('key') means the action will be done until the botton is released.
|
| 22 |
+
Btw, I'm also putting here a small function to detect if a gamepad is connected and split the inputs :)
|
| 23 |
+
*/
|
| 24 |
+
function isGamepadConnected(index) {
|
| 25 |
+
if (navigator.getGamepads) {
|
| 26 |
+
var gamepads = navigator.getGamepads();
|
| 27 |
+
if (gamepads && gamepads[index]) {
|
| 28 |
+
var gamepad = gamepads[index];
|
| 29 |
+
return gamepad.connected;
|
| 30 |
+
}
|
| 31 |
+
}
|
| 32 |
+
return false;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
Input.gamepadMapper = {
|
| 36 |
+
//Gamepad 1
|
| 37 |
+
0: 'ok', // A
|
| 38 |
+
1: 'cancel', // B
|
| 39 |
+
2: 'shift', // X
|
| 40 |
+
3: 'menu', // Y
|
| 41 |
+
4: 'LB', // LB
|
| 42 |
+
5: 'RB', // RB
|
| 43 |
+
6: 'LT', // LT
|
| 44 |
+
7: 'RT', // RT
|
| 45 |
+
8: 'select', //Select (Generic)
|
| 46 |
+
9: 'start', //Select (Generic)
|
| 47 |
+
10: 'L3', //Left Stick Press
|
| 48 |
+
11: 'R3', //Right Stick Press
|
| 49 |
+
12: 'up', // D-pad up
|
| 50 |
+
13: 'down', // D-pad down
|
| 51 |
+
14: 'left', // D-pad left
|
| 52 |
+
15: 'right', // D-pad right
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
BattleManager.lmbsUpdateCommand = function() {
|
| 56 |
+
|
| 57 |
+
let inputMethod = "keyboard";
|
| 58 |
+
if (isGamepadConnected(0)) {
|
| 59 |
+
inputMethod = "gamepad";
|
| 60 |
+
}
|
| 61 |
+
else {
|
| 62 |
+
inputMethod = "keyboard";
|
| 63 |
+
}
|
| 64 |
+
//If anyone checks the code this might sound redundant but I don't want errors :3
|
| 65 |
+
|
| 66 |
+
if (inputMethod === "keyboard"){
|
| 67 |
+
if (Input.isTriggered(Moghunter.lmbsKeyMenu) && this.lmbsCanCallMenu()) {
|
| 68 |
+
$gameTemp._lmbsSelectPhase[0] = true;
|
| 69 |
+
$gameTemp._lmbsMenuPhase[0] = true;
|
| 70 |
+
SoundManager.playCursor();
|
| 71 |
+
return
|
| 72 |
+
};
|
| 73 |
+
if (Input.isPressed(Moghunter.lmbsKeyGuard)) {this._lmbsActor.lmbsGuard()};
|
| 74 |
+
if (Input.isTriggered(Moghunter.lmbsKeyAttack)) {this._lmbsActor.lmbsAttackAction()};
|
| 75 |
+
if (Input.isTriggered(Moghunter.lmbsKeySkill)) {this._lmbsActor.lmbsSkillActionActor()};
|
| 76 |
+
if (Input.isTriggered('up')) {
|
| 77 |
+
this._lmbsActor.lmbsJump();
|
| 78 |
+
} else if (Input.isPressed('down')) {
|
| 79 |
+
};
|
| 80 |
+
if (Input.isPressed('left')) {
|
| 81 |
+
this._lmbsActor.lmbsMove(2);
|
| 82 |
+
} else if (Input.isPressed('right')) {
|
| 83 |
+
this._lmbsActor.lmbsMove(3);
|
| 84 |
+
};
|
| 85 |
+
if (Input.isPressed(Moghunter.lmbsKeyDash)) {this._lmbsActor.lmbsUpdateDash()
|
| 86 |
+
} else {this._lmbsActor._lmbs_Dash[1] = false};
|
| 87 |
+
if (Input.isTriggered(Moghunter.lmbsKeyDash)) {this._lmbsActor.lmbsAirDash()};
|
| 88 |
+
if (Input.isTriggered(Moghunter.lmbsKeyPrev) && this.lmbsCanCallMenu()) {
|
| 89 |
+
var act = BattleManager._lmbsActor
|
| 90 |
+
BattleManager._lmbsActor = BattleManager.lmbsPrevTarget(-1,0,true);
|
| 91 |
+
$gameTemp._lmbsPlayerCursor[0] = $gameTemp._lmbsPlayerCursor[1];
|
| 92 |
+
SoundManager.playCursor();
|
| 93 |
+
if (act != BattleManager._lmbsActor) {this.lmbsPlayTurnVoice()};
|
| 94 |
+
} else if (Input.isTriggered(Moghunter.lmbsKeyNext) && this.lmbsCanCallMenu()) {
|
| 95 |
+
var act = BattleManager._lmbsActor
|
| 96 |
+
BattleManager._lmbsActor = BattleManager.lmbsNextTarget(1,0,true);
|
| 97 |
+
$gameTemp._lmbsPlayerCursor[0] = $gameTemp._lmbsPlayerCursor[1];
|
| 98 |
+
SoundManager.playCursor();
|
| 99 |
+
if (act != BattleManager._lmbsActor) {this.lmbsPlayTurnVoice()};
|
| 100 |
+
};
|
| 101 |
+
}else if(inputMethod === "gamepad"){
|
| 102 |
+
//Gamepad Inputs Start here. Just replace what's between the ''
|
| 103 |
+
if (Input.isTriggered('start') && this.lmbsCanCallMenu()) {
|
| 104 |
+
$gameTemp._lmbsSelectPhase[0] = true;
|
| 105 |
+
$gameTemp._lmbsMenuPhase[0] = true;
|
| 106 |
+
SoundManager.playCursor();
|
| 107 |
+
return
|
| 108 |
+
};
|
| 109 |
+
//Guard
|
| 110 |
+
if (Input.isPressed('cancel')) {this._lmbsActor.lmbsGuard()};
|
| 111 |
+
//Normal Attack
|
| 112 |
+
if (Input.isTriggered('ok')) {this._lmbsActor.lmbsAttackAction()};
|
| 113 |
+
//Skills
|
| 114 |
+
if (Input.isTriggered('RT')) {this._lmbsActor.lmbsSkillActionActor()};
|
| 115 |
+
//Movement
|
| 116 |
+
if (Input.isTriggered('up')) {
|
| 117 |
+
this._lmbsActor.lmbsJump();
|
| 118 |
+
} else if (Input.isPressed('down')) {
|
| 119 |
+
};
|
| 120 |
+
if (Input.isPressed('left')) {
|
| 121 |
+
this._lmbsActor.lmbsMove(2);
|
| 122 |
+
} else if (Input.isPressed('right')) {
|
| 123 |
+
this._lmbsActor.lmbsMove(3);
|
| 124 |
+
};
|
| 125 |
+
//Dash
|
| 126 |
+
if (Input.isPressed('shift')) {this._lmbsActor.lmbsUpdateDash()
|
| 127 |
+
} else {this._lmbsActor._lmbs_Dash[1] = false};
|
| 128 |
+
//AirDash
|
| 129 |
+
if (Input.isTriggered('shift')) {this._lmbsActor.lmbsAirDash()};
|
| 130 |
+
//Change Playable Character (Left)
|
| 131 |
+
if (Input.isTriggered('LB') && this.lmbsCanCallMenu()) {
|
| 132 |
+
var act = BattleManager._lmbsActor
|
| 133 |
+
BattleManager._lmbsActor = BattleManager.lmbsPrevTarget(-1,0,true);
|
| 134 |
+
$gameTemp._lmbsPlayerCursor[0] = $gameTemp._lmbsPlayerCursor[1];
|
| 135 |
+
SoundManager.playCursor();
|
| 136 |
+
if (act != BattleManager._lmbsActor) {this.lmbsPlayTurnVoice()};
|
| 137 |
+
//Change Playable Character (Right)
|
| 138 |
+
} else if (Input.isTriggered('RB') && this.lmbsCanCallMenu()) {
|
| 139 |
+
var act = BattleManager._lmbsActor
|
| 140 |
+
BattleManager._lmbsActor = BattleManager.lmbsNextTarget(1,0,true);
|
| 141 |
+
$gameTemp._lmbsPlayerCursor[0] = $gameTemp._lmbsPlayerCursor[1];
|
| 142 |
+
SoundManager.playCursor();
|
| 143 |
+
if (act != BattleManager._lmbsActor) {this.lmbsPlayTurnVoice()};
|
| 144 |
+
};
|
| 145 |
+
}
|
| 146 |
+
if (BattleManager._lmbsActor.lmbsIsEscaping()) {BattleManager._lmbsActor.lmbsUpdateEscape()};
|
| 147 |
+
|
| 148 |
+
};
|