Replace DualEnum with normal enum

This commit is contained in:
redphx 2024-05-01 21:36:17 +07:00
parent 7883949b94
commit 006e21f477
2 changed files with 41 additions and 38 deletions

View File

@ -1,32 +1,34 @@
import type { GamepadKeyNameType } from "../../types/mkb"; import type { GamepadKeyNameType } from "../../types/mkb";
export const GamepadKey: DualEnum = {}; export enum GamepadKey {
GamepadKey[GamepadKey.A = 0] = 'A'; A = 0,
GamepadKey[GamepadKey.B = 1] = 'B'; B = 1,
GamepadKey[GamepadKey.X = 2] = 'X'; X = 2,
GamepadKey[GamepadKey.Y = 3] = 'Y'; Y = 3,
GamepadKey[GamepadKey.LB = 4] = 'LB'; LB = 4,
GamepadKey[GamepadKey.RB = 5] = 'RB'; RB = 5,
GamepadKey[GamepadKey.LT = 6] = 'LT'; LT = 6,
GamepadKey[GamepadKey.RT = 7] = 'RT'; RT = 7,
GamepadKey[GamepadKey.SELECT = 8] = 'SELECT'; SELECT = 8,
GamepadKey[GamepadKey.START = 9] = 'START'; START = 9,
GamepadKey[GamepadKey.L3 = 10] = 'L3'; L3 = 10,
GamepadKey[GamepadKey.R3 = 11] = 'R3'; R3 = 11,
GamepadKey[GamepadKey.UP = 12] = 'UP'; UP = 12,
GamepadKey[GamepadKey.DOWN = 13] = 'DOWN'; DOWN = 13,
GamepadKey[GamepadKey.LEFT = 14] = 'LEFT'; LEFT = 14,
GamepadKey[GamepadKey.RIGHT = 15] = 'RIGHT'; RIGHT = 15,
GamepadKey[GamepadKey.HOME = 16] = 'HOME'; HOME = 16,
GamepadKey[GamepadKey.LS_UP = 100] = 'LS_UP'; LS_UP = 100,
GamepadKey[GamepadKey.LS_DOWN = 101] = 'LS_DOWN'; LS_DOWN = 101,
GamepadKey[GamepadKey.LS_LEFT = 102] = 'LS_LEFT'; LS_LEFT = 102,
GamepadKey[GamepadKey.LS_RIGHT = 103] = 'LS_RIGHT'; LS_RIGHT = 103,
GamepadKey[GamepadKey.RS_UP = 200] = 'RS_UP';
GamepadKey[GamepadKey.RS_DOWN = 201] = 'RS_DOWN'; RS_UP = 200,
GamepadKey[GamepadKey.RS_LEFT = 202] = 'RS_LEFT'; RS_DOWN = 201,
GamepadKey[GamepadKey.RS_RIGHT = 203] = 'RS_RIGHT'; RS_LEFT = 202,
RS_RIGHT = 203,
};
export const GamepadKeyName: GamepadKeyNameType = { export const GamepadKeyName: GamepadKeyNameType = {
@ -74,10 +76,11 @@ export enum MouseButtonCode {
MIDDLE_CLICK = 'Mouse1', MIDDLE_CLICK = 'Mouse1',
}; };
export const MouseMapTo: DualEnum = {}; export enum MouseMapTo {
MouseMapTo[MouseMapTo.OFF = 0] = 'OFF'; OFF = 0,
MouseMapTo[MouseMapTo.LS = 1] = 'LS'; LS = 1,
MouseMapTo[MouseMapTo.RS = 2] = 'RS'; RS = 2,
}
export enum WheelCode { export enum WheelCode {

View File

@ -64,11 +64,11 @@ export class MkbHandler {
#$message?: HTMLElement; #$message?: HTMLElement;
#STICK_MAP: {[index: keyof typeof GamepadKey]: (number | number[])[]}; #STICK_MAP: {[key in GamepadKey]?: [GamepadKey[], number, number]};
#LEFT_STICK_X: number[] = []; #LEFT_STICK_X: GamepadKey[] = [];
#LEFT_STICK_Y: number[] = []; #LEFT_STICK_Y: GamepadKey[] = [];
#RIGHT_STICK_X: number[] = []; #RIGHT_STICK_X: GamepadKey[] = [];
#RIGHT_STICK_Y: number[] = []; #RIGHT_STICK_Y: GamepadKey[] = [];
constructor() { constructor() {
this.#STICK_MAP = { this.#STICK_MAP = {
@ -128,11 +128,11 @@ export class MkbHandler {
gamepad.timestamp = performance.now(); gamepad.timestamp = performance.now();
} }
#pressButton = (buttonIndex: number, pressed: boolean) => { #pressButton = (buttonIndex: GamepadKey, pressed: boolean) => {
const virtualGamepad = this.#getVirtualGamepad(); const virtualGamepad = this.#getVirtualGamepad();
if (buttonIndex >= 100) { if (buttonIndex >= 100) {
let [valueArr, axisIndex] = this.#STICK_MAP[buttonIndex]; let [valueArr, axisIndex] = this.#STICK_MAP[buttonIndex]!;
valueArr = valueArr as number[]; valueArr = valueArr as number[];
axisIndex = axisIndex as number; axisIndex = axisIndex as number;
@ -148,7 +148,7 @@ export class MkbHandler {
let value; let value;
if (valueArr.length) { if (valueArr.length) {
// Get value of the last key of the axis // Get value of the last key of the axis
value = this.#STICK_MAP[valueArr[valueArr.length - 1]][2] as number; value = this.#STICK_MAP[valueArr[valueArr.length - 1]]![2] as number;
} else { } else {
value = 0; value = 0;
} }