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;
|
||||
}
|
||||
export function getKeyFromKeyboardKey(config: InterfaceConfig, key): String | null {
|
||||
export function getKeyFromKeyboardKeyCode(config: InterfaceConfig, key): String | null {
|
||||
for (const _key of Object.keys(config.gamepadMapping)) {
|
||||
if (config.gamepadMapping[_key] === key) return _key;
|
||||
}
|
||||
|
@ -46,8 +46,8 @@ export function getCurrenlyAssignedIconFromInputIndex(config: InterfaceConfig, i
|
|||
return config.icons[key];
|
||||
}
|
||||
|
||||
export function getCurrenlyAssignedIconFromKeyboardKey(config: InterfaceConfig, key): String {
|
||||
const _key = getKeyFromKeyboardKey(config, key);
|
||||
export function getCurrenlyAssignedIconFromKeyboardKeyCode(config: InterfaceConfig, key): String {
|
||||
const _key = getKeyFromKeyboardKeyCode(config, key);
|
||||
return config.icons[_key];
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,12 @@ import {Mode} from "./ui/ui";
|
|||
import SettingsGamepadUiHandler from "./ui/settings/settings-gamepad-ui-handler";
|
||||
import {SettingGamepad} from "./system/settings-gamepad";
|
||||
import {
|
||||
getCurrenlyAssignedIconFromInputIndex, getCurrentlyAssignedIconToSettingName,
|
||||
getKeyFromInputIndex, getCurrentlyAssignedToSettingName, getCurrenlyAssignedIconFromKeyboardKey
|
||||
getCurrenlyAssignedIconFromInputIndex,
|
||||
getCurrentlyAssignedIconToSettingName,
|
||||
getKeyFromInputIndex,
|
||||
getCurrentlyAssignedToSettingName,
|
||||
getCurrenlyAssignedIconFromKeyboardKeyCode,
|
||||
getKeyFromKeyboardKeyCode
|
||||
} from "./configs/gamepad-utils";
|
||||
import SettingsKeyboardUiHandler from "./ui/settings/settings-keyboard-ui-handler";
|
||||
import cfg_keyboard_azerty from "./configs/cfg_keyboard_azerty";
|
||||
|
@ -88,6 +92,7 @@ export class InputsController {
|
|||
private pauseUpdate: boolean = false;
|
||||
|
||||
public lastSource: string = 'keyboard';
|
||||
private keys: Array<number> = [];
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
// Keyboard
|
||||
this.setupKeyboardControls();
|
||||
// this.setupKeyboardControls();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,7 +236,8 @@ export class InputsController {
|
|||
// Prevents repeating button interactions when gamepad support is disabled.
|
||||
if (
|
||||
(!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
|
||||
) {
|
||||
// Deletes the last interaction for a button if gamepad is disabled.
|
||||
|
@ -372,14 +378,37 @@ export class InputsController {
|
|||
}
|
||||
|
||||
keyboardKeyDown(event): void {
|
||||
const keyDown = event.key;
|
||||
const keyCode = event.keyCode
|
||||
const keyDown = event.keyCode;
|
||||
if (!this.keyboardConfigs[this.chosenKeyboard]?.padID)
|
||||
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 {
|
||||
|
||||
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 {
|
||||
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.targetButtonIcon.setVisible(false);
|
||||
this.swapText.setVisible(false);
|
||||
this.buttonPressed = null;
|
||||
}
|
||||
|
||||
onInputDown(buttonIcon: string, assignedButtonIcon: string, type: string): void {
|
||||
|
|
Loading…
Reference in New Issue