mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 00:22:58 +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.OnlinePlay.Multiplayer.Spectate;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
using osu.Game.Tests.Beatmaps.IO;
|
using osu.Game.Tests.Beatmaps.IO;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Multiplayer
|
namespace osu.Game.Tests.Visual.Multiplayer
|
||||||
{
|
{
|
||||||
@ -47,8 +48,9 @@ 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);
|
||||||
|
|
||||||
playingUserIds.Add(PLAYER_1_ID);
|
playingUserIds.Add(PLAYER_1_ID);
|
||||||
playingUserIds.Add(PLAYER_2_ID);
|
playingUserIds.Add(PLAYER_2_ID);
|
||||||
});
|
});
|
||||||
@ -264,7 +266,8 @@ 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);
|
||||||
|
|
||||||
SpectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId);
|
SpectatorClient.StartPlay(id, beatmapId ?? importedBeatmapId);
|
||||||
playingUserIds.Add(id);
|
playingUserIds.Add(id);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ using osu.Game.Scoring;
|
|||||||
using osu.Game.Screens.Play.HUD;
|
using osu.Game.Screens.Play.HUD;
|
||||||
using osu.Game.Tests.Visual.OnlinePlay;
|
using osu.Game.Tests.Visual.OnlinePlay;
|
||||||
using osu.Game.Tests.Visual.Spectator;
|
using osu.Game.Tests.Visual.Spectator;
|
||||||
|
using osu.Game.Users;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Multiplayer
|
namespace osu.Game.Tests.Visual.Multiplayer
|
||||||
{
|
{
|
||||||
@ -53,10 +54,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
|
var playable = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
|
||||||
|
|
||||||
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 }, true);
|
||||||
// Todo: This is REALLY bad.
|
}
|
||||||
Client.CurrentMatchPlayingUserIds.AddRange(users);
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
|
@ -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)
|
||||||
|
@ -31,7 +31,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;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -50,7 +50,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
public void Disconnect() => isConnected.Value = false;
|
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));
|
public void AddNullUser(int userId) => ((IMultiplayerClient)this).UserJoined(new MultiplayerRoomUser(userId));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user