refactor to simplify the overcomplicated config file (#1)

* refactor done

* starting gamepad tests

* renamed tests
pull/685/head
Greenlamp2 2024-05-16 01:15:11 +02:00 committed by GitHub
parent 85a0debb6c
commit 7ca1a276a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 952 additions and 1785 deletions

View File

@ -165,7 +165,43 @@ const cfg_keyboard_azerty = {
KEY_BACKSPACE: "T_Backspace_Alt_Key_Dark.png",
KEY_ALT: "T_Alt_Key_Dark.png"
},
setting: {
settings: {
[SettingKeyboard.Button_Up]: Button.UP,
[SettingKeyboard.Button_Down]: Button.DOWN,
[SettingKeyboard.Button_Left]: Button.LEFT,
[SettingKeyboard.Button_Right]: Button.RIGHT,
[SettingKeyboard.Button_Submit]: Button.SUBMIT,
[SettingKeyboard.Button_Action]: Button.ACTION,
[SettingKeyboard.Button_Cancel]: Button.CANCEL,
[SettingKeyboard.Button_Menu]: Button.MENU,
[SettingKeyboard.Button_Stats]: Button.STATS,
[SettingKeyboard.Button_Cycle_Shiny]: Button.CYCLE_SHINY,
[SettingKeyboard.Button_Cycle_Form]: Button.CYCLE_FORM,
[SettingKeyboard.Button_Cycle_Gender]: Button.CYCLE_GENDER,
[SettingKeyboard.Button_Cycle_Ability]: Button.CYCLE_ABILITY,
[SettingKeyboard.Button_Cycle_Nature]: Button.CYCLE_NATURE,
[SettingKeyboard.Button_Cycle_Variant]: Button.CYCLE_VARIANT,
[SettingKeyboard.Button_Speed_Up]: Button.SPEED_UP,
[SettingKeyboard.Button_Slow_Down]: Button.SLOW_DOWN,
[SettingKeyboard.Alt_Button_Up]: Button.UP,
[SettingKeyboard.Alt_Button_Down]: Button.DOWN,
[SettingKeyboard.Alt_Button_Left]: Button.LEFT,
[SettingKeyboard.Alt_Button_Right]: Button.RIGHT,
[SettingKeyboard.Alt_Button_Submit]: Button.SUBMIT,
[SettingKeyboard.Alt_Button_Action]: Button.ACTION,
[SettingKeyboard.Alt_Button_Cancel]: Button.CANCEL,
[SettingKeyboard.Alt_Button_Menu]: Button.MENU,
[SettingKeyboard.Alt_Button_Stats]: Button.STATS,
[SettingKeyboard.Alt_Button_Cycle_Shiny]: Button.CYCLE_SHINY,
[SettingKeyboard.Alt_Button_Cycle_Form]: Button.CYCLE_FORM,
[SettingKeyboard.Alt_Button_Cycle_Gender]: Button.CYCLE_GENDER,
[SettingKeyboard.Alt_Button_Cycle_Ability]: Button.CYCLE_ABILITY,
[SettingKeyboard.Alt_Button_Cycle_Nature]: Button.CYCLE_NATURE,
[SettingKeyboard.Alt_Button_Cycle_Variant]: Button.CYCLE_VARIANT,
[SettingKeyboard.Alt_Button_Speed_Up]: Button.SPEED_UP,
[SettingKeyboard.Alt_Button_Slow_Down]: Button.SLOW_DOWN,
},
default: {
KEY_ARROW_UP: SettingKeyboard.Button_Up,
KEY_ARROW_DOWN: SettingKeyboard.Button_Down,
KEY_ARROW_LEFT: SettingKeyboard.Button_Left,
@ -183,62 +219,25 @@ const cfg_keyboard_azerty = {
KEY_V: SettingKeyboard.Button_Cycle_Variant,
KEY_PLUS: SettingKeyboard.Button_Speed_Up,
KEY_MINUS: SettingKeyboard.Button_Slow_Down,
KEY_Z: SettingKeyboard.Alt_Button_Up,
KEY_S: SettingKeyboard.Alt_Button_Down,
KEY_Q: SettingKeyboard.Alt_Button_Left,
KEY_D: SettingKeyboard.Alt_Button_Right,
KEY_CTRL: SettingKeyboard.Alt_Button_Submit,
KEY_W: SettingKeyboard.Alt_Button_Action,
KEY_X: SettingKeyboard.Alt_Button_Cancel,
KEY_TAB: SettingKeyboard.Alt_Button_Menu,
KEY_SHIFT: SettingKeyboard.Alt_Button_Stats,
KEY_P: SettingKeyboard.Alt_Button_Cycle_Shiny,
KEY_M: SettingKeyboard.Alt_Button_Cycle_Form,
KEY_O: SettingKeyboard.Alt_Button_Cycle_Gender,
KEY_L: SettingKeyboard.Alt_Button_Cycle_Ability,
KEY_I: SettingKeyboard.Alt_Button_Cycle_Nature,
KEY_K: SettingKeyboard.Alt_Button_Cycle_Variant,
KEY_PAGE_UP: SettingKeyboard.Alt_Button_Speed_Up,
KEY_PAGE_DOWN: SettingKeyboard.Alt_Button_Slow_Down,
},
default: {
KEY_ARROW_UP: Button.UP,
KEY_ARROW_DOWN: Button.DOWN,
KEY_ARROW_LEFT: Button.LEFT,
KEY_ARROW_RIGHT: Button.RIGHT,
KEY_ENTER: Button.SUBMIT,
KEY_SPACE: Button.ACTION,
KEY_BACKSPACE: Button.CANCEL,
KEY_ESC: Button.MENU,
KEY_C: Button.STATS,
KEY_R: Button.CYCLE_SHINY,
KEY_F: Button.CYCLE_FORM,
KEY_G: Button.CYCLE_GENDER,
KEY_E: Button.CYCLE_ABILITY,
KEY_N: Button.CYCLE_NATURE,
KEY_V: Button.CYCLE_VARIANT,
KEY_PLUS: Button.SPEED_UP,
KEY_MINUS: Button.SLOW_DOWN,
KEY_A: -1,
KEY_B: -1,
KEY_D: Button.RIGHT,
KEY_D: SettingKeyboard.Alt_Button_Right,
KEY_H: -1,
KEY_I: Button.CYCLE_NATURE,
KEY_I: SettingKeyboard.Alt_Button_Cycle_Nature,
KEY_J: -1,
KEY_K: Button.CYCLE_VARIANT,
KEY_L: Button.CYCLE_ABILITY,
KEY_M: Button.CYCLE_FORM,
KEY_O: Button.CYCLE_GENDER,
KEY_P: Button.CYCLE_SHINY,
KEY_Q: Button.LEFT,
KEY_S: Button.DOWN,
KEY_K: SettingKeyboard.Alt_Button_Cycle_Variant,
KEY_L: SettingKeyboard.Alt_Button_Cycle_Ability,
KEY_M: SettingKeyboard.Alt_Button_Cycle_Form,
KEY_O: SettingKeyboard.Alt_Button_Cycle_Gender,
KEY_P: SettingKeyboard.Alt_Button_Cycle_Shiny,
KEY_Q: SettingKeyboard.Alt_Button_Left,
KEY_S: SettingKeyboard.Alt_Button_Down,
KEY_T: -1,
KEY_U: -1,
KEY_W: Button.ACTION,
KEY_X: Button.CANCEL,
KEY_W: SettingKeyboard.Alt_Button_Action,
KEY_X: SettingKeyboard.Alt_Button_Cancel,
KEY_Y: -1,
KEY_Z: Button.UP,
KEY_Z: SettingKeyboard.Alt_Button_Up,
KEY_0: -1,
KEY_1: -1,
KEY_2: -1,
@ -249,7 +248,7 @@ const cfg_keyboard_azerty = {
KEY_7: -1,
KEY_8: -1,
KEY_9: -1,
KEY_CTRL: Button.SUBMIT,
KEY_CTRL: SettingKeyboard.Alt_Button_Submit,
KEY_DEL: -1,
KEY_END: -1,
KEY_F1: -1,
@ -266,17 +265,19 @@ const cfg_keyboard_azerty = {
KEY_F12: -1,
KEY_HOME: -1,
KEY_INSERT: -1,
KEY_PAGE_DOWN: Button.SLOW_DOWN,
KEY_PAGE_UP: Button.SPEED_UP,
KEY_PAGE_DOWN: SettingKeyboard.Alt_Button_Slow_Down,
KEY_PAGE_UP: SettingKeyboard.Alt_Button_Speed_Up,
KEY_QUOTATION: -1,
KEY_SHIFT: Button.STATS,
KEY_TAB: Button.MENU,
KEY_SHIFT: SettingKeyboard.Alt_Button_Stats,
KEY_TAB: SettingKeyboard.Alt_Button_Menu,
KEY_TILDE: -1,
KEY_LEFT_BRACKET: -1,
KEY_RIGHT_BRACKET: -1,
KEY_SEMICOLON: -1,
KEY_ALT: -1
}
},
main: [],
alt: [],
};
export default cfg_keyboard_azerty;

View File

@ -0,0 +1,136 @@
export function getKeyWithKeycode(config, keycode) {
return Object.keys(config.gamepadMapping).find(key => config.gamepadMapping[key] === keycode);
}
export function getSettingNameWithKeycode(config, keycode) {
const key = getKeyWithKeycode(config, keycode);
return config.custom[key];
}
export function getIconWithKeycode(config, keycode) {
const key = getKeyWithKeycode(config, keycode);
return config.icons[key];
}
export function getButtonWithKeycode(config, keycode) {
const settingName = getSettingNameWithKeycode(config, keycode);
return config.settings[settingName];
}
export function getKeycodeWithKey(config, key) {
return config.gamepadMapping[key]
}
export function getKeyWithSettingName(config, settingName) {
return Object.keys(config.custom).find(key => config.custom[key] === settingName);
}
export function getSettingNameWithKey(config, key) {
return config.custom[key]
}
export function getIconWithKey(config, key) {
return config.icons[key]
}
export function getIconSpecialCase(config, keycode, settingName) {
const potentialKey = isAlreadyBinded(config, keycode, settingName);
if (potentialKey) return getIconWithKey(config, potentialKey);
return null;
}
export function getButtonWithSettingName(config, settingName) {
return config.settings[settingName];
}
export function getButtonWithKey(config, key) {
const settingName = config.custom[key];
return getButtonWithSettingName(config, settingName);
}
export function getIconWithSettingName(config, settingName) {
const key = getKeyWithSettingName(config, settingName);
return getIconWithKey(config, key);
}
export function getKeycodeWithSettingName(config, settingName) {
const key = getKeyWithSettingName(config, settingName);
return getKeycodeWithKey(config, key);
}
export function getSettingNameWithButton(config, button, alt= false) {
return Object.keys(config.settings).find(k => {
const a = !alt && !k.includes("ALT_");
const b = alt && k.includes("ALT_");
const c = config.settings[k] === button;
return (a || b) && c;
});
}
export function getKeyWithButton(config, button, alt= false) {
const settingName = getSettingNameWithButton(config, button, alt);
return getKeyWithSettingName(config, settingName);
}
export function getKeycodeWithButton(config, button, alt= false) {
const key = getKeyWithButton(config, button, alt);
return getKeycodeWithKey(config, key);
}
export function getIconWithButton(config, button, alt= false) {
const key = getKeyWithButton(config, button, alt);
return getIconWithKey(config, key);
}
export function isAlreadyBinded(config, keycode, settingNameTarget) {
const key = getKeyWithKeycode(config, keycode);
const isMain = config.main.includes(key);
const isTargetMain = !settingNameTarget.includes("ALT_");
const potentialExistingButton = getButtonWithSettingName(config, settingNameTarget);
const potentialExistingKey = getKeyWithButton(config, potentialExistingButton, !isMain);
if (potentialExistingKey && isMain !== isTargetMain) return potentialExistingKey;
return null;
}
export function swap(config, settingNameTarget, keycode) {
// 2 alt can't do the same thing
// 2 main can't do the same thing
// can't swap an alt if another alt is already doing the same
// can't swap a main if another main is already doing the same
const isDeleted = !getKeyWithSettingName(config, settingNameTarget);
if (isDeleted) {
const new_key = getKeyWithKeycode(config, keycode);
config.custom[new_key] = settingNameTarget;
return;
}
const potentialExistingKey = isAlreadyBinded(config, keycode, settingNameTarget);
const prev_key = potentialExistingKey || getKeyWithSettingName(config, settingNameTarget);
const prev_settingName = getSettingNameWithKey(config, prev_key);
const new_key = getKeyWithKeycode(config, keycode);
const new_settingName = getSettingNameWithKey(config, new_key);
config.custom[prev_key] = new_settingName;
config.custom[new_key] = prev_settingName;
regenerateIdentifiers(config);
}
export function deleteBind(config, settingName) {
const key = getKeyWithSettingName(config, settingName);
config.custom[key] = -1;
regenerateIdentifiers(config);
}
export function regenerateIdentifiers(config) {
config.main = Object.keys(config.custom).filter(key => {
const value = config.custom[key]
return value !== -1 && !value.includes("ALT_");
});
config.alt = Object.keys(config.custom).filter(key => {
const value = config.custom[key]
return value !== -1 && value.includes("ALT_");
});
}

View File

@ -1,184 +0,0 @@
import {InterfaceConfig} from "../inputs-controller";
import {Button} from "#app/enums/buttons";
import {deepCopy} from "#app/utils";
// Given a button index from an input event, return its naming from the mapping config
export function getKeyFromMapping(config: InterfaceConfig, index: number): String | null {
for (const key of Object.keys(config.gamepadMapping)) {
if (config.gamepadMapping[key] === index) return key;
}
return null;
}
// Given a setting name, return the key assigned to it from the config file
export function getKeyForSettingName(config: InterfaceConfig, settingName: string): String | null {
for (const key of Object.keys(config.setting)) {
if (config.setting[key] === settingName) return key;
}
return null;
}
// Given a setting name, return the key assigned to it from the config file
export function getIconForSettingName(config: InterfaceConfig, settingName: string): String | null {
const key = getKeyForSettingName(config, settingName);
return config.icons[key];
}
// Given a Button, return the custom key assigned to it from the config file
export function getKeyWithAction(config: InterfaceConfig, action: Button, alt: boolean = false): String | null {
// need to find a way to differentiate main/alt button
const { key } = getKeyAndSettingNameFromCurrentKeysWithAction(config, action, alt);
return key;
}
// Given a button index from an input event, return its icon from the config file
export function getIconWithPressedButton(config: InterfaceConfig, pressedButton: number): String {
const key = getKeyFromMapping(config, pressedButton);
return config.icons[key];
}
// Given a setting name, return the icon currently assigned to this setting name
export function getIconWithSettingName(config: InterfaceConfig, settingName: string): string {
const { icon } = getKeyAndActionFromCurrentKeysWithSettingName(config, settingName)
return icon;
}
function getKeyAndSettingNameFromCurrentKeysWithAction(config, _action, alt: boolean = false) {
for (const _settingName of Object.keys(config.currentKeys)) {
if (alt && !_settingName.includes("ALT_")) continue;
if (config.currentKeys[_settingName].action === _action) return {
settingName: _settingName,
key: config.currentKeys[_settingName].key,
};
}
return null;
}
export function getKeyAndActionFromCurrentKeysWithSettingName(config, settingName) {
return config.currentKeys[settingName];
}
export function getKeyAndActionFromCurrentKeysWithPressedButton(config, pressedButton) {
const key = getKeyFromMapping(config, pressedButton);
const settingName = Object.keys(config.currentKeys).find(_s => config.currentKeys[_s].key === key);
return getKeyAndActionFromCurrentKeysWithSettingName(config, settingName);
}
export function assignNewKey(config: InterfaceConfig, settingName, pressedButton, previousBind): void {
const key = getKeyFromMapping(config, pressedButton);
const icon = config.ogIcons[key];
config.icons[previousBind.key] = icon;
config.currentKeys[settingName].icon = icon;
config.custom[previousBind.key] = -1;
config.custom[key] = previousBind.action !== -1 ? previousBind.action : previousBind.from.action;
config.currentKeys[settingName].replacedBy = key;
config.currentKeys[settingName].latestIsDeleted = false;
delete config.currentKeys[settingName].from
}
export function swapCurrentKeys(config: InterfaceConfig, settingName, pressedButton): void {
const previousBind = getKeyAndActionFromCurrentKeysWithSettingName(config, settingName);
const prevKey = deepCopy(previousBind);
const newBind = getKeyAndActionFromCurrentKeysWithPressedButton(config, pressedButton);
if (newBind?.action === -1 && previousBind.action === -1) {
assignNewKey(config, settingName, pressedButton, previousBind);
} else if (newBind && previousBind.action === -1) {
//special case when rebinding deleted key with already assigned key
const toRestore = deepCopy(newBind);
const iconFromThePressedButton = config.ogIcons[prevKey.key];
config.custom[newBind.key] = prevKey.from.action;
config.icons[prevKey.key] = newBind.icon || iconFromThePressedButton;
config.icons[newBind.key] = prevKey.from.icon;
delete prevKey.from;
const nextSettingName = getKeyAndSettingNameFromCurrentKeysWithAction(config, newBind.action, newBind.isAlt).settingName;
config.currentKeys[nextSettingName].from = toRestore.action === -1 ? config.currentKeys[nextSettingName].from : toRestore;
config.currentKeys[nextSettingName].isDeleted = true;
config.currentKeys[settingName].isDeleted = false;
config.currentKeys[settingName].replacedBy = toRestore.key;
} else if (!newBind) {
assignNewKey(config, settingName, pressedButton, previousBind);
} else {
const nextKey = deepCopy(newBind);
if (prevKey.key === nextKey.key && prevKey.from) {
// special case when back to back and not enough info to get back to previous button
const toRestore = getKeyAndSettingNameFromCurrentKeysWithAction(config, prevKey.from.action, settingName.includes("ALT_"));
config.custom[prevKey.key] = prevKey.from.action;
config.icons[prevKey.key] = prevKey.from.icon;
config.custom[toRestore.key] = prevKey.action;
config.icons[toRestore.key] = prevKey.icon;
delete config.currentKeys[settingName].from;
delete config.currentKeys[toRestore.settingName].from;
} else {
config.custom[previousBind.key] = newBind.action;
config.custom[newBind.key] = previousBind.action;
config.icons[previousBind.key] = newBind.icon;
config.icons[newBind.key] = previousBind.icon;
const nextSettingName = getKeyAndSettingNameFromCurrentKeysWithAction(config, newBind.action, newBind.isAlt).settingName;
config.currentKeys[settingName].from = prevKey;
config.currentKeys[nextSettingName].from = nextKey;
}
}
reloadCurrentKeys(config);
}
export function reloadCurrentKeys(config): void {
// need to rework this to include keys that were not there at the begining
const currentKeys = config.currentKeys ? deepCopy(config.currentKeys) : {};
for (const key of Object.keys(config.setting)) {
const settingName = config.setting[key];
const action = config.custom[key];
const icon = config.icons[key];
if (!currentKeys[settingName]) currentKeys[settingName] = {};
currentKeys[settingName].key = key;
currentKeys[settingName].isAlt = settingName.includes("ALT_");
const previousAction = config.custom[currentKeys[settingName].replacedBy]
if (action === -1 && previousAction !== undefined && !currentKeys[settingName].isDeleted) {
currentKeys[settingName].action = previousAction;
currentKeys[settingName].icon = icon;
currentKeys[settingName].latestReplacedBy = config.currentKeys[settingName].replacedBy
} else if (currentKeys[settingName].isDeleted) {
currentKeys[settingName].action = -1;
currentKeys[settingName].icon = undefined;
currentKeys[settingName].latestIsDeleted = config.currentKeys[settingName].isDeleted
delete currentKeys[settingName].isDeleted;
} else {
currentKeys[settingName].action = action;
currentKeys[settingName].icon = action === -1 ? undefined : icon;
}
}
config.currentKeys = deepCopy(currentKeys);
}
export function regenerateCustom(config): void {
const custom = deepCopy(config.custom);
for (const settingName of Object.keys(config.currentKeys)) {
const {key, action, latestReplacedBy, latestIsDeleted} = config.currentKeys[settingName];
if (latestReplacedBy) {
custom[key] = -1;
custom[latestReplacedBy] = action;
} else if (!latestIsDeleted) {
custom[key] = action;
} else if (latestIsDeleted) {
custom[key] = -1;
}
}
config.custom = deepCopy(custom);
}
export function deleteBind(config, settingName): void {
const { key } = getKeyAndActionFromCurrentKeysWithSettingName(config, settingName);
const prev = deepCopy(config.currentKeys[settingName]);
delete config.currentKeys[settingName].icon
const actualKey = prev.replacedBy || key;
config.currentKeys[settingName].from = prev;
config.custom[actualKey] = -1;
config.currentKeys[settingName].isDeleted = true;
reloadCurrentKeys(config);
}

View File

@ -45,7 +45,30 @@ const pad_dualshock = {
LC_E: "T_P4_Dpad_Right_Default.png",
TOUCH: "T_P4_Touch_Pad_Default.png"
},
setting: {
settings: {
[SettingGamepad.Button_Up]: Button.UP,
[SettingGamepad.Button_Down]: Button.DOWN,
[SettingGamepad.Button_Left]: Button.LEFT,
[SettingGamepad.Button_Right]: Button.RIGHT,
[SettingGamepad.Button_Action]: Button.ACTION,
[SettingGamepad.Button_Cancel]: Button.CANCEL,
[SettingGamepad.Button_Cycle_Nature]: Button.CYCLE_NATURE,
[SettingGamepad.Button_Cycle_Variant]: Button.CYCLE_VARIANT,
[SettingGamepad.Button_Menu]: Button.MENU,
[SettingGamepad.Button_Stats]: Button.STATS,
[SettingGamepad.Button_Cycle_Form]: Button.CYCLE_FORM,
[SettingGamepad.Button_Cycle_Shiny]: Button.CYCLE_SHINY,
[SettingGamepad.Button_Cycle_Gender]: Button.CYCLE_GENDER,
[SettingGamepad.Button_Cycle_Ability]: Button.CYCLE_ABILITY,
[SettingGamepad.Button_Speed_Up]: Button.SPEED_UP,
[SettingGamepad.Button_Slow_Down]: Button.SLOW_DOWN,
[SettingGamepad.Button_Submit]: Button.SUBMIT
},
default: {
LC_N: SettingGamepad.Button_Up,
LC_S: SettingGamepad.Button_Down,
LC_W: SettingGamepad.Button_Left,
LC_E: SettingGamepad.Button_Right,
RC_S: SettingGamepad.Button_Action,
RC_E: SettingGamepad.Button_Cancel,
RC_W: SettingGamepad.Button_Cycle_Nature,
@ -60,25 +83,8 @@ const pad_dualshock = {
RS: SettingGamepad.Button_Slow_Down,
TOUCH: SettingGamepad.Button_Submit,
},
default: {
RC_S: Button.ACTION,
RC_E: Button.CANCEL,
RC_W: Button.CYCLE_NATURE,
RC_N: Button.CYCLE_VARIANT,
START: Button.MENU,
SELECT: Button.STATS,
LB: Button.CYCLE_FORM,
RB: Button.CYCLE_SHINY,
LT: Button.CYCLE_GENDER,
RT: Button.CYCLE_ABILITY,
LS: Button.SPEED_UP,
RS: Button.SLOW_DOWN,
LC_N: Button.UP,
LC_S: Button.DOWN,
LC_W: Button.LEFT,
LC_E: Button.RIGHT,
TOUCH: Button.SUBMIT,
}
main: [],
alt: [],
};
export default pad_dualshock;

View File

@ -43,7 +43,29 @@ const pad_generic = {
LC_W: "T_X_Dpad_Left_Alt.png",
LC_E: "T_X_Dpad_Right_Alt.png",
},
setting: {
settings: {
[SettingGamepad.Button_Up]: Button.UP,
[SettingGamepad.Button_Down]: Button.DOWN,
[SettingGamepad.Button_Left]: Button.LEFT,
[SettingGamepad.Button_Right]: Button.RIGHT,
[SettingGamepad.Button_Action]: Button.ACTION,
[SettingGamepad.Button_Cancel]: Button.CANCEL,
[SettingGamepad.Button_Cycle_Nature]: Button.CYCLE_NATURE,
[SettingGamepad.Button_Cycle_Variant]: Button.CYCLE_VARIANT,
[SettingGamepad.Button_Menu]: Button.MENU,
[SettingGamepad.Button_Stats]: Button.STATS,
[SettingGamepad.Button_Cycle_Form]: Button.CYCLE_FORM,
[SettingGamepad.Button_Cycle_Shiny]: Button.CYCLE_SHINY,
[SettingGamepad.Button_Cycle_Gender]: Button.CYCLE_GENDER,
[SettingGamepad.Button_Cycle_Ability]: Button.CYCLE_ABILITY,
[SettingGamepad.Button_Speed_Up]: Button.SPEED_UP,
[SettingGamepad.Button_Slow_Down]: Button.SLOW_DOWN
},
default: {
LC_N: SettingGamepad.Button_Up,
LC_S: SettingGamepad.Button_Down,
LC_W: SettingGamepad.Button_Left,
LC_E: SettingGamepad.Button_Right,
RC_S: SettingGamepad.Button_Action,
RC_E: SettingGamepad.Button_Cancel,
RC_W: SettingGamepad.Button_Cycle_Nature,
@ -55,26 +77,10 @@ const pad_generic = {
LT: SettingGamepad.Button_Cycle_Gender,
RT: SettingGamepad.Button_Cycle_Ability,
LS: SettingGamepad.Button_Speed_Up,
RS: SettingGamepad.Button_Slow_Down,
RS: SettingGamepad.Button_Slow_Down
},
default: {
RC_S: Button.ACTION, //5
RC_E: Button.CANCEL, // 6
RC_W: Button.CYCLE_NATURE,
RC_N: Button.CYCLE_VARIANT,
START: Button.MENU,
SELECT: Button.STATS,
LB: Button.CYCLE_FORM, //10
RB: Button.CYCLE_SHINY, //9
LT: Button.CYCLE_GENDER, //11
RT: Button.CYCLE_ABILITY,
LS: Button.SPEED_UP,
RS: Button.SLOW_DOWN,
LC_N: Button.UP,
LC_S: Button.DOWN,
LC_W: Button.LEFT,
LC_E: Button.RIGHT,
}
main: [],
alt: [],
};
export default pad_generic;

View File

@ -35,7 +35,29 @@ const pad_unlicensedSNES = {
LC_W: "T_X_Dpad_Left_Alt.png",
LC_E: "T_X_Dpad_Right_Alt.png",
},
setting: {
settings: {
[SettingGamepad.Button_Up]: Button.UP,
[SettingGamepad.Button_Down]: Button.DOWN,
[SettingGamepad.Button_Left]: Button.LEFT,
[SettingGamepad.Button_Right]: Button.RIGHT,
[SettingGamepad.Button_Action]: Button.ACTION,
[SettingGamepad.Button_Cancel]: Button.CANCEL,
[SettingGamepad.Button_Cycle_Nature]: Button.CYCLE_NATURE,
[SettingGamepad.Button_Cycle_Variant]: Button.CYCLE_VARIANT,
[SettingGamepad.Button_Menu]: Button.MENU,
[SettingGamepad.Button_Stats]: Button.STATS,
[SettingGamepad.Button_Cycle_Form]: Button.CYCLE_FORM,
[SettingGamepad.Button_Cycle_Shiny]: Button.CYCLE_SHINY,
[SettingGamepad.Button_Cycle_Gender]: Button.CYCLE_GENDER,
[SettingGamepad.Button_Cycle_Ability]: Button.CYCLE_ABILITY,
[SettingGamepad.Button_Speed_Up]: Button.SPEED_UP,
[SettingGamepad.Button_Slow_Down]: Button.SLOW_DOWN
},
default: {
LC_N: SettingGamepad.Button_Up,
LC_S: SettingGamepad.Button_Down,
LC_W: SettingGamepad.Button_Left,
LC_E: SettingGamepad.Button_Right,
RC_S: SettingGamepad.Button_Action,
RC_E: SettingGamepad.Button_Cancel,
RC_W: SettingGamepad.Button_Cycle_Nature,
@ -44,21 +66,13 @@ const pad_unlicensedSNES = {
SELECT: SettingGamepad.Button_Stats,
LB: SettingGamepad.Button_Cycle_Form,
RB: SettingGamepad.Button_Cycle_Shiny,
LT: -1,
RT: -1,
LS: -1,
RS: -1
},
default: {
RC_S: Button.ACTION,
RC_E: Button.CANCEL,
RC_W: Button.CYCLE_NATURE,
RC_N: Button.CYCLE_VARIANT,
START: Button.MENU,
SELECT: Button.STATS,
LB: Button.CYCLE_FORM,
RB: Button.CYCLE_SHINY,
LC_N: Button.UP,
LC_S: Button.DOWN,
LC_W: Button.LEFT,
LC_E: Button.RIGHT,
}
main: [],
alt: [],
};
export default pad_unlicensedSNES;

View File

@ -43,7 +43,29 @@ const pad_xbox360 = {
LC_W: "T_X_Dpad_Left_Alt.png",
LC_E: "T_X_Dpad_Right_Alt.png",
},
setting: {
settings: {
[SettingGamepad.Button_Up]: Button.UP,
[SettingGamepad.Button_Down]: Button.DOWN,
[SettingGamepad.Button_Left]: Button.LEFT,
[SettingGamepad.Button_Right]: Button.RIGHT,
[SettingGamepad.Button_Action]: Button.ACTION,
[SettingGamepad.Button_Cancel]: Button.CANCEL,
[SettingGamepad.Button_Cycle_Nature]: Button.CYCLE_NATURE,
[SettingGamepad.Button_Cycle_Variant]: Button.CYCLE_VARIANT,
[SettingGamepad.Button_Menu]: Button.MENU,
[SettingGamepad.Button_Stats]: Button.STATS,
[SettingGamepad.Button_Cycle_Form]: Button.CYCLE_FORM,
[SettingGamepad.Button_Cycle_Shiny]: Button.CYCLE_SHINY,
[SettingGamepad.Button_Cycle_Gender]: Button.CYCLE_GENDER,
[SettingGamepad.Button_Cycle_Ability]: Button.CYCLE_ABILITY,
[SettingGamepad.Button_Speed_Up]: Button.SPEED_UP,
[SettingGamepad.Button_Slow_Down]: Button.SLOW_DOWN
},
default: {
LC_N: SettingGamepad.Button_Up,
LC_S: SettingGamepad.Button_Down,
LC_W: SettingGamepad.Button_Left,
LC_E: SettingGamepad.Button_Right,
RC_S: SettingGamepad.Button_Action,
RC_E: SettingGamepad.Button_Cancel,
RC_W: SettingGamepad.Button_Cycle_Nature,
@ -55,26 +77,10 @@ const pad_xbox360 = {
LT: SettingGamepad.Button_Cycle_Gender,
RT: SettingGamepad.Button_Cycle_Ability,
LS: SettingGamepad.Button_Speed_Up,
RS: SettingGamepad.Button_Slow_Down,
RS: SettingGamepad.Button_Slow_Down
},
default: {
RC_S: Button.ACTION, //5
RC_E: Button.CANCEL, // 6
RC_W: Button.CYCLE_NATURE,
RC_N: Button.CYCLE_VARIANT, //14
START: Button.MENU, //7
SELECT: Button.STATS, //8
LB: Button.CYCLE_FORM,
RB: Button.CYCLE_SHINY,
LT: Button.CYCLE_GENDER,
RT: Button.CYCLE_ABILITY,
LS: Button.SPEED_UP,
RS: Button.SLOW_DOWN,
LC_N: Button.UP,
LC_S: Button.DOWN,
LC_W: Button.LEFT,
LC_E: Button.RIGHT,
}
main: [],
alt: [],
};
export default pad_xbox360;

4
src/enums/devices.ts Normal file
View File

@ -0,0 +1,4 @@
export enum Device {
GAMEPAD,
KEYBOARD,
}

View File

@ -1,4 +1,5 @@
import * as Utils from "./utils";
import {deepCopy} from "./utils";
import {initTouchControls} from './touch-controls';
import pad_generic from "./configs/pad_generic";
import pad_unlicensedSNES from "./configs/pad_unlicensedSNES";
@ -9,12 +10,8 @@ import {Mode} from "./ui/ui";
import SettingsGamepadUiHandler from "./ui/settings/settings-gamepad-ui-handler";
import SettingsKeyboardUiHandler from "./ui/settings/settings-keyboard-ui-handler";
import cfg_keyboard_azerty from "./configs/cfg_keyboard_azerty";
import {
getKeyAndActionFromCurrentKeysWithPressedButton,
getKeyFromMapping, regenerateCustom,
reloadCurrentKeys, swapCurrentKeys
} from "#app/configs/gamepad-utils";
import {deepCopy} from "./utils";
import {Device} from "#app/enums/devices";
import {getButtonWithKeycode, regenerateIdentifiers, swap} from "#app/configs/configHandler";
export interface GamepadMapping {
[key: string]: number;
@ -78,12 +75,10 @@ export class InputsController {
private interactions: Map<Button, Map<string, boolean>> = new Map();
private time: Phaser.Time.Clock;
private configs: Map<string, InterfaceConfig> = new Map();
private keyboardConfigs: Map<string, InterfaceConfig> = new Map();
private gamepadSupport: boolean = true;
public selectedDevice;
public chosenGamepad: String;
public chosenKeyboard: string = "default";
private disconnectedGamepads: Array<String> = new Array();
private pauseUpdate: boolean = false;
@ -102,10 +97,15 @@ export class InputsController {
* Specific buttons like MENU and STATS are set not to repeat their actions.
* It concludes by calling the `init` method to complete the setup.
*/
constructor(scene: Phaser.Scene) {
this.scene = scene;
this.time = this.scene.time;
this.buttonKeys = [];
this.selectedDevice = {
[Device.GAMEPAD]: null,
[Device.KEYBOARD]: 'default'
}
for (const b of Utils.getEnumValues(Button)) {
this.interactions[b] = {
@ -131,8 +131,8 @@ export class InputsController {
init(): void {
this.events = this.scene.game.events;
if (localStorage.hasOwnProperty('chosenGamepad')) {
this.chosenGamepad = localStorage.getItem('chosenGamepad');
if (localStorage.hasOwnProperty('selectedDevice')) {
this.selectedDevice = JSON.parse(localStorage.getItem('selectedDevice'));
}
this.scene.game.events.on(Phaser.Core.Events.BLUR, () => {
this.loseFocus()
@ -234,8 +234,8 @@ export class InputsController {
// Prevents repeating button interactions when gamepad support is disabled.
if (
(!this.gamepadSupport && this.interactions[b].source === 'gamepad') ||
(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.interactions[b].source === 'gamepad' && this.interactions[b].sourceName && this.interactions[b].sourceName !== this.selectedDevice[Device.GAMEPAD]) ||
(this.interactions[b].source === 'keyboard' && this.interactions[b].sourceName && this.interactions[b].sourceName !== this.selectedDevice[Device.KEYBOARD]) ||
this.pauseUpdate
) {
// Deletes the last interaction for a button if gamepad is disabled.
@ -266,23 +266,17 @@ export class InputsController {
* @param gamepadName Optional parameter to specify the name of the gamepad to initialize as chosen.
*/
initChosenGamepad(gamepadName?: String): void {
let name = gamepadName;
if (gamepadName)
this.chosenGamepad = gamepadName;
else
name = this.chosenGamepad;
localStorage.setItem('chosenGamepad', name);
this.selectedDevice[Device.GAMEPAD] = gamepadName.toLowerCase();
localStorage.setItem('selectedDevice', JSON.stringify(this.selectedDevice));
const handler = this.scene.ui?.handlers[Mode.SETTINGS_GAMEPAD] as SettingsGamepadUiHandler;
handler && handler.updateChosenGamepadDisplay()
}
initChosenLayoutKeyboard(layoutKeyboard?: String): void {
let name = layoutKeyboard;
if (layoutKeyboard)
this.chosenKeyboard = layoutKeyboard;
else
name = this.chosenKeyboard;
localStorage.setItem('chosenKeyboardLayout', name);
this.selectedDevice[Device.KEYBOARD] = layoutKeyboard.toLowerCase();
localStorage.setItem('selectedDevice', JSON.stringify(this.selectedDevice));
const handler = this.scene.ui?.handlers[Mode.SETTINGS_KEYBOARD] as SettingsKeyboardUiHandler;
handler && handler.updateChosenKeyboardDisplay()
}
@ -297,22 +291,6 @@ export class InputsController {
*/
onDisconnect(thisGamepad: Phaser.Input.Gamepad.Gamepad): void {
this.disconnectedGamepads.push(thisGamepad.id);
/** commented for now this code because i don't know anymore if it's good to do that
* for example i'm playing with a wireless gamepad that shutdown after 5 min
* i don't want my game to use my second controller when i turn back on my main gamepad
* we look for gamepads still connected by substracting the 2 arrays
*/
// const gamepadsLeft = this.gamepads.filter(g => !this.disconnectedGamepads.includes(g.id)).map(g => g);
// we check if the chosen gamepad is still connected
// const chosenIsConnected = gamepadsLeft.some(g => g.id === this.chosenGamepad);
// if the chosen gamepad is disconnected, and we got others gamepad connected
// if (!chosenIsConnected && gamepadsLeft?.length) {
// We remove the previously chosen gamepad
// this.clearChosenGamepad();
// and we set the first of the gamepad still connected as the chosen one.
// this.setChosenGamepad(gamepadsLeft[0].id);
// return;
// }
}
/**
@ -338,36 +316,24 @@ export class InputsController {
const allGamepads = this.getGamepadsName();
for (const gamepad of allGamepads) {
const gamepadID = gamepad.toLowerCase();
if (!this.selectedDevice[Device.GAMEPAD])
this.setChosenGamepad(gamepadID);
const config = deepCopy(this.getConfig(gamepadID));
config.custom = this.configs[gamepad]?.custom || {...config.default};
config.ogIcons = {...config.icons};
config.icons = this.configs[gamepad]?.icons || {...config.icons};
config.currentKeys = this.configs[gamepad]?.currentKeys;
if (!this.configs[gamepad]?.currentKeys)
reloadCurrentKeys(config);
else
regenerateCustom(config);
this.configs[gamepad] = config;
this.scene.gameData?.saveCustomMapping(this.chosenGamepad, this.configs[gamepad]?.currentKeys, this.configs[gamepad]?.icons);
config.custom = this.configs[gamepadID]?.custom || {...config.default};
this.configs[gamepadID] = config;
this.scene.gameData?.saveMappingConfigs(gamepadID, this.configs[gamepadID]);
}
if (this.chosenGamepad === thisGamepad.id) this.initChosenGamepad(this.chosenGamepad)
this.initChosenGamepad(this.selectedDevice[Device.GAMEPAD])
}
setupKeyboard(): void {
for (const layout of ['default']) {
const config = deepCopy(this.getConfigKeyboard(layout));
config.custom = this.keyboardConfigs[layout]?.custom || {...config.default};
config.ogIcons = {...config.icons};
config.icons = this.keyboardConfigs[layout]?.icons || {...config.icons};
config.currentKeys = this.keyboardConfigs[layout]?.currentKeys;
if (!this.keyboardConfigs[layout]?.currentKeys)
reloadCurrentKeys(config);
else
regenerateCustom(config);
this.keyboardConfigs[layout] = config;
this.scene.gameData?.saveCustomKeyboardMapping(this.chosenKeyboard, this.keyboardConfigs[layout]?.currentKeys, this.keyboardConfigs[layout]?.icons);
config.custom = this.configs[layout]?.custom || {...config.default};
this.configs[layout] = config;
this.scene.gameData?.saveMappingConfigs(this.selectedDevice[Device.KEYBOARD], this.configs[layout]);
}
this.initChosenLayoutKeyboard(this.chosenKeyboard)
this.initChosenLayoutKeyboard(this.selectedDevice[Device.KEYBOARD])
}
/**
@ -390,7 +356,7 @@ export class InputsController {
}
checkIfKeyboardIsInit(): void {
if (!this.keyboardConfigs[this.chosenKeyboard]?.padID)
if (!this.getActiveConfig(Device.KEYBOARD)?.padID)
this.setupKeyboard();
}
@ -399,15 +365,14 @@ export class InputsController {
this.checkIfKeyboardIsInit();
if (this.keys.includes(keyDown)) return;
this.keys.push(keyDown);
const key = getKeyFromMapping(this.keyboardConfigs[this.chosenKeyboard], keyDown);
const buttonDown = this.keyboardConfigs[this.chosenKeyboard].custom[key];
const buttonDown = getButtonWithKeycode(this.getActiveConfig(Device.KEYBOARD), keyDown);
this.lastSource = 'keyboard';
if (buttonDown !== undefined) {
this.events.emit('input_down', {
controller_type: 'keyboard',
button: buttonDown,
});
this.setLastProcessedMovementTime(buttonDown, 'keyboard', this.chosenKeyboard);
this.setLastProcessedMovementTime(buttonDown, 'keyboard', this.selectedDevice[Device.KEYBOARD]);
}
}
@ -415,8 +380,7 @@ export class InputsController {
const keyDown = event.keyCode;
this.keys = this.keys.filter(k => k !== keyDown);
this.checkIfKeyboardIsInit()
const key = getKeyFromMapping(this.keyboardConfigs[this.chosenKeyboard], keyDown);
const buttonUp = this.keyboardConfigs[this.chosenKeyboard].custom[key];
const buttonUp = getButtonWithKeycode(this.getActiveConfig(Device.KEYBOARD), keyDown);
if (buttonUp !== undefined) {
this.events.emit('input_up', {
controller_type: 'keyboard',
@ -436,14 +400,13 @@ export class InputsController {
* @param value The intensity or value of the button press, if applicable.
*/
gamepadButtonDown(pad: Phaser.Input.Gamepad.Gamepad, button: Phaser.Input.Gamepad.Button, value: number): void {
if (!this.keyboardConfigs[this.chosenKeyboard]?.padID)
if (!this.configs[this.selectedDevice[Device.KEYBOARD]]?.padID)
this.setupKeyboard();
if (!pad) return;
if (!this.chosenGamepad)
if (!this.selectedDevice[Device.GAMEPAD])
this.setChosenGamepad(pad.id);
if (!this.gamepadSupport || pad.id.toLowerCase() !== this.chosenGamepad.toLowerCase()) return;
const key = getKeyFromMapping(this.configs[pad.id], button.index);
const buttonDown = this.configs[pad.id].custom[key];
if (!this.gamepadSupport || pad.id.toLowerCase() !== this.selectedDevice[Device.GAMEPAD].toLowerCase()) return;
const buttonDown = getButtonWithKeycode(this.getActiveConfig(Device.GAMEPAD), button.index);
this.lastSource = 'gamepad';
if (buttonDown !== undefined) {
this.events.emit('input_down', {
@ -465,9 +428,8 @@ export class InputsController {
*/
gamepadButtonUp(pad: Phaser.Input.Gamepad.Gamepad, button: Phaser.Input.Gamepad.Button, value: number): void {
if (!pad) return;
if (!this.gamepadSupport || pad.id !== this.chosenGamepad) return;
const key = getKeyFromMapping(this.configs[pad.id], button.index);
const buttonUp = this.configs[pad.id]?.custom[key];
if (!this.gamepadSupport || pad.id.toLowerCase() !== this.selectedDevice[Device.GAMEPAD]) return;
const buttonUp = getButtonWithKeycode(this.getActiveConfig(Device.GAMEPAD), button.index);
if (buttonUp !== undefined) {
this.events.emit('input_up', {
controller_type: 'gamepad',
@ -477,100 +439,6 @@ export class InputsController {
}
}
/**
* Configures keyboard controls for the game, mapping physical keys to game actions.
*
* @remarks
* This method sets up keyboard bindings for game controls using Phaser's `KeyCodes`. Each game action, represented
* by a button in the `Button` enum, is associated with one or more physical keys. For example, movement actions
* (up, down, left, right) are mapped to both arrow keys and WASD keys. Actions such as submit, cancel, and other
* game-specific functions are mapped to appropriate keys like Enter, Space, etc.
*
* The method does the following:
* - Defines a `keyConfig` object that associates each `Button` enum value with an array of `KeyCodes`.
* - Iterates over all values of the `Button` enum to set up these key bindings within the Phaser game scene.
* - For each button, it adds the respective keys to the game's input system and stores them in `this.buttonKeys`.
* - Additional configurations for mobile or alternative input schemes are stored in `mobileKeyConfig`.
*
* Post-setup, it initializes touch controls (if applicable) and starts listening for keyboard inputs using
* `listenInputKeyboard`, ensuring that all configured keys are actively monitored for player interactions.
*/
setupKeyboardControls(): void {
const keyCodes = Phaser.Input.Keyboard.KeyCodes;
const keyConfig = {
[Button.UP]: [keyCodes.UP, keyCodes.W],
[Button.DOWN]: [keyCodes.DOWN, keyCodes.S],
[Button.LEFT]: [keyCodes.LEFT, keyCodes.A],
[Button.RIGHT]: [keyCodes.RIGHT, keyCodes.D],
[Button.SUBMIT]: [keyCodes.ENTER],
[Button.ACTION]: [keyCodes.SPACE, keyCodes.Z],
[Button.CANCEL]: [keyCodes.BACKSPACE, keyCodes.X],
[Button.MENU]: [keyCodes.ESC, keyCodes.M],
[Button.STATS]: [keyCodes.SHIFT, keyCodes.C],
[Button.CYCLE_SHINY]: [keyCodes.R],
[Button.CYCLE_FORM]: [keyCodes.F],
[Button.CYCLE_GENDER]: [keyCodes.G],
[Button.CYCLE_ABILITY]: [keyCodes.E],
[Button.CYCLE_NATURE]: [keyCodes.N],
[Button.CYCLE_VARIANT]: [keyCodes.V],
[Button.SPEED_UP]: [keyCodes.PLUS],
[Button.SLOW_DOWN]: [keyCodes.MINUS]
};
const mobileKeyConfig = {};
for (const b of Utils.getEnumValues(Button)) {
const keys: Phaser.Input.Keyboard.Key[] = [];
if (keyConfig.hasOwnProperty(b)) {
for (let k of keyConfig[b])
keys.push(this.scene.input.keyboard.addKey(k, false));
mobileKeyConfig[Button[b]] = keys[0];
}
this.buttonKeys[b] = keys;
}
initTouchControls(mobileKeyConfig);
this.listenInputKeyboard();
}
/**
* Sets up event listeners for keyboard inputs on all registered keys.
*
* @remarks
* This method iterates over an array of keyboard button rows (`this.buttonKeys`), adding 'down' and 'up'
* event listeners for each key. These listeners handle key press and release actions respectively.
*
* - **Key Down Event**: When a key is pressed down, the method emits an 'input_down' event with the button
* and the source ('keyboard'). It also records the time and state of the key press by calling
* `setLastProcessedMovementTime`.
*
* - **Key Up Event**: When a key is released, the method emits an 'input_up' event similarly, specifying the button
* and source. It then clears the recorded press time and state by calling
* `delLastProcessedMovementTime`.
*
* This setup ensures that each key on the keyboard is monitored for press and release events,
* and that these events are properly communicated within the system.
*/
listenInputKeyboard(): void {
this.buttonKeys.forEach((row, index) => {
for (const key of row) {
key.on('down', () => {
this.lastSource = 'keyboard';
this.events.emit('input_down', {
controller_type: 'keyboard',
button: index,
});
this.setLastProcessedMovementTime(index, 'keyboard');
});
key.on('up', () => {
this.events.emit('input_up', {
controller_type: 'keyboard',
button: index,
});
this.delLastProcessedMovementTime(index);
});
}
});
}
/**
* Retrieves the configuration object for a gamepad based on its identifier. The method identifies specific gamepad models
* based on substrings in the identifier and returns predefined configurations for recognized models.
@ -633,7 +501,7 @@ export class InputsController {
this.interactions[button].pressTime = this.time.now;
this.interactions[button].isPressed = true;
this.interactions[button].source = source;
this.interactions[button].sourceName = sourceName;
this.interactions[button].sourceName = sourceName.toLowerCase();
}
/**
@ -741,24 +609,13 @@ export class InputsController {
}
/**
* Retrieves the active configuration for the currently chosen gamepad.
* It checks if a specific gamepad ID is stored under the chosen gamepad's configurations and returns it.
* Retrieves the active configuration for the currently chosen device.
* It checks if a specific device ID is stored in configurations and returns it.
*
* @returns InterfaceConfig The configuration object for the active gamepad, or null if not set.
*/
getActiveConfig(): InterfaceConfig | null {
if (this.configs[this.chosenGamepad]?.padID) return this.configs[this.chosenGamepad]
return null;
}
/**
* Retrieves the active configuration for the currently chosen gamepad.
* It checks if a specific gamepad ID is stored under the chosen gamepad's configurations and returns it.
*
* @returns InterfaceConfig The configuration object for the active gamepad, or null if not set.
*/
getActiveKeyboardConfig(): InterfaceConfig | null {
if (this.keyboardConfigs[this.chosenKeyboard]?.padID) return this.keyboardConfigs[this.chosenKeyboard]
getActiveConfig(device: Device) {
if (this.configs[this.selectedDevice[device]]?.padID) return this.configs[this.selectedDevice[device]]
return null;
}
@ -769,20 +626,17 @@ export class InputsController {
* @param gamepadName The identifier of the gamepad to configure.
* @param customMappings The custom mapping configuration to apply to the gamepad.
*/
injectConfig(gamepadName: String, customMappings): void {
if (!this.configs[gamepadName]) this.configs[gamepadName] = {};
this.configs[gamepadName].currentKeys = customMappings.currentKeys;
this.configs[gamepadName].icons = customMappings.icons;
}
injectKeyboardConfig(layout: string, customMappings): void {
if (!this.keyboardConfigs[layout]) this.keyboardConfigs[layout] = {};
this.keyboardConfigs[layout].currentKeys = customMappings.currentKeys;
this.keyboardConfigs[layout].icons = customMappings.icons;
injectConfig(selectedDevice: string, mappingConfigs): void {
if (!this.configs[selectedDevice]) this.configs[selectedDevice] = {};
this.configs[selectedDevice].custom = mappingConfigs.custom;
this.configs[selectedDevice].main = mappingConfigs.main;
this.configs[selectedDevice].alt = mappingConfigs.alt;
regenerateIdentifiers(this.configs[selectedDevice]);
}
swapBinding(config, settingName, pressedButton): void {
this.pauseUpdate = true;
swapCurrentKeys(config, settingName, pressedButton)
swap(config, settingName, pressedButton);
setTimeout(() => this.pauseUpdate = false, 500);
}
}

View File

@ -233,8 +233,7 @@ export class GameData {
this.scene = scene;
this.loadSettings();
this.loadGamepadSettings();
this.loadCustomMapping();
this.loadCustomKeyboardMapping();
this.loadMappingConfigs();
this.trainerId = Utils.randInt(65536);
this.secretId = Utils.randInt(65536);
this.starterData = {};
@ -498,45 +497,23 @@ export class GameData {
return true;
}
public saveCustomMapping(gamepadName: string, currentKeys, icons): boolean {
let customMappings: object = {};
if (localStorage.hasOwnProperty('customMapping'))
customMappings = JSON.parse(localStorage.getItem('customMapping'));
customMappings[gamepadName] = {
currentKeys,
icons
};
localStorage.setItem('customMapping', JSON.stringify(customMappings));
public saveMappingConfigs(gamepadName: string, config): boolean {
const key = gamepadName.toLowerCase();
let mappingConfigs: object = {};
if (localStorage.hasOwnProperty('mappingConfigs'))
mappingConfigs = JSON.parse(localStorage.getItem('mappingConfigs'));
if (!mappingConfigs[key]) mappingConfigs[key] = {};
mappingConfigs[key].custom = config.custom;
localStorage.setItem('mappingConfigs', JSON.stringify(mappingConfigs));
return true;
}
public saveCustomKeyboardMapping(keyboardLayout: string, currentKeys, icons): boolean {
let customKeyboardMappings: object = {};
if (localStorage.hasOwnProperty('customKeyboardMappings'))
customKeyboardMappings = JSON.parse(localStorage.getItem('customKeyboardMappings'));
customKeyboardMappings[keyboardLayout] = {
currentKeys,
icons
};
localStorage.setItem('customKeyboardMappings', JSON.stringify(customKeyboardMappings));
return true;
}
public loadCustomKeyboardMapping(): boolean {
if (!localStorage.hasOwnProperty('customKeyboardMappings'))
public loadMappingConfigs(): boolean {
if (!localStorage.hasOwnProperty('mappingConfigs'))
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 {
if (!localStorage.hasOwnProperty('customMapping'))
return false;
const customMappings = JSON.parse(localStorage.getItem('customMapping'));
for (const key of Object.keys(customMappings))
this.scene.inputController.injectConfig(key, customMappings[key]);
const mappingConfigs = JSON.parse(localStorage.getItem('mappingConfigs'));
for (const key of Object.keys(mappingConfigs))
this.scene.inputController.injectConfig(key, mappingConfigs[key]);
}

View File

@ -8,6 +8,10 @@ import {Button} from "../enums/buttons";
export enum SettingGamepad {
Default_Controller = "DEFAULT_CONTROLLER",
Gamepad_Support = "GAMEPAD_SUPPORT",
Button_Up = "BUTTON_UP",
Button_Down = "BUTTON_DOWN",
Button_Left = "BUTTON_LEFT",
Button_Right = "BUTTON_RIGHT",
Button_Action = "BUTTON_ACTION",
Button_Cancel = "BUTTON_CANCEL",
Button_Menu = "BUTTON_MENU",
@ -26,6 +30,10 @@ export enum SettingGamepad {
export const settingGamepadOptions: SettingOptions = {
[SettingGamepad.Default_Controller]: ['Default', 'Change'],
[SettingGamepad.Gamepad_Support]: ['Auto', 'Disabled'],
[SettingGamepad.Button_Up]: [`KEY ${Button.UP.toString()}`, 'Change'],
[SettingGamepad.Button_Down]: [`KEY ${Button.DOWN.toString()}`, 'Change'],
[SettingGamepad.Button_Left]: [`KEY ${Button.LEFT.toString()}`, 'Change'],
[SettingGamepad.Button_Right]: [`KEY ${Button.RIGHT.toString()}`, 'Change'],
[SettingGamepad.Button_Action]: [`KEY ${Button.ACTION.toString()}`, 'Change'],
[SettingGamepad.Button_Cancel]: [`KEY ${Button.CANCEL.toString()}`, 'Change'],
[SettingGamepad.Button_Menu]: [`KEY ${Button.MENU.toString()}`, 'Change'],
@ -44,6 +52,10 @@ export const settingGamepadOptions: SettingOptions = {
export const settingGamepadDefaults: SettingDefaults = {
[SettingGamepad.Default_Controller]: 0,
[SettingGamepad.Gamepad_Support]: 0,
[SettingGamepad.Button_Up]: 0,
[SettingGamepad.Button_Down]: 0,
[SettingGamepad.Button_Left]: 0,
[SettingGamepad.Button_Right]: 0,
[SettingGamepad.Button_Action]: 0,
[SettingGamepad.Button_Cancel]: 0,
[SettingGamepad.Button_Menu]: 0,

View File

@ -1,97 +0,0 @@
import {Button} from "#app/enums/buttons";
export enum SettingInterfaceGamepad {
Default_Controller = "DEFAULT_CONTROLLER",
Gamepad_Support = "GAMEPAD_SUPPORT",
Button_Action = "BUTTON_ACTION",
Button_Cancel = "BUTTON_CANCEL",
Button_Menu = "BUTTON_MENU",
Button_Stats = "BUTTON_STATS",
Button_Cycle_Form = "BUTTON_CYCLE_FORM",
Button_Cycle_Shiny = "BUTTON_CYCLE_SHINY",
Button_Cycle_Gender = "BUTTON_CYCLE_GENDER",
Button_Cycle_Ability = "BUTTON_CYCLE_ABILITY",
Button_Cycle_Nature = "BUTTON_CYCLE_NATURE",
Button_Cycle_Variant = "BUTTON_CYCLE_VARIANT",
Button_Speed_Up = "BUTTON_SPEED_UP",
Button_Slow_Down = "BUTTON_SLOW_DOWN",
Button_Submit = "BUTTON_SUBMIT",
}
/**
* Generic pad mapping
*/
const pad_xbox360 = {
padID: 'Xbox 360 controller (XInput STANDARD GAMEPAD)',
padType: 'xbox',
gamepadMapping: {
RC_S: 0,
RC_E: 1,
RC_W: 2,
RC_N: 3,
START: 9,
SELECT: 8,
LB: 4,
RB: 5,
LT: 6,
RT: 7,
LS: 10,
RS: 11,
LC_N: 12,
LC_S: 13,
LC_W: 14,
LC_E: 15
},
icons: {
RC_S: "T_X_A_Color_Alt.png",
RC_E: "T_X_B_Color_Alt.png",
RC_W: "T_X_X_Color_Alt.png",
RC_N: "T_X_Y_Color_Alt.png",
START: "T_X_X_Alt.png",
SELECT: "T_X_Share_Alt.png",
LB: "T_X_LB_Alt.png",
RB: "T_X_RB_Alt.png",
LT: "T_X_LT_Alt.png",
RT: "T_X_RT_Alt.png",
LS: "T_X_Left_Stick_Click_Alt_Alt.png",
RS: "T_X_Right_Stick_Click_Alt_Alt.png",
LC_N: "T_X_Dpad_Up_Alt.png",
LC_S: "T_X_Dpad_Down_Alt.png",
LC_W: "T_X_Dpad_Left_Alt.png",
LC_E: "T_X_Dpad_Right_Alt.png",
},
setting: {
RC_S: SettingInterfaceGamepad.Button_Action,
RC_E: SettingInterfaceGamepad.Button_Cancel,
RC_W: SettingInterfaceGamepad.Button_Cycle_Nature,
RC_N: SettingInterfaceGamepad.Button_Cycle_Variant,
START: SettingInterfaceGamepad.Button_Menu,
SELECT: SettingInterfaceGamepad.Button_Stats,
LB: SettingInterfaceGamepad.Button_Cycle_Form,
RB: SettingInterfaceGamepad.Button_Cycle_Shiny,
LT: SettingInterfaceGamepad.Button_Cycle_Gender,
RT: SettingInterfaceGamepad.Button_Cycle_Ability,
LS: SettingInterfaceGamepad.Button_Speed_Up,
RS: SettingInterfaceGamepad.Button_Slow_Down,
},
default: {
RC_S: Button.ACTION, //5
RC_E: Button.CANCEL, // 6
RC_W: Button.CYCLE_NATURE,
RC_N: Button.CYCLE_VARIANT, //14
START: Button.MENU, //7
SELECT: Button.STATS, //8
LB: Button.CYCLE_FORM,
RB: Button.CYCLE_SHINY,
LT: Button.CYCLE_GENDER,
RT: Button.CYCLE_ABILITY,
LS: Button.SPEED_UP,
RS: Button.SLOW_DOWN,
LC_N: Button.UP,
LC_S: Button.DOWN,
LC_W: Button.LEFT,
LC_E: Button.RIGHT,
}
};
export default pad_xbox360;

View File

@ -1,6 +1,6 @@
import {Button} from "#app/enums/buttons";
export enum SettingInterfaceKeyboard {
export enum SettingInterface {
Default_Layout = "DEFAULT_LAYOUT",
Button_Up = "BUTTON_UP",
Alt_Button_Up = "ALT_BUTTON_UP",
@ -202,80 +202,79 @@ const cfg_keyboard_azerty = {
KEY_BACKSPACE: "T_Backspace_Alt_Key_Dark.png",
KEY_ALT: "T_Alt_Key_Dark.png"
},
setting: {
KEY_ARROW_UP: SettingInterfaceKeyboard.Button_Up,
KEY_ARROW_DOWN: SettingInterfaceKeyboard.Button_Down,
KEY_ARROW_LEFT: SettingInterfaceKeyboard.Button_Left,
KEY_ARROW_RIGHT: SettingInterfaceKeyboard.Button_Right,
KEY_ENTER: SettingInterfaceKeyboard.Button_Submit,
KEY_SPACE: SettingInterfaceKeyboard.Button_Action,
KEY_BACKSPACE: SettingInterfaceKeyboard.Button_Cancel,
KEY_ESC: SettingInterfaceKeyboard.Button_Menu,
KEY_C: SettingInterfaceKeyboard.Button_Stats,
KEY_R: SettingInterfaceKeyboard.Button_Cycle_Shiny,
KEY_F: SettingInterfaceKeyboard.Button_Cycle_Form,
KEY_G: SettingInterfaceKeyboard.Button_Cycle_Gender,
KEY_E: SettingInterfaceKeyboard.Button_Cycle_Ability,
KEY_N: SettingInterfaceKeyboard.Button_Cycle_Nature,
KEY_V: SettingInterfaceKeyboard.Button_Cycle_Variant,
KEY_PLUS: SettingInterfaceKeyboard.Button_Speed_Up,
KEY_MINUS: SettingInterfaceKeyboard.Button_Slow_Down,
KEY_Z: SettingInterfaceKeyboard.Alt_Button_Up,
KEY_S: SettingInterfaceKeyboard.Alt_Button_Down,
KEY_Q: SettingInterfaceKeyboard.Alt_Button_Left,
KEY_D: SettingInterfaceKeyboard.Alt_Button_Right,
KEY_CTRL: SettingInterfaceKeyboard.Alt_Button_Submit,
KEY_W: SettingInterfaceKeyboard.Alt_Button_Action,
KEY_X: SettingInterfaceKeyboard.Alt_Button_Cancel,
KEY_TAB: SettingInterfaceKeyboard.Alt_Button_Menu,
KEY_SHIFT: SettingInterfaceKeyboard.Alt_Button_Stats,
KEY_P: SettingInterfaceKeyboard.Alt_Button_Cycle_Shiny,
KEY_M: SettingInterfaceKeyboard.Alt_Button_Cycle_Form,
KEY_O: SettingInterfaceKeyboard.Alt_Button_Cycle_Gender,
KEY_L: SettingInterfaceKeyboard.Alt_Button_Cycle_Ability,
KEY_I: SettingInterfaceKeyboard.Alt_Button_Cycle_Nature,
KEY_K: SettingInterfaceKeyboard.Alt_Button_Cycle_Variant,
KEY_PAGE_UP: SettingInterfaceKeyboard.Alt_Button_Speed_Up,
KEY_PAGE_DOWN: SettingInterfaceKeyboard.Alt_Button_Slow_Down,
settings: {
[SettingInterface.Button_Up]: Button.UP,
[SettingInterface.Button_Down]: Button.DOWN,
[SettingInterface.Button_Left]: Button.LEFT,
[SettingInterface.Button_Right]: Button.RIGHT,
[SettingInterface.Button_Submit]: Button.SUBMIT,
[SettingInterface.Button_Action]: Button.ACTION,
[SettingInterface.Button_Cancel]: Button.CANCEL,
[SettingInterface.Button_Menu]: Button.MENU,
[SettingInterface.Button_Stats]: Button.STATS,
[SettingInterface.Button_Cycle_Shiny]: Button.CYCLE_SHINY,
[SettingInterface.Button_Cycle_Form]: Button.CYCLE_FORM,
[SettingInterface.Button_Cycle_Gender]: Button.CYCLE_GENDER,
[SettingInterface.Button_Cycle_Ability]: Button.CYCLE_ABILITY,
[SettingInterface.Button_Cycle_Nature]: Button.CYCLE_NATURE,
[SettingInterface.Button_Cycle_Variant]: Button.CYCLE_VARIANT,
[SettingInterface.Button_Speed_Up]: Button.SPEED_UP,
[SettingInterface.Button_Slow_Down]: Button.SLOW_DOWN,
[SettingInterface.Alt_Button_Up]: Button.UP,
[SettingInterface.Alt_Button_Down]: Button.DOWN,
[SettingInterface.Alt_Button_Left]: Button.LEFT,
[SettingInterface.Alt_Button_Right]: Button.RIGHT,
[SettingInterface.Alt_Button_Submit]: Button.SUBMIT,
[SettingInterface.Alt_Button_Action]: Button.ACTION,
[SettingInterface.Alt_Button_Cancel]: Button.CANCEL,
[SettingInterface.Alt_Button_Menu]: Button.MENU,
[SettingInterface.Alt_Button_Stats]: Button.STATS,
[SettingInterface.Alt_Button_Cycle_Shiny]: Button.CYCLE_SHINY,
[SettingInterface.Alt_Button_Cycle_Form]: Button.CYCLE_FORM,
[SettingInterface.Alt_Button_Cycle_Gender]: Button.CYCLE_GENDER,
[SettingInterface.Alt_Button_Cycle_Ability]: Button.CYCLE_ABILITY,
[SettingInterface.Alt_Button_Cycle_Nature]: Button.CYCLE_NATURE,
[SettingInterface.Alt_Button_Cycle_Variant]: Button.CYCLE_VARIANT,
[SettingInterface.Alt_Button_Speed_Up]: Button.SPEED_UP,
[SettingInterface.Alt_Button_Slow_Down]: Button.SLOW_DOWN,
},
default: {
KEY_ARROW_UP: Button.UP,
KEY_ARROW_DOWN: Button.DOWN,
KEY_ARROW_LEFT: Button.LEFT,
KEY_ARROW_RIGHT: Button.RIGHT,
KEY_ENTER: Button.SUBMIT,
KEY_SPACE: Button.ACTION,
KEY_BACKSPACE: Button.CANCEL,
KEY_ESC: Button.MENU,
KEY_C: Button.STATS,
KEY_R: Button.CYCLE_SHINY,
KEY_F: Button.CYCLE_FORM,
KEY_G: Button.CYCLE_GENDER,
KEY_E: Button.CYCLE_ABILITY,
KEY_N: Button.CYCLE_NATURE,
KEY_V: Button.CYCLE_VARIANT,
KEY_PLUS: Button.SPEED_UP,
KEY_MINUS: Button.SLOW_DOWN,
KEY_ARROW_UP: SettingInterface.Button_Up,
KEY_ARROW_DOWN: SettingInterface.Button_Down,
KEY_ARROW_LEFT: SettingInterface.Button_Left,
KEY_ARROW_RIGHT: SettingInterface.Button_Right,
KEY_ENTER: SettingInterface.Button_Submit,
KEY_SPACE: SettingInterface.Button_Action,
KEY_BACKSPACE: SettingInterface.Button_Cancel,
KEY_ESC: SettingInterface.Button_Menu,
KEY_C: SettingInterface.Button_Stats,
KEY_R: SettingInterface.Button_Cycle_Shiny,
KEY_F: SettingInterface.Button_Cycle_Form,
KEY_G: SettingInterface.Button_Cycle_Gender,
KEY_E: SettingInterface.Button_Cycle_Ability,
KEY_N: SettingInterface.Button_Cycle_Nature,
KEY_V: SettingInterface.Button_Cycle_Variant,
KEY_PLUS: SettingInterface.Button_Speed_Up,
KEY_MINUS: SettingInterface.Button_Slow_Down,
KEY_A: -1,
KEY_B: -1,
KEY_D: Button.RIGHT,
KEY_D: SettingInterface.Alt_Button_Right,
KEY_H: -1,
KEY_I: Button.CYCLE_NATURE,
KEY_I: SettingInterface.Alt_Button_Cycle_Nature,
KEY_J: -1,
KEY_K: Button.CYCLE_VARIANT,
KEY_L: Button.CYCLE_ABILITY,
KEY_M: Button.CYCLE_FORM,
KEY_O: Button.CYCLE_GENDER,
KEY_P: Button.CYCLE_SHINY,
KEY_Q: Button.LEFT,
KEY_S: Button.DOWN,
KEY_K: SettingInterface.Alt_Button_Cycle_Variant,
KEY_L: SettingInterface.Alt_Button_Cycle_Ability,
KEY_M: SettingInterface.Alt_Button_Cycle_Form,
KEY_O: SettingInterface.Alt_Button_Cycle_Gender,
KEY_P: SettingInterface.Alt_Button_Cycle_Shiny,
KEY_Q: SettingInterface.Alt_Button_Left,
KEY_S: SettingInterface.Alt_Button_Down,
KEY_T: -1,
KEY_U: -1,
KEY_W: Button.ACTION,
KEY_X: Button.CANCEL,
KEY_W: SettingInterface.Alt_Button_Action,
KEY_X: SettingInterface.Alt_Button_Cancel,
KEY_Y: -1,
KEY_Z: Button.UP,
KEY_Z: SettingInterface.Alt_Button_Up,
KEY_0: -1,
KEY_1: -1,
KEY_2: -1,
@ -286,7 +285,7 @@ const cfg_keyboard_azerty = {
KEY_7: -1,
KEY_8: -1,
KEY_9: -1,
KEY_CTRL: Button.SUBMIT,
KEY_CTRL: SettingInterface.Alt_Button_Submit,
KEY_DEL: -1,
KEY_END: -1,
KEY_F1: -1,
@ -303,17 +302,19 @@ const cfg_keyboard_azerty = {
KEY_F12: -1,
KEY_HOME: -1,
KEY_INSERT: -1,
KEY_PAGE_DOWN: Button.SLOW_DOWN,
KEY_PAGE_UP: Button.SPEED_UP,
KEY_PAGE_DOWN: SettingInterface.Alt_Button_Slow_Down,
KEY_PAGE_UP: SettingInterface.Alt_Button_Speed_Up,
KEY_QUOTATION: -1,
KEY_SHIFT: Button.STATS,
KEY_TAB: Button.MENU,
KEY_SHIFT: SettingInterface.Alt_Button_Stats,
KEY_TAB: SettingInterface.Alt_Button_Menu,
KEY_TILDE: -1,
KEY_LEFT_BRACKET: -1,
KEY_RIGHT_BRACKET: -1,
KEY_SEMICOLON: -1,
KEY_ALT: -1
}
},
main: [],
alt: [],
};
export default cfg_keyboard_azerty;

View File

@ -1,257 +0,0 @@
import {beforeEach, expect, describe, it} from "vitest";
import cfg_gamepad_example, {SettingInterfaceGamepad} from "./cfg_gamepad_example";
import {
getIconWithPressedButton,
getIconWithSettingName,
getKeyAndActionFromCurrentKeysWithSettingName,
getKeyForSettingName,
getKeyFromMapping,
getKeyWithAction, regenerateCustom,
reloadCurrentKeys,
swapCurrentKeys,
} from "#app/configs/gamepad-utils";
import {Button} from "#app/enums/buttons";
function deepCopy(config) {
return JSON.parse(JSON.stringify(config));
}
describe('Test Keyboard', () => {
let config;
beforeEach(() => {
const temp = {...cfg_gamepad_example}
config = deepCopy(temp);
config.custom = {...config.default}
config.ogIcons = {...config.icons}
reloadCurrentKeys(config);
});
it('Check if config is loaded', () => {
expect(config).not.toBeNull();
});
it('Check key for setting name', () => {
const settingName = SettingInterfaceGamepad.Button_Action;
const key = getKeyForSettingName(config, settingName);
expect(config.custom[key]).toEqual(Button.ACTION);
});
it('Check key for Keyboard KeyCode', () => {
const key = getKeyFromMapping(config, 0);
expect(config.custom[key]).toEqual(Button.ACTION);
});
it('Check key for currenly Assigned to action not alt', () => {
const key = getKeyWithAction(config, Button.ACTION, false);
expect(key).toEqual('RC_S');
});
it('Check key for currenly Assigned to setting name', () => {
const settingName = SettingInterfaceGamepad.Button_Action;
const { key } = getKeyAndActionFromCurrentKeysWithSettingName(config, settingName);
expect(key).toEqual('RC_S');
});
it('Check icon for currenly Assigned to key code', () => {
const icon = getIconWithPressedButton(config, 0);
expect(icon).toEqual('T_X_A_Color_Alt.png');
});
it('Check icon for currenly Assigned to setting name', () => {
const settingName = SettingInterfaceGamepad.Button_Action;
const icon = getIconWithSettingName(config, settingName);
expect(icon).toEqual('T_X_A_Color_Alt.png');
});
it('Check if current keys return the same', () => {
const settingNameA = SettingInterfaceGamepad.Button_Action;
const keyA = getKeyForSettingName(config, settingNameA);
const action = config.custom[keyA];
expect(keyA).toEqual("RC_S");
expect(action).toEqual(Button.ACTION);
expect(config.currentKeys[settingNameA].key).toEqual(keyA);
expect(config.currentKeys[settingNameA].action).toEqual(action);
});
it('Check if new swap is working', () => {
const settingNameA = SettingInterfaceGamepad.Button_Action;
swapCurrentKeys(config, settingNameA, 1);
expect(config.currentKeys[settingNameA].key).toEqual("RC_S");
expect(config.currentKeys[settingNameA].action).toEqual(Button.CANCEL);
});
it('Check if new double swap is working', () => {
const settingNameA = SettingInterfaceGamepad.Button_Action;
swapCurrentKeys(config, settingNameA, 1);
expect(config.currentKeys[settingNameA].key).toEqual("RC_S");
expect(config.currentKeys[settingNameA].action).toEqual(Button.CANCEL);
swapCurrentKeys(config, settingNameA, 2);
expect(config.currentKeys[settingNameA].key).toEqual("RC_S");
expect(config.currentKeys[settingNameA].action).toEqual(Button.CYCLE_NATURE);
});
it('Check if new triple swap is working', () => {
const settingNameA = SettingInterfaceGamepad.Button_Action;
const settingNameB = SettingInterfaceGamepad.Button_Cancel;
const settingNameC = SettingInterfaceGamepad.Button_Cycle_Nature;
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].key).toEqual("RC_E");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].action).toEqual(Button.CANCEL);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cycle_Nature].key).toEqual("RC_W");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cycle_Nature].action).toEqual(Button.CYCLE_NATURE);
let iconA = getIconWithSettingName(config, settingNameA);
let iconB = getIconWithSettingName(config, settingNameB);
let iconC = getIconWithSettingName(config, settingNameC);
expect(iconA).toEqual('T_X_A_Color_Alt.png');
expect(iconB).toEqual('T_X_B_Color_Alt.png');
expect(iconC).toEqual('T_X_X_Color_Alt.png');
swapCurrentKeys(config, SettingInterfaceGamepad.Button_Action, 1); // cancel
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.CANCEL);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].key).toEqual("RC_E");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cycle_Nature].key).toEqual("RC_W");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cycle_Nature].action).toEqual(Button.CYCLE_NATURE);
iconA = getIconWithSettingName(config, settingNameA);
iconB = getIconWithSettingName(config, settingNameB);
iconC = getIconWithSettingName(config, settingNameC);
expect(iconA).toEqual('T_X_B_Color_Alt.png');
expect(iconB).toEqual('T_X_A_Color_Alt.png');
expect(iconC).toEqual('T_X_X_Color_Alt.png');
swapCurrentKeys(config, SettingInterfaceGamepad.Button_Cancel, 2); // cycle nature
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.CANCEL); // 6
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].key).toEqual("RC_E");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].action).toEqual(Button.CYCLE_NATURE); // 13
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cycle_Nature].key).toEqual("RC_W");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cycle_Nature].action).toEqual(Button.ACTION); // 5
iconA = getIconWithSettingName(config, settingNameA);
iconB = getIconWithSettingName(config, settingNameB);
iconC = getIconWithSettingName(config, settingNameC);
expect(iconA).toEqual('T_X_B_Color_Alt.png');
expect(iconB).toEqual('T_X_X_Color_Alt.png');
expect(iconC).toEqual('T_X_A_Color_Alt.png');
swapCurrentKeys(config, SettingInterfaceGamepad.Button_Cycle_Nature, 1); // cancel
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.CANCEL);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].key).toEqual("RC_E");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cycle_Nature].key).toEqual("RC_W");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cycle_Nature].action).toEqual(Button.CYCLE_NATURE);
iconA = getIconWithSettingName(config, settingNameA);
iconB = getIconWithSettingName(config, settingNameB);
iconC = getIconWithSettingName(config, settingNameC);
expect(iconA).toEqual('T_X_B_Color_Alt.png');
expect(iconB).toEqual('T_X_A_Color_Alt.png');
expect(iconC).toEqual('T_X_X_Color_Alt.png');
expect(config.ogIcons["RC_S"]).toEqual("T_X_A_Color_Alt.png")
expect(config.ogIcons["RC_E"]).toEqual("T_X_B_Color_Alt.png")
expect(config.ogIcons["RC_N"]).toEqual("T_X_Y_Color_Alt.png")
expect(config.ogIcons["RC_W"]).toEqual("T_X_X_Color_Alt.png")
});
it('Check 2 swap back to back', () => {
swapCurrentKeys(config, SettingInterfaceGamepad.Button_Action, 1); // cancel
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.CANCEL);
let iconA = getIconWithSettingName(config, SettingInterfaceGamepad.Button_Action);
expect(iconA).toEqual('T_X_B_Color_Alt.png');
swapCurrentKeys(config, SettingInterfaceGamepad.Button_Action, 0); // cancel
let iconB = getIconWithSettingName(config, SettingInterfaceGamepad.Button_Action);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.ACTION);
expect(iconB).toEqual('T_X_A_Color_Alt.png');
});
it('Check 4 swap back to back', () => {
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].icon).toEqual('T_X_A_Color_Alt.png');
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].key).toEqual("RC_E");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].action).toEqual(Button.CANCEL);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].icon).toEqual('T_X_B_Color_Alt.png');
swapCurrentKeys(config, SettingInterfaceGamepad.Button_Action, 1); // cancel
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.CANCEL);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].icon).toEqual('T_X_B_Color_Alt.png');
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].key).toEqual("RC_E");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].icon).toEqual('T_X_A_Color_Alt.png');
swapCurrentKeys(config, SettingInterfaceGamepad.Button_Action, 0); // cancel
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].icon).toEqual('T_X_A_Color_Alt.png');
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].key).toEqual("RC_E");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].action).toEqual(Button.CANCEL);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].icon).toEqual('T_X_B_Color_Alt.png');
swapCurrentKeys(config, SettingInterfaceGamepad.Button_Action, 1); // cancel
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.CANCEL);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].icon).toEqual('T_X_B_Color_Alt.png');
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].key).toEqual("RC_E");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].icon).toEqual('T_X_A_Color_Alt.png');
swapCurrentKeys(config, SettingInterfaceGamepad.Button_Action, 0); // cancel
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].icon).toEqual('T_X_A_Color_Alt.png');
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].key).toEqual("RC_E");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].action).toEqual(Button.CANCEL);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].icon).toEqual('T_X_B_Color_Alt.png');
});
it('Custom scenario: B icon duplicate', () => {
config.currentKeys[SettingInterfaceGamepad.Button_Action] = {
"key": "RC_S",
"action": 6,
"icon": "T_X_B_Color_Alt.png",
"from": {
"key": "RC_S",
"action": 5,
"icon": "T_X_A_Color_Alt.png"
}
};
config.currentKeys[SettingInterfaceGamepad.Button_Cancel] = {
"key": "RC_E",
"action": 5,
"icon": "T_X_A_Color_Alt.png",
"from": {
"key": "RC_E",
"action": 6,
"icon": "T_X_B_Color_Alt.png"
}
};
regenerateCustom(config);
swapCurrentKeys(config, SettingInterfaceGamepad.Button_Action, 0); // cancel
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].key).toEqual("RC_S");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Action].icon).toEqual('T_X_A_Color_Alt.png');
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].key).toEqual("RC_E");
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].action).toEqual(Button.CANCEL);
expect(config.currentKeys[SettingInterfaceGamepad.Button_Cancel].icon).toEqual('T_X_B_Color_Alt.png');
})
});

View File

@ -0,0 +1,44 @@
import {getSettingNameWithKeycode} from "#app/configs/configHandler";
import {expect} from "vitest";
import {SettingInterface} from "#app/test/cfg_keyboard.example";
export class InGameManip {
private config;
private keycode;
private settingName;
private icon;
constructor(config) {
this.config = config;
this.keycode = null;
this.settingName = null;
this.icon = null;
}
whenWePressOnKeyboard(keycode) {
this.keycode = Phaser.Input.Keyboard.KeyCodes[keycode.toUpperCase()];
return this;
}
nothingShouldHappen() {
const settingName = getSettingNameWithKeycode(this.config, this.keycode);
expect(settingName).toEqual(-1);
return this;
}
normalizeSettingNameString(input) {
// Convert the input string to lower case
const lowerCasedInput = input.toLowerCase();
// Replace underscores with spaces, capitalize the first letter of each word, and join them back with underscores
const words = lowerCasedInput.split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1));
const result = words.join('_');
return result;
}
weShouldTriggerTheButton(settingName) {
this.settingName = SettingInterface[this.normalizeSettingNameString(settingName)];
expect(getSettingNameWithKeycode(this.config, this.keycode)).toEqual(this.settingName);
return this;
}
}

View File

@ -0,0 +1,96 @@
import {SettingInterface} from "#app/test/cfg_keyboard.example";
import {expect} from "vitest";
import {Button} from "#app/enums/buttons";
import {
deleteBind,
getIconWithKey,
getIconWithKeycode,
getIconWithSettingName,
getKeyWithKeycode, getKeyWithSettingName, isAlreadyBinded, swap
} from "#app/configs/configHandler";
export class MenuManip {
private config;
private settingName;
private keycode;
private icon;
private iconDisplayed;
private specialCaseIcon;
constructor(config) {
this.config = config;
this.settingName = null;
this.icon = null;
this.iconDisplayed = null;
this.specialCaseIcon = null;
}
convertNameToButtonString(input) {
// Check if the input starts with "Alt_Button"
if (input.startsWith("Alt_Button")) {
// Return the last part in uppercase
return input.split('_').pop().toUpperCase();
}
// Split the input string by underscore
const parts = input.split('_');
// Skip the first part and join the rest with an underscore
const result = parts.slice(1).map(part => part.toUpperCase()).join('_');
return result;
}
whenCursorIsOnSetting(settingName) {
this.settingName = SettingInterface[settingName];
const buttonName = this.convertNameToButtonString(settingName);
expect(this.config.settings[this.settingName]).toEqual(Button[buttonName]);
return this;
}
iconDisplayedIs(icon) {
this.iconDisplayed = this.config.icons[icon];
expect(getIconWithSettingName(this.config, this.settingName)).toEqual(this.iconDisplayed);
return this;
}
thereShouldBeNoIconAnymore() {
const icon = getIconWithSettingName(this.config, this.settingName);
expect(icon === undefined).toEqual(true);
return this;
}
thereShouldBeNoIcon() {
return this.thereShouldBeNoIconAnymore();
}
weWantThisBindInstead(keycode) {
this.keycode = Phaser.Input.Keyboard.KeyCodes[keycode];
const icon = getIconWithKeycode(this.config, this.keycode);
const key = getKeyWithKeycode(this.config, this.keycode);
const _keys = key.toLowerCase().split("_");
const iconIdentifier = _keys[_keys.length-1];
expect(icon.toLowerCase().includes(iconIdentifier)).toEqual(true);
return this;
}
OopsSpecialCaseIcon(icon) {
this.specialCaseIcon = this.config.icons[icon];
const potentialExistingKey = isAlreadyBinded(this.config, this.keycode, this.settingName);
const prev_key = potentialExistingKey || getKeyWithSettingName(this.config, this.settingName);
expect(getIconWithKey(this.config, prev_key)).toEqual(this.specialCaseIcon);
return this;
}
whenWeDelete(settingName?: string) {
this.settingName = SettingInterface[settingName] || this.settingName;
const key = getKeyWithSettingName(this.config, this.settingName);
deleteBind(this.config, this.settingName);
expect(this.config.custom[key]).toEqual(-1);
return this;
}
confirm() {
swap(this.config, this.settingName, this.keycode);
}
}

View File

@ -1,770 +0,0 @@
import {beforeEach, expect, describe, it} from "vitest";
import cfg_keyboard_example, {SettingInterfaceKeyboard} from "#app/test/cfg_keyboard_example";
import {
deleteBind,
getIconWithPressedButton,
getIconWithSettingName,
getKeyAndActionFromCurrentKeysWithSettingName,
getKeyForSettingName,
getKeyFromMapping,
getKeyWithAction, regenerateCustom,
reloadCurrentKeys,
swapCurrentKeys,
} from "#app/configs/gamepad-utils";
import {Button} from "#app/enums/buttons";
function deepCopy(config) {
return JSON.parse(JSON.stringify(config));
}
describe('Test Keyboard', () => {
let config;
beforeEach(() => {
config = deepCopy(cfg_keyboard_example);
config.custom = {...config.default}
config.ogIcons = {...config.icons}
reloadCurrentKeys(config);
});
it('Check if config is loaded', () => {
expect(config).not.toBeNull();
});
it('Check key for setting name', () => {
const settingName = SettingInterfaceKeyboard.Button_Left;
const key = getKeyForSettingName(config, settingName);
expect(config.custom[key]).toEqual(Button.LEFT);
});
it('Check key for Keyboard KeyCode', () => {
const key = getKeyFromMapping(config, Phaser.Input.Keyboard.KeyCodes.LEFT);
expect(config.custom[key]).toEqual(Button.LEFT);
});
it('Check key for currenly Assigned to action not alt', () => {
const key = getKeyWithAction(config, Button.LEFT, false);
expect(key).toEqual('KEY_ARROW_LEFT');
});
it('Check key for currenly Assigned to action alt', () => {
const key = getKeyWithAction(config, Button.LEFT, true);
expect(key).toEqual('KEY_Q');
});
it('Check key for currenly Assigned to setting name', () => {
const settingName = SettingInterfaceKeyboard.Button_Left;
const {key} = getKeyAndActionFromCurrentKeysWithSettingName(config, settingName);
expect(key).toEqual('KEY_ARROW_LEFT');
});
it('Check key for currenly Assigned to setting name alt', () => {
const settingName = SettingInterfaceKeyboard.Alt_Button_Left;
const {key} = getKeyAndActionFromCurrentKeysWithSettingName(config, settingName);
expect(key).toEqual('KEY_Q');
});
it('Check icon for currenly Assigned to key code', () => {
const icon = getIconWithPressedButton(config, Phaser.Input.Keyboard.KeyCodes.LEFT);
expect(icon).toEqual('T_Left_Key_Dark.png');
});
it('Check icon for currenly Assigned to key code alt', () => {
const icon = getIconWithPressedButton(config, Phaser.Input.Keyboard.KeyCodes.Q);
expect(icon).toEqual('T_Q_Key_Dark.png');
});
it('Check icon for currenly Assigned to setting name', () => {
const settingName = SettingInterfaceKeyboard.Button_Left;
const icon = getIconWithSettingName(config, settingName);
expect(icon).toEqual('T_Left_Key_Dark.png');
});
it('Check icon for currenly Assigned to setting name alt', () => {
const settingName = SettingInterfaceKeyboard.Alt_Button_Left;
const icon = getIconWithSettingName(config, settingName);
expect(icon).toEqual('T_Q_Key_Dark.png');
});
it('Check if current keys return the same', () => {
const settingNameA = SettingInterfaceKeyboard.Button_Left;
const keyA = getKeyForSettingName(config, settingNameA);
const action = config.custom[keyA];
expect(keyA).toEqual("KEY_ARROW_LEFT");
expect(action).toEqual(Button.LEFT);
expect(config.currentKeys[settingNameA].key).toEqual(keyA);
expect(config.currentKeys[settingNameA].action).toEqual(action);
});
it('Check if new swap is working', () => {
const settingNameA = SettingInterfaceKeyboard.Button_Left;
swapCurrentKeys(config, settingNameA, Phaser.Input.Keyboard.KeyCodes.RIGHT);
expect(config.currentKeys[settingNameA].key).toEqual("KEY_ARROW_LEFT");
expect(config.currentKeys[settingNameA].action).toEqual(Button.RIGHT);
});
it('Check if new double swap is working', () => {
const settingNameA = SettingInterfaceKeyboard.Button_Left;
swapCurrentKeys(config, settingNameA, Phaser.Input.Keyboard.KeyCodes.RIGHT);
expect(config.currentKeys[settingNameA].key).toEqual("KEY_ARROW_LEFT");
expect(config.currentKeys[settingNameA].action).toEqual(Button.RIGHT);
swapCurrentKeys(config, settingNameA, Phaser.Input.Keyboard.KeyCodes.UP);
expect(config.currentKeys[settingNameA].key).toEqual("KEY_ARROW_LEFT");
expect(config.currentKeys[settingNameA].action).toEqual(Button.UP);
});
it('Check if new triple swap is working', () => {
const settingNameA = SettingInterfaceKeyboard.Button_Left;
const settingNameB = SettingInterfaceKeyboard.Button_Action;
const settingNameC = SettingInterfaceKeyboard.Button_Right;
const settingNameD = SettingInterfaceKeyboard.Button_Up;
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].key).toEqual("KEY_ARROW_LEFT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].action).toEqual(Button.LEFT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Action].key).toEqual("KEY_SPACE");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Action].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.UP);
let iconA = getIconWithSettingName(config, settingNameA);
let iconB = getIconWithSettingName(config, settingNameB);
let iconC = getIconWithSettingName(config, settingNameC);
let iconD = getIconWithSettingName(config, settingNameD);
expect(iconA).toEqual('T_Left_Key_Dark.png');
expect(iconB).toEqual('T_Space_Key_Dark.png');
expect(iconC).toEqual('T_Right_Key_Dark.png');
expect(iconD).toEqual('T_Up_Key_Dark.png');
swapCurrentKeys(config, SettingInterfaceKeyboard.Button_Left, Phaser.Input.Keyboard.KeyCodes.RIGHT); // left->RIGHT, right->LEFT
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].key).toEqual("KEY_ARROW_LEFT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Action].key).toEqual("KEY_SPACE");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Action].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.LEFT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.UP);
iconA = getIconWithSettingName(config, settingNameA);
iconB = getIconWithSettingName(config, settingNameB);
iconC = getIconWithSettingName(config, settingNameC);
iconD = getIconWithSettingName(config, settingNameD);
expect(iconA).toEqual('T_Right_Key_Dark.png');
expect(iconB).toEqual('T_Space_Key_Dark.png');
expect(iconC).toEqual('T_Left_Key_Dark.png');
expect(iconD).toEqual('T_Up_Key_Dark.png');
swapCurrentKeys(config, SettingInterfaceKeyboard.Button_Action, Phaser.Input.Keyboard.KeyCodes.UP); // action->UP
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].key).toEqual("KEY_ARROW_LEFT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Action].key).toEqual("KEY_SPACE");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Action].action).toEqual(Button.UP)
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.LEFT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.ACTION);
iconA = getIconWithSettingName(config, settingNameA);
iconB = getIconWithSettingName(config, settingNameB);
iconC = getIconWithSettingName(config, settingNameC);
iconD = getIconWithSettingName(config, settingNameD);
expect(iconA).toEqual('T_Right_Key_Dark.png');
expect(iconB).toEqual('T_Up_Key_Dark.png');
expect(iconC).toEqual('T_Left_Key_Dark.png');
expect(iconD).toEqual('T_Space_Key_Dark.png');
swapCurrentKeys(config, SettingInterfaceKeyboard.Button_Right, Phaser.Input.Keyboard.KeyCodes.UP); // right->UP, action->LEFT
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].key).toEqual("KEY_ARROW_LEFT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Action].key).toEqual("KEY_SPACE");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Action].action).toEqual(Button.UP)
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.ACTION);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.LEFT);
iconA = getIconWithSettingName(config, settingNameA);
iconB = getIconWithSettingName(config, settingNameB);
iconC = getIconWithSettingName(config, settingNameC);
iconD = getIconWithSettingName(config, settingNameD);
expect(iconA).toEqual('T_Right_Key_Dark.png');
expect(iconB).toEqual('T_Up_Key_Dark.png');
expect(iconC).toEqual('T_Space_Key_Dark.png');
expect(iconD).toEqual('T_Left_Key_Dark.png');
});
it('Swap alt with another main', () => {
const settingNameA = SettingInterfaceKeyboard.Button_Left;
const settingNameB = SettingInterfaceKeyboard.Alt_Button_Right;
const settingNameC = SettingInterfaceKeyboard.Button_Up;
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].key).toEqual("KEY_ARROW_LEFT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].action).toEqual(Button.LEFT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].icon).toEqual("T_Left_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_D_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Up_Key_Dark.png");
swapCurrentKeys(config, SettingInterfaceKeyboard.Button_Left, Phaser.Input.Keyboard.KeyCodes.D);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].key).toEqual("KEY_ARROW_LEFT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].icon).toEqual("T_D_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Left].key).toEqual("KEY_Q");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Left].action).toEqual(Button.LEFT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Left].icon).toEqual("T_Q_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Right_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.LEFT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_Left_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Up_Key_Dark.png");
swapCurrentKeys(config, SettingInterfaceKeyboard.Button_Up, Phaser.Input.Keyboard.KeyCodes.LEFT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].key).toEqual("KEY_ARROW_LEFT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Left].icon).toEqual("T_Up_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Left].key).toEqual("KEY_Q");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Left].action).toEqual(Button.LEFT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Left].icon).toEqual("T_Q_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Right_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.LEFT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_Left_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_D_Key_Dark.png");
})
it('Swap alt with a key not binded yet', () => {
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.B);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_B_Key_Dark.png");
})
it('Delete bind', () => {
const settingNameA = SettingInterfaceKeyboard.Alt_Button_Up;
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
deleteBind(config, settingNameA)
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual(undefined);
})
it('Delete bind then asign not existing button', () => {
const settingNameA = SettingInterfaceKeyboard.Alt_Button_Up;
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
deleteBind(config, settingNameA)
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual(undefined);
expect(config.custom["KEY_Z"]).toEqual(-1);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.B);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_B_Key_Dark.png");
expect(config.custom["KEY_B"]).toEqual(Button.UP);
expect(config.custom["KEY_Z"]).toEqual(-1);
})
it('swap bind, then Delete bind then assign bind', () => {
const settingNameA = SettingInterfaceKeyboard.Alt_Button_Up;
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
expect(config.custom["KEY_B"]).toEqual(-1);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.B);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_B_Key_Dark.png");
expect(config.custom["KEY_B"]).toEqual(Button.UP);
expect(config.custom["KEY_Z"]).toEqual(-1);
deleteBind(config, settingNameA);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual(undefined);
expect(config.custom["KEY_Z"]).toEqual(-1);
expect(config.custom["KEY_B"]).toEqual(-1);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.B);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_B_Key_Dark.png");
expect(config.custom["KEY_B"]).toEqual(Button.UP);
expect(config.custom["KEY_Z"]).toEqual(-1);
})
it('Delete bind then asign not already existing button', () => {
const settingNameA = SettingInterfaceKeyboard.Alt_Button_Up;
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
deleteBind(config, settingNameA)
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual(undefined);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Cycle_Ability].key).toEqual("KEY_L");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Cycle_Ability].action).toEqual(Button.CYCLE_ABILITY);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Cycle_Ability].icon).toEqual("T_L_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(-1);
expect(config.custom["KEY_L"]).toEqual(Button.CYCLE_ABILITY);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.L);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_L_Key_Dark.png");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Cycle_Ability].key).toEqual("KEY_L");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Cycle_Ability].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Cycle_Ability].icon).toEqual(undefined);
expect(config.custom["KEY_Z"]).toEqual(-1);
expect(config.custom["KEY_L"]).toEqual(Button.UP);
})
it('Custom scenario 2, regenerate customs when init key is not from setting', () => {
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
expect(config.custom["KEY_T"]).toEqual(-1);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.T);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_T_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(-1);
expect(config.custom["KEY_T"]).toEqual(Button.UP);
})
it('change alt to unknown touch than another one alt with another unknown touch', () => {
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.T);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_T_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(-1);
expect(config.custom["KEY_T"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].key).toEqual("KEY_S");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].action).toEqual(Button.DOWN);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].icon).toEqual("T_S_Key_Dark.png");
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Down, Phaser.Input.Keyboard.KeyCodes.U);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].key).toEqual("KEY_S");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].action).toEqual(Button.DOWN);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].icon).toEqual("T_U_Key_Dark.png");
expect(config.custom["KEY_S"]).toEqual(-1);
expect(config.custom["KEY_U"]).toEqual(Button.DOWN);
expect(config.custom["KEY_Z"]).toEqual(-1);
expect(config.custom["KEY_T"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_T_Key_Dark.png");
})
it('reload scenario with 1 bind already reassigned', () => {
config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up] = {
"key": "KEY_Z",
"isAlt": true,
"action": 3,
"icon": "T_D_Key_Dark.png",
"from": {
"key": "KEY_Z",
"isAlt": true,
"action": 0,
"icon": "T_Z_Key_Dark.png"
}
};
config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right] = {
"key": "KEY_D",
"isAlt": true,
"action": 0,
"icon": "T_Z_Key_Dark.png",
"from": {
"key": "KEY_D",
"isAlt": true,
"action": 3,
"icon": "T_D_Key_Dark.png"
}
}
config.icons["KEY_D"] = "T_Z_Key_Dark.png";
config.icons["KEY_Z"] = "T_D_Key_Dark.png";
regenerateCustom(config);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_D_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_D"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.UP);
swapCurrentKeys(config, SettingInterfaceKeyboard.Button_Up, Phaser.Input.Keyboard.KeyCodes.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_D_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_D"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Right_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_RIGHT"]).toEqual(Button.UP);
});
it('Swap multiple touch alt and main', () => {
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Right_Key_Dark.png");
expect(config.custom["KEY_ARROW_RIGHT"]).toEqual(Button.RIGHT);
swapCurrentKeys(config, SettingInterfaceKeyboard.Button_Up, Phaser.Input.Keyboard.KeyCodes.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Right_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_RIGHT"]).toEqual(Button.UP);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.D);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Right_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_D_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_RIGHT"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_D"]).toEqual(Button.UP);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.Z);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Right_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_RIGHT"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_D_Key_Dark.png");
expect(config.custom["KEY_D"]).toEqual(Button.RIGHT);
})
it('by method: Delete 2 binds, than rebind one of them', () => {
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
deleteBind(config, SettingInterfaceKeyboard.Alt_Button_Up);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual(undefined);
expect(config.custom["KEY_Z"]).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].key).toEqual("KEY_S");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].action).toEqual(Button.DOWN);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].icon).toEqual("T_S_Key_Dark.png");
expect(config.custom["KEY_S"]).toEqual(Button.DOWN);
deleteBind(config, SettingInterfaceKeyboard.Alt_Button_Down);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].key).toEqual("KEY_S");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].icon).toEqual(undefined);
expect(config.custom["KEY_S"]).toEqual(-1);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.Z);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].key).toEqual("KEY_S");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].icon).toEqual(undefined);
expect(config.custom["KEY_S"]).toEqual(-1);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Down, Phaser.Input.Keyboard.KeyCodes.S);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].key).toEqual("KEY_S");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].action).toEqual(Button.DOWN);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].icon).toEqual("T_S_Key_Dark.png");
expect(config.custom["KEY_S"]).toEqual(Button.DOWN);
let keyDown = Phaser.Input.Keyboard.KeyCodes.S;
let key = getKeyFromMapping(config, keyDown);
let buttonDown = config.custom[key];
expect(buttonDown).toEqual(Button.DOWN);
keyDown = Phaser.Input.Keyboard.KeyCodes.Z;
key = getKeyFromMapping(config, keyDown);
buttonDown = config.custom[key];
expect(buttonDown).toEqual(Button.UP);
});
it("test keyboard listener", () => {
const keyDown = Phaser.Input.Keyboard.KeyCodes.S;
const key = getKeyFromMapping(config, keyDown);
const buttonDown = config.custom[key];
expect(buttonDown).toEqual(Button.DOWN);
});
it("another test with 2 delete", () => {
config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up] = {
"key": "KEY_Z",
"isAlt": true,
"action": -1,
"from": {
"key": "KEY_Z",
"isAlt": true,
"action": 0,
"icon": "T_Z_Key_Dark.png"
},
"latestIsDeleted": true
};
regenerateCustom(config);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual(undefined);
expect(config.custom["KEY_Z"]).toEqual(-1);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Down, Phaser.Input.Keyboard.KeyCodes.S);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].key).toEqual("KEY_S");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].action).toEqual(Button.DOWN);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Down].icon).toEqual("T_S_Key_Dark.png");
expect(config.custom["KEY_S"]).toEqual(Button.DOWN);
});
it("another test with 2 delete", () => {
config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up] = {
"key": "KEY_Z",
"isAlt": true,
"action": -1,
"from": {
"key": "KEY_Z",
"isAlt": true,
"action": 0,
"icon": "T_Z_Key_Dark.png"
},
"latestIsDeleted": true
};
regenerateCustom(config);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual(undefined);
expect(config.custom["KEY_Z"]).toEqual(-1);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.Z);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
let keyDown = Phaser.Input.Keyboard.KeyCodes.S;
let key = getKeyFromMapping(config, keyDown);
let buttonDown = config.custom[key];
expect(buttonDown).toEqual(Button.DOWN);
keyDown = Phaser.Input.Keyboard.KeyCodes.Z;
key = getKeyFromMapping(config, keyDown);
buttonDown = config.custom[key];
expect(buttonDown).toEqual(Button.UP);
});
it("another test with 2 delete part 2", () => {
config.currentKeys = {
"ALT_BUTTON_UP": {
"key": "KEY_Z",
"isAlt": true,
"action": -1,
"from": {
"key": "KEY_Z",
"isAlt": true,
"action": 0,
"icon": "T_Z_Key_Dark.png"
},
"latestIsDeleted": true
},
"ALT_BUTTON_DOWN": {
"key": "KEY_S",
"isAlt": true,
"action": -1,
"from": {
"key": "KEY_S",
"isAlt": true,
"action": 1,
"icon": "T_S_Key_Dark.png"
},
"latestIsDeleted": true
},
}
regenerateCustom(config);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(-1);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual(undefined);
expect(config.custom["KEY_Z"]).toEqual(-1);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.Z);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
const keyDown = Phaser.Input.Keyboard.KeyCodes.Z;
const key = getKeyFromMapping(config, keyDown);
const buttonDown = config.custom[key];
expect(buttonDown).toEqual(Button.UP);
});
})
;

View File

@ -0,0 +1,311 @@
import {afterEach, beforeEach, describe, expect, it} from "vitest";
import cfg_keyboard_azerty from "#app/test/cfg_keyboard.example";
import {SettingInterface} from "#app/test/cfg_keyboard.example";
import {Button} from "#app/enums/buttons";
import {deepCopy} from "#app/utils";
import {
getButtonWithSettingName,
getIconWithSettingName,
getKeyWithKeycode,
getKeyWithSettingName,
getSettingNameWithKeycode,
regenerateIdentifiers,
swap
} from "#app/configs/configHandler";
import {MenuManip} from "#app/test/helpers/menuManip";
import {InGameManip} from "#app/test/helpers/inGameManip";
describe('Test Rebinding', () => {
let config;
let inGame;
let inTheSettingMenu;
beforeEach(() => {
config = deepCopy(cfg_keyboard_azerty);
config.custom = {...config.default}
regenerateIdentifiers(config);
inGame = new InGameManip(config);
inTheSettingMenu = new MenuManip(config);
});
it('Check if config is loaded', () => {
expect(config).not.toBeNull();
});
it('Check button for setting name', () => {
const settingName = SettingInterface.Button_Left;
const button = config.settings[settingName];
expect(button).toEqual(Button.LEFT);
});
it('Check key for Keyboard KeyCode', () => {
const key = getKeyWithKeycode(config, Phaser.Input.Keyboard.KeyCodes.LEFT);
const settingName = config.custom[key];
const button = config.settings[settingName];
expect(button).toEqual(Button.LEFT);
});
it('Check key for currenly Assigned to action not alt', () => {
const key = getKeyWithKeycode(config, Phaser.Input.Keyboard.KeyCodes.Q);
const settingName = config.custom[key];
const button = config.settings[settingName];
expect(button).toEqual(Button.LEFT);
});
it('Check key for currenly Assigned to setting name', () => {
const settingName = SettingInterface.Button_Left;
const key = getKeyWithSettingName(config, settingName);
expect(key).toEqual('KEY_ARROW_LEFT');
});
it('Check key for currenly Assigned to setting name alt', () => {
const settingName = SettingInterface.Alt_Button_Left;
const key = getKeyWithSettingName(config, settingName);
expect(key).toEqual('KEY_Q');
});
it('Check key from key code', () => {
const keycode = Phaser.Input.Keyboard.KeyCodes.LEFT;
const key = getKeyWithKeycode(config, keycode);
expect(key).toEqual('KEY_ARROW_LEFT');
});
it('Check icon for currenly Assigned to key code', () => {
const keycode = Phaser.Input.Keyboard.KeyCodes.LEFT;
const key = getKeyWithKeycode(config, keycode);
const icon = config.icons[key];
expect(icon).toEqual('T_Left_Key_Dark.png');
});
it('Check icon for currenly Assigned to key code', () => {
const keycode = Phaser.Input.Keyboard.KeyCodes.Q;
const key = getKeyWithKeycode(config, keycode);
const icon = config.icons[key];
expect(icon).toEqual('T_Q_Key_Dark.png');
});
it('Check icon for currenly Assigned to setting name', () => {
const settingName = SettingInterface.Button_Left;
const key = getKeyWithSettingName(config, settingName);
const icon = config.icons[key];
expect(icon).toEqual('T_Left_Key_Dark.png');
});
it('Check icon for currenly Assigned to setting name alt', () => {
const settingName = SettingInterface.Alt_Button_Left;
const key = getKeyWithSettingName(config, settingName);
const icon = config.icons[key];
expect(icon).toEqual('T_Q_Key_Dark.png');
});
it('Check if is working', () => {
const settingNameA = SettingInterface.Button_Left;
const settingNameB = SettingInterface.Button_Right;
swap(config, SettingInterface.Button_Left, Phaser.Input.Keyboard.KeyCodes.RIGHT);
expect(getButtonWithSettingName(config, settingNameA)).toEqual(Button.LEFT);
expect(getSettingNameWithKeycode(config, Phaser.Input.Keyboard.KeyCodes.RIGHT)).toEqual(SettingInterface.Button_Left)
expect(getButtonWithSettingName(config, settingNameB)).toEqual(Button.RIGHT);
expect(getSettingNameWithKeycode(config, Phaser.Input.Keyboard.KeyCodes.LEFT)).toEqual(SettingInterface.Button_Right)
expect(getIconWithSettingName(config, settingNameA)).toEqual(config.icons.KEY_ARROW_RIGHT);
expect(getIconWithSettingName(config, settingNameB)).toEqual(config.icons.KEY_ARROW_LEFT);
});
it('Check if double swap is working', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").confirm();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_RIGHT").weWantThisBindInstead("UP").confirm();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Left");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_UP").weWantThisBindInstead("RIGHT").confirm();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
});
it('Check if triple swap is working', () => {
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").confirm();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Right").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("UP").confirm();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Right");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_RIGHT").weWantThisBindInstead("LEFT").confirm();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Right");
});
it('Swap alt with another main', () => {
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("D").OopsSpecialCaseIcon("KEY_Q").confirm();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Right");
});
it('multiple Swap alt with another main', () => {
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("D").OopsSpecialCaseIcon("KEY_Q").confirm();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Up").iconDisplayedIs("KEY_ARROW_UP").weWantThisBindInstead("LEFT").confirm();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Left");
});
it('Swap alt with a key not binded yet', () => {
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Up").iconDisplayedIs("KEY_Z").weWantThisBindInstead("B").confirm();
inGame.whenWePressOnKeyboard("Z").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").weShouldTriggerTheButton("Alt_Button_Up");
});
it('Delete bind', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inTheSettingMenu.whenWeDelete("Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
});
it('Delete bind then assign a not yet binded button', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inTheSettingMenu.whenWeDelete("Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").thereShouldBeNoIcon().weWantThisBindInstead("B").confirm();
inGame.whenWePressOnKeyboard("B").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
})
it('Delete bind then assign a not yet binded button', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inTheSettingMenu.whenWeDelete("Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").thereShouldBeNoIcon().weWantThisBindInstead("RIGHT").confirm();
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
});
it('swap 2 bind, than delete 1 bind than assign another bind', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").confirm();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").whenWeDelete().thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").nothingShouldHappen();
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Up").iconDisplayedIs("KEY_Z").weWantThisBindInstead("B").confirm();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").weShouldTriggerTheButton("Alt_Button_Up");
});
it('Delete bind then assign not already existing button', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inTheSettingMenu.whenWeDelete("Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").thereShouldBeNoIcon().weWantThisBindInstead("L").confirm();
inGame.whenWePressOnKeyboard("L").weShouldTriggerTheButton("Button_Left");
});
it('change alt bind to not already existing button, than another one alt bind with another not already existing button', () => {
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("S").weShouldTriggerTheButton("Alt_Button_Down");
inGame.whenWePressOnKeyboard("T").nothingShouldHappen();
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Up").iconDisplayedIs("KEY_Z").weWantThisBindInstead("T").confirm();
inGame.whenWePressOnKeyboard("T").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("Z").nothingShouldHappen();
inGame.whenWePressOnKeyboard("U").nothingShouldHappen();
inGame.whenWePressOnKeyboard("S").weShouldTriggerTheButton("Alt_Button_Down");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Down").iconDisplayedIs("KEY_S").weWantThisBindInstead("U").confirm();
inGame.whenWePressOnKeyboard("T").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("Z").nothingShouldHappen();
inGame.whenWePressOnKeyboard("U").weShouldTriggerTheButton("Alt_Button_Down");
inGame.whenWePressOnKeyboard("S").nothingShouldHappen();
});
it('Swap multiple touch alt and main', () => {
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inTheSettingMenu.whenCursorIsOnSetting("Button_Up").iconDisplayedIs("KEY_ARROW_UP").weWantThisBindInstead("RIGHT").confirm();
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Up").iconDisplayedIs("KEY_Z").weWantThisBindInstead("D").confirm();
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Right");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Up").iconDisplayedIs("KEY_D").weWantThisBindInstead("Z").confirm();
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
})
it('Delete 2 bind then reassign one of them', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inTheSettingMenu.whenWeDelete("Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inTheSettingMenu.whenWeDelete("Alt_Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").thereShouldBeNoIcon().weWantThisBindInstead("Q").confirm();
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
});
it("test keyboard listener", () => {
const keyDown = Phaser.Input.Keyboard.KeyCodes.S;
const key = getKeyWithKeycode(config, keyDown);
const settingName = config.custom[key];
const buttonDown = config.settings[settingName];
expect(buttonDown).toEqual(Button.DOWN);
});
});

View File

@ -5,10 +5,7 @@ import {InterfaceConfig} from "../../inputs-controller";
import {addWindow} from "../ui-theme";
import {addTextObject, TextStyle} from "../text";
import {Button} from "../../enums/buttons";
import {
getKeyAndActionFromCurrentKeysWithSettingName,
getKeyForSettingName
} from "#app/configs/gamepad-utils";
import {getIconWithSettingName, getKeyWithSettingName} from "#app/configs/configHandler";
export interface InputsIcons {
[key: string]: Phaser.GameObjects.Sprite;
@ -107,7 +104,7 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
optionsContainer.setVisible(false);
// Gather all gamepad binding settings from the configuration.
const bindingSettings = Object.keys(config.setting).map(k => config.setting[k]);
const bindingSettings = Object.keys(config.settings);
// Array to hold labels for different settings such as 'Default Controller', 'Gamepad Support', etc.
const settingLabels: Phaser.GameObjects.Text[] = [];
@ -121,7 +118,7 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
// Fetch common setting keys such as 'Default Controller' and 'Gamepad Support' from gamepad settings.
const commonSettingKeys = Object.keys(this.settingDevice).slice(0, this.commonSettingsCount).map(key => this.settingDevice[key]);
// Combine common and specific bindings into a single array.
const specificBindingKeys = [...commonSettingKeys, ...Object.keys(config.setting).map(k => config.setting[k])];
const specificBindingKeys = [...commonSettingKeys, ...Object.keys(config.settings)];
// Fetch default values for these settings and prepare to highlight selected options.
const optionCursors = Object.values(Object.keys(this.settingDeviceDefaults).filter(s => specificBindingKeys.includes(s)).map(k => this.settingDeviceDefaults[k]));
@ -142,6 +139,9 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
const valueLabels: Phaser.GameObjects.Text[] = []
// Process each option for the current setting.
const aaa = this.settingDeviceOptions;
const bbb = this.settingDevice;
const ccc = this.settingDevice[setting];
for (const [o, option] of this.settingDeviceOptions[this.settingDevice[setting]].entries()) {
// Check if the current setting is for binding keys.
if (bindingSettings.includes(this.settingDevice[setting])) {
@ -154,11 +154,10 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
continue;
}
// For null options, add an icon for the key.
const key = getKeyForSettingName(config as InterfaceConfig, this.settingDevice[setting]);
const icon = this.scene.add.sprite(0, 0, this.textureOverride ? this.textureOverride : config.padType);
icon.setScale(0.1);
icon.setOrigin(0, -0.1);
inputsIcons[key] = icon;
inputsIcons[this.settingDevice[setting]] = icon;
optionsContainer.add(icon);
valueLabels.push(icon);
continue;
@ -242,12 +241,13 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
// For each element in the binding settings, update the icon according to the current assignment.
for (const elm of this.bindingSettings) {
const {key, icon} = getKeyAndActionFromCurrentKeysWithSettingName(activeConfig, elm);
const icon = getIconWithSettingName(activeConfig, elm);
if (icon) {
this.inputsIcons[key].setFrame(icon);
this.inputsIcons[key].alpha = 1;
this.inputsIcons[elm].setFrame(icon);
this.inputsIcons[elm].alpha = 1;
} else {
this.inputsIcons[key].alpha = 0;
if (!this.inputsIcons[elm]) debugger;
this.inputsIcons[elm].alpha = 0;
}
}

View File

@ -1,9 +1,8 @@
import BattleScene from "../../battle-scene";
import AbstractBindingUiHandler from "../settings/abrast-binding-ui-handler";
import {Mode} from "../ui";
import {
getKeyAndActionFromCurrentKeysWithSettingName, getKeyFromMapping, regenerateCustom,
} from "#app/configs/gamepad-utils";
import {Device} from "#app/enums/devices";
import {getIconSpecialCase, getIconWithSettingName, getKeyWithKeycode} from "#app/configs/configHandler";
export default class GamepadBindingUiHandler extends AbstractBindingUiHandler {
@ -14,25 +13,29 @@ export default class GamepadBindingUiHandler extends AbstractBindingUiHandler {
scene.input.gamepad.on('down', this.gamepadButtonDown, this);
}
getSelectedDevice() {
return this.scene.inputController?.selectedDevice[Device.GAMEPAD];
}
gamepadButtonDown(pad: Phaser.Input.Gamepad.Gamepad, button: Phaser.Input.Gamepad.Button, value: number): void {
const blacklist = [12, 13, 14, 15]; // d-pad buttons are blacklisted.
// Check conditions before processing the button press.
if (!this.listening || pad.id !== this.scene.inputController?.chosenGamepad || blacklist.includes(button.index) || this.buttonPressed !== null) return;
const activeConfig = this.scene.inputController.getActiveConfig();
if (!this.listening || pad.id.toLowerCase() !== this.getSelectedDevice() || blacklist.includes(button.index) || this.buttonPressed !== null) return;
const activeConfig = this.scene.inputController.getActiveConfig(Device.GAMEPAD);
const type = activeConfig.padType
const key = getKeyFromMapping(activeConfig, button.index);
const buttonIcon = activeConfig.ogIcons[key];
const key = getKeyWithKeycode(activeConfig, button.index);
const buttonIcon = activeConfig.icons[key];
if (!buttonIcon) return;
this.buttonPressed = button.index;
const assignedButtonIcon = getKeyAndActionFromCurrentKeysWithSettingName(activeConfig, this.target)?.icon;
this.onInputDown(buttonIcon, assignedButtonIcon, type);
const specialCaseIcon = getIconSpecialCase(activeConfig, button.index, this.target);
const assignedButtonIcon = getIconWithSettingName(activeConfig, this.target);
this.onInputDown(buttonIcon, specialCaseIcon || assignedButtonIcon, type);
}
swapAction() {
const activeConfig = this.scene.inputController.getActiveConfig();
const activeConfig = this.scene.inputController.getActiveConfig(Device.GAMEPAD);
this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed)
this.scene.gameData.saveCustomMapping(this.scene.inputController?.chosenGamepad, activeConfig.currentKeys, activeConfig.icons);
regenerateCustom(activeConfig);
this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig);
return true;
}
}

View File

@ -1,9 +1,8 @@
import BattleScene from "../../battle-scene";
import AbstractBindingUiHandler from "../settings/abrast-binding-ui-handler";
import {Mode} from "../ui";
import {
getKeyAndActionFromCurrentKeysWithSettingName, getKeyFromMapping, regenerateCustom,
} from "#app/configs/gamepad-utils";
import {getIconSpecialCase, getIconWithSettingName, getKeyWithKeycode} from "#app/configs/configHandler";
import {Device} from "#app/enums/devices";
export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler {
@ -14,24 +13,28 @@ export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler {
scene.input.keyboard.on('keydown', this.onKeyDown, this);
}
getSelectedDevice() {
return this.scene.inputController?.selectedDevice[Device.KEYBOARD];
}
onKeyDown(event): void {
const key = event.keyCode;
// // Check conditions before processing the button press.
if (!this.listening || this.buttonPressed !== null) return;
const activeConfig = this.scene.inputController.getActiveKeyboardConfig();
const _key = getKeyFromMapping(activeConfig, key);
const buttonIcon = activeConfig.ogIcons[_key];
const activeConfig = this.scene.inputController.getActiveConfig(Device.KEYBOARD);
const _key = getKeyWithKeycode(activeConfig, key);
const buttonIcon = activeConfig.icons[_key];
if (!buttonIcon) return;
this.buttonPressed = key;
const assignedButtonIcon = getKeyAndActionFromCurrentKeysWithSettingName(activeConfig, this.target)?.icon;
this.onInputDown(buttonIcon, assignedButtonIcon, 'keyboard');
const specialCaseIcon = getIconSpecialCase(activeConfig, key, this.target);
const assignedButtonIcon = getIconWithSettingName(activeConfig, this.target);
this.onInputDown(buttonIcon, specialCaseIcon || assignedButtonIcon, 'keyboard');
}
swapAction() {
const activeConfig = this.scene.inputController.getActiveKeyboardConfig();
const activeConfig = this.scene.inputController.getActiveConfig(Device.KEYBOARD);
this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed)
this.scene.gameData.saveCustomKeyboardMapping(this.scene.inputController?.chosenKeyboard, activeConfig.currentKeys, activeConfig.icons);
regenerateCustom(activeConfig);
this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig);
return true;
}

View File

@ -2,12 +2,12 @@ import BattleScene from "../../battle-scene";
import {addTextObject, TextStyle} from "../text";
import {Mode} from "../ui";
import {SettingGamepad, settingGamepadDefaults, settingGamepadOptions} from "../../system/settings-gamepad";
import {truncateString} from "../../utils";
import pad_xbox360 from "#app/configs/pad_xbox360";
import pad_dualshock from "#app/configs/pad_dualshock";
import pad_unlicensedSNES from "#app/configs/pad_unlicensedSNES";
import {InterfaceConfig} from "#app/inputs-controller";
import AbstractSettingsUiUiHandler from "#app/ui/settings/abstract-settings-ui-handler";
import {Device} from "#app/enums/devices";
export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandler {
@ -39,7 +39,7 @@ export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandle
}
getActiveConfig(): InterfaceConfig {
return this.scene.inputController.getActiveConfig();
return this.scene.inputController.getActiveConfig(Device.GAMEPAD);
}
getLocalStorageSetting(): object {
@ -89,7 +89,7 @@ export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandle
// Update the text of the first option label under the current setting to the name of the chosen gamepad,
// truncating the name to 30 characters if necessary.
this.layout[_key].optionValueLabels[index][0].setText(truncateString(this.scene.inputController.chosenGamepad, 30));
this.layout[_key].optionValueLabels[index][0].setText(this.scene.inputController.selectedDevice[Device.GAMEPAD], 30);
}
}
}

View File

@ -5,8 +5,9 @@ import {SettingKeyboard, settingKeyboardDefaults, settingKeyboardOptions} from "
import {reverseValueToKeySetting, truncateString} from "#app/utils";
import AbstractSettingsUiUiHandler from "#app/ui/settings/abstract-settings-ui-handler";
import {InterfaceConfig} from "#app/inputs-controller";
import {deleteBind} from "#app/configs/gamepad-utils";
import {addTextObject, TextStyle} from "#app/ui/text";
import {deleteBind} from "#app/configs/configHandler";
import {Device} from "#app/enums/devices";
export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandler {
@ -53,7 +54,7 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
}
getActiveConfig(): InterfaceConfig {
return this.scene.inputController.getActiveKeyboardConfig();
return this.scene.inputController.getActiveConfig(Device.KEYBOARD);
}
getLocalStorageSetting(): object {
@ -101,7 +102,7 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
if (_key === 'noKeyboard') continue; // Skip updating the no gamepad layout.
// Update the text of the first option label under the current setting to the name of the chosen gamepad,
// truncating the name to 30 characters if necessary.
this.layout[_key].optionValueLabels[index][0].setText(truncateString(this.scene.inputController.chosenKeyboard, 30));
this.layout[_key].optionValueLabels[index][0].setText(truncateString(this.scene.inputController.selectedDevice[Device.KEYBOARD], 30));
}
}
}
@ -109,7 +110,7 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
}
saveCustomKeyboardMappingToLocalStorage(config): void {
this.scene.gameData.saveCustomKeyboardMapping(this.scene.inputController?.chosenKeyboard, config.currentKeys, config.icons);
this.scene.gameData.saveMappingConfigs(this.scene.inputController?.selectedDevice[Device.KEYBOARD], config);
}
saveSettingToLocalStorage(settingName, cursor): void {