fix icons issue + identified a new bug => new test scenario

pull/685/head
Greenlamp 2024-05-14 18:20:01 +02:00
parent 3251846aea
commit c1e9e0c691
6 changed files with 170 additions and 13 deletions

View File

@ -340,13 +340,14 @@ export class InputsController {
const config = deepCopy(this.getConfig(gamepadID)); const config = deepCopy(this.getConfig(gamepadID));
config.custom = this.configs[gamepad]?.custom || {...config.default}; config.custom = this.configs[gamepad]?.custom || {...config.default};
config.ogIcons = {...config.icons}; config.ogIcons = {...config.icons};
config.icons = this.configs[gamepad]?.icons || {...config.icons};
config.currentKeys = this.configs[gamepad]?.currentKeys; config.currentKeys = this.configs[gamepad]?.currentKeys;
if (!this.configs[gamepad]?.currentKeys) if (!this.configs[gamepad]?.currentKeys)
reloadCurrentKeys(config); reloadCurrentKeys(config);
else else
regenerateCustom(config); regenerateCustom(config);
this.configs[gamepad] = config; this.configs[gamepad] = config;
this.scene.gameData?.saveCustomMapping(this.chosenGamepad, this.configs[gamepad]?.currentKeys); this.scene.gameData?.saveCustomMapping(this.chosenGamepad, this.configs[gamepad]?.currentKeys, this.configs[gamepad]?.icons);
} }
if (this.chosenGamepad === thisGamepad.id) this.initChosenGamepad(this.chosenGamepad) if (this.chosenGamepad === thisGamepad.id) this.initChosenGamepad(this.chosenGamepad)
} }
@ -355,14 +356,15 @@ export class InputsController {
for (const layout of ['default']) { for (const layout of ['default']) {
const config = deepCopy(this.getConfigKeyboard(layout)); const config = deepCopy(this.getConfigKeyboard(layout));
config.custom = this.keyboardConfigs[layout]?.custom || {...config.default}; config.custom = this.keyboardConfigs[layout]?.custom || {...config.default};
config.currentKeys = this.keyboardConfigs[layout]?.currentKeys;
config.ogIcons = {...config.icons}; config.ogIcons = {...config.icons};
config.icons = this.keyboardConfigs[layout]?.icons || {...config.icons};
config.currentKeys = this.keyboardConfigs[layout]?.currentKeys;
if (!this.keyboardConfigs[layout]?.currentKeys) if (!this.keyboardConfigs[layout]?.currentKeys)
reloadCurrentKeys(config); reloadCurrentKeys(config);
else else
regenerateCustom(config); regenerateCustom(config);
this.keyboardConfigs[layout] = config; this.keyboardConfigs[layout] = config;
this.scene.gameData?.saveCustomKeyboardMapping(this.chosenKeyboard, this.keyboardConfigs[layout]?.currentKeys); this.scene.gameData?.saveCustomKeyboardMapping(this.chosenKeyboard, this.keyboardConfigs[layout]?.currentKeys, this.keyboardConfigs[layout]?.icons);
} }
this.initChosenLayoutKeyboard(this.chosenKeyboard) this.initChosenLayoutKeyboard(this.chosenKeyboard)
} }
@ -765,11 +767,13 @@ export class InputsController {
*/ */
injectConfig(gamepadName: String, customMappings): void { injectConfig(gamepadName: String, customMappings): void {
if (!this.configs[gamepadName]) this.configs[gamepadName] = {}; if (!this.configs[gamepadName]) this.configs[gamepadName] = {};
this.configs[gamepadName].currentKeys = customMappings; this.configs[gamepadName].currentKeys = customMappings.currentKeys;
this.configs[gamepadName].icons = customMappings.icons;
} }
injectKeyboardConfig(layout: string, customMappings): void { injectKeyboardConfig(layout: string, customMappings): void {
if (!this.keyboardConfigs[layout]) this.keyboardConfigs[layout] = {}; if (!this.keyboardConfigs[layout]) this.keyboardConfigs[layout] = {};
this.keyboardConfigs[layout].currentKeys = customMappings; this.keyboardConfigs[layout].currentKeys = customMappings.currentKeys;
this.keyboardConfigs[layout].icons = customMappings.icons;
} }
swapBinding(config, settingName, pressedButton): void { swapBinding(config, settingName, pressedButton): void {

View File

@ -498,20 +498,26 @@ export class GameData {
return true; return true;
} }
public saveCustomMapping(gamepadName: string, currentKeys): boolean { public saveCustomMapping(gamepadName: string, currentKeys, icons): boolean {
let customMappings: object = {}; let customMappings: object = {};
if (localStorage.hasOwnProperty('customMapping')) if (localStorage.hasOwnProperty('customMapping'))
customMappings = JSON.parse(localStorage.getItem('customMapping')); customMappings = JSON.parse(localStorage.getItem('customMapping'));
customMappings[gamepadName] = currentKeys; customMappings[gamepadName] = {
currentKeys,
icons
};
localStorage.setItem('customMapping', JSON.stringify(customMappings)); localStorage.setItem('customMapping', JSON.stringify(customMappings));
return true; return true;
} }
public saveCustomKeyboardMapping(keyboardLayout: string, currentKeys): boolean { public saveCustomKeyboardMapping(keyboardLayout: string, currentKeys, icons): boolean {
let customKeyboardMappings: object = {}; let customKeyboardMappings: object = {};
if (localStorage.hasOwnProperty('customKeyboardMappings')) if (localStorage.hasOwnProperty('customKeyboardMappings'))
customKeyboardMappings = JSON.parse(localStorage.getItem('customKeyboardMappings')); customKeyboardMappings = JSON.parse(localStorage.getItem('customKeyboardMappings'));
customKeyboardMappings[keyboardLayout] = currentKeys; customKeyboardMappings[keyboardLayout] = {
currentKeys,
icons
};
localStorage.setItem('customKeyboardMappings', JSON.stringify(customKeyboardMappings)); localStorage.setItem('customKeyboardMappings', JSON.stringify(customKeyboardMappings));
return true; return true;
} }

View File

@ -7,7 +7,7 @@ import {
getKeyAndActionFromCurrentKeysWithSettingName, getKeyAndActionFromCurrentKeysWithSettingName,
getKeyForSettingName, getKeyForSettingName,
getKeyFromMapping, getKeyFromMapping,
getKeyWithAction, getKeyWithAction, regenerateCustom,
reloadCurrentKeys, reloadCurrentKeys,
swapCurrentKeys, swapCurrentKeys,
} from "#app/configs/gamepad-utils"; } from "#app/configs/gamepad-utils";
@ -443,4 +443,151 @@ describe('Test Keyboard', () => {
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_T_Key_Dark.png"); expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_T_Key_Dark.png");
}) })
it('reload scenario with 1 bind already reassigned', () => {
config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up] = {
"key": "KEY_Z",
"isAlt": true,
"action": 3,
"icon": "T_D_Key_Dark.png",
"from": {
"key": "KEY_Z",
"isAlt": true,
"action": 0,
"icon": "T_Z_Key_Dark.png"
}
};
config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right] = {
"key": "KEY_D",
"isAlt": true,
"action": 0,
"icon": "T_Z_Key_Dark.png",
"from": {
"key": "KEY_D",
"isAlt": true,
"action": 3,
"icon": "T_D_Key_Dark.png"
}
}
config.icons["KEY_D"] = "T_Z_Key_Dark.png";
config.icons["KEY_Z"] = "T_D_Key_Dark.png";
regenerateCustom(config);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_D_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_D"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.UP);
swapCurrentKeys(config, SettingInterfaceKeyboard.Button_Up, Phaser.Input.Keyboard.KeyCodes.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_D_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_D"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Right_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_RIGHT"]).toEqual(Button.UP);
});
it('Swap multiple touch alt and main', () => {
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Right_Key_Dark.png");
expect(config.custom["KEY_ARROW_RIGHT"]).toEqual(Button.RIGHT);
swapCurrentKeys(config, SettingInterfaceKeyboard.Button_Up, Phaser.Input.Keyboard.KeyCodes.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Right_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_RIGHT"]).toEqual(Button.UP);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.D);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Right_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_D_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_RIGHT"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_D"]).toEqual(Button.UP);
swapCurrentKeys(config, SettingInterfaceKeyboard.Alt_Button_Up, Phaser.Input.Keyboard.KeyCodes.Z);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].key).toEqual("KEY_ARROW_UP");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Up].icon).toEqual("T_Right_Key_Dark.png");
expect(config.custom["KEY_ARROW_UP"]).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].key).toEqual("KEY_Z");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Up].icon).toEqual("T_Z_Key_Dark.png");
expect(config.custom["KEY_Z"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].key).toEqual("KEY_ARROW_RIGHT");
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].action).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Button_Right].icon).toEqual("T_Up_Key_Dark.png");
expect(config.custom["KEY_ARROW_RIGHT"]).toEqual(Button.UP);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].key).toEqual("KEY_D");
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].action).toEqual(Button.RIGHT);
expect(config.currentKeys[SettingInterfaceKeyboard.Alt_Button_Right].icon).toEqual("T_D_Key_Dark.png");
expect(config.custom["KEY_D"]).toEqual(Button.RIGHT);
})
}); });

View File

@ -31,7 +31,7 @@ export default class GamepadBindingUiHandler extends AbstractBindingUiHandler {
swapAction() { swapAction() {
const activeConfig = this.scene.inputController.getActiveConfig(); const activeConfig = this.scene.inputController.getActiveConfig();
this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed) this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed)
this.scene.gameData.saveCustomMapping(this.scene.inputController?.chosenGamepad, activeConfig.currentKeys); this.scene.gameData.saveCustomMapping(this.scene.inputController?.chosenGamepad, activeConfig.currentKeys, activeConfig.icons);
regenerateCustom(activeConfig); regenerateCustom(activeConfig);
return true; return true;
} }

View File

@ -30,7 +30,7 @@ export default class KeyboardBindingUiHandler extends AbstractBindingUiHandler {
swapAction() { swapAction() {
const activeConfig = this.scene.inputController.getActiveKeyboardConfig(); const activeConfig = this.scene.inputController.getActiveKeyboardConfig();
this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed) this.scene.inputController.swapBinding(activeConfig, this.target, this.buttonPressed)
this.scene.gameData.saveCustomKeyboardMapping(this.scene.inputController?.chosenKeyboard, activeConfig.currentKeys); this.scene.gameData.saveCustomKeyboardMapping(this.scene.inputController?.chosenKeyboard, activeConfig.currentKeys, activeConfig.icons);
regenerateCustom(activeConfig); regenerateCustom(activeConfig);
return true; return true;
} }

View File

@ -77,7 +77,7 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
} }
saveCustomKeyboardMappingToLocalStorage(config): void { saveCustomKeyboardMappingToLocalStorage(config): void {
this.scene.gameData.saveCustomKeyboardMapping(this.scene.inputController?.chosenKeyboard, config.currentKeys); this.scene.gameData.saveCustomKeyboardMapping(this.scene.inputController?.chosenKeyboard, config.currentKeys, config.icons);
} }
saveSettingToLocalStorage(settingName, cursor): void { saveSettingToLocalStorage(settingName, cursor): void {