mirror of https://github.com/ppy/osu
Change to explicit method instead
This commit is contained in:
parent
5652490d61
commit
ca74f413cd
|
@ -221,7 +221,7 @@ public void OnUserBeganPlayingCallbackInvokedOnNewAdd()
|
|||
callbackInvoked = false;
|
||||
});
|
||||
|
||||
AddStep("bind event again", () => testSpectatorStreamingClient.OnUserBeganPlaying += callbackAction);
|
||||
AddStep("bind event with run once immediately", () => testSpectatorStreamingClient.BindUserBeganPlaying(callbackAction, true));
|
||||
AddAssert("callback invoked", () => callbackInvoked);
|
||||
|
||||
// Don't leave the event bound if test run succeeded.
|
||||
|
|
|
@ -69,25 +69,10 @@ public class SpectatorStreamingClient : Component, ISpectatorClient
|
|||
/// </summary>
|
||||
public event Action<int, FrameDataBundle> OnNewFrames;
|
||||
|
||||
private event Action<int, SpectatorState> onUserBeganPlaying;
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever a user starts a play session, or immediately if the user is being watched and currently in a play session.
|
||||
/// </summary>
|
||||
public event Action<int, SpectatorState> OnUserBeganPlaying
|
||||
{
|
||||
add
|
||||
{
|
||||
onUserBeganPlaying += value;
|
||||
|
||||
lock (userLock)
|
||||
{
|
||||
foreach (var (userId, state) in currentUserStates)
|
||||
value?.Invoke(userId, state);
|
||||
}
|
||||
}
|
||||
remove => onUserBeganPlaying -= value;
|
||||
}
|
||||
public event Action<int, SpectatorState> OnUserBeganPlaying;
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever a user finishes a play session.
|
||||
|
@ -153,7 +138,7 @@ Task ISpectatorClient.UserBeganPlaying(int userId, SpectatorState state)
|
|||
lock (userLock)
|
||||
currentUserStates[userId] = state;
|
||||
|
||||
onUserBeganPlaying?.Invoke(userId, state);
|
||||
OnUserBeganPlaying?.Invoke(userId, state);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
@ -290,5 +275,24 @@ private void purgePendingFrames()
|
|||
|
||||
lastSendTime = Time.Current;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind an action to <see cref="OnUserBeganPlaying"/> with the option of running the bound action once immediately.
|
||||
/// </summary>
|
||||
/// <param name="callback">The action to perform when a user begins playing.</param>
|
||||
/// <param name="runOnceImmediately">Whether the action provided in <paramref name="callback"/> should be run once immediately for all users currently playing.</param>
|
||||
public void BindUserBeganPlaying(Action<int, SpectatorState> callback, bool runOnceImmediately = false)
|
||||
{
|
||||
OnUserBeganPlaying += callback;
|
||||
|
||||
if (!runOnceImmediately)
|
||||
return;
|
||||
|
||||
lock (userLock)
|
||||
{
|
||||
foreach (var (userId, state) in currentUserStates)
|
||||
callback(userId, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue