fixed save config logic

This commit is contained in:
uncavo-hdmi 2025-02-17 20:59:51 +01:00
parent 8cc74dab08
commit e238ea85c9

View File

@ -70,17 +70,21 @@ namespace Ryujinx.Ava.Input
_viewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, _configurationState.Hid.EnableKeyboard, _configurationState.Hid.EnableMouse); _viewModel.AppHost?.NpadManager.ReloadConfiguration(newConfig, _configurationState.Hid.EnableKeyboard, _configurationState.Hid.EnableMouse);
if (hasNewControllersConnected) if (!hasNewControllersConnected)
{ {
ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath); // there is no *new* controller, we must switch the order of the controllers in
} // oldConfig to match the new order since probably a controller was disconnected
else // or an old controller was reconnected
{
// we must switch the order of the controllers in oldConfig to match the new order
newConfig = ReorderControllers(newConfig, oldConfig); newConfig = ReorderControllers(newConfig, oldConfig);
} }
_configurationState.Hid.InputConfig.Value = newConfig; _configurationState.Hid.InputConfig.Value = newConfig;
// we want to save the configuration only if a *new* controller was connected
if(hasNewControllersConnected)
{
ConfigurationState.Instance.ToFileFormat().SaveConfig(Program.ConfigurationPath);
}
ConfigurationUpdated?.Invoke(); ConfigurationUpdated?.Invoke();
} }
@ -119,10 +123,10 @@ namespace Ryujinx.Ava.Input
List<IGamepad> remainingControllers = controllers.Where(c => c?.Id != null).ToList(); List<IGamepad> remainingControllers = controllers.Where(c => c?.Id != null).ToList();
// Assign controllers that have an existing configuration // Assign controllers that have an existing configuration
AssignExistingControllers(remainingControllers, oldConfigMap, playerIndexMap, usedIndices, ref recognizedControllersCount); AddExistingControllers(remainingControllers, oldConfigMap, playerIndexMap, usedIndices, ref recognizedControllersCount);
// Assign new controllers // Assign new controllers
AssignNewControllers(remainingControllers, playerIndexMap, usedIndices); AddNewControllers(remainingControllers, playerIndexMap, usedIndices);
List<InputConfig> orderedConfigs = playerIndexMap.OrderBy(x => x.Key).Select(x => x.Value).ToList(); List<InputConfig> orderedConfigs = playerIndexMap.OrderBy(x => x.Key).Select(x => x.Value).ToList();
@ -134,9 +138,9 @@ namespace Ryujinx.Ava.Input
} }
/// <summary> /// <summary>
/// Assigns controllers with existing configurations while keeping their PlayerIndex if available. /// Adds controllers with existing configurations while keeping their PlayerIndex if available.
/// </summary> /// </summary>
private void AssignExistingControllers( private void AddExistingControllers(
List<IGamepad> controllers, List<IGamepad> controllers,
Dictionary<string, InputConfig> oldConfigMap, Dictionary<string, InputConfig> oldConfigMap,
Dictionary<int, InputConfig> playerIndexMap, Dictionary<int, InputConfig> playerIndexMap,
@ -167,9 +171,9 @@ namespace Ryujinx.Ava.Input
} }
/// <summary> /// <summary>
/// Assigns new controllers to the first available PlayerIndex. /// Adds new controllers to the first available PlayerIndex.
/// </summary> /// </summary>
private void AssignNewControllers( private void AddNewControllers(
List<IGamepad> controllers, List<IGamepad> controllers,
Dictionary<int, InputConfig> playerIndexMap, Dictionary<int, InputConfig> playerIndexMap,
HashSet<int> usedIndices) HashSet<int> usedIndices)