fix indirect delete blacklisted button

This commit is contained in:
Greenlamp 2024-05-17 12:24:50 +02:00
parent e1be1a3f82
commit 79c0116e81
5 changed files with 37 additions and 17 deletions

View File

@ -120,7 +120,7 @@ export function assign(config, settingNameTarget, keycode): boolean {
// first, we need to check if this keycode is already used on another settingName // first, we need to check if this keycode is already used on another settingName
const previousSettingName = getSettingNameWithKeycode(config, keycode); const previousSettingName = getSettingNameWithKeycode(config, keycode);
const key = getKeyWithSettingName(config, previousSettingName); const key = getKeyWithSettingName(config, previousSettingName);
if (!canIAssignThisKey(config, key)) return false; if (!canIAssignThisKey(config, key) || ! canIOverrideThisSetting(config, settingNameTarget)) return false;
// if it was already bound, we delete the bind // if it was already bound, we delete the bind
if (previousSettingName) { if (previousSettingName) {
const previousKey = getKeyWithSettingName(config, previousSettingName); const previousKey = getKeyWithSettingName(config, previousSettingName);
@ -169,6 +169,12 @@ export function canIAssignThisKey(config, key) {
return true; return true;
} }
export function canIOverrideThisSetting(config, settingName) {
const key = getKeyWithSettingName(config, settingName);
if (config.blacklist?.includes(key) || isTheLatestBind(config, settingName)) return false;
return true;
}
export function canIDeleteThisKey(config, key) { export function canIDeleteThisKey(config, key) {
return canIAssignThisKey(config, key); return canIAssignThisKey(config, key);
} }

View File

@ -8,7 +8,7 @@ import {
getKeyWithKeycode, getKeyWithKeycode,
getKeyWithSettingName, getKeyWithSettingName,
assign, assign,
getSettingNameWithKeycode, canIAssignThisKey, canIDeleteThisKey getSettingNameWithKeycode, canIAssignThisKey, canIDeleteThisKey, canIOverrideThisSetting
} from "#app/configs/configHandler"; } from "#app/configs/configHandler";
export class MenuManip { export class MenuManip {
@ -112,12 +112,17 @@ export class MenuManip {
assign(this.config, this.settingName, this.keycode); assign(this.config, this.settingName, this.keycode);
} }
weCantConfirm() { weCantAssignThisKey() {
const key = getKeyWithKeycode(this.config, this.keycode); const key = getKeyWithKeycode(this.config, this.keycode);
expect(canIAssignThisKey(this.config, key)).toEqual(false); expect(canIAssignThisKey(this.config, key)).toEqual(false);
return this; return this;
} }
weCantOverrideThisBind() {
expect(canIOverrideThisSetting(this.config, this.settingName)).toEqual(false);
return this;
}
weCantDelete() { weCantDelete() {
const key = getKeyWithSettingName(this.config, this.settingName); const key = getKeyWithSettingName(this.config, this.settingName);
expect(canIDeleteThisKey(this.config, key)).toEqual(false); expect(canIDeleteThisKey(this.config, key)).toEqual(false);

View File

@ -103,30 +103,37 @@ describe('Test Rebinding', () => {
it('Check prevent rebind indirectly the d-pad buttons', () => { it('Check prevent rebind indirectly the d-pad buttons', () => {
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("Q") inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("Q")
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Right").iconDisplayedIs("D") inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Right").iconDisplayedIs("D")
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("Q").weWantThisBindInstead("LEFT").weCantConfirm().butLetsForceIt(); inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("Q").weWantThisBindInstead("LEFT").weCantAssignThisKey().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Left"); inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Left");
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left"); inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right"); inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
}); });
it('Swap alt with a d-pad main', () => {
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Up").iconDisplayedIs("KEY_ARROW_UP").weWantThisBindInstead("Z").weCantOverrideThisBind().butLetsForceIt();
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
});
it('Check if double assign d-pad is blocked', () => { it('Check if double assign d-pad is blocked', () => {
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right"); inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up"); inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantConfirm().butLetsForceIt(); inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantOverrideThisBind().weCantAssignThisKey().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left"); inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right"); inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up"); inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("UP").weCantConfirm().butLetsForceIt(); inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("UP").weCantOverrideThisBind().weCantAssignThisKey().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left"); inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right"); inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up"); inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantConfirm().butLetsForceIt(); inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantOverrideThisBind().weCantAssignThisKey().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left"); inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right"); inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
@ -158,18 +165,18 @@ describe('Test Rebinding', () => {
}); });
it('Check if triple swap d-pad is prevented', () => { it('Check if triple swap d-pad is prevented', () => {
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantConfirm().butLetsForceIt(); inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantOverrideThisBind().weCantAssignThisKey().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left"); inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right"); inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up"); inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Right").iconDisplayedIs("KEY_ARROW_RIGHT").weWantThisBindInstead("UP").weCantConfirm().butLetsForceIt(); inTheSettingMenu.whenCursorIsOnSetting("Button_Right").iconDisplayedIs("KEY_ARROW_RIGHT").weWantThisBindInstead("UP").weCantOverrideThisBind().weCantAssignThisKey().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left"); inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right"); inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up"); inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("LEFT").weCantConfirm().butLetsForceIt(); inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("LEFT").weCantOverrideThisBind().weCantAssignThisKey().butLetsForceIt();
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left"); inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right"); inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up"); inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
@ -327,7 +334,7 @@ describe('Test Rebinding', () => {
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right"); inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up"); inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right"); inGame.whenWePressOnKeyboard("D").weShouldTriggerTheButton("Alt_Button_Right");
inTheSettingMenu.whenCursorIsOnSetting("Button_Up").iconDisplayedIs("KEY_ARROW_UP").weWantThisBindInstead("RIGHT").weCantConfirm().butLetsForceIt(); inTheSettingMenu.whenCursorIsOnSetting("Button_Up").iconDisplayedIs("KEY_ARROW_UP").weWantThisBindInstead("RIGHT").weCantOverrideThisBind().weCantAssignThisKey().butLetsForceIt();
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up"); inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right"); inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up"); inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");

View File

@ -241,11 +241,13 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
onInputDown(buttonIcon: string, assignedButtonIcon: string, type: string): void { onInputDown(buttonIcon: string, assignedButtonIcon: string, type: string): void {
this.newButtonIcon.setTexture(type); this.newButtonIcon.setTexture(type);
this.newButtonIcon.setFrame(buttonIcon); this.newButtonIcon.setFrame(buttonIcon);
this.targetButtonIcon.setTexture(type); if (assignedButtonIcon) {
this.targetButtonIcon.setFrame(assignedButtonIcon); this.targetButtonIcon.setTexture(type);
this.targetButtonIcon.setFrame(assignedButtonIcon);
this.targetButtonIcon.setVisible(true);
this.swapText.setVisible(true);
}
this.newButtonIcon.setVisible(true); this.newButtonIcon.setVisible(true);
this.targetButtonIcon.setVisible(true);
this.swapText.setVisible(true);
this.setCursor(0); this.setCursor(0);
this.actionsContainer.setVisible(true); this.actionsContainer.setVisible(true);
} }

View File

@ -27,7 +27,7 @@ export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler {
if (!buttonIcon) return; if (!buttonIcon) return;
this.buttonPressed = key; this.buttonPressed = key;
const assignedButtonIcon = getIconWithSettingName(activeConfig, this.target); const assignedButtonIcon = getIconWithSettingName(activeConfig, this.target);
this.onInputDown(buttonIcon, assignedButtonIcon, 'keyboard'); this.onInputDown(buttonIcon, null, 'keyboard');
} }
swapAction(): boolean { swapAction(): boolean {