adding tests to welcome new behaviour

This commit is contained in:
Greenlamp 2024-05-17 00:43:23 +02:00
parent 5568a7136f
commit e8b6e588a5
5 changed files with 108 additions and 2 deletions

View File

@ -278,6 +278,16 @@ const cfg_keyboard_azerty = {
},
main: [],
alt: [],
blacklist: [
"KEY_ENTER",
"KEY_ESC",
"KEY_ARROW_UP",
"KEY_ARROW_DOWN",
"KEY_ARROW_LEFT",
"KEY_ARROW_RIGHT",
"KEY_DELETE",
"KEY_HOME",
]
};
export default cfg_keyboard_azerty;

View File

@ -211,6 +211,23 @@ export function swap(config, settingNameTarget, keycode) {
regenerateIdentifiers(config);
}
export function assign(config, settingNameTarget, keycode) {
// first, we need to check if this keycode is already used on another settingName
const previousSettingName = getSettingNameWithKeycode(config, keycode);
// if it was already bound, we delete the bind
if (previousSettingName) {
const previousKey = getKeyWithSettingName(config, previousSettingName);
config.custom[previousKey] = -1;
}
// then, we need to delete the current key for this settingName
const currentKey = getKeyWithSettingName(config, settingNameTarget);
config.custom[currentKey] = -1;
// then, the new key is assigned to the new settingName
const newKey = getKeyWithKeycode(config, keycode);
config.custom[newKey] = settingNameTarget;
}
/**
* Deletes the binding of the specified setting name.
*
@ -223,6 +240,29 @@ export function deleteBind(config, settingName) {
regenerateIdentifiers(config);
}
/**
* 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 isTheLatestBind(config, settingName) {
const isAlt = settingName.includes("ALT_");
let altSettingName;
if (isAlt)
altSettingName = settingName.split("ALT_").splice(1)[0];
else
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.

View File

@ -315,6 +315,16 @@ const cfg_keyboard_azerty = {
},
main: [],
alt: [],
blacklist: [
"KEY_ENTER",
"KEY_ESC",
"KEY_ARROW_UP",
"KEY_ARROW_DOWN",
"KEY_ARROW_LEFT",
"KEY_ARROW_RIGHT",
"KEY_DELETE",
"KEY_HOME",
]
};
export default cfg_keyboard_azerty;

View File

@ -6,7 +6,7 @@ import {
getIconWithKey,
getIconWithKeycode,
getIconWithSettingName,
getKeyWithKeycode, getKeyWithSettingName, getKeySolvingConflict, swap
getKeyWithKeycode, getKeyWithSettingName, getKeySolvingConflict, swap, assign, safeDeleteBind
} from "#app/configs/configHandler";
export class MenuManip {
@ -44,7 +44,8 @@ export class MenuManip {
whenCursorIsOnSetting(settingName) {
if (!settingName.includes("Button_")) settingName = "Button_" + settingName;
this.settingName = SettingInterface[settingName];
const buttonName = this.convertNameToButtonString(settingName);
const isAlt = settingName.includes("ALT_");
const buttonName = isAlt ? settingName.toUpperCase().split("ALT_BUTTON_").splice(1)[0] : settingName.toUpperCase().split("BUTTON_").splice(1)[0];
expect(this.config.settings[this.settingName]).toEqual(Button[buttonName]);
return this;
}
@ -91,6 +92,16 @@ export class MenuManip {
return this;
}
whenWeTryToDelete(settingName?: string) {
this.settingName = SettingInterface[settingName] || this.settingName;
safeDeleteBind(this.config, this.settingName);
return this;
}
confirmAssignment() {
assign(this.config, this.settingName, this.keycode);
}
confirm() {
swap(this.config, this.settingName, this.keycode);
}

View File

@ -323,4 +323,39 @@ describe('Test Rebinding', () => {
inGame.forTheSource("keyboard").forTheWantedBind("Cycle_Shiny").weShouldSeeTheIcon("R")
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");
inGame.whenWePressOnKeyboard("DOWN").weShouldTriggerTheButton("Button_Down");
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
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();
});
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")
});
});