mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-16 21:32:18 +02:00
fix indirect delete blacklisted button
This commit is contained in:
parent
e1be1a3f82
commit
79c0116e81
@ -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
|
||||
const previousSettingName = getSettingNameWithKeycode(config, keycode);
|
||||
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 (previousSettingName) {
|
||||
const previousKey = getKeyWithSettingName(config, previousSettingName);
|
||||
@ -169,6 +169,12 @@ export function canIAssignThisKey(config, key) {
|
||||
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) {
|
||||
return canIAssignThisKey(config, key);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
getKeyWithKeycode,
|
||||
getKeyWithSettingName,
|
||||
assign,
|
||||
getSettingNameWithKeycode, canIAssignThisKey, canIDeleteThisKey
|
||||
getSettingNameWithKeycode, canIAssignThisKey, canIDeleteThisKey, canIOverrideThisSetting
|
||||
} from "#app/configs/configHandler";
|
||||
|
||||
export class MenuManip {
|
||||
@ -112,12 +112,17 @@ export class MenuManip {
|
||||
assign(this.config, this.settingName, this.keycode);
|
||||
}
|
||||
|
||||
weCantConfirm() {
|
||||
weCantAssignThisKey() {
|
||||
const key = getKeyWithKeycode(this.config, this.keycode);
|
||||
expect(canIAssignThisKey(this.config, key)).toEqual(false);
|
||||
return this;
|
||||
}
|
||||
|
||||
weCantOverrideThisBind() {
|
||||
expect(canIOverrideThisSetting(this.config, this.settingName)).toEqual(false);
|
||||
return this;
|
||||
}
|
||||
|
||||
weCantDelete() {
|
||||
const key = getKeyWithSettingName(this.config, this.settingName);
|
||||
expect(canIDeleteThisKey(this.config, key)).toEqual(false);
|
||||
|
@ -103,30 +103,37 @@ describe('Test Rebinding', () => {
|
||||
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();
|
||||
inTheSettingMenu.whenCursorIsOnSetting("Alt_Button_Left").iconDisplayedIs("Q").weWantThisBindInstead("LEFT").weCantAssignThisKey().butLetsForceIt();
|
||||
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Left");
|
||||
inGame.whenWePressOnKeyboard("Q").weShouldTriggerTheButton("Alt_Button_Left");
|
||||
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', () => {
|
||||
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").weCantConfirm().butLetsForceIt();
|
||||
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantOverrideThisBind().weCantAssignThisKey().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("UP").weCantConfirm().butLetsForceIt();
|
||||
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("UP").weCantOverrideThisBind().weCantAssignThisKey().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("RIGHT").weCantConfirm().butLetsForceIt();
|
||||
inTheSettingMenu.whenCursorIsOnSetting("Button_Left").iconDisplayedIs("KEY_ARROW_LEFT").weWantThisBindInstead("RIGHT").weCantOverrideThisBind().weCantAssignThisKey().butLetsForceIt();
|
||||
|
||||
inGame.whenWePressOnKeyboard("LEFT").weShouldTriggerTheButton("Button_Left");
|
||||
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
|
||||
@ -158,18 +165,18 @@ describe('Test Rebinding', () => {
|
||||
});
|
||||
|
||||
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("RIGHT").weShouldTriggerTheButton("Button_Right");
|
||||
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("RIGHT").weShouldTriggerTheButton("Button_Right");
|
||||
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("RIGHT").weShouldTriggerTheButton("Button_Right");
|
||||
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
|
||||
@ -327,7 +334,7 @@ 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").weCantConfirm().butLetsForceIt();
|
||||
inTheSettingMenu.whenCursorIsOnSetting("Button_Up").iconDisplayedIs("KEY_ARROW_UP").weWantThisBindInstead("RIGHT").weCantOverrideThisBind().weCantAssignThisKey().butLetsForceIt();
|
||||
inGame.whenWePressOnKeyboard("UP").weShouldTriggerTheButton("Button_Up");
|
||||
inGame.whenWePressOnKeyboard("RIGHT").weShouldTriggerTheButton("Button_Right");
|
||||
inGame.whenWePressOnKeyboard("Z").weShouldTriggerTheButton("Alt_Button_Up");
|
||||
|
@ -241,11 +241,13 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
||||
onInputDown(buttonIcon: string, assignedButtonIcon: string, type: string): void {
|
||||
this.newButtonIcon.setTexture(type);
|
||||
this.newButtonIcon.setFrame(buttonIcon);
|
||||
this.targetButtonIcon.setTexture(type);
|
||||
this.targetButtonIcon.setFrame(assignedButtonIcon);
|
||||
if (assignedButtonIcon) {
|
||||
this.targetButtonIcon.setTexture(type);
|
||||
this.targetButtonIcon.setFrame(assignedButtonIcon);
|
||||
this.targetButtonIcon.setVisible(true);
|
||||
this.swapText.setVisible(true);
|
||||
}
|
||||
this.newButtonIcon.setVisible(true);
|
||||
this.targetButtonIcon.setVisible(true);
|
||||
this.swapText.setVisible(true);
|
||||
this.setCursor(0);
|
||||
this.actionsContainer.setVisible(true);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler {
|
||||
if (!buttonIcon) return;
|
||||
this.buttonPressed = key;
|
||||
const assignedButtonIcon = getIconWithSettingName(activeConfig, this.target);
|
||||
this.onInputDown(buttonIcon, assignedButtonIcon, 'keyboard');
|
||||
this.onInputDown(buttonIcon, null, 'keyboard');
|
||||
}
|
||||
|
||||
swapAction(): boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user