Merge pull request #16778 from smoogipoo/simplify-test-spectator-client

Refactor TestSpectatorClient implementation
This commit is contained in:
Dean Herbert 2022-02-05 00:26:44 +09:00 committed by GitHub
commit fd81842ade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -40,11 +39,7 @@ namespace osu.Game.Tests.Visual.Spectator
public TestSpectatorClient()
{
OnNewFrames += (i, bundle) =>
{
if (PlayingUsers.Contains(i))
lastReceivedUserFrames[i] = bundle.Frames[^1];
};
OnNewFrames += (i, bundle) => lastReceivedUserFrames[i] = bundle.Frames[^1];
}
/// <summary>
@ -65,7 +60,7 @@ namespace osu.Game.Tests.Visual.Spectator
/// <param name="userId">The user to end play for.</param>
public void EndPlay(int userId)
{
if (!PlayingUsers.Contains(userId))
if (!userBeatmapDictionary.ContainsKey(userId))
return;
((ISpectatorClient)this).UserFinishedPlaying(userId, new SpectatorState
@ -73,6 +68,8 @@ namespace osu.Game.Tests.Visual.Spectator
BeatmapID = userBeatmapDictionary[userId],
RulesetID = 0,
});
userBeatmapDictionary.Remove(userId);
}
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)
{
// When newly watching a user, the server sends the playing state immediately.
if (PlayingUsers.Contains(userId))
if (userBeatmapDictionary.ContainsKey(userId))
sendPlayingState(userId);
return Task.CompletedTask;