mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-08 01:12:17 +02:00
added return type for inputs-controller
This commit is contained in:
parent
a84f9f89bf
commit
4526683c5a
@ -7,6 +7,19 @@ import pad_xbox360 from "./configs/pad_xbox360";
|
|||||||
import pad_dualshock from "./configs/pad_dualshock";
|
import pad_dualshock from "./configs/pad_dualshock";
|
||||||
import {Button} from "./enums/buttons";
|
import {Button} from "./enums/buttons";
|
||||||
|
|
||||||
|
export interface GamepadMapping {
|
||||||
|
[key: string]: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GamepadConfig {
|
||||||
|
padID: string;
|
||||||
|
padType: string;
|
||||||
|
gamepadMapping: GamepadMapping;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ActionGamepadMapping {
|
||||||
|
[key: string]: Button;
|
||||||
|
}
|
||||||
|
|
||||||
const repeatInputDelayMillis = 250;
|
const repeatInputDelayMillis = 250;
|
||||||
|
|
||||||
@ -20,6 +33,7 @@ export class InputsController {
|
|||||||
private buttonLock: Button;
|
private buttonLock: Button;
|
||||||
private interactions: Map<Button, Map<string, boolean>> = new Map();
|
private interactions: Map<Button, Map<string, boolean>> = new Map();
|
||||||
private time: Time;
|
private time: Time;
|
||||||
|
private player: Map<String, GamepadMapping> = new Map();
|
||||||
|
|
||||||
constructor(scene: Phaser.Scene) {
|
constructor(scene: Phaser.Scene) {
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
@ -38,7 +52,7 @@ export class InputsController {
|
|||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {
|
init(): void {
|
||||||
this.events = new Phaser.Events.EventEmitter();
|
this.events = new Phaser.Events.EventEmitter();
|
||||||
|
|
||||||
if (typeof this.scene.input.gamepad !== 'undefined') {
|
if (typeof this.scene.input.gamepad !== 'undefined') {
|
||||||
@ -64,7 +78,7 @@ export class InputsController {
|
|||||||
this.setupKeyboardControls();
|
this.setupKeyboardControls();
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update(): void {
|
||||||
for (const b of Utils.getEnumValues(Button)) {
|
for (const b of Utils.getEnumValues(Button)) {
|
||||||
if (!this.interactions.hasOwnProperty(b)) continue;
|
if (!this.interactions.hasOwnProperty(b)) continue;
|
||||||
if (this.repeatInputDurationJustPassed(b)) {
|
if (this.repeatInputDurationJustPassed(b)) {
|
||||||
@ -77,12 +91,10 @@ export class InputsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupGamepad(thisGamepad): void {
|
setupGamepad(thisGamepad: Phaser.Input.Gamepad.Gamepad): void {
|
||||||
let gamepadID = thisGamepad.id.toLowerCase();
|
let gamepadID = thisGamepad.id.toLowerCase();
|
||||||
const mappedPad = this.mapGamepad(gamepadID);
|
const mappedPad = this.mapGamepad(gamepadID);
|
||||||
this.player = {
|
this.player['mapping'] = mappedPad.gamepadMapping;
|
||||||
'mapping': mappedPad.gamepadMapping,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshGamepads(): void {
|
refreshGamepads(): void {
|
||||||
@ -96,7 +108,7 @@ export class InputsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getActionGamepadMapping() {
|
getActionGamepadMapping(): ActionGamepadMapping {
|
||||||
const gamepadMapping = {};
|
const gamepadMapping = {};
|
||||||
gamepadMapping[this.player.mapping.LC_N] = Button.UP;
|
gamepadMapping[this.player.mapping.LC_N] = Button.UP;
|
||||||
gamepadMapping[this.player.mapping.LC_S] = Button.DOWN;
|
gamepadMapping[this.player.mapping.LC_S] = Button.DOWN;
|
||||||
@ -119,7 +131,7 @@ export class InputsController {
|
|||||||
return gamepadMapping;
|
return gamepadMapping;
|
||||||
}
|
}
|
||||||
|
|
||||||
gamepadButtonDown(pad, button, value): void {
|
gamepadButtonDown(pad: Phaser.Input.Gamepad.Gamepad, button: Phaser.Input.Gamepad.Button, value: number): void {
|
||||||
const actionMapping = this.getActionGamepadMapping();
|
const actionMapping = this.getActionGamepadMapping();
|
||||||
const buttonDown = actionMapping.hasOwnProperty(button.index) && actionMapping[button.index];
|
const buttonDown = actionMapping.hasOwnProperty(button.index) && actionMapping[button.index];
|
||||||
if (buttonDown !== undefined) {
|
if (buttonDown !== undefined) {
|
||||||
@ -131,7 +143,7 @@ export class InputsController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gamepadButtonUp(pad, button, value): void {
|
gamepadButtonUp(pad: Phaser.Input.Gamepad.Gamepad, button: Phaser.Input.Gamepad.Button, value: number): void {
|
||||||
const actionMapping = this.getActionGamepadMapping();
|
const actionMapping = this.getActionGamepadMapping();
|
||||||
const buttonUp = actionMapping.hasOwnProperty(button.index) && actionMapping[button.index];
|
const buttonUp = actionMapping.hasOwnProperty(button.index) && actionMapping[button.index];
|
||||||
if (buttonUp !== undefined) {
|
if (buttonUp !== undefined) {
|
||||||
@ -200,19 +212,18 @@ export class InputsController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
mapGamepad(id) {
|
mapGamepad(id: string): GamepadConfig {
|
||||||
id = id.toLowerCase();
|
id = id.toLowerCase();
|
||||||
let padConfig = pad_generic;
|
|
||||||
|
|
||||||
if (id.includes('081f') && id.includes('e401')) {
|
if (id.includes('081f') && id.includes('e401')) {
|
||||||
padConfig = pad_unlicensedSNES;
|
return pad_unlicensedSNES;
|
||||||
} else if (id.includes('xbox') && id.includes('360')) {
|
} else if (id.includes('xbox') && id.includes('360')) {
|
||||||
padConfig = pad_xbox360;
|
return pad_xbox360;
|
||||||
} else if (id.includes('054c')) {
|
} else if (id.includes('054c')) {
|
||||||
padConfig = pad_dualshock;
|
return pad_dualshock;
|
||||||
}
|
}
|
||||||
|
|
||||||
return padConfig;
|
return pad_generic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user