فهرست منبع

misc: chore: use ObservableProperty on input view models

Evan Husted 1 سال پیش
والد
کامیت
d4a7ee25ea

+ 4 - 21
src/Ryujinx/UI/ViewModels/Input/ControllerInputViewModel.cs

@@ -1,21 +1,13 @@
 using Avalonia.Svg.Skia;
+using CommunityToolkit.Mvvm.ComponentModel;
 using Ryujinx.Ava.UI.Models.Input;
 using Ryujinx.Ava.UI.Views.Input;
 
 namespace Ryujinx.Ava.UI.ViewModels.Input
 {
-    public class ControllerInputViewModel : BaseModel
+    public partial class ControllerInputViewModel : BaseModel
     {
-        private GamepadInputConfig _config;
-        public GamepadInputConfig Config
-        {
-            get => _config;
-            set
-            {
-                _config = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private GamepadInputConfig _config;
 
         private bool _isLeft;
         public bool IsLeft
@@ -43,16 +35,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
 
         public bool HasSides => IsLeft ^ IsRight;
 
-        private SvgImage _image;
-        public SvgImage Image
-        {
-            get => _image;
-            set
-            {
-                _image = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private SvgImage _image;
 
         public readonly InputViewModel ParentModel;
 

+ 4 - 26
src/Ryujinx/UI/ViewModels/Input/InputViewModel.cs

@@ -1,9 +1,8 @@
-using Avalonia;
 using Avalonia.Collections;
 using Avalonia.Controls;
-using Avalonia.Controls.ApplicationLifetimes;
 using Avalonia.Svg.Skia;
 using Avalonia.Threading;
+using CommunityToolkit.Mvvm.ComponentModel;
 using Ryujinx.Ava.Common.Locale;
 using Ryujinx.Ava.Input;
 using Ryujinx.Ava.UI.Helpers;
@@ -32,7 +31,7 @@ using Key = Ryujinx.Common.Configuration.Hid.Key;
 
 namespace Ryujinx.Ava.UI.ViewModels.Input
 {
-    public class InputViewModel : BaseModel, IDisposable
+    public partial class InputViewModel : BaseModel, IDisposable
     {
         private const string Disabled = "disabled";
         private const string ProControllerResource = "Ryujinx/Assets/Icons/Controller_ProCon.svg";
@@ -48,8 +47,8 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
         private int _controller;
         private string _controllerImage;
         private int _device;
-        private object _configViewModel;
-        private string _profileName;
+        [ObservableProperty] private object _configViewModel;
+        [ObservableProperty] private string _profileName;
         private bool _isLoaded;
 
         private static readonly InputConfigJsonSerializerContext _serializerContext = new(JsonHelper.GetDefaultSerializerOptions());
@@ -73,17 +72,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
         public bool IsModified { get; set; }
         public event Action NotifyChangesEvent;
 
-        public object ConfigViewModel
-        {
-            get => _configViewModel;
-            set
-            {
-                _configViewModel = value;
-
-                OnPropertyChanged();
-            }
-        }
-
         public PlayerIndex PlayerIdChoose
         {
             get => _playerIdChoose;
@@ -200,16 +188,6 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
             }
         }
 
-        public string ProfileName
-        {
-            get => _profileName; set
-            {
-                _profileName = value;
-
-                OnPropertyChanged();
-            }
-        }
-
         public int Device
         {
             get => _device;

+ 4 - 21
src/Ryujinx/UI/ViewModels/Input/KeyboardInputViewModel.cs

@@ -1,20 +1,12 @@
 using Avalonia.Svg.Skia;
+using CommunityToolkit.Mvvm.ComponentModel;
 using Ryujinx.Ava.UI.Models.Input;
 
 namespace Ryujinx.Ava.UI.ViewModels.Input
 {
-    public class KeyboardInputViewModel : BaseModel
+    public partial class KeyboardInputViewModel : BaseModel
     {
-        private KeyboardInputConfig _config;
-        public KeyboardInputConfig Config
-        {
-            get => _config;
-            set
-            {
-                _config = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private KeyboardInputConfig _config;
 
         private bool _isLeft;
         public bool IsLeft
@@ -42,16 +34,7 @@ namespace Ryujinx.Ava.UI.ViewModels.Input
 
         public bool HasSides => IsLeft ^ IsRight;
 
-        private SvgImage _image;
-        public SvgImage Image
-        {
-            get => _image;
-            set
-            {
-                _image = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private SvgImage _image;
 
         public readonly InputViewModel ParentModel;
 

+ 11 - 81
src/Ryujinx/UI/ViewModels/Input/MotionInputViewModel.cs

@@ -1,93 +1,23 @@
+using CommunityToolkit.Mvvm.ComponentModel;
+
 namespace Ryujinx.Ava.UI.ViewModels.Input
 {
-    public class MotionInputViewModel : BaseModel
+    public partial class MotionInputViewModel : BaseModel
     {
-        private int _slot;
-        public int Slot
-        {
-            get => _slot;
-            set
-            {
-                _slot = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private int _slot;
 
-        private int _altSlot;
-        public int AltSlot
-        {
-            get => _altSlot;
-            set
-            {
-                _altSlot = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private int _altSlot;
 
-        private string _dsuServerHost;
-        public string DsuServerHost
-        {
-            get => _dsuServerHost;
-            set
-            {
-                _dsuServerHost = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private string _dsuServerHost;
 
-        private int _dsuServerPort;
-        public int DsuServerPort
-        {
-            get => _dsuServerPort;
-            set
-            {
-                _dsuServerPort = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private int _dsuServerPort;
 
-        private bool _mirrorInput;
-        public bool MirrorInput
-        {
-            get => _mirrorInput;
-            set
-            {
-                _mirrorInput = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private bool _mirrorInput;
 
-        private int _sensitivity;
-        public int Sensitivity
-        {
-            get => _sensitivity;
-            set
-            {
-                _sensitivity = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private int _sensitivity;
 
-        private double _gryoDeadzone;
-        public double GyroDeadzone
-        {
-            get => _gryoDeadzone;
-            set
-            {
-                _gryoDeadzone = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private double _gryoDeadzone;
 
-        private bool _enableCemuHookMotion;
-        public bool EnableCemuHookMotion
-        {
-            get => _enableCemuHookMotion;
-            set
-            {
-                _enableCemuHookMotion = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private bool _enableCemuHookMotion;
     }
 }

+ 5 - 21
src/Ryujinx/UI/ViewModels/Input/RumbleInputViewModel.cs

@@ -1,27 +1,11 @@
+using CommunityToolkit.Mvvm.ComponentModel;
+
 namespace Ryujinx.Ava.UI.ViewModels.Input
 {
-    public class RumbleInputViewModel : BaseModel
+    public partial class RumbleInputViewModel : BaseModel
     {
-        private float _strongRumble;
-        public float StrongRumble
-        {
-            get => _strongRumble;
-            set
-            {
-                _strongRumble = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private float _strongRumble;
 
-        private float _weakRumble;
-        public float WeakRumble
-        {
-            get => _weakRumble;
-            set
-            {
-                _weakRumble = value;
-                OnPropertyChanged();
-            }
-        }
+        [ObservableProperty] private float _weakRumble;
     }
 }