1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 09:03:00 +08:00

Simplify method of marking players as playing in test scenes

This commit is contained in:
Dean Herbert 2021-08-09 19:18:13 +09:00
parent 5f3d087101
commit 551929cf5a
6 changed files with 21 additions and 28 deletions

View File

@ -49,11 +49,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
AddStep("start players silently", () =>
{
Client.CurrentMatchPlayingUserIds.Add(PLAYER_1_ID);
Client.CurrentMatchPlayingUserIds.Add(PLAYER_2_ID);
OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_1_ID });
OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_2_ID });
OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_1_ID }, true);
OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_2_ID }, true);
playingUserIds.Add(PLAYER_1_ID);
playingUserIds.Add(PLAYER_2_ID);
@ -87,16 +84,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
AddStep("start players", () =>
{
Client.CurrentMatchPlayingUserIds.Add(PLAYER_1_ID);
Client.CurrentMatchPlayingUserIds.Add(PLAYER_2_ID);
var player1 = OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_1_ID });
var player1 = OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_1_ID }, true);
player1.MatchState = new TeamVersusUserState
{
TeamID = 0,
};
var player2 = OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_2_ID });
var player2 = OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_2_ID }, true);
player2.MatchState = new TeamVersusUserState
{
TeamID = 1,
@ -305,8 +299,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
foreach (int id in userIds)
{
Client.CurrentMatchPlayingUserIds.Add(id);
OnlinePlayDependencies.Client.AddUser(new User { Id = id });
OnlinePlayDependencies.Client.AddUser(new User { Id = id }, true);
SpectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId);
playingUserIds.Add(id);

View File

@ -56,12 +56,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
foreach (var user in users)
{
SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0);
OnlinePlayDependencies.Client.AddUser(new User { Id = user });
OnlinePlayDependencies.Client.AddUser(new User { Id = user }, true);
}
// Todo: This is REALLY bad.
Client.CurrentMatchPlayingUserIds.AddRange(users);
Children = new Drawable[]
{
scoreProcessor = new OsuScoreProcessor(),

View File

@ -60,7 +60,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
foreach (var user in users)
{
SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0);
var roomUser = OnlinePlayDependencies.Client.AddUser(new User { Id = user });
var roomUser = OnlinePlayDependencies.Client.AddUser(new User { Id = user }, true);
roomUser.MatchState = new TeamVersusUserState
{
@ -68,9 +68,6 @@ namespace osu.Game.Tests.Visual.Multiplayer
};
}
// Todo: This is REALLY bad.
Client.CurrentMatchPlayingUserIds.AddRange(users);
Children = new Drawable[]
{
scoreProcessor = new OsuScoreProcessor(),

View File

@ -62,7 +62,9 @@ namespace osu.Game.Online.Multiplayer
/// <summary>
/// The users in the joined <see cref="Room"/> which are participating in the current gameplay loop.
/// </summary>
public readonly BindableList<int> CurrentMatchPlayingUserIds = new BindableList<int>();
public IBindableList<int> CurrentMatchPlayingUserIds => PlayingUserIds;
protected readonly BindableList<int> PlayingUserIds = new BindableList<int>();
public readonly Bindable<PlaylistItem?> CurrentMatchPlayingItem = new Bindable<PlaylistItem?>();
@ -179,7 +181,7 @@ namespace osu.Game.Online.Multiplayer
{
APIRoom = null;
Room = null;
CurrentMatchPlayingUserIds.Clear();
PlayingUserIds.Clear();
RoomUpdated?.Invoke();
});
@ -376,7 +378,7 @@ namespace osu.Game.Online.Multiplayer
return;
Room.Users.Remove(user);
CurrentMatchPlayingUserIds.Remove(user.UserID);
PlayingUserIds.Remove(user.UserID);
RoomUpdated?.Invoke();
}, false);
@ -659,16 +661,16 @@ namespace osu.Game.Online.Multiplayer
/// <param name="state">The new state of the user.</param>
private void updateUserPlayingState(int userId, MultiplayerUserState state)
{
bool wasPlaying = CurrentMatchPlayingUserIds.Contains(userId);
bool wasPlaying = PlayingUserIds.Contains(userId);
bool isPlaying = state >= MultiplayerUserState.WaitingForLoad && state <= MultiplayerUserState.FinishedPlay;
if (isPlaying == wasPlaying)
return;
if (isPlaying)
CurrentMatchPlayingUserIds.Add(userId);
PlayingUserIds.Add(userId);
else
CurrentMatchPlayingUserIds.Remove(userId);
PlayingUserIds.Remove(userId);
}
private Task scheduleAsync(Action action, CancellationToken cancellationToken = default)

View File

@ -41,7 +41,7 @@ namespace osu.Game.Screens.Play.HUD
private UserLookupCache userLookupCache { get; set; }
private readonly ScoreProcessor scoreProcessor;
private readonly BindableList<int> playingUsers;
private readonly IBindableList<int> playingUsers;
private Bindable<ScoringMode> scoringMode;
private bool hasTeams => TeamScores.Count > 0;

View File

@ -50,10 +50,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
public void Disconnect() => isConnected.Value = false;
public MultiplayerRoomUser AddUser(User user)
public MultiplayerRoomUser AddUser(User user, bool markAsPlaying = false)
{
var roomUser = new MultiplayerRoomUser(user.Id) { User = user };
((IMultiplayerClient)this).UserJoined(roomUser);
if (markAsPlaying)
PlayingUserIds.Add(user.Id);
return roomUser;
}