mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 19:10:32 +00:00
style(SyncList): formatting
This commit is contained in:
parent
bdac4445ca
commit
fb1fc3a0ae
@ -6,23 +6,23 @@ namespace Mirror
|
|||||||
{
|
{
|
||||||
public class SyncList<T> : SyncObject, IList<T>, IReadOnlyList<T>
|
public class SyncList<T> : SyncObject, IList<T>, IReadOnlyList<T>
|
||||||
{
|
{
|
||||||
|
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 delegate void SyncListChanged(Operation op, int itemIndex, T oldItem, T newItem);
|
||||||
|
public event SyncListChanged Callback;
|
||||||
|
|
||||||
readonly IList<T> objects;
|
readonly IList<T> objects;
|
||||||
readonly IEqualityComparer<T> comparer;
|
readonly IEqualityComparer<T> comparer;
|
||||||
|
|
||||||
public int Count => objects.Count;
|
public int Count => objects.Count;
|
||||||
public bool IsReadOnly => !IsWritable();
|
public bool IsReadOnly => !IsWritable();
|
||||||
public event SyncListChanged Callback;
|
|
||||||
|
|
||||||
public enum Operation : byte
|
|
||||||
{
|
|
||||||
OP_ADD,
|
|
||||||
OP_CLEAR,
|
|
||||||
OP_INSERT,
|
|
||||||
OP_REMOVEAT,
|
|
||||||
OP_SET
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Change
|
struct Change
|
||||||
{
|
{
|
||||||
@ -43,7 +43,7 @@ struct Change
|
|||||||
// so we need to skip them
|
// so we need to skip them
|
||||||
int changesAhead;
|
int changesAhead;
|
||||||
|
|
||||||
public SyncList() : this(EqualityComparer<T>.Default) {}
|
public SyncList() : this(EqualityComparer<T>.Default) { }
|
||||||
|
|
||||||
public SyncList(IEqualityComparer<T> comparer)
|
public SyncList(IEqualityComparer<T> comparer)
|
||||||
{
|
{
|
||||||
@ -71,9 +71,7 @@ public override void Reset()
|
|||||||
void AddOperation(Operation op, int itemIndex, T oldItem, T newItem, bool checkAccess)
|
void AddOperation(Operation op, int itemIndex, T oldItem, T newItem, bool checkAccess)
|
||||||
{
|
{
|
||||||
if (checkAccess && IsReadOnly)
|
if (checkAccess && IsReadOnly)
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Synclists can only be modified by the owner.");
|
throw new InvalidOperationException("Synclists can only be modified by the owner.");
|
||||||
}
|
|
||||||
|
|
||||||
Change change = new Change
|
Change change = new Change
|
||||||
{
|
{
|
||||||
@ -265,9 +263,7 @@ public void Add(T item)
|
|||||||
public void AddRange(IEnumerable<T> range)
|
public void AddRange(IEnumerable<T> range)
|
||||||
{
|
{
|
||||||
foreach (T entry in range)
|
foreach (T entry in range)
|
||||||
{
|
|
||||||
Add(entry);
|
Add(entry);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
@ -331,9 +327,8 @@ public bool Remove(T item)
|
|||||||
int index = IndexOf(item);
|
int index = IndexOf(item);
|
||||||
bool result = index >= 0;
|
bool result = index >= 0;
|
||||||
if (result)
|
if (result)
|
||||||
{
|
|
||||||
RemoveAt(index);
|
RemoveAt(index);
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,9 +347,7 @@ public int RemoveAll(Predicate<T> match)
|
|||||||
toRemove.Add(objects[i]);
|
toRemove.Add(objects[i]);
|
||||||
|
|
||||||
foreach (T entry in toRemove)
|
foreach (T entry in toRemove)
|
||||||
{
|
|
||||||
Remove(entry);
|
Remove(entry);
|
||||||
}
|
|
||||||
|
|
||||||
return toRemove.Count;
|
return toRemove.Count;
|
||||||
}
|
}
|
||||||
@ -393,6 +386,7 @@ public struct Enumerator : IEnumerator<T>
|
|||||||
{
|
{
|
||||||
readonly SyncList<T> list;
|
readonly SyncList<T> list;
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
public T Current { get; private set; }
|
public T Current { get; private set; }
|
||||||
|
|
||||||
public Enumerator(SyncList<T> list)
|
public Enumerator(SyncList<T> list)
|
||||||
@ -405,16 +399,15 @@ public Enumerator(SyncList<T> list)
|
|||||||
public bool MoveNext()
|
public bool MoveNext()
|
||||||
{
|
{
|
||||||
if (++index >= list.Count)
|
if (++index >= list.Count)
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
Current = list[index];
|
Current = list[index];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset() => index = -1;
|
public void Reset() => index = -1;
|
||||||
object IEnumerator.Current => Current;
|
object IEnumerator.Current => Current;
|
||||||
public void Dispose() {}
|
public void Dispose() { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user