]> git.deb.at Git - rhonda/impostor.git/commitdiff
Add dirty tracking to PlayerOutfit
authorminiduikboot <mini@duikbo.at>
Sun, 21 Jul 2024 20:31:41 +0000 (22:31 +0200)
committerminiduikboot <mini@duikbo.at>
Tue, 20 Aug 2024 19:41:38 +0000 (21:41 +0200)
To prevent excessive modifications in the codebase, which is prone to
issues if a callsite is missed, automatically do this using properties.

Keep the access modifiers intact for now.

src/Impostor.Api/Innersloth/Customization/PlayerOutfit.cs

index c6abce057dee93ef7b01f9dd64e26a27e0860791..a93fc5e844936d32bd38027c3c44541953d5c2b4 100644 (file)
@@ -2,19 +2,57 @@ namespace Impostor.Api.Innersloth.Customization
 {
     public class PlayerOutfit
     {
-        public string PlayerName { get; internal set; } = string.Empty;
+        private string _playerName = string.Empty;
+        private ColorType _color = (ColorType)(-1);
+        private string _hatId = "missing";
+        private string _petId = "missing";
+        private string _skinId = "missing";
+        private string _visorId = "missing";
+        private string _namePlateId = "missing";
 
-        public ColorType Color { get; internal set; } = (ColorType)(-1);
+        public bool IsDirty { get; internal set; }
 
-        public string HatId { get; internal set; } = "missing";
+        public string PlayerName
+        {
+            get => _playerName;
+            internal set => SetField(ref _playerName, value);
+        }
 
-        public string PetId { get; internal set; } = "missing";
+        public ColorType Color
+        {
+            get => _color;
+            internal set => SetField(ref _color, value);
+        }
 
-        public string SkinId { get; internal set; } = "missing";
+        public string HatId
+        {
+            get => _hatId;
+            internal set => SetField(ref _hatId, value);
+        }
 
-        public string VisorId { get; internal set; } = "missing";
+        public string PetId
+        {
+            get => _petId;
+            internal set => SetField(ref _petId, value);
+        }
 
-        public string NamePlateId { get; internal set; } = "missing";
+        public string SkinId
+        {
+            get => _skinId;
+            internal set => SetField(ref _skinId, value);
+        }
+
+        public string VisorId
+        {
+            get => _visorId;
+            internal set => SetField(ref _visorId, value);
+        }
+
+        public string NamePlateId
+        {
+            get => _namePlateId;
+            internal set => SetField(ref _namePlateId, value);
+        }
 
         private byte HatSequenceId { get; set; } = 0;
 
@@ -70,5 +108,11 @@ namespace Impostor.Api.Innersloth.Customization
             VisorSequenceId = reader.ReadByte();
             NamePlateSequenceId = reader.ReadByte();
         }
+
+        private void SetField<T>(ref T field, T value)
+        {
+            field = value;
+            IsDirty = true;
+        }
     }
 }