mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 21:32:57 +08:00
Change to explicit method instead
This commit is contained in:
parent
5652490d61
commit
ca74f413cd
@ -221,7 +221,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
callbackInvoked = false;
|
callbackInvoked = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("bind event again", () => testSpectatorStreamingClient.OnUserBeganPlaying += callbackAction);
|
AddStep("bind event with run once immediately", () => testSpectatorStreamingClient.BindUserBeganPlaying(callbackAction, true));
|
||||||
AddAssert("callback invoked", () => callbackInvoked);
|
AddAssert("callback invoked", () => callbackInvoked);
|
||||||
|
|
||||||
// Don't leave the event bound if test run succeeded.
|
// Don't leave the event bound if test run succeeded.
|
||||||
|
@ -69,25 +69,10 @@ namespace osu.Game.Online.Spectator
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action<int, FrameDataBundle> OnNewFrames;
|
public event Action<int, FrameDataBundle> OnNewFrames;
|
||||||
|
|
||||||
private event Action<int, SpectatorState> onUserBeganPlaying;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called whenever a user starts a play session, or immediately if the user is being watched and currently in a play session.
|
/// Called whenever a user starts a play session, or immediately if the user is being watched and currently in a play session.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action<int, SpectatorState> OnUserBeganPlaying
|
public event Action<int, SpectatorState> OnUserBeganPlaying;
|
||||||
{
|
|
||||||
add
|
|
||||||
{
|
|
||||||
onUserBeganPlaying += value;
|
|
||||||
|
|
||||||
lock (userLock)
|
|
||||||
{
|
|
||||||
foreach (var (userId, state) in currentUserStates)
|
|
||||||
value?.Invoke(userId, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
remove => onUserBeganPlaying -= value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called whenever a user finishes a play session.
|
/// Called whenever a user finishes a play session.
|
||||||
@ -153,7 +138,7 @@ namespace osu.Game.Online.Spectator
|
|||||||
lock (userLock)
|
lock (userLock)
|
||||||
currentUserStates[userId] = state;
|
currentUserStates[userId] = state;
|
||||||
|
|
||||||
onUserBeganPlaying?.Invoke(userId, state);
|
OnUserBeganPlaying?.Invoke(userId, state);
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
@ -290,5 +275,24 @@ namespace osu.Game.Online.Spectator
|
|||||||
|
|
||||||
lastSendTime = Time.Current;
|
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
Block a user