mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Merge pull request #14178 from peppy/simplify-player-users-test-usage
Simplify method of marking players as playing in test scenes
This commit is contained in:
commit
6da977f99a
@ -12,6 +12,7 @@ using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Spectate;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Tests.Beatmaps.IO;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
@ -47,8 +48,9 @@ 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 }, true);
|
||||
OnlinePlayDependencies.Client.AddUser(new User { Id = PLAYER_2_ID }, true);
|
||||
|
||||
playingUserIds.Add(PLAYER_1_ID);
|
||||
playingUserIds.Add(PLAYER_2_ID);
|
||||
});
|
||||
@ -264,7 +266,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
foreach (int id in userIds)
|
||||
{
|
||||
Client.CurrentMatchPlayingUserIds.Add(id);
|
||||
OnlinePlayDependencies.Client.AddUser(new User { Id = id }, true);
|
||||
|
||||
SpectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId);
|
||||
playingUserIds.Add(id);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ using osu.Game.Scoring;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osu.Game.Tests.Visual.OnlinePlay;
|
||||
using osu.Game.Tests.Visual.Spectator;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
@ -53,10 +54,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
|
||||
|
||||
foreach (var user in users)
|
||||
{
|
||||
SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0);
|
||||
|
||||
// Todo: This is REALLY bad.
|
||||
Client.CurrentMatchPlayingUserIds.AddRange(users);
|
||||
OnlinePlayDependencies.Client.AddUser(new User { Id = user }, true);
|
||||
}
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
|
@ -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)
|
||||
|
@ -31,7 +31,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;
|
||||
|
||||
/// <summary>
|
||||
|
@ -50,7 +50,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
public void Disconnect() => isConnected.Value = false;
|
||||
|
||||
public void AddUser(User user) => ((IMultiplayerClient)this).UserJoined(new MultiplayerRoomUser(user.Id) { 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;
|
||||
}
|
||||
|
||||
public void AddNullUser(int userId) => ((IMultiplayerClient)this).UserJoined(new MultiplayerRoomUser(userId));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user