1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 22:12:53 +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", () => AddStep("start players silently", () =>
{ {
Client.CurrentMatchPlayingUserIds.Add(PLAYER_1_ID); OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_1_ID }, true);
Client.CurrentMatchPlayingUserIds.Add(PLAYER_2_ID); OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_2_ID }, true);
OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_1_ID });
OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_2_ID });
playingUserIds.Add(PLAYER_1_ID); playingUserIds.Add(PLAYER_1_ID);
playingUserIds.Add(PLAYER_2_ID); playingUserIds.Add(PLAYER_2_ID);
@ -87,16 +84,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
AddStep("start players", () => AddStep("start players", () =>
{ {
Client.CurrentMatchPlayingUserIds.Add(PLAYER_1_ID); var player1 = OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_1_ID }, true);
Client.CurrentMatchPlayingUserIds.Add(PLAYER_2_ID);
var player1 = OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_1_ID });
player1.MatchState = new TeamVersusUserState player1.MatchState = new TeamVersusUserState
{ {
TeamID = 0, 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 player2.MatchState = new TeamVersusUserState
{ {
TeamID = 1, TeamID = 1,
@ -305,8 +299,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{ {
foreach (int id in userIds) foreach (int id in userIds)
{ {
Client.CurrentMatchPlayingUserIds.Add(id); OnlinePlayDependencies.Client.AddUser(new User { Id = id }, true);
OnlinePlayDependencies.Client.AddUser(new User { Id = id });
SpectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId); SpectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId);
playingUserIds.Add(id); playingUserIds.Add(id);

View File

@ -56,12 +56,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
foreach (var user in users) foreach (var user in users)
{ {
SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0); 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[] Children = new Drawable[]
{ {
scoreProcessor = new OsuScoreProcessor(), scoreProcessor = new OsuScoreProcessor(),

View File

@ -60,7 +60,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
foreach (var user in users) foreach (var user in users)
{ {
SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0); 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 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[] Children = new Drawable[]
{ {
scoreProcessor = new OsuScoreProcessor(), scoreProcessor = new OsuScoreProcessor(),

View File

@ -62,7 +62,9 @@ namespace osu.Game.Online.Multiplayer
/// <summary> /// <summary>
/// The users in the joined <see cref="Room"/> which are participating in the current gameplay loop. /// The users in the joined <see cref="Room"/> which are participating in the current gameplay loop.
/// </summary> /// </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?>(); public readonly Bindable<PlaylistItem?> CurrentMatchPlayingItem = new Bindable<PlaylistItem?>();
@ -179,7 +181,7 @@ namespace osu.Game.Online.Multiplayer
{ {
APIRoom = null; APIRoom = null;
Room = null; Room = null;
CurrentMatchPlayingUserIds.Clear(); PlayingUserIds.Clear();
RoomUpdated?.Invoke(); RoomUpdated?.Invoke();
}); });
@ -376,7 +378,7 @@ namespace osu.Game.Online.Multiplayer
return; return;
Room.Users.Remove(user); Room.Users.Remove(user);
CurrentMatchPlayingUserIds.Remove(user.UserID); PlayingUserIds.Remove(user.UserID);
RoomUpdated?.Invoke(); RoomUpdated?.Invoke();
}, false); }, false);
@ -659,16 +661,16 @@ namespace osu.Game.Online.Multiplayer
/// <param name="state">The new state of the user.</param> /// <param name="state">The new state of the user.</param>
private void updateUserPlayingState(int userId, MultiplayerUserState state) 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; bool isPlaying = state >= MultiplayerUserState.WaitingForLoad && state <= MultiplayerUserState.FinishedPlay;
if (isPlaying == wasPlaying) if (isPlaying == wasPlaying)
return; return;
if (isPlaying) if (isPlaying)
CurrentMatchPlayingUserIds.Add(userId); PlayingUserIds.Add(userId);
else else
CurrentMatchPlayingUserIds.Remove(userId); PlayingUserIds.Remove(userId);
} }
private Task scheduleAsync(Action action, CancellationToken cancellationToken = default) 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 UserLookupCache userLookupCache { get; set; }
private readonly ScoreProcessor scoreProcessor; private readonly ScoreProcessor scoreProcessor;
private readonly BindableList<int> playingUsers; private readonly IBindableList<int> playingUsers;
private Bindable<ScoringMode> scoringMode; private Bindable<ScoringMode> scoringMode;
private bool hasTeams => TeamScores.Count > 0; 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 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 }; var roomUser = new MultiplayerRoomUser(user.Id) { User = user };
((IMultiplayerClient)this).UserJoined(roomUser); ((IMultiplayerClient)this).UserJoined(roomUser);
if (markAsPlaying)
PlayingUserIds.Add(user.Id);
return roomUser; return roomUser;
} }