get missmatch function call

pull/685/head
Greenlamp 2024-05-11 18:42:32 +02:00
parent e5e100990e
commit 83a26d8e58
5 changed files with 26 additions and 7 deletions

View File

@ -29,10 +29,18 @@ export function getKeyForRebindedAction(config: GamepadConfig, action: Button):
return null;
}
export function getKeyForAction(config: GamepadConfig, action: Button): String {
for (const key of Object.keys(config.custom)) {
if (config.custom[key] === action) return key;
}
return null;
}
export function getKeyForRebindedSettingName(config: GamepadConfig, settingName: SettingGamepad): String {
const oldKey = getKeyForSettingName(config, settingName)
const action = config.custom[oldKey];
return getKeyForRebindedAction(config, action);
const key = getKeyForRebindedAction(config, action);
return key;
}
export function getIconForRebindedKey(config: GamepadConfig, _key): String {
@ -48,3 +56,10 @@ export function getKeyForSettingName(config: GamepadConfig, settingName: Setting
}
return null;
}
export function getIconForSettingName(config: GamepadConfig, settingName: SettingGamepad) {
const key = getKeyForSettingName(config, settingName);
const action = config.default[key];
const rebindedKey = getKeyForAction(config, action);
return config.icons[rebindedKey];
}

View File

@ -58,8 +58,8 @@ const pad_generic = {
RS: SettingGamepad.Button_Slow_Down,
},
default: {
RC_S: Button.ACTION,
RC_E: Button.CANCEL,
RC_S: Button.ACTION, //5
RC_E: Button.CANCEL, // 6
RC_W: Button.CYCLE_NATURE,
RC_N: Button.CYCLE_VARIANT,
START: Button.MENU,

View File

@ -59,7 +59,7 @@ const pad_xbox360 = {
},
default: {
RC_S: Button.ACTION, //5
RC_E: Button.CANCEL,
RC_E: Button.CANCEL, // 6
RC_W: Button.CYCLE_NATURE,
RC_N: Button.CYCLE_VARIANT, //14
START: Button.MENU, //7

View File

@ -307,8 +307,9 @@ export class InputsController {
// for each gamepad, we set its mapping in this.configs
const gamepadID = gamepad.toLowerCase();
const config = this.getConfig(gamepadID);
config.custom = this.configs[gamepad]?.custom || config.default;
config.custom = this.configs[gamepad]?.custom || {...config.default};
this.configs[gamepad] = config;
this.scene.gameData?.saveCustomMapping(this.chosenGamepad, this.configs[gamepad]?.custom);
}
if (this.chosenGamepad === thisGamepad.id) this.initChosenGamepad(this.chosenGamepad)
}

View File

@ -12,7 +12,10 @@ import {
settingGamepadOptions
} from "../system/settings-gamepad";
import {truncateString} from "../utils";
import {getIconForRebindedKey, getKeyForSettingName} from "#app/configs/gamepad-utils";
import {
getIconForSettingName,
getKeyForSettingName
} from "#app/configs/gamepad-utils";
export default class SettingsGamepadUiHandler extends UiHandler {
private settingsContainer: Phaser.GameObjects.Container;
@ -141,7 +144,7 @@ export default class SettingsGamepadUiHandler extends UiHandler {
const activeConfig = this.scene.inputController.getActiveConfig();
for (const elm of noOptionsCursors) {
const key = getKeyForSettingName(activeConfig, elm);
const icon = getIconForRebindedKey(activeConfig, key);
const icon = getIconForSettingName(activeConfig, elm);
this.inputsIcons[key].setFrame(icon);
}
}