Fix up TestSpectatorClient implementation

Rather than using a list which is supposed to be updated "client"-side,
now uses the "server"-side list.
This commit is contained in:
Dan Balasescu 2022-02-02 23:00:43 +09:00
parent 6d3bc005ea
commit 9d1d13c715

View File

@ -39,11 +39,7 @@ namespace osu.Game.Tests.Visual.Spectator
public TestSpectatorClient() public TestSpectatorClient()
{ {
OnNewFrames += (i, bundle) => OnNewFrames += (i, bundle) => lastReceivedUserFrames[i] = bundle.Frames[^1];
{
if (PlayingUserStates.ContainsKey(i))
lastReceivedUserFrames[i] = bundle.Frames[^1];
};
} }
/// <summary> /// <summary>
@ -62,16 +58,20 @@ namespace osu.Game.Tests.Visual.Spectator
/// Ends play for an arbitrary user. /// Ends play for an arbitrary user.
/// </summary> /// </summary>
/// <param name="userId">The user to end play for.</param> /// <param name="userId">The user to end play for.</param>
public void EndPlay(int userId) /// <param name="state">The spectator state to end play with.</param>
public void EndPlay(int userId, SpectatingUserState state = SpectatingUserState.Quit)
{ {
if (!PlayingUserStates.ContainsKey(userId)) if (!userBeatmapDictionary.ContainsKey(userId))
return; return;
((ISpectatorClient)this).UserFinishedPlaying(userId, new SpectatorState ((ISpectatorClient)this).UserFinishedPlaying(userId, new SpectatorState
{ {
BeatmapID = userBeatmapDictionary[userId], BeatmapID = userBeatmapDictionary[userId],
RulesetID = 0, RulesetID = 0,
State = state
}); });
userBeatmapDictionary.Remove(userId);
} }
public new void Schedule(Action action) => base.Schedule(action); public new void Schedule(Action action) => base.Schedule(action);
@ -130,7 +130,7 @@ namespace osu.Game.Tests.Visual.Spectator
protected override Task WatchUserInternal(int userId) protected override Task WatchUserInternal(int userId)
{ {
// When newly watching a user, the server sends the playing state immediately. // When newly watching a user, the server sends the playing state immediately.
if (PlayingUserStates.ContainsKey(userId)) if (userBeatmapDictionary.ContainsKey(userId))
sendPlayingState(userId); sendPlayingState(userId);
return Task.CompletedTask; return Task.CompletedTask;
@ -144,6 +144,7 @@ namespace osu.Game.Tests.Visual.Spectator
{ {
BeatmapID = userBeatmapDictionary[userId], BeatmapID = userBeatmapDictionary[userId],
RulesetID = 0, RulesetID = 0,
State = SpectatingUserState.Playing
}); });
} }
} }