pull/685/head
Greenlamp 2024-05-14 02:54:21 +02:00
parent ea4372e1f3
commit 5dd9e017ea
2 changed files with 75 additions and 9 deletions

View File

@ -72,19 +72,14 @@ export function swapCurrentKeys(config: InterfaceConfig, settingName, pressedBut
if (prevKey.key === nextKey.key) {
// special case when back to back and not enough info to get back to previous button
const toRestore = getKeyAndSettingNameFromCurrentKeysWithAction(config, prevKey.from.action);
const iconToRestore = config.icons[toRestore.key];
config.custom[prevKey.key] = prevKey.from.action;
config.icons[prevKey.key] = iconToRestore;
config.icons[prevKey.key] = prevKey.from.icon;
config.custom[toRestore.key] = prevKey.action;
config.icons[toRestore.key] = prevKey.icon;
config.currentKeys[settingName].from = prevKey;
config.currentKeys[toRestore.settingName].from = {
key: toRestore.key,
action: prevKey.from.action,
icon: iconToRestore,
};
delete config.currentKeys[settingName].from;
delete config.currentKeys[toRestore.settingName].from;
} else {
config.custom[previousBind.key] = newBind.action;
config.custom[newBind.key] = previousBind.action;

View File

@ -6,7 +6,7 @@ import {
getKeyAndActionFromCurrentKeysWithSettingName,
getKeyForSettingName,
getKeyFromMapping,
getKeyWithAction,
getKeyWithAction, regenerateCustom,
reloadCurrentKeys,
swapCurrentKeys,
} from "#app/configs/gamepad-utils";
@ -183,4 +183,75 @@ describe('Test Keyboard', () => {
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');
})
});