From 9a8a926851c059f77092d980df79a8c8562b8b34 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Sat, 12 Aug 2023 12:20:27 +0100 Subject: [PATCH] Code style fixes --- .../UI/ViewModels/Input/InputViewModel.cs | 52 +++++++++---------- .../Views/Input/ControllerInputView.axaml.cs | 2 +- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs index a1303372f..c3f1bb400 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/Input/InputViewModel.cs @@ -1,3 +1,4 @@ +using Avalonia; using Avalonia.Collections; using Avalonia.Controls; using Avalonia.Controls.ApplicationLifetimes; @@ -44,15 +45,14 @@ namespace Ryujinx.Ava.UI.ViewModels.Input private PlayerIndex _playerId; private int _controller; - private int _controllerNumber = 0; + private int _controllerNumber; private string _controllerImage; private int _device; private object _configViewModel; private string _profileName; private bool _isLoaded; - private readonly UserControl _owner; - private static readonly InputConfigJsonSerializerContext SerializerContext = new(JsonHelper.GetDefaultSerializerOptions()); + private static readonly InputConfigJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions()); public IGamepadDriver AvaloniaKeyboardDriver { get; } public IGamepad SelectedGamepad { get; private set; } @@ -177,11 +177,11 @@ namespace Ryujinx.Ava.UI.ViewModels.Input { get { - SvgImage image = new SvgImage(); + SvgImage image = new(); if (!string.IsNullOrWhiteSpace(_controllerImage)) { - SvgSource source = new SvgSource(); + SvgSource source = new(); source.Load(EmbeddedResources.GetStream(_controllerImage)); @@ -235,22 +235,17 @@ namespace Ryujinx.Ava.UI.ViewModels.Input public InputViewModel(UserControl owner) : this() { - _owner = owner; - if (Program.PreviewerDetached) { _mainWindow = - (MainWindow)((IClassicDesktopStyleApplicationLifetime)Avalonia.Application.Current + (MainWindow)((IClassicDesktopStyleApplicationLifetime)Application.Current .ApplicationLifetime).MainWindow; AvaloniaKeyboardDriver = new AvaloniaKeyboardDriver(owner); _mainWindow.InputManager.GamepadDriver.OnGamepadConnected += HandleOnGamepadConnected; _mainWindow.InputManager.GamepadDriver.OnGamepadDisconnected += HandleOnGamepadDisconnected; - if (_mainWindow.ViewModel.AppHost != null) - { - _mainWindow.ViewModel.AppHost.NpadManager.BlockInputUpdates(); - } + _mainWindow.ViewModel.AppHost?.NpadManager.BlockInputUpdates(); _isLoaded = false; @@ -342,7 +337,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input { return; } - else if (type == DeviceType.Keyboard) + + if (type == DeviceType.Keyboard) { if (_mainWindow.InputManager.KeyboardDriver is AvaloniaKeyboardDriver) { @@ -439,7 +435,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input const string Hyphen = "-"; const int Offset = 1; - return str.Substring(str.IndexOf(Hyphen) + Offset); + return str[(str.IndexOf(Hyphen) + Offset)..]; } public void LoadDevices() @@ -553,7 +549,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input ButtonL = Key.E, ButtonZl = Key.Q, ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound + ButtonSr = Key.Unbound, }, LeftJoyconStick = new JoyconConfigKeyboardStick @@ -562,7 +558,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input StickDown = Key.S, StickLeft = Key.A, StickRight = Key.D, - StickButton = Key.F + StickButton = Key.F, }, RightJoycon = new RightJoyconCommonConfig { @@ -574,7 +570,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input ButtonR = Key.U, ButtonZr = Key.O, ButtonSl = Key.Unbound, - ButtonSr = Key.Unbound + ButtonSr = Key.Unbound, }, RightJoyconStick = new JoyconConfigKeyboardStick { @@ -582,8 +578,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input StickDown = Key.K, StickLeft = Key.J, StickRight = Key.L, - StickButton = Key.H - } + StickButton = Key.H, + }, }; } else if (activeDevice.Type == DeviceType.Controller) @@ -613,14 +609,14 @@ namespace Ryujinx.Ava.UI.ViewModels.Input ButtonL = ConfigGamepadInputId.LeftShoulder, ButtonZl = ConfigGamepadInputId.LeftTrigger, ButtonSl = ConfigGamepadInputId.Unbound, - ButtonSr = ConfigGamepadInputId.Unbound + ButtonSr = ConfigGamepadInputId.Unbound, }, LeftJoyconStick = new JoyconConfigControllerStick { Joystick = ConfigStickInputId.Left, StickButton = ConfigGamepadInputId.LeftStick, InvertStickX = false, - InvertStickY = false + InvertStickY = false, }, RightJoycon = new RightJoyconCommonConfig { @@ -632,28 +628,28 @@ namespace Ryujinx.Ava.UI.ViewModels.Input ButtonR = ConfigGamepadInputId.RightShoulder, ButtonZr = ConfigGamepadInputId.RightTrigger, ButtonSl = ConfigGamepadInputId.Unbound, - ButtonSr = ConfigGamepadInputId.Unbound + ButtonSr = ConfigGamepadInputId.Unbound, }, RightJoyconStick = new JoyconConfigControllerStick { Joystick = ConfigStickInputId.Right, StickButton = ConfigGamepadInputId.RightStick, InvertStickX = false, - InvertStickY = false + InvertStickY = false, }, Motion = new StandardMotionConfigController { MotionBackend = MotionInputBackendType.GamepadDriver, EnableMotion = true, Sensitivity = 100, - GyroDeadzone = 1 + GyroDeadzone = 1, }, Rumble = new RumbleConfigController { StrongRumble = 1f, WeakRumble = 1f, - EnableRumble = false - } + EnableRumble = false, + }, }; } else @@ -700,7 +696,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input try { - config = JsonHelper.DeserializeFromFile(path, SerializerContext.InputConfig); + config = JsonHelper.DeserializeFromFile(path, _serializerContext.InputConfig); } catch (JsonException) { } catch (InvalidOperationException) @@ -766,7 +762,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input config.ControllerType = Controllers[_controller].Type; - string jsonString = JsonHelper.Serialize(config, SerializerContext.InputConfig); + string jsonString = JsonHelper.Serialize(config, _serializerContext.InputConfig); await File.WriteAllTextAsync(path, jsonString); diff --git a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs index edf7b6eba..5743bfe4d 100644 --- a/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs +++ b/src/Ryujinx.Ava/UI/Views/Input/ControllerInputView.axaml.cs @@ -23,7 +23,7 @@ namespace Ryujinx.Ava.UI.Views.Input foreach (ILogical visual in SettingButtons.GetLogicalDescendants()) { - if (visual is ToggleButton button && !(visual is CheckBox)) + if (visual is ToggleButton button and not CheckBox) { button.IsCheckedChanged += Button_IsCheckedChanged; }