game is using the custom config with keyboard
parent
e798f72a63
commit
769412e452
|
@ -9,7 +9,7 @@ export function getKeyFromInputIndex(config: InterfaceConfig, index: number): St
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
export function getKeyFromKeyboardKey(config: InterfaceConfig, key): String | null {
|
export function getKeyFromKeyboardKeyCode(config: InterfaceConfig, key): String | null {
|
||||||
for (const _key of Object.keys(config.gamepadMapping)) {
|
for (const _key of Object.keys(config.gamepadMapping)) {
|
||||||
if (config.gamepadMapping[_key] === key) return _key;
|
if (config.gamepadMapping[_key] === key) return _key;
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,8 @@ export function getCurrenlyAssignedIconFromInputIndex(config: InterfaceConfig, i
|
||||||
return config.icons[key];
|
return config.icons[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCurrenlyAssignedIconFromKeyboardKey(config: InterfaceConfig, key): String {
|
export function getCurrenlyAssignedIconFromKeyboardKeyCode(config: InterfaceConfig, key): String {
|
||||||
const _key = getKeyFromKeyboardKey(config, key);
|
const _key = getKeyFromKeyboardKeyCode(config, key);
|
||||||
return config.icons[_key];
|
return config.icons[_key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,12 @@ import {Mode} from "./ui/ui";
|
||||||
import SettingsGamepadUiHandler from "./ui/settings/settings-gamepad-ui-handler";
|
import SettingsGamepadUiHandler from "./ui/settings/settings-gamepad-ui-handler";
|
||||||
import {SettingGamepad} from "./system/settings-gamepad";
|
import {SettingGamepad} from "./system/settings-gamepad";
|
||||||
import {
|
import {
|
||||||
getCurrenlyAssignedIconFromInputIndex, getCurrentlyAssignedIconToSettingName,
|
getCurrenlyAssignedIconFromInputIndex,
|
||||||
getKeyFromInputIndex, getCurrentlyAssignedToSettingName, getCurrenlyAssignedIconFromKeyboardKey
|
getCurrentlyAssignedIconToSettingName,
|
||||||
|
getKeyFromInputIndex,
|
||||||
|
getCurrentlyAssignedToSettingName,
|
||||||
|
getCurrenlyAssignedIconFromKeyboardKeyCode,
|
||||||
|
getKeyFromKeyboardKeyCode
|
||||||
} from "./configs/gamepad-utils";
|
} from "./configs/gamepad-utils";
|
||||||
import SettingsKeyboardUiHandler from "./ui/settings/settings-keyboard-ui-handler";
|
import SettingsKeyboardUiHandler from "./ui/settings/settings-keyboard-ui-handler";
|
||||||
import cfg_keyboard_azerty from "./configs/cfg_keyboard_azerty";
|
import cfg_keyboard_azerty from "./configs/cfg_keyboard_azerty";
|
||||||
|
@ -88,6 +92,7 @@ export class InputsController {
|
||||||
private pauseUpdate: boolean = false;
|
private pauseUpdate: boolean = false;
|
||||||
|
|
||||||
public lastSource: string = 'keyboard';
|
public lastSource: string = 'keyboard';
|
||||||
|
private keys: Array<number> = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new instance of the game control system, setting up initial state and configurations.
|
* Initializes a new instance of the game control system, setting up initial state and configurations.
|
||||||
|
@ -163,7 +168,7 @@ export class InputsController {
|
||||||
this.scene.input.keyboard.on('keyup', this.keyboardKeyUp, this);
|
this.scene.input.keyboard.on('keyup', this.keyboardKeyUp, this);
|
||||||
}
|
}
|
||||||
// Keyboard
|
// Keyboard
|
||||||
this.setupKeyboardControls();
|
// this.setupKeyboardControls();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -231,7 +236,8 @@ export class InputsController {
|
||||||
// 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 && this.interactions[b].sourceName !== this.chosenGamepad) ||
|
(this.interactions[b].source === 'gamepad' && this.interactions[b].sourceName && this.interactions[b].sourceName !== this.chosenGamepad) ||
|
||||||
|
(this.interactions[b].source === 'keyboard' && this.interactions[b].sourceName && this.interactions[b].sourceName !== this.chosenKeyboard) ||
|
||||||
this.pauseUpdate
|
this.pauseUpdate
|
||||||
) {
|
) {
|
||||||
// Deletes the last interaction for a button if gamepad is disabled.
|
// Deletes the last interaction for a button if gamepad is disabled.
|
||||||
|
@ -372,14 +378,37 @@ export class InputsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
keyboardKeyDown(event): void {
|
keyboardKeyDown(event): void {
|
||||||
const keyDown = event.key;
|
const keyDown = event.keyCode;
|
||||||
const keyCode = event.keyCode
|
|
||||||
if (!this.keyboardConfigs[this.chosenKeyboard]?.padID)
|
if (!this.keyboardConfigs[this.chosenKeyboard]?.padID)
|
||||||
this.setupKeyboard();
|
this.setupKeyboard();
|
||||||
|
if (this.keys.includes(keyDown)) return;
|
||||||
|
this.keys.push(keyDown);
|
||||||
|
const key = getKeyFromKeyboardKeyCode(this.keyboardConfigs[this.chosenKeyboard], keyDown);
|
||||||
|
const buttonDown = this.keyboardConfigs[this.chosenKeyboard].custom[key];
|
||||||
|
this.lastSource = 'keyboard';
|
||||||
|
if (buttonDown !== undefined) {
|
||||||
|
this.events.emit('input_down', {
|
||||||
|
controller_type: 'keyboard',
|
||||||
|
button: buttonDown,
|
||||||
|
});
|
||||||
|
this.setLastProcessedMovementTime(buttonDown, 'keyboard', this.chosenKeyboard);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keyboardKeyUp(event): void {
|
keyboardKeyUp(event): void {
|
||||||
|
const keyDown = event.keyCode;
|
||||||
|
this.keys = this.keys.filter(k => k !== keyDown);
|
||||||
|
if (!this.keyboardConfigs[this.chosenKeyboard]?.padID)
|
||||||
|
this.setupKeyboard();
|
||||||
|
const key = getKeyFromKeyboardKeyCode(this.keyboardConfigs[this.chosenKeyboard], keyDown);
|
||||||
|
const buttonUp = this.keyboardConfigs[this.chosenKeyboard].custom[key];
|
||||||
|
if (buttonUp !== undefined) {
|
||||||
|
this.events.emit('input_up', {
|
||||||
|
controller_type: 'keyboard',
|
||||||
|
button: buttonUp,
|
||||||
|
});
|
||||||
|
this.delLastProcessedMovementTime(buttonUp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -729,7 +758,7 @@ export class InputsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
getPressedKeyLabel(key): string {
|
getPressedKeyLabel(key): string {
|
||||||
return getCurrenlyAssignedIconFromKeyboardKey(this.keyboardConfigs[this.chosenKeyboard], key);
|
return getCurrenlyAssignedIconFromKeyboardKeyCode(this.keyboardConfigs[this.chosenKeyboard], key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -184,6 +184,7 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
||||||
this.newButtonIcon.setVisible(false);
|
this.newButtonIcon.setVisible(false);
|
||||||
this.targetButtonIcon.setVisible(false);
|
this.targetButtonIcon.setVisible(false);
|
||||||
this.swapText.setVisible(false);
|
this.swapText.setVisible(false);
|
||||||
|
this.buttonPressed = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
onInputDown(buttonIcon: string, assignedButtonIcon: string, type: string): void {
|
onInputDown(buttonIcon: string, assignedButtonIcon: string, type: string): void {
|
||||||
|
|
Loading…
Reference in New Issue