Skip to content

Commit

Permalink
feat: adding syncList methods to set an index as dirty
Browse files Browse the repository at this point in the history
when using classes with synclist there is no way to detect if a class is changed. and setting the index to be the same item again requires first setting it to null.

the new function allows us to use it instead of having to find the index, set null, then set value again.
  • Loading branch information
James-Frowen committed Jun 16, 2023
1 parent 704ea8f commit 4dfe8df
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Assets/Mirage/Runtime/Collections/SyncList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,38 @@ public int RemoveAll(Predicate<T> match)
}
}

/// <summary>
/// Can be used to set item dirty manually.
/// <para>should be used with classes to avoid having to clear field first</para>
/// <para>Will invoke OnSet</para>
/// </summary>
/// <param name="item"></param>
/// <exception cref="ArgumentException">Throws when item is not found in this synclist</exception>"
public void SetItemDirty(T item)
{
var index = IndexOf(item);
if (index >= 0)
{
SetItemDirtyAt(index);
}
else
{
throw new ArgumentException("Item could not be found in list");
}
}

/// <summary>
/// Can be used to set item dirty manually.
/// <para>should be used with classes to avoid having to clear field first</para>
/// </summary>
/// <param name="item"></param>
public void SetItemDirtyAt(int index)
{
// need to also call OnSet, so that it matches what happens on client side. See other uses of Op_Set
OnSet?.Invoke(index, _objects[index], _objects[index]);
AddOperation(Operation.OP_SET, index, _objects[index]);
}

public Enumerator GetEnumerator() => new Enumerator(this);

IEnumerator<T> IEnumerable<T>.GetEnumerator() => new Enumerator(this);
Expand Down

0 comments on commit 4dfe8df

Please sign in to comment.