Fix Errors in inputs-controller.ts (#1523)
This commit is contained in:
parent
47d39388ac
commit
d34e0dd2c6
|
@ -1,4 +1,4 @@
|
|||
import Phaser, {Time} from "phaser";
|
||||
import Phaser from "phaser";
|
||||
import * as Utils from "./utils";
|
||||
import {initTouchControls} from "./touch-controls";
|
||||
import pad_generic from "./configs/pad_generic";
|
||||
|
@ -6,6 +6,7 @@ import pad_unlicensedSNES from "./configs/pad_unlicensedSNES";
|
|||
import pad_xbox360 from "./configs/pad_xbox360";
|
||||
import pad_dualshock from "./configs/pad_dualshock";
|
||||
import {Button} from "./enums/buttons";
|
||||
import BattleScene from "./battle-scene";
|
||||
|
||||
export interface GamepadMapping {
|
||||
[key: string]: number;
|
||||
|
@ -47,16 +48,17 @@ const repeatInputDelayMillis = 250;
|
|||
*/
|
||||
export class InputsController {
|
||||
private buttonKeys: Phaser.Input.Keyboard.Key[][];
|
||||
private gamepads: Array<string> = new Array();
|
||||
private scene: Phaser.Scene;
|
||||
private gamepads: Phaser.Input.Gamepad.Gamepad[] = new Array();
|
||||
private scene: BattleScene;
|
||||
|
||||
private buttonLock: Button;
|
||||
private buttonLock2: Button;
|
||||
private interactions: Map<Button, Map<string, boolean>> = new Map();
|
||||
private time: Time;
|
||||
private player: Map<String, GamepadMapping> = new Map();
|
||||
private time: Phaser.Time.Clock;
|
||||
private player: GamepadMapping;
|
||||
|
||||
private gamepadSupport: boolean = true;
|
||||
public events: Phaser.Events.EventEmitter;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of the game control system, setting up initial state and configurations.
|
||||
|
@ -69,7 +71,7 @@ export class InputsController {
|
|||
* Specific buttons like MENU and STATS are set not to repeat their actions.
|
||||
* It concludes by calling the `init` method to complete the setup.
|
||||
*/
|
||||
constructor(scene: Phaser.Scene) {
|
||||
constructor(scene: BattleScene) {
|
||||
this.scene = scene;
|
||||
this.time = this.scene.time;
|
||||
this.buttonKeys = [];
|
||||
|
@ -108,7 +110,6 @@ export class InputsController {
|
|||
}, this);
|
||||
|
||||
// Check to see if the gamepad has already been setup by the browser
|
||||
this.scene.input.gamepad.refreshPads();
|
||||
if (this.scene.input.gamepad.total) {
|
||||
this.refreshGamepads();
|
||||
for (const thisGamepad of this.gamepads) {
|
||||
|
@ -201,7 +202,7 @@ export class InputsController {
|
|||
setupGamepad(thisGamepad: Phaser.Input.Gamepad.Gamepad): void {
|
||||
const gamepadID = thisGamepad.id.toLowerCase();
|
||||
const mappedPad = this.mapGamepad(gamepadID);
|
||||
this.player["mapping"] = mappedPad.gamepadMapping;
|
||||
this.player = mappedPad.gamepadMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -236,26 +237,26 @@ export class InputsController {
|
|||
*/
|
||||
getActionGamepadMapping(): ActionGamepadMapping {
|
||||
const gamepadMapping = {};
|
||||
if (!this.player?.mapping) {
|
||||
if (!this?.player) {
|
||||
return gamepadMapping;
|
||||
}
|
||||
gamepadMapping[this.player.mapping.LC_N] = Button.UP;
|
||||
gamepadMapping[this.player.mapping.LC_S] = Button.DOWN;
|
||||
gamepadMapping[this.player.mapping.LC_W] = Button.LEFT;
|
||||
gamepadMapping[this.player.mapping.LC_E] = Button.RIGHT;
|
||||
gamepadMapping[this.player.mapping.TOUCH] = Button.SUBMIT;
|
||||
gamepadMapping[this.player.mapping.RC_S] = this.scene.abSwapped ? Button.CANCEL : Button.ACTION;
|
||||
gamepadMapping[this.player.mapping.RC_E] = this.scene.abSwapped ? Button.ACTION : Button.CANCEL;
|
||||
gamepadMapping[this.player.mapping.SELECT] = Button.STATS;
|
||||
gamepadMapping[this.player.mapping.START] = Button.MENU;
|
||||
gamepadMapping[this.player.mapping.RB] = Button.CYCLE_SHINY;
|
||||
gamepadMapping[this.player.mapping.LB] = Button.CYCLE_FORM;
|
||||
gamepadMapping[this.player.mapping.LT] = Button.CYCLE_GENDER;
|
||||
gamepadMapping[this.player.mapping.RT] = Button.CYCLE_ABILITY;
|
||||
gamepadMapping[this.player.mapping.RC_W] = Button.CYCLE_NATURE;
|
||||
gamepadMapping[this.player.mapping.RC_N] = Button.CYCLE_VARIANT;
|
||||
gamepadMapping[this.player.mapping.LS] = Button.SPEED_UP;
|
||||
gamepadMapping[this.player.mapping.RS] = Button.SLOW_DOWN;
|
||||
gamepadMapping[this.player.LC_N] = Button.UP;
|
||||
gamepadMapping[this.player.LC_S] = Button.DOWN;
|
||||
gamepadMapping[this.player.LC_W] = Button.LEFT;
|
||||
gamepadMapping[this.player.LC_E] = Button.RIGHT;
|
||||
gamepadMapping[this.player.TOUCH] = Button.SUBMIT;
|
||||
gamepadMapping[this.player.RC_S] = this.scene.abSwapped ? Button.CANCEL : Button.ACTION;
|
||||
gamepadMapping[this.player.RC_E] = this.scene.abSwapped ? Button.ACTION : Button.CANCEL;
|
||||
gamepadMapping[this.player.SELECT] = Button.STATS;
|
||||
gamepadMapping[this.player.START] = Button.MENU;
|
||||
gamepadMapping[this.player.RB] = Button.CYCLE_SHINY;
|
||||
gamepadMapping[this.player.LB] = Button.CYCLE_FORM;
|
||||
gamepadMapping[this.player.LT] = Button.CYCLE_GENDER;
|
||||
gamepadMapping[this.player.RT] = Button.CYCLE_ABILITY;
|
||||
gamepadMapping[this.player.RC_W] = Button.CYCLE_NATURE;
|
||||
gamepadMapping[this.player.RC_N] = Button.CYCLE_VARIANT;
|
||||
gamepadMapping[this.player.LS] = Button.SPEED_UP;
|
||||
gamepadMapping[this.player.RS] = Button.SLOW_DOWN;
|
||||
|
||||
return gamepadMapping;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue