mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 19:10:32 +00:00
feat: add SyncList.RemoveAll (#1881)
* Added SyncList.RemoveAll and unit test. * Added RemoveAllNone unit test for SyncList * SyncList.RemoveAll cleanup * RemoveAll no longer calls collections .Add Unit tests for SyncList.RemoveAll now check clientSyncList.
This commit is contained in:
parent
e9ea117e61
commit
eb7c87d15a
@ -356,6 +356,21 @@ public void RemoveAt(int index)
|
|||||||
AddOperation(Operation.OP_REMOVEAT, index, oldItem, default);
|
AddOperation(Operation.OP_REMOVEAT, index, oldItem, default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int RemoveAll(Predicate<T> match)
|
||||||
|
{
|
||||||
|
List<T> toRemove = new List<T>();
|
||||||
|
for (int i = 0; i < objects.Count; ++i)
|
||||||
|
if (match(objects[i]))
|
||||||
|
toRemove.Add(objects[i]);
|
||||||
|
|
||||||
|
foreach (T entry in toRemove)
|
||||||
|
{
|
||||||
|
Remove(entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
return toRemove.Count;
|
||||||
|
}
|
||||||
|
|
||||||
public T this[int i]
|
public T this[int i]
|
||||||
{
|
{
|
||||||
get => objects[i];
|
get => objects[i];
|
||||||
|
@ -107,6 +107,22 @@ public void TestSetNull()
|
|||||||
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "Hello", "yay", "!" }));
|
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "Hello", "yay", "!" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestRemoveAll()
|
||||||
|
{
|
||||||
|
serverSyncList.RemoveAll(entry => entry.Contains("l"));
|
||||||
|
SerializeDeltaTo(serverSyncList, clientSyncList);
|
||||||
|
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "!" }));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestRemoveAllNone()
|
||||||
|
{
|
||||||
|
serverSyncList.RemoveAll(entry => entry == "yay");
|
||||||
|
SerializeDeltaTo(serverSyncList, clientSyncList);
|
||||||
|
Assert.That(clientSyncList, Is.EquivalentTo(new[] { "Hello", "World", "!" }));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestRemoveAt()
|
public void TestRemoveAt()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user