Refactor/assign instead swap (#2)

* tests updated

* adjust the code to use assign instead of swap for the keyboard mapping
This commit is contained in:
Greenlamp2 2024-05-17 12:10:53 +02:00 committed by GitHub
parent e8b6e588a5
commit e1be1a3f82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 293 additions and 330 deletions

View File

@ -276,8 +276,6 @@ const cfg_keyboard_azerty = {
KEY_SEMICOLON: -1,
KEY_ALT: -1
},
main: [],
alt: [],
blacklist: [
"KEY_ENTER",
"KEY_ESC",

View File

@ -80,34 +80,6 @@ export function getIconWithKey(config, key) {
return config.icons[key];
}
/**
* Retrieves the icon for a special case where a key is bound to a different type of binding.
* This special case occurs when attempting to bind a key from either a main or alternate binding
* to a different type of binding, resulting in two main or two alternate bindings having the same action.
* In such cases, the two bindings are swapped to maintain uniqueness.
*
* @param config - The configuration object containing icons.
* @param keycode - The keycode to search for.
* @param settingName - The setting name to search for.
* @returns The icon associated with the special case or null if not found.
*/
export function getIconSpecialCase(config, keycode, settingName) {
const potentialKey = getKeySolvingConflict(config, keycode, settingName);
if (potentialKey) return getIconWithKey(config, potentialKey);
return null;
}
/**
* Retrieves the button associated with the specified setting name.
*
* @param config - The configuration object containing settings.
* @param settingName - The setting name to search for.
* @returns The button associated with the specified setting name.
*/
export function getButtonWithSettingName(config, settingName) {
return config.settings[settingName];
}
/**
* Retrieves the icon associated with the specified setting name.
*
@ -144,76 +116,11 @@ export function getSettingNameWithButton(config, button, alt = false) {
});
}
/**
* Retrieves the key associated with the specified button.
*
* @param config - The configuration object containing custom settings.
* @param button - The button to search for.
* @param alt - A flag indicating if the search is for an alternate setting.
* @returns The key associated with the specified button.
*/
export function getKeyWithButton(config, button, alt = false) {
const settingName = getSettingNameWithButton(config, button, alt);
return getKeyWithSettingName(config, settingName);
}
/**
* Identifies a key that resolves a binding conflict when attempting to bind a keycode to a specified setting name target.
* This function checks if the keycode is already bound to a different type of binding (main or alternate) and returns
* the conflicting key if found.
*
* @param config - The configuration object containing custom settings.
* @param keycode - The keycode to check.
* @param settingNameTarget - The setting name target to bind.
* @returns The conflicting key if found, or null if no conflict is found.
*/
export function getKeySolvingConflict(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;
}
/**
* Swaps the binding of a keycode with the specified setting name target.
* If the target setting is deleted, it directly binds the keycode to the target setting.
* Otherwise, it handles any potential conflicts by swapping the bindings.
*
* @param config - The configuration object containing custom settings.
* @param settingNameTarget - The setting name target to swap.
* @param keycode - The keycode to swap.
*/
export function swap(config, settingNameTarget, keycode) {
// Check if the setting name target is already deleted (i.e., not bound to any key).
const isDeleted = !getKeyWithSettingName(config, settingNameTarget);
// If the setting name target is deleted, bind the new key to the setting name target and return.
if (isDeleted) {
const new_key = getKeyWithKeycode(config, keycode);
config.custom[new_key] = settingNameTarget;
return;
}
// Check for any potential conflict with existing bindings.
const potentialExistingKey = getKeySolvingConflict(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 assign(config, settingNameTarget, keycode) {
export function assign(config, settingNameTarget, keycode): boolean {
// first, we need to check if this keycode is already used on another settingName
const previousSettingName = getSettingNameWithKeycode(config, keycode);
const key = getKeyWithSettingName(config, previousSettingName);
if (!canIAssignThisKey(config, key)) return false;
// if it was already bound, we delete the bind
if (previousSettingName) {
const previousKey = getKeyWithSettingName(config, previousSettingName);
@ -226,6 +133,20 @@ export function assign(config, settingNameTarget, keycode) {
// then, the new key is assigned to the new settingName
const newKey = getKeyWithKeycode(config, keycode);
config.custom[newKey] = settingNameTarget;
return true;
}
export function swap(config, settingNameTarget, keycode) {
// only for gamepad
if (config.padType === 'keyboard') return false;
const prev_key = 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;
}
/**
@ -236,23 +157,24 @@ export function assign(config, settingNameTarget, keycode) {
*/
export function deleteBind(config, settingName) {
const key = getKeyWithSettingName(config, settingName);
if (config.blacklist.includes(key) || isTheLatestBind(config, settingName)) return false;
config.custom[key] = -1;
regenerateIdentifiers(config);
return true;
}
/**
* Deletes the binding of the specified setting name. but prevent the deletion of keys in the blacklist
*
* @param config - The configuration object containing custom settings.
* @param settingName - The setting name to delete.
*/
export function safeDeleteBind(config, settingName) {
const key = getKeyWithSettingName(config, settingName);
if (config.blacklist.includes(key) || isTheLatestBind(config, settingName)) return;
config.custom[key] = -1;
export function canIAssignThisKey(config, key) {
const settingName = getSettingNameWithKey(config, key);
if (settingName === -1) return true;
if (config.blacklist?.includes(key) || isTheLatestBind(config, settingName)) return false;
return true;
}
export function canIDeleteThisKey(config, key) {
return canIAssignThisKey(config, key);
}
export function isTheLatestBind(config, settingName) {
if (config.padType !== 'keyboard') return false;
const isAlt = settingName.includes("ALT_");
let altSettingName;
if (isAlt)
@ -261,22 +183,4 @@ export function isTheLatestBind(config, settingName) {
altSettingName = `ALT_${settingName}`;
const secondButton = getKeyWithSettingName(config, altSettingName);
return secondButton === undefined;
}
/**
* Regenerates the identifiers for main and alternate settings.
* This allows distinguishing between main and alternate bindings.
*
* @param config - The configuration object containing custom settings.
*/
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

@ -83,8 +83,6 @@ const pad_dualshock = {
RS: SettingGamepad.Button_Slow_Down,
TOUCH: SettingGamepad.Button_Submit,
},
main: [],
alt: [],
};
export default pad_dualshock;

View File

@ -79,8 +79,6 @@ const pad_generic = {
LS: SettingGamepad.Button_Speed_Up,
RS: SettingGamepad.Button_Slow_Down
},
main: [],
alt: [],
};
export default pad_generic;

View File

@ -71,8 +71,6 @@ const pad_unlicensedSNES = {
LS: -1,
RS: -1
},
main: [],
alt: [],
};
export default pad_unlicensedSNES;

View File

@ -79,8 +79,6 @@ const pad_xbox360 = {
LS: SettingGamepad.Button_Speed_Up,
RS: SettingGamepad.Button_Slow_Down
},
main: [],
alt: [],
};
export default pad_xbox360;

View File

@ -11,7 +11,11 @@ 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 {Device} from "#app/enums/devices";
import {getButtonWithKeycode, getIconForLatestInput, regenerateIdentifiers, swap} from "#app/configs/configHandler";
import {
assign,
getButtonWithKeycode,
getIconForLatestInput, swap,
} from "#app/configs/configHandler";
export interface DeviceMapping {
[key: string]: number;
@ -685,9 +689,6 @@ export class InputsController {
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]);
}
/**
@ -697,9 +698,11 @@ export class InputsController {
* @param settingName The name of the setting to swap.
* @param pressedButton The button that was pressed.
*/
swapBinding(config, settingName, pressedButton): void {
assignBinding(config, settingName, pressedButton): boolean {
this.pauseUpdate = true;
swap(config, settingName, pressedButton);
setTimeout(() => this.pauseUpdate = false, 500);
if (config.padType === 'keyboard')
return assign(config, settingName, pressedButton);
else return swap(config, settingName, pressedButton);
}
}

View File

@ -65,6 +65,7 @@ export class InGameManip {
}
weShouldTriggerTheButton(settingName) {
if (!settingName.includes("Button_")) settingName = "Button_" + settingName;
this.settingName = SettingInterface[this.normalizeSettingNameString(settingName)];
expect(getSettingNameWithKeycode(this.config, this.keycode)).toEqual(this.settingName);
return this;

View File

@ -3,10 +3,12 @@ import {expect} from "vitest";
import {Button} from "#app/enums/buttons";
import {
deleteBind,
getIconWithKey,
getIconWithKeycode,
getIconWithSettingName,
getKeyWithKeycode, getKeyWithSettingName, getKeySolvingConflict, swap, assign, safeDeleteBind
getKeyWithKeycode,
getKeyWithSettingName,
assign,
getSettingNameWithKeycode, canIAssignThisKey, canIDeleteThisKey
} from "#app/configs/configHandler";
export class MenuManip {
@ -51,6 +53,7 @@ export class MenuManip {
}
iconDisplayedIs(icon) {
if (!(icon.toUpperCase().includes("KEY_"))) icon = "KEY_" + icon.toUpperCase();
this.iconDisplayed = this.config.icons[icon];
expect(getIconWithSettingName(this.config, this.settingName)).toEqual(this.iconDisplayed);
return this;
@ -66,6 +69,12 @@ export class MenuManip {
return this.thereShouldBeNoIconAnymore();
}
nothingShouldHappen() {
const settingName = getSettingNameWithKeycode(this.config, this.keycode);
expect(settingName).toEqual(-1);
return this;
}
weWantThisBindInstead(keycode) {
this.keycode = Phaser.Input.Keyboard.KeyCodes[keycode];
const icon = getIconWithKeycode(this.config, this.keycode);
@ -76,25 +85,17 @@ export class MenuManip {
return this;
}
OopsSpecialCaseIcon(icon) {
this.specialCaseIcon = this.config.icons[icon];
const potentialExistingKey = getKeySolvingConflict(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);
// expect(this.config.custom[key]).toEqual(-1);
return this;
}
whenWeTryToDelete(settingName?: string) {
this.settingName = SettingInterface[settingName] || this.settingName;
safeDeleteBind(this.config, this.settingName);
deleteBind(this.config, this.settingName);
return this;
}
@ -102,7 +103,24 @@ export class MenuManip {
assign(this.config, this.settingName, this.keycode);
}
butLetsForceIt() {
this.confirm();
}
confirm() {
swap(this.config, this.settingName, this.keycode);
assign(this.config, this.settingName, this.keycode);
}
weCantConfirm() {
const key = getKeyWithKeycode(this.config, this.keycode);
expect(canIAssignThisKey(this.config, key)).toEqual(false);
return this;
}
weCantDelete() {
const key = getKeyWithSettingName(this.config, this.settingName);
expect(canIDeleteThisKey(this.config, key)).toEqual(false);
return this;
}
}

View File

@ -4,13 +4,8 @@ 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";
@ -31,7 +26,6 @@ describe('Test Rebinding', () => {
beforeEach(() => {
config = deepCopy(cfg_keyboard_azerty);
config.custom = {...config.default}
regenerateIdentifiers(config);
configs.default = config;
inGame = new InGameManip(configs, config, selectedDevice);
inTheSettingMenu = new MenuManip(config);
@ -97,85 +91,137 @@ describe('Test Rebinding', () => {
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 is working', () => {
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("Q")
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Right").iconDisplayedIs("D")
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("Q").weWantThisBindInstead("D").confirm();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Left");
});
it('Check if double swap is working', () => {
it('Check prevent rebind indirectly the d-pad buttons', () => {
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("Q")
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Right").iconDisplayedIs("D")
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("Q").weWantThisBindInstead("LEFT").weCantConfirm().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Left");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
});
it('Check if double assign d-pad is blocked', () => {
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();
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantConfirm().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
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_RIGHT").weWantThisBindInstead("UP").confirm();
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("UP").weCantConfirm().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Left");
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_UP").weWantThisBindInstead("RIGHT").confirm();
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantConfirm().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
});
it('Check if double assign is working', () => {
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("KEY_Q").weWantThisBindInstead("D").confirm();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("KEY_D").weWantThisBindInstead("Z").confirm();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("D").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Left");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("KEY_Z").weWantThisBindInstead("D").confirm();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("Z").nothingShouldHappen();
});
it('Check if triple swap d-pad is prevented', () => {
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantConfirm().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Right").iconDisplayedIs("KEY_ARROW_RIGHT").weWantThisBindInstead("UP").weCantConfirm().butLetsForceIt();
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("LEFT").weCantConfirm().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
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("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("KEY_Q").weWantThisBindInstead("D").confirm();
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");
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
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");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Right").thereShouldBeNoIcon().weWantThisBindInstead("Z").confirm();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Right");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("KEY_D").weWantThisBindInstead("Q").confirm();
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("D").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Right");
});
it('Swap alt with another main', () => {
it('Swap alt with a 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");
inGame.whenWePressOnKeyboard("R").weShouldTriggerTheButton("Cycle_Shiny");
inTheSettingMenu.whenCursorIsOnSetting("Cycle_Shiny").iconDisplayedIs("KEY_R").weWantThisBindInstead("D").confirm();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Cycle_Shiny");
inGame.whenWePressOnKeyboard("R").nothingShouldHappen();
});
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");
inGame.whenWePressOnKeyboard("R").weShouldTriggerTheButton("Button_Cycle_Shiny");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("F").weShouldTriggerTheButton("Button_Cycle_Form");
inTheSettingMenu.whenCursorIsOnSetting("Button_Cycle_Shiny").iconDisplayedIs("KEY_R").weWantThisBindInstead("D").confirm();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Button_Cycle_Shiny");
inGame.whenWePressOnKeyboard("R").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("F").weShouldTriggerTheButton("Button_Cycle_Form");
inTheSettingMenu.whenCursorIsOnSetting("Button_Cycle_Form").iconDisplayedIs("KEY_F").weWantThisBindInstead("R").confirm();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Button_Cycle_Shiny");
inGame.whenWePressOnKeyboard("R").weShouldTriggerTheButton("Button_Cycle_Form");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("F").nothingShouldHappen();
});
it('Swap alt with a key not binded yet', () => {
@ -184,84 +230,96 @@ describe('Test Rebinding', () => {
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Up").iconDisplayedIs("KEY_Z").weWantThisBindInstead("B").confirm();
inGame.whenWePressOnKeyboard("Z").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").weShouldTriggerTheButton("Alt_Button_Up");
});
it('Delete blacklisted bind', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inTheSettingMenu.whenWeDelete("Button_Left").weCantDelete().iconDisplayedIs("KEY_ARROW_LEFT");
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
});
it('Delete bind', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inTheSettingMenu.whenWeDelete("Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inTheSettingMenu.whenWeDelete("Alt_Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
});
it('Delete bind then assign a not yet binded button', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inTheSettingMenu.whenWeDelete("Alt_Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
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");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").thereShouldBeNoIcon().weWantThisBindInstead("B").confirm();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").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");
inGame.whenWePressOnKeyboard("R").weShouldTriggerTheButton("Button_Cycle_Shiny");
inGame.whenWePressOnKeyboard("F").weShouldTriggerTheButton("Button_Cycle_Form");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inTheSettingMenu.whenCursorIsOnSetting("Button_Cycle_Shiny").iconDisplayedIs("KEY_R").weWantThisBindInstead("D").confirm();
inGame.whenWePressOnKeyboard("R").nothingShouldHappen();
inGame.whenWePressOnKeyboard("F").weShouldTriggerTheButton("Button_Cycle_Form");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Button_Cycle_Shiny");
inTheSettingMenu.whenCursorIsOnSetting("Button_Cycle_Form").iconDisplayedIs("KEY_F").weWantThisBindInstead("Z").confirm();
inGame.whenWePressOnKeyboard("R").nothingShouldHappen();
inGame.whenWePressOnKeyboard("F").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Button_Cycle_Form");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Button_Cycle_Shiny");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inTheSettingMenu.whenWeDelete("Alt_Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("R").nothingShouldHappen();
inGame.whenWePressOnKeyboard("F").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Button_Cycle_Form");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Button_Cycle_Shiny");
inGame.whenWePressOnKeyboard("S").weShouldTriggerTheButton("Alt_Button_Down");
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Down").iconDisplayedIs("KEY_S").weWantThisBindInstead("B").confirm();
inGame.whenWePressOnKeyboard("R").nothingShouldHappen();
inGame.whenWePressOnKeyboard("F").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Button_Cycle_Form");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Button_Cycle_Shiny");
inGame.whenWePressOnKeyboard("S").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").weShouldTriggerTheButton("Alt_Button_Down");
});
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");
inTheSettingMenu.whenWeDelete("Alt_Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").thereShouldBeNoIcon().weWantThisBindInstead("B").confirm();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").weShouldTriggerTheButton("Alt_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("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inGame.whenWePressOnKeyboard("B").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();
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("KEY_Q").weWantThisBindInstead("B").confirm();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inGame.whenWePressOnKeyboard("B").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("U").nothingShouldHappen();
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Right").iconDisplayedIs("KEY_D").weWantThisBindInstead("U").confirm();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("D").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("U").weShouldTriggerTheButton("Alt_Button_Right");
});
it('Swap multiple touch alt and main', () => {
@ -269,45 +327,40 @@ describe('Test Rebinding', () => {
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");
inTheSettingMenu.whenCursorIsOnSetting("Button_Up").iconDisplayedIs("KEY_ARROW_UP").weWantThisBindInstead("RIGHT").weCantConfirm().butLetsForceIt();
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("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("UP").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("Z").nothingShouldHappen();
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("UP").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
})
inGame.whenWePressOnKeyboard("D").nothingShouldHappen();
});
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();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inTheSettingMenu.whenWeDelete("Alt_Button_Left").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("B").nothingShouldHappen();
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inTheSettingMenu.whenWeDelete("Alt_Button_Right").thereShouldBeNoIconAnymore();
inGame.whenWePressOnKeyboard("Q").nothingShouldHappen();
inGame.whenWePressOnKeyboard("D").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();
inGame.whenWePressOnKeyboard("D").nothingShouldHappen();
});
it("test keyboard listener", () => {
@ -317,6 +370,7 @@ describe('Test Rebinding', () => {
const buttonDown = config.settings[settingName];
expect(buttonDown).toEqual(Button.DOWN);
});
it("retrieve the correct icon for a given source", () => {
inTheSettingMenu.whenCursorIsOnSetting("Cycle_Shiny").iconDisplayedIs("KEY_R");
inTheSettingMenu.whenCursorIsOnSetting("Cycle_Form").iconDisplayedIs("KEY_F");
@ -324,17 +378,6 @@ describe('Test Rebinding', () => {
inGame.forTheSource("keyboard").forTheWantedBind("Cycle_Form").weShouldSeeTheIcon("F")
});
it("test new assign feature to delete the bind from the previous action instead of swaping it", () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").confirmAssignment();
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_RIGHT").weWantThisBindInstead("RIGHT").confirmAssignment();
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("LEFT").nothingShouldHappen();
});
it("check the key displayed on confirm", () => {
inGame.whenWePressOnKeyboard("ENTER").weShouldTriggerTheButton("Button_Submit");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
@ -343,19 +386,19 @@ describe('Test Rebinding', () => {
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("ESC").weShouldTriggerTheButton("Button_Menu");
inGame.whenWePressOnKeyboard("HOME").nothingShouldHappen();
inTheSettingMenu.whenCursorIsOnSetting("Button_Submit").iconDisplayedIs("KEY_ENTER").whenWeTryToDelete().iconDisplayedIs("KEY_ENTER")
inTheSettingMenu.whenCursorIsOnSetting("Button_Up").iconDisplayedIs("KEY_ARROW_UP").whenWeTryToDelete().iconDisplayedIs("KEY_ARROW_UP")
inTheSettingMenu.whenCursorIsOnSetting("Button_Down").iconDisplayedIs("KEY_ARROW_DOWN").whenWeTryToDelete().iconDisplayedIs("KEY_ARROW_DOWN")
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").whenWeTryToDelete().iconDisplayedIs("KEY_ARROW_LEFT")
inTheSettingMenu.whenCursorIsOnSetting("Button_Right").iconDisplayedIs("KEY_ARROW_RIGHT").whenWeTryToDelete().iconDisplayedIs("KEY_ARROW_RIGHT")
inTheSettingMenu.whenCursorIsOnSetting("Button_Menu").iconDisplayedIs("KEY_ESC").whenWeTryToDelete().iconDisplayedIs("KEY_ESC")
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Up").iconDisplayedIs("KEY_Z").whenWeTryToDelete().thereShouldBeNoIconAnymore();
inTheSettingMenu.whenCursorIsOnSetting("Button_Submit").iconDisplayedIs("KEY_ENTER").whenWeDelete().iconDisplayedIs("KEY_ENTER")
inTheSettingMenu.whenCursorIsOnSetting("Button_Up").iconDisplayedIs("KEY_ARROW_UP").whenWeDelete().iconDisplayedIs("KEY_ARROW_UP")
inTheSettingMenu.whenCursorIsOnSetting("Button_Down").iconDisplayedIs("KEY_ARROW_DOWN").whenWeDelete().iconDisplayedIs("KEY_ARROW_DOWN")
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").whenWeDelete().iconDisplayedIs("KEY_ARROW_LEFT")
inTheSettingMenu.whenCursorIsOnSetting("Button_Right").iconDisplayedIs("KEY_ARROW_RIGHT").whenWeDelete().iconDisplayedIs("KEY_ARROW_RIGHT")
inTheSettingMenu.whenCursorIsOnSetting("Button_Menu").iconDisplayedIs("KEY_ESC").whenWeDelete().iconDisplayedIs("KEY_ESC")
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Up").iconDisplayedIs("KEY_Z").whenWeDelete().thereShouldBeNoIconAnymore();
});
it("check to delete all the binds of an action", () => {
inGame.whenWePressOnKeyboard("V").weShouldTriggerTheButton("Button_Cycle_Variant");
inGame.whenWePressOnKeyboard("K").weShouldTriggerTheButton("Alt_Button_Cycle_Variant");
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Cycle_Variant").iconDisplayedIs("KEY_K").whenWeTryToDelete().thereShouldBeNoIconAnymore();
inTheSettingMenu.whenCursorIsOnSetting("Button_Cycle_Variant").iconDisplayedIs("KEY_V").whenWeTryToDelete().iconDisplayedIs("KEY_V")
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Cycle_Variant").iconDisplayedIs("KEY_K").whenWeDelete().thereShouldBeNoIconAnymore();
inTheSettingMenu.whenCursorIsOnSetting("Button_Cycle_Variant").iconDisplayedIs("KEY_V").whenWeDelete().iconDisplayedIs("KEY_V")
});
});

View File

@ -2,7 +2,7 @@ import BattleScene from "../../battle-scene";
import AbstractBindingUiHandler from "../settings/abrast-binding-ui-handler";
import {Mode} from "../ui";
import {Device} from "#app/enums/devices";
import {getIconSpecialCase, getIconWithSettingName, getKeyWithKeycode} from "#app/configs/configHandler";
import {getIconWithSettingName, getKeyWithKeycode} from "#app/configs/configHandler";
export default class GamepadBindingUiHandler extends AbstractBindingUiHandler {
@ -27,15 +27,16 @@ export default class GamepadBindingUiHandler extends AbstractBindingUiHandler {
const buttonIcon = activeConfig.icons[key];
if (!buttonIcon) return;
this.buttonPressed = button.index;
const specialCaseIcon = getIconSpecialCase(activeConfig, button.index, this.target);
const assignedButtonIcon = getIconWithSettingName(activeConfig, this.target);
this.onInputDown(buttonIcon, specialCaseIcon || assignedButtonIcon, type);
this.onInputDown(buttonIcon, assignedButtonIcon, type);
}
swapAction(): boolean {
const activeConfig = this.scene.inputController.getActiveConfig(Device.GAMEPAD);
this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed)
this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig);
return true;
if(this.scene.inputController.assignBinding(activeConfig, this.target, this.buttonPressed)) {
this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig);
return true;
}
return false;
}
}

View File

@ -1,7 +1,7 @@
import BattleScene from "../../battle-scene";
import AbstractBindingUiHandler from "../settings/abrast-binding-ui-handler";
import {Mode} from "../ui";
import {getIconSpecialCase, getIconWithSettingName, getKeyWithKeycode} from "#app/configs/configHandler";
import { getIconWithSettingName, getKeyWithKeycode} from "#app/configs/configHandler";
import {Device} from "#app/enums/devices";
@ -26,16 +26,17 @@ export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler {
const buttonIcon = activeConfig.icons[_key];
if (!buttonIcon) return;
this.buttonPressed = key;
const specialCaseIcon = getIconSpecialCase(activeConfig, key, this.target);
const assignedButtonIcon = getIconWithSettingName(activeConfig, this.target);
this.onInputDown(buttonIcon, specialCaseIcon || assignedButtonIcon, 'keyboard');
this.onInputDown(buttonIcon, assignedButtonIcon, 'keyboard');
}
swapAction(): boolean {
const activeConfig = this.scene.inputController.getActiveConfig(Device.KEYBOARD);
this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed)
this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig);
return true;
if (this.scene.inputController.assignBinding(activeConfig, this.target, this.buttonPressed)) {
this.scene.gameData.saveMappingConfigs(this.getSelectedDevice(), activeConfig);
return true;
}
return false;
}
}

View File

@ -62,11 +62,13 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position.
const selection = this.settingLabels[cursor].text;
const key = reverseValueToKeySetting(selection);
const setting = SettingKeyboard[key];
const settingName = SettingKeyboard[key];
const activeConfig = this.getActiveConfig();
deleteBind(this.getActiveConfig(), setting);
this.saveCustomKeyboardMappingToLocalStorage(activeConfig);
this.updateBindings();
const success = deleteBind(this.getActiveConfig(), settingName);
if (success) {
this.saveCustomKeyboardMappingToLocalStorage(activeConfig);
this.updateBindings();
}
}
/**