cleaned up a bit the code + added some more config
parent
931ec61f87
commit
cffcf9afd0
|
@ -48,6 +48,17 @@ const pad_dualshock = {
|
||||||
setting: {
|
setting: {
|
||||||
RC_S: SettingGamepad.Button_Action,
|
RC_S: SettingGamepad.Button_Action,
|
||||||
RC_E: SettingGamepad.Button_Cancel,
|
RC_E: SettingGamepad.Button_Cancel,
|
||||||
|
RC_W: SettingGamepad.Button_Cycle_Nature,
|
||||||
|
RC_N: SettingGamepad.Button_Cycle_Variant,
|
||||||
|
START: SettingGamepad.Button_Menu,
|
||||||
|
SELECT: SettingGamepad.Button_Stats,
|
||||||
|
LB: SettingGamepad.Button_Cycle_Form,
|
||||||
|
RB: SettingGamepad.Button_Cycle_Shiny,
|
||||||
|
LT: SettingGamepad.Button_Cycle_Gender,
|
||||||
|
RT: SettingGamepad.Button_Cycle_Ability,
|
||||||
|
LS: SettingGamepad.Button_Speed_Up,
|
||||||
|
RS: SettingGamepad.Button_Slow_Down,
|
||||||
|
TOUCH: SettingGamepad.Button_Submit,
|
||||||
},
|
},
|
||||||
default: {
|
default: {
|
||||||
RC_S: Button.ACTION,
|
RC_S: Button.ACTION,
|
||||||
|
|
|
@ -42,11 +42,20 @@ const pad_generic = {
|
||||||
LC_S: "T_X_Dpad_Down_Alt.png",
|
LC_S: "T_X_Dpad_Down_Alt.png",
|
||||||
LC_W: "T_X_Dpad_Left_Alt.png",
|
LC_W: "T_X_Dpad_Left_Alt.png",
|
||||||
LC_E: "T_X_Dpad_Right_Alt.png",
|
LC_E: "T_X_Dpad_Right_Alt.png",
|
||||||
MENU: ""
|
|
||||||
},
|
},
|
||||||
setting: {
|
setting: {
|
||||||
RC_S: SettingGamepad.Button_Action,
|
RC_S: SettingGamepad.Button_Action,
|
||||||
RC_E: SettingGamepad.Button_Cancel,
|
RC_E: SettingGamepad.Button_Cancel,
|
||||||
|
RC_W: SettingGamepad.Button_Cycle_Nature,
|
||||||
|
RC_N: SettingGamepad.Button_Cycle_Variant,
|
||||||
|
START: SettingGamepad.Button_Menu,
|
||||||
|
SELECT: SettingGamepad.Button_Stats,
|
||||||
|
LB: SettingGamepad.Button_Cycle_Form,
|
||||||
|
RB: SettingGamepad.Button_Cycle_Shiny,
|
||||||
|
LT: SettingGamepad.Button_Cycle_Gender,
|
||||||
|
RT: SettingGamepad.Button_Cycle_Ability,
|
||||||
|
LS: SettingGamepad.Button_Speed_Up,
|
||||||
|
RS: SettingGamepad.Button_Slow_Down,
|
||||||
},
|
},
|
||||||
default: {
|
default: {
|
||||||
RC_S: Button.ACTION,
|
RC_S: Button.ACTION,
|
||||||
|
@ -65,7 +74,6 @@ const pad_generic = {
|
||||||
LC_S: Button.DOWN,
|
LC_S: Button.DOWN,
|
||||||
LC_W: Button.LEFT,
|
LC_W: Button.LEFT,
|
||||||
LC_E: Button.RIGHT,
|
LC_E: Button.RIGHT,
|
||||||
TOUCH: Button.SUBMIT,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,12 @@ const pad_unlicensedSNES = {
|
||||||
setting: {
|
setting: {
|
||||||
RC_S: SettingGamepad.Button_Action,
|
RC_S: SettingGamepad.Button_Action,
|
||||||
RC_E: SettingGamepad.Button_Cancel,
|
RC_E: SettingGamepad.Button_Cancel,
|
||||||
|
RC_W: SettingGamepad.Button_Cycle_Nature,
|
||||||
|
RC_N: SettingGamepad.Button_Cycle_Variant,
|
||||||
|
START: SettingGamepad.Button_Menu,
|
||||||
|
SELECT: SettingGamepad.Button_Stats,
|
||||||
|
LB: SettingGamepad.Button_Cycle_Form,
|
||||||
|
RB: SettingGamepad.Button_Cycle_Shiny,
|
||||||
},
|
},
|
||||||
default: {
|
default: {
|
||||||
RC_S: Button.ACTION,
|
RC_S: Button.ACTION,
|
||||||
|
@ -52,7 +58,6 @@ const pad_unlicensedSNES = {
|
||||||
LC_S: Button.DOWN,
|
LC_S: Button.DOWN,
|
||||||
LC_W: Button.LEFT,
|
LC_W: Button.LEFT,
|
||||||
LC_E: Button.RIGHT,
|
LC_E: Button.RIGHT,
|
||||||
TOUCH: Button.SUBMIT,
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import Phaser, {Time} from "phaser";
|
|
||||||
import * as Utils from "./utils";
|
import * as Utils from "./utils";
|
||||||
import {initTouchControls} from './touch-controls';
|
import {initTouchControls} from './touch-controls';
|
||||||
import pad_generic from "./configs/pad_generic";
|
import pad_generic from "./configs/pad_generic";
|
||||||
|
@ -65,13 +64,14 @@ const repeatInputDelayMillis = 250;
|
||||||
*/
|
*/
|
||||||
export class InputsController {
|
export class InputsController {
|
||||||
private buttonKeys: Phaser.Input.Keyboard.Key[][];
|
private buttonKeys: Phaser.Input.Keyboard.Key[][];
|
||||||
private gamepads: Array<string> = new Array();
|
private gamepads: Array<Phaser.Input.Gamepad.Gamepad> = new Array();
|
||||||
private scene: Phaser.Scene;
|
private scene: Phaser.Scene;
|
||||||
|
private events: Phaser.Events.EventEmitter;
|
||||||
|
|
||||||
private buttonLock: Button;
|
private buttonLock: Button;
|
||||||
private buttonLock2: Button;
|
private buttonLock2: Button;
|
||||||
private interactions: Map<Button, Map<string, boolean>> = new Map();
|
private interactions: Map<Button, Map<string, boolean>> = new Map();
|
||||||
private time: Time;
|
private time: Phaser.Time.Clock;
|
||||||
private player;
|
private player;
|
||||||
|
|
||||||
private gamepadSupport: boolean = true;
|
private gamepadSupport: boolean = true;
|
||||||
|
@ -118,7 +118,7 @@ export class InputsController {
|
||||||
* Additionally, it manages the game's behavior when it loses focus to prevent unwanted game actions during this state.
|
* Additionally, it manages the game's behavior when it loses focus to prevent unwanted game actions during this state.
|
||||||
*/
|
*/
|
||||||
init(): void {
|
init(): void {
|
||||||
this.events = new Phaser.Events.EventEmitter();
|
this.events = this.scene.game.events;
|
||||||
|
|
||||||
if (localStorage.hasOwnProperty('chosenGamepad')) {
|
if (localStorage.hasOwnProperty('chosenGamepad')) {
|
||||||
this.chosenGamepad = localStorage.getItem('chosenGamepad');
|
this.chosenGamepad = localStorage.getItem('chosenGamepad');
|
||||||
|
@ -206,16 +206,16 @@ export class InputsController {
|
||||||
for (const b of Utils.getEnumValues(Button).reverse()) {
|
for (const b of Utils.getEnumValues(Button).reverse()) {
|
||||||
if (
|
if (
|
||||||
this.interactions.hasOwnProperty(b) &&
|
this.interactions.hasOwnProperty(b) &&
|
||||||
this.repeatInputDurationJustPassed(b) &&
|
this.repeatInputDurationJustPassed(b as Button) &&
|
||||||
this.interactions[b].isPressed
|
this.interactions[b].isPressed
|
||||||
) {
|
) {
|
||||||
// Prevents repeating button interactions when gamepad support is disabled.
|
// Prevents repeating button interactions when gamepad support is disabled.
|
||||||
if (
|
if (
|
||||||
(!this.gamepadSupport && this.interactions[b].source === 'gamepad') ||
|
(!this.gamepadSupport && this.interactions[b].source === 'gamepad') ||
|
||||||
(this.interactions[b].sourceName !== null && this.interactions[b].sourceName !== this.chosenGamepad)
|
(this.interactions[b].sourceName && this.interactions[b].sourceName !== this.chosenGamepad)
|
||||||
) {
|
) {
|
||||||
// Deletes the last interaction for a button if gamepad is disabled.
|
// Deletes the last interaction for a button if gamepad is disabled.
|
||||||
this.delLastProcessedMovementTime(b);
|
this.delLastProcessedMovementTime(b as Button);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Emits an event for the button press.
|
// Emits an event for the button press.
|
||||||
|
@ -223,7 +223,7 @@ export class InputsController {
|
||||||
controller_type: this.interactions[b].source,
|
controller_type: this.interactions[b].source,
|
||||||
button: b,
|
button: b,
|
||||||
});
|
});
|
||||||
this.setLastProcessedMovementTime(b, this.interactions[b].source, this.interactions[b].sourceName);
|
this.setLastProcessedMovementTime(b as Button, this.interactions[b].source, this.interactions[b].sourceName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -572,7 +572,7 @@ export class InputsController {
|
||||||
*
|
*
|
||||||
* Additionally, this method locks the button (by calling `setButtonLock`) to prevent it from being re-processed until it is released, ensuring that each press is handled distinctly.
|
* Additionally, this method locks the button (by calling `setButtonLock`) to prevent it from being re-processed until it is released, ensuring that each press is handled distinctly.
|
||||||
*/
|
*/
|
||||||
setLastProcessedMovementTime(button: Button, source: String = 'keyboard', sourceName: String): void {
|
setLastProcessedMovementTime(button: Button, source: String = 'keyboard', sourceName?: String): void {
|
||||||
if (!this.interactions.hasOwnProperty(button)) return;
|
if (!this.interactions.hasOwnProperty(button)) return;
|
||||||
this.setButtonLock(button);
|
this.setButtonLock(button);
|
||||||
this.interactions[button].pressTime = this.time.now;
|
this.interactions[button].pressTime = this.time.now;
|
||||||
|
|
|
@ -21,6 +21,7 @@ export enum SettingGamepad {
|
||||||
Button_Cycle_Variant = "BUTTON_CYCLE_VARIANT",
|
Button_Cycle_Variant = "BUTTON_CYCLE_VARIANT",
|
||||||
Button_Speed_Up = "BUTTON_SPEED_UP",
|
Button_Speed_Up = "BUTTON_SPEED_UP",
|
||||||
Button_Slow_Down = "BUTTON_SLOW_DOWN",
|
Button_Slow_Down = "BUTTON_SLOW_DOWN",
|
||||||
|
Button_Submit = "BUTTON_SUBMIT",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const settingGamepadOptions: SettingOptions = {
|
export const settingGamepadOptions: SettingOptions = {
|
||||||
|
@ -38,7 +39,8 @@ export const settingGamepadOptions: SettingOptions = {
|
||||||
[SettingGamepad.Button_Cycle_Nature]: [`KEY ${Button.CYCLE_NATURE.toString()}`, 'Change'],
|
[SettingGamepad.Button_Cycle_Nature]: [`KEY ${Button.CYCLE_NATURE.toString()}`, 'Change'],
|
||||||
[SettingGamepad.Button_Cycle_Variant]: [`KEY ${Button.CYCLE_VARIANT.toString()}`, 'Change'],
|
[SettingGamepad.Button_Cycle_Variant]: [`KEY ${Button.CYCLE_VARIANT.toString()}`, 'Change'],
|
||||||
[SettingGamepad.Button_Speed_Up]: [`KEY ${Button.SPEED_UP.toString()}`, 'Change'],
|
[SettingGamepad.Button_Speed_Up]: [`KEY ${Button.SPEED_UP.toString()}`, 'Change'],
|
||||||
[SettingGamepad.Button_Slow_Down]: [`KEY ${Button.SLOW_DOWN.toString()}`, 'Change']
|
[SettingGamepad.Button_Slow_Down]: [`KEY ${Button.SLOW_DOWN.toString()}`, 'Change'],
|
||||||
|
[SettingGamepad.Button_Submit]: [`KEY ${Button.SUBMIT.toString()}`, 'Change']
|
||||||
};
|
};
|
||||||
|
|
||||||
export const settingGamepadDefaults: SettingDefaults = {
|
export const settingGamepadDefaults: SettingDefaults = {
|
||||||
|
@ -57,6 +59,7 @@ export const settingGamepadDefaults: SettingDefaults = {
|
||||||
[SettingGamepad.Button_Cycle_Variant]: 0,
|
[SettingGamepad.Button_Cycle_Variant]: 0,
|
||||||
[SettingGamepad.Button_Speed_Up]: 0,
|
[SettingGamepad.Button_Speed_Up]: 0,
|
||||||
[SettingGamepad.Button_Slow_Down]: 0,
|
[SettingGamepad.Button_Slow_Down]: 0,
|
||||||
|
[SettingGamepad.Button_Submit]: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const noOptionsCursors: Array<SettingGamepad> = [
|
export const noOptionsCursors: Array<SettingGamepad> = [
|
||||||
|
@ -72,6 +75,7 @@ export const noOptionsCursors: Array<SettingGamepad> = [
|
||||||
SettingGamepad.Button_Cycle_Variant,
|
SettingGamepad.Button_Cycle_Variant,
|
||||||
SettingGamepad.Button_Speed_Up,
|
SettingGamepad.Button_Speed_Up,
|
||||||
SettingGamepad.Button_Slow_Down,
|
SettingGamepad.Button_Slow_Down,
|
||||||
|
SettingGamepad.Button_Submit,
|
||||||
];
|
];
|
||||||
|
|
||||||
export function setSettingGamepad(scene: BattleScene, setting: SettingGamepad, value: integer): boolean {
|
export function setSettingGamepad(scene: BattleScene, setting: SettingGamepad, value: integer): boolean {
|
||||||
|
|
Loading…
Reference in New Issue