From 5dd9e017ea0749f5531791e76bc6875a38673ad5 Mon Sep 17 00:00:00 2001 From: Greenlamp Date: Tue, 14 May 2024 02:54:21 +0200 Subject: [PATCH] fix icon --- src/configs/gamepad-utils.ts | 11 ++--- src/test/gamepad_remaping.test.ts | 73 ++++++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 9 deletions(-) diff --git a/src/configs/gamepad-utils.ts b/src/configs/gamepad-utils.ts index 473336ef2..b6445cbf0 100644 --- a/src/configs/gamepad-utils.ts +++ b/src/configs/gamepad-utils.ts @@ -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; diff --git a/src/test/gamepad_remaping.test.ts b/src/test/gamepad_remaping.test.ts index 8bd683519..7ac8b0a05 100644 --- a/src/test/gamepad_remaping.test.ts +++ b/src/test/gamepad_remaping.test.ts @@ -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'); + }) }); \ No newline at end of file