effective keyboard key swap

pull/685/head
Greenlamp 2024-05-13 02:51:59 +02:00
parent b8856d246e
commit 665ecc0e4b
3 changed files with 79 additions and 2 deletions

View File

@ -202,6 +202,62 @@ const cfg_keyboard_azerty = {
KEY_V: Button.CYCLE_VARIANT, KEY_V: Button.CYCLE_VARIANT,
KEY_PLUS: Button.SPEED_UP, KEY_PLUS: Button.SPEED_UP,
KEY_MINUS: Button.SLOW_DOWN, KEY_MINUS: Button.SLOW_DOWN,
KEY_A: -1,
KEY_B: -1,
KEY_D: -1,
KEY_H: -1,
KEY_I: -1,
KEY_J: -1,
KEY_K: -1,
KEY_L: -1,
KEY_M: -1,
KEY_O: -1,
KEY_P: -1,
KEY_Q: -1,
KEY_S: -1,
KEY_T: -1,
KEY_U: -1,
KEY_W: -1,
KEY_X: -1,
KEY_Y: -1,
KEY_Z: -1,
KEY_0: -1,
KEY_1: -1,
KEY_2: -1,
KEY_3: -1,
KEY_4: -1,
KEY_5: -1,
KEY_6: -1,
KEY_7: -1,
KEY_8: -1,
KEY_9: -1,
KEY_CTRL: -1,
KEY_DEL: -1,
KEY_END: -1,
KEY_F1: -1,
KEY_F2: -1,
KEY_F3: -1,
KEY_F4: -1,
KEY_F5: -1,
KEY_F6: -1,
KEY_F7: -1,
KEY_F8: -1,
KEY_F9: -1,
KEY_F10: -1,
KEY_F11: -1,
KEY_F12: -1,
KEY_HOME: -1,
KEY_INSERT: -1,
KEY_PAGE_DOWN: -1,
KEY_PAGE_UP: -1,
KEY_QUOTATION: -1,
KEY_SHIFT: -1,
KEY_TAB: -1,
KEY_TILDE: -1,
KEY_LEFT_BRACKET: -1,
KEY_RIGHT_BRACKET: -1,
KEY_SEMICOLON: -1,
KEY_ALT: -1
} }
}; };

View File

@ -796,7 +796,15 @@ export class InputsController {
} }
swapKeyboardBinding(settingName, pressedButton): void { swapKeyboardBinding(settingName, pressedButton): void {
console.log('swap'); this.pauseUpdate = true;
const keyTarget = getCurrentlyAssignedToSettingName(this.keyboardConfigs[this.chosenKeyboard], settingName)
const keyNewBinding = getKeyFromKeyboardKeyCode(this.keyboardConfigs[this.chosenKeyboard], pressedButton);
const previousActionForThisNewBinding = this.keyboardConfigs[this.chosenKeyboard].custom[keyNewBinding];
const ActionForThisNewBinding = this.keyboardConfigs[this.chosenKeyboard].custom[keyTarget];
this.keyboardConfigs[this.chosenKeyboard].custom[keyTarget] = previousActionForThisNewBinding;
this.keyboardConfigs[this.chosenKeyboard].custom[keyNewBinding] = ActionForThisNewBinding;
this.scene.gameData.saveCustomKeyboardMapping(this.chosenKeyboard, this.keyboardConfigs[this.chosenKeyboard].custom);
setTimeout(() => this.pauseUpdate = false, 500);
} }
/** /**
@ -810,4 +818,8 @@ export class InputsController {
if (!this.configs[gamepadName]) this.configs[gamepadName] = {}; if (!this.configs[gamepadName]) this.configs[gamepadName] = {};
this.configs[gamepadName].custom = customMappings; this.configs[gamepadName].custom = customMappings;
} }
injectKeyboardConfig(layout: string, customMappings: MappingLayout): void {
if (!this.keyboardConfigs[layout]) this.keyboardConfigs[layout] = {};
this.keyboardConfigs[layout].custom = customMappings;
}
} }

View File

@ -233,6 +233,7 @@ export class GameData {
this.loadSettings(); this.loadSettings();
this.loadGamepadSettings(); this.loadGamepadSettings();
this.loadCustomMapping(); this.loadCustomMapping();
this.loadCustomKeyboardMapping();
this.trainerId = Utils.randInt(65536); this.trainerId = Utils.randInt(65536);
this.secretId = Utils.randInt(65536); this.secretId = Utils.randInt(65536);
this.starterData = {}; this.starterData = {};
@ -510,8 +511,16 @@ export class GameData {
return true; return true;
} }
public loadCustomKeyboardMapping(): boolean {
if (!localStorage.hasOwnProperty('customKeyboardMappings'))
return false;
const customKeyboardMappings = JSON.parse(localStorage.getItem('customKeyboardMappings'));
for (const key of Object.keys(customKeyboardMappings))
this.scene.inputController.injectKeyboardConfig(key, customKeyboardMappings[key]);
}
public loadCustomMapping(): boolean { public loadCustomMapping(): boolean {
console.log('loadCustomMapping');
if (!localStorage.hasOwnProperty('customMapping')) if (!localStorage.hasOwnProperty('customMapping'))
return false; return false;
const customMappings = JSON.parse(localStorage.getItem('customMapping')); const customMappings = JSON.parse(localStorage.getItem('customMapping'));