Simplify TestSpectatorClient implementation

This commit is contained in:
Dan Balasescu 2022-02-04 22:38:40 +09:00
parent 07fde1db6d
commit 750f90e728

View File

@ -6,7 +6,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -40,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 (PlayingUsers.Contains(i))
lastReceivedUserFrames[i] = bundle.Frames[^1];
};
} }
/// <summary> /// <summary>
@ -65,7 +60,7 @@ namespace osu.Game.Tests.Visual.Spectator
/// <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) public void EndPlay(int userId)
{ {
if (!PlayingUsers.Contains(userId)) if (!userBeatmapDictionary.ContainsKey(userId))
return; return;
((ISpectatorClient)this).UserFinishedPlaying(userId, new SpectatorState ((ISpectatorClient)this).UserFinishedPlaying(userId, new SpectatorState
@ -73,6 +68,8 @@ namespace osu.Game.Tests.Visual.Spectator
BeatmapID = userBeatmapDictionary[userId], BeatmapID = userBeatmapDictionary[userId],
RulesetID = 0, RulesetID = 0,
}); });
userBeatmapDictionary.Remove(userId);
} }
public new void Schedule(Action action) => base.Schedule(action); public new void Schedule(Action action) => base.Schedule(action);
@ -131,7 +128,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 (PlayingUsers.Contains(userId)) if (userBeatmapDictionary.ContainsKey(userId))
sendPlayingState(userId); sendPlayingState(userId);
return Task.CompletedTask; return Task.CompletedTask;