From fb1fc3a0aeb955614653390275c80b89e78f6b07 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Sat, 23 Mar 2024 11:48:22 -0400 Subject: [PATCH] style(SyncList): formatting --- Assets/Mirror/Core/SyncList.cs | 37 ++++++++++++++-------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/Assets/Mirror/Core/SyncList.cs b/Assets/Mirror/Core/SyncList.cs index 8b70eed22..c9614ae77 100644 --- a/Assets/Mirror/Core/SyncList.cs +++ b/Assets/Mirror/Core/SyncList.cs @@ -6,23 +6,23 @@ namespace Mirror { public class SyncList : SyncObject, IList, IReadOnlyList { + public enum Operation : byte + { + OP_ADD, + OP_SET, + OP_INSERT, + OP_REMOVEAT, + OP_CLEAR + } + public delegate void SyncListChanged(Operation op, int itemIndex, T oldItem, T newItem); + public event SyncListChanged Callback; readonly IList objects; readonly IEqualityComparer comparer; public int Count => objects.Count; public bool IsReadOnly => !IsWritable(); - public event SyncListChanged Callback; - - public enum Operation : byte - { - OP_ADD, - OP_CLEAR, - OP_INSERT, - OP_REMOVEAT, - OP_SET - } struct Change { @@ -43,7 +43,7 @@ struct Change // so we need to skip them int changesAhead; - public SyncList() : this(EqualityComparer.Default) {} + public SyncList() : this(EqualityComparer.Default) { } public SyncList(IEqualityComparer comparer) { @@ -71,9 +71,7 @@ public override void Reset() void AddOperation(Operation op, int itemIndex, T oldItem, T newItem, bool checkAccess) { if (checkAccess && IsReadOnly) - { throw new InvalidOperationException("Synclists can only be modified by the owner."); - } Change change = new Change { @@ -265,9 +263,7 @@ public void Add(T item) public void AddRange(IEnumerable range) { foreach (T entry in range) - { Add(entry); - } } public void Clear() @@ -331,9 +327,8 @@ public bool Remove(T item) int index = IndexOf(item); bool result = index >= 0; if (result) - { RemoveAt(index); - } + return result; } @@ -352,9 +347,7 @@ public int RemoveAll(Predicate match) toRemove.Add(objects[i]); foreach (T entry in toRemove) - { Remove(entry); - } return toRemove.Count; } @@ -393,6 +386,7 @@ public struct Enumerator : IEnumerator { readonly SyncList list; int index; + public T Current { get; private set; } public Enumerator(SyncList list) @@ -405,16 +399,15 @@ public Enumerator(SyncList list) public bool MoveNext() { if (++index >= list.Count) - { return false; - } + Current = list[index]; return true; } public void Reset() => index = -1; object IEnumerator.Current => Current; - public void Dispose() {} + public void Dispose() { } } } }