mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Merge branch 'master' into fix-spectator-seeks
This commit is contained in:
@ -0,0 +1,204 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Spectator;
|
||||
using osu.Game.Replays.Legacy;
|
||||
using osu.Game.Rulesets.Osu.Scoring;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public abstract class MultiplayerGameplayLeaderboardTestScene : OsuTestScene
|
||||
{
|
||||
protected readonly BindableList<MultiplayerRoomUser> MultiplayerUsers = new BindableList<MultiplayerRoomUser>();
|
||||
|
||||
protected MultiplayerGameplayLeaderboard Leaderboard { get; private set; }
|
||||
|
||||
protected virtual MultiplayerRoomUser CreateUser(int userId) => new MultiplayerRoomUser(userId);
|
||||
|
||||
protected abstract MultiplayerGameplayLeaderboard CreateLeaderboard(OsuScoreProcessor scoreProcessor);
|
||||
|
||||
private readonly BindableList<int> multiplayerUserIds = new BindableList<int>();
|
||||
|
||||
private OsuConfigManager config;
|
||||
|
||||
private readonly Mock<SpectatorClient> spectatorClient = new Mock<SpectatorClient>();
|
||||
private readonly Mock<MultiplayerClient> multiplayerClient = new Mock<MultiplayerClient>();
|
||||
|
||||
private readonly Dictionary<int, FrameHeader> lastHeaders = new Dictionary<int, FrameHeader>();
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Dependencies.Cache(config = new OsuConfigManager(LocalStorage));
|
||||
Dependencies.CacheAs(spectatorClient.Object);
|
||||
Dependencies.CacheAs(multiplayerClient.Object);
|
||||
|
||||
// To emulate `MultiplayerClient.CurrentMatchPlayingUserIds` we need a bindable list of *only IDs*.
|
||||
// This tracks the list of users 1:1.
|
||||
MultiplayerUsers.BindCollectionChanged((c, e) =>
|
||||
{
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
Debug.Assert(e.NewItems != null);
|
||||
|
||||
foreach (var user in e.NewItems.OfType<MultiplayerRoomUser>())
|
||||
multiplayerUserIds.Add(user.UserID);
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
Debug.Assert(e.OldItems != null);
|
||||
|
||||
foreach (var user in e.OldItems.OfType<MultiplayerRoomUser>())
|
||||
multiplayerUserIds.Remove(user.UserID);
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Reset:
|
||||
multiplayerUserIds.Clear();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
multiplayerClient.SetupGet(c => c.CurrentMatchPlayingUserIds)
|
||||
.Returns(() => multiplayerUserIds);
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
public virtual void SetUpSteps()
|
||||
{
|
||||
AddStep("reset counts", () => spectatorClient.Invocations.Clear());
|
||||
|
||||
AddStep("set local user", () => ((DummyAPIAccess)API).LocalUser.Value = new APIUser
|
||||
{
|
||||
Id = 1,
|
||||
});
|
||||
|
||||
AddStep("populate users", () =>
|
||||
{
|
||||
MultiplayerUsers.Clear();
|
||||
for (int i = 0; i < 16; i++)
|
||||
MultiplayerUsers.Add(CreateUser(i));
|
||||
});
|
||||
|
||||
AddStep("create leaderboard", () =>
|
||||
{
|
||||
Leaderboard?.Expire();
|
||||
|
||||
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
|
||||
var playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
|
||||
OsuScoreProcessor scoreProcessor = new OsuScoreProcessor();
|
||||
scoreProcessor.ApplyBeatmap(playableBeatmap);
|
||||
|
||||
Child = scoreProcessor;
|
||||
|
||||
LoadComponentAsync(Leaderboard = CreateLeaderboard(scoreProcessor), Add);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for load", () => Leaderboard.IsLoaded);
|
||||
|
||||
AddStep("check watch requests were sent", () =>
|
||||
{
|
||||
foreach (var user in MultiplayerUsers)
|
||||
spectatorClient.Verify(s => s.WatchUser(user.UserID), Times.Once);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScoreUpdates()
|
||||
{
|
||||
AddRepeatStep("update state", UpdateUserStatesRandomly, 100);
|
||||
AddToggleStep("switch compact mode", expanded => Leaderboard.Expanded.Value = expanded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUserQuit()
|
||||
{
|
||||
AddUntilStep("mark users quit", () =>
|
||||
{
|
||||
if (MultiplayerUsers.Count == 0)
|
||||
return true;
|
||||
|
||||
MultiplayerUsers.RemoveAt(0);
|
||||
return false;
|
||||
});
|
||||
|
||||
AddStep("check stop watching requests were sent", () =>
|
||||
{
|
||||
foreach (var user in MultiplayerUsers)
|
||||
spectatorClient.Verify(s => s.StopWatchingUser(user.UserID), Times.Once);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestChangeScoringMode()
|
||||
{
|
||||
AddRepeatStep("update state", UpdateUserStatesRandomly, 5);
|
||||
AddStep("change to classic", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Classic));
|
||||
AddStep("change to standardised", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Standardised));
|
||||
}
|
||||
|
||||
protected void UpdateUserStatesRandomly()
|
||||
{
|
||||
foreach (var user in MultiplayerUsers)
|
||||
{
|
||||
if (RNG.NextBool())
|
||||
continue;
|
||||
|
||||
int userId = user.UserID;
|
||||
|
||||
if (!lastHeaders.TryGetValue(userId, out var header))
|
||||
{
|
||||
lastHeaders[userId] = header = new FrameHeader(new ScoreInfo
|
||||
{
|
||||
Statistics = new Dictionary<HitResult, int>
|
||||
{
|
||||
[HitResult.Miss] = 0,
|
||||
[HitResult.Meh] = 0,
|
||||
[HitResult.Great] = 0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
switch (RNG.Next(0, 3))
|
||||
{
|
||||
case 0:
|
||||
header.Combo = 0;
|
||||
header.Statistics[HitResult.Miss]++;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
header.Combo++;
|
||||
header.MaxCombo = Math.Max(header.MaxCombo, header.Combo);
|
||||
header.Statistics[HitResult.Meh]++;
|
||||
break;
|
||||
|
||||
default:
|
||||
header.Combo++;
|
||||
header.MaxCombo = Math.Max(header.MaxCombo, header.Combo);
|
||||
header.Statistics[HitResult.Great]++;
|
||||
break;
|
||||
}
|
||||
|
||||
spectatorClient.Raise(s => s.OnNewFrames -= null, userId, new FrameDataBundle(header, new[] { new LegacyReplayFrame(Time.Current, 0, 0, ReplayButtonState.None) }));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
@ -34,9 +35,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
[Test]
|
||||
public void TestMultipleStatuses()
|
||||
{
|
||||
FillFlowContainer rooms = null;
|
||||
|
||||
AddStep("create rooms", () =>
|
||||
{
|
||||
Child = new FillFlowContainer
|
||||
Child = rooms = new FillFlowContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
@ -124,6 +127,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
AddUntilStep("wait for panel load", () => rooms.Count == 5);
|
||||
AddUntilStep("correct status text", () => rooms.ChildrenOfType<OsuSpriteText>().Count(s => s.Text.ToString().StartsWith("Currently playing", StringComparison.Ordinal)) == 2);
|
||||
AddUntilStep("correct status text", () => rooms.ChildrenOfType<OsuSpriteText>().Count(s => s.Text.ToString().StartsWith("Ready to play", StringComparison.Ordinal)) == 3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -9,13 +9,14 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osu.Game.Screens.Play;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneGameplayChatDisplay : MultiplayerTestScene
|
||||
public class TestSceneGameplayChatDisplay : OsuManualInputManagerTestScene
|
||||
{
|
||||
private GameplayChatDisplay chatDisplay;
|
||||
|
||||
@ -35,11 +36,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
public override void SetUpSteps()
|
||||
public void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay(SelectedRoom.Value)
|
||||
AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay(new Room())
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
|
@ -1,161 +1,22 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Spectator;
|
||||
using osu.Game.Replays.Legacy;
|
||||
using osu.Game.Rulesets.Osu.Scoring;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Scoring;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osu.Game.Tests.Visual.OnlinePlay;
|
||||
using osu.Game.Tests.Visual.Spectator;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiplayerGameplayLeaderboard : MultiplayerTestScene
|
||||
public class TestSceneMultiplayerGameplayLeaderboard : MultiplayerGameplayLeaderboardTestScene
|
||||
{
|
||||
private static IEnumerable<int> users => Enumerable.Range(0, 16);
|
||||
|
||||
public new TestMultiplayerSpectatorClient SpectatorClient => (TestMultiplayerSpectatorClient)OnlinePlayDependencies?.SpectatorClient;
|
||||
|
||||
private MultiplayerGameplayLeaderboard leaderboard;
|
||||
private OsuConfigManager config;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
protected override MultiplayerGameplayLeaderboard CreateLeaderboard(OsuScoreProcessor scoreProcessor)
|
||||
{
|
||||
Dependencies.Cache(config = new OsuConfigManager(LocalStorage));
|
||||
}
|
||||
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("set local user", () => ((DummyAPIAccess)API).LocalUser.Value = UserLookupCache.GetUserAsync(1).GetResultSafely());
|
||||
|
||||
AddStep("create leaderboard", () =>
|
||||
return new MultiplayerGameplayLeaderboard(Ruleset.Value, scoreProcessor, MultiplayerUsers.ToArray())
|
||||
{
|
||||
leaderboard?.Expire();
|
||||
|
||||
OsuScoreProcessor scoreProcessor;
|
||||
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
|
||||
|
||||
var playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
|
||||
var multiplayerUsers = new List<MultiplayerRoomUser>();
|
||||
|
||||
foreach (int user in users)
|
||||
{
|
||||
SpectatorClient.SendStartPlay(user, Beatmap.Value.BeatmapInfo.OnlineID);
|
||||
multiplayerUsers.Add(OnlinePlayDependencies.MultiplayerClient.AddUser(new APIUser { Id = user }, true));
|
||||
}
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
scoreProcessor = new OsuScoreProcessor(),
|
||||
};
|
||||
|
||||
scoreProcessor.ApplyBeatmap(playableBeatmap);
|
||||
|
||||
LoadComponentAsync(leaderboard = new MultiplayerGameplayLeaderboard(Ruleset.Value, scoreProcessor, multiplayerUsers.ToArray())
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
}, Add);
|
||||
});
|
||||
|
||||
AddUntilStep("wait for load", () => leaderboard.IsLoaded);
|
||||
AddUntilStep("wait for user population", () => MultiplayerClient.CurrentMatchPlayingUserIds.Count > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScoreUpdates()
|
||||
{
|
||||
AddRepeatStep("update state", () => SpectatorClient.RandomlyUpdateState(), 100);
|
||||
AddToggleStep("switch compact mode", expanded => leaderboard.Expanded.Value = expanded);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUserQuit()
|
||||
{
|
||||
foreach (int user in users)
|
||||
AddStep($"mark user {user} quit", () => MultiplayerClient.RemoveUser(UserLookupCache.GetUserAsync(user).GetResultSafely().AsNonNull()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestChangeScoringMode()
|
||||
{
|
||||
AddRepeatStep("update state", () => SpectatorClient.RandomlyUpdateState(), 5);
|
||||
AddStep("change to classic", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Classic));
|
||||
AddStep("change to standardised", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Standardised));
|
||||
}
|
||||
|
||||
protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new TestDependencies();
|
||||
|
||||
protected class TestDependencies : MultiplayerTestSceneDependencies
|
||||
{
|
||||
protected override TestSpectatorClient CreateSpectatorClient() => new TestMultiplayerSpectatorClient();
|
||||
}
|
||||
|
||||
public class TestMultiplayerSpectatorClient : TestSpectatorClient
|
||||
{
|
||||
private readonly Dictionary<int, FrameHeader> lastHeaders = new Dictionary<int, FrameHeader>();
|
||||
|
||||
public void RandomlyUpdateState()
|
||||
{
|
||||
foreach ((int userId, _) in WatchedUserStates)
|
||||
{
|
||||
if (RNG.NextBool())
|
||||
continue;
|
||||
|
||||
if (!lastHeaders.TryGetValue(userId, out var header))
|
||||
{
|
||||
lastHeaders[userId] = header = new FrameHeader(new ScoreInfo
|
||||
{
|
||||
Statistics = new Dictionary<HitResult, int>
|
||||
{
|
||||
[HitResult.Miss] = 0,
|
||||
[HitResult.Meh] = 0,
|
||||
[HitResult.Great] = 0
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
switch (RNG.Next(0, 3))
|
||||
{
|
||||
case 0:
|
||||
header.Combo = 0;
|
||||
header.Statistics[HitResult.Miss]++;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
header.Combo++;
|
||||
header.MaxCombo = Math.Max(header.MaxCombo, header.Combo);
|
||||
header.Statistics[HitResult.Meh]++;
|
||||
break;
|
||||
|
||||
default:
|
||||
header.Combo++;
|
||||
header.MaxCombo = Math.Max(header.MaxCombo, header.Combo);
|
||||
header.Statistics[HitResult.Great]++;
|
||||
break;
|
||||
}
|
||||
|
||||
((ISpectatorClient)this).UserSentFrames(userId, new FrameDataBundle(header, new[] { new LegacyReplayFrame(Time.Current, 0, 0, ReplayButtonState.None) }));
|
||||
}
|
||||
}
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,121 +1,56 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Rulesets.Osu.Scoring;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
using osu.Game.Tests.Visual.OnlinePlay;
|
||||
using osu.Game.Tests.Visual.Spectator;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneMultiplayerGameplayLeaderboardTeams : MultiplayerTestScene
|
||||
public class TestSceneMultiplayerGameplayLeaderboardTeams : MultiplayerGameplayLeaderboardTestScene
|
||||
{
|
||||
private static IEnumerable<int> users => Enumerable.Range(0, 16);
|
||||
|
||||
public new TestSceneMultiplayerGameplayLeaderboard.TestMultiplayerSpectatorClient SpectatorClient =>
|
||||
(TestSceneMultiplayerGameplayLeaderboard.TestMultiplayerSpectatorClient)OnlinePlayDependencies?.SpectatorClient;
|
||||
|
||||
protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new TestDependencies();
|
||||
|
||||
protected class TestDependencies : MultiplayerTestSceneDependencies
|
||||
protected override MultiplayerRoomUser CreateUser(int userId)
|
||||
{
|
||||
protected override TestSpectatorClient CreateSpectatorClient() => new TestSceneMultiplayerGameplayLeaderboard.TestMultiplayerSpectatorClient();
|
||||
var user = base.CreateUser(userId);
|
||||
user.MatchState = new TeamVersusUserState
|
||||
{
|
||||
TeamID = RNG.Next(0, 2)
|
||||
};
|
||||
return user;
|
||||
}
|
||||
|
||||
private MultiplayerGameplayLeaderboard leaderboard;
|
||||
private GameplayMatchScoreDisplay gameplayScoreDisplay;
|
||||
|
||||
protected override Room CreateRoom()
|
||||
{
|
||||
var room = base.CreateRoom();
|
||||
room.Type.Value = MatchType.TeamVersus;
|
||||
return room;
|
||||
}
|
||||
protected override MultiplayerGameplayLeaderboard CreateLeaderboard(OsuScoreProcessor scoreProcessor) =>
|
||||
new MultiplayerGameplayLeaderboard(Ruleset.Value, scoreProcessor, MultiplayerUsers.ToArray())
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
};
|
||||
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("set local user", () => ((DummyAPIAccess)API).LocalUser.Value = UserLookupCache.GetUserAsync(1).GetResultSafely());
|
||||
|
||||
AddStep("create leaderboard", () =>
|
||||
AddStep("Add external display components", () =>
|
||||
{
|
||||
leaderboard?.Expire();
|
||||
|
||||
OsuScoreProcessor scoreProcessor;
|
||||
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
|
||||
|
||||
var playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
|
||||
var multiplayerUsers = new List<MultiplayerRoomUser>();
|
||||
|
||||
foreach (int user in users)
|
||||
LoadComponentAsync(new MatchScoreDisplay
|
||||
{
|
||||
SpectatorClient.SendStartPlay(user, Beatmap.Value.BeatmapInfo.OnlineID);
|
||||
var roomUser = OnlinePlayDependencies.MultiplayerClient.AddUser(new APIUser { Id = user }, true);
|
||||
Team1Score = { BindTarget = Leaderboard.TeamScores[0] },
|
||||
Team2Score = { BindTarget = Leaderboard.TeamScores[1] }
|
||||
}, Add);
|
||||
|
||||
roomUser.MatchState = new TeamVersusUserState
|
||||
{
|
||||
TeamID = RNG.Next(0, 2)
|
||||
};
|
||||
|
||||
multiplayerUsers.Add(roomUser);
|
||||
}
|
||||
|
||||
Children = new Drawable[]
|
||||
LoadComponentAsync(new GameplayMatchScoreDisplay
|
||||
{
|
||||
scoreProcessor = new OsuScoreProcessor(),
|
||||
};
|
||||
|
||||
scoreProcessor.ApplyBeatmap(playableBeatmap);
|
||||
|
||||
LoadComponentAsync(leaderboard = new MultiplayerGameplayLeaderboard(Ruleset.Value, scoreProcessor, multiplayerUsers.ToArray())
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
}, gameplayLeaderboard =>
|
||||
{
|
||||
LoadComponentAsync(new MatchScoreDisplay
|
||||
{
|
||||
Team1Score = { BindTarget = leaderboard.TeamScores[0] },
|
||||
Team2Score = { BindTarget = leaderboard.TeamScores[1] }
|
||||
}, Add);
|
||||
|
||||
LoadComponentAsync(gameplayScoreDisplay = new GameplayMatchScoreDisplay
|
||||
{
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Team1Score = { BindTarget = leaderboard.TeamScores[0] },
|
||||
Team2Score = { BindTarget = leaderboard.TeamScores[1] }
|
||||
}, Add);
|
||||
|
||||
Add(gameplayLeaderboard);
|
||||
});
|
||||
});
|
||||
|
||||
AddUntilStep("wait for load", () => leaderboard.IsLoaded);
|
||||
AddUntilStep("wait for user population", () => MultiplayerClient.CurrentMatchPlayingUserIds.Count > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestScoreUpdates()
|
||||
{
|
||||
AddRepeatStep("update state", () => SpectatorClient.RandomlyUpdateState(), 100);
|
||||
AddToggleStep("switch compact mode", expanded =>
|
||||
{
|
||||
leaderboard.Expanded.Value = expanded;
|
||||
gameplayScoreDisplay.Expanded.Value = expanded;
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Team1Score = { BindTarget = Leaderboard.TeamScores[0] },
|
||||
Team2Score = { BindTarget = Leaderboard.TeamScores[1] },
|
||||
Expanded = { BindTarget = Leaderboard.Expanded },
|
||||
}, Add);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
@ -13,13 +14,19 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
{
|
||||
Child = new Container
|
||||
Child = new PopoverContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 50,
|
||||
Child = new MultiplayerMatchFooter()
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new Container
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Height = 50,
|
||||
Child = new MultiplayerMatchFooter()
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -8,13 +8,12 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.TypeExtensions;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets;
|
||||
@ -27,6 +26,7 @@ using osu.Game.Rulesets.Taiko.Mods;
|
||||
using osu.Game.Screens.OnlinePlay;
|
||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||
using osu.Game.Screens.Select;
|
||||
using osu.Game.Tests.Resources;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
@ -35,10 +35,12 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
private BeatmapManager manager;
|
||||
private RulesetStore rulesets;
|
||||
|
||||
private List<BeatmapInfo> beatmaps;
|
||||
private IList<BeatmapInfo> beatmaps => importedBeatmapSet?.PerformRead(s => s.Beatmaps) ?? new List<BeatmapInfo>();
|
||||
|
||||
private TestMultiplayerMatchSongSelect songSelect;
|
||||
|
||||
private Live<BeatmapSetInfo> importedBeatmapSet;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(GameHost host, AudioManager audio)
|
||||
{
|
||||
@ -46,44 +48,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default));
|
||||
Dependencies.Cache(Realm);
|
||||
|
||||
beatmaps = new List<BeatmapInfo>();
|
||||
|
||||
var metadata = new BeatmapMetadata
|
||||
{
|
||||
Artist = "Some Artist",
|
||||
Title = "Some Beatmap",
|
||||
Author = { Username = "Some Author" },
|
||||
};
|
||||
|
||||
var beatmapSetInfo = new BeatmapSetInfo
|
||||
{
|
||||
OnlineID = 10,
|
||||
Hash = Guid.NewGuid().ToString().ComputeMD5Hash(),
|
||||
DateAdded = DateTimeOffset.UtcNow
|
||||
};
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
int beatmapId = 10 * 10 + i;
|
||||
|
||||
int length = RNG.Next(30000, 200000);
|
||||
double bpm = RNG.NextSingle(80, 200);
|
||||
|
||||
var beatmap = new BeatmapInfo
|
||||
{
|
||||
Ruleset = rulesets.GetRuleset(i % 4) ?? throw new InvalidOperationException(),
|
||||
OnlineID = beatmapId,
|
||||
Length = length,
|
||||
BPM = bpm,
|
||||
Metadata = metadata,
|
||||
Difficulty = new BeatmapDifficulty()
|
||||
};
|
||||
|
||||
beatmaps.Add(beatmap);
|
||||
beatmapSetInfo.Beatmaps.Add(beatmap);
|
||||
}
|
||||
|
||||
manager.Import(beatmapSetInfo);
|
||||
importedBeatmapSet = manager.Import(TestResources.CreateTestBeatmapSetInfo(8, rulesets.AvailableRulesets.ToArray()));
|
||||
}
|
||||
|
||||
public override void SetUpSteps()
|
||||
|
@ -1,67 +1,68 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
public class TestSceneRankRangePill : MultiplayerTestScene
|
||||
public class TestSceneRankRangePill : OsuTestScene
|
||||
{
|
||||
[SetUp]
|
||||
public new void Setup() => Schedule(() =>
|
||||
private readonly Mock<MultiplayerClient> multiplayerClient = new Mock<MultiplayerClient>();
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
||||
// not used directly in component, but required due to it inheriting from OnlinePlayComposite.
|
||||
new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent));
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Dependencies.CacheAs(multiplayerClient.Object);
|
||||
|
||||
Child = new RankRangePill
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSingleUser()
|
||||
{
|
||||
AddStep("add user", () =>
|
||||
setupRoomWithUsers(new APIUser
|
||||
{
|
||||
MultiplayerClient.AddUser(new APIUser
|
||||
{
|
||||
Id = 2,
|
||||
Statistics = { GlobalRank = 1234 }
|
||||
});
|
||||
|
||||
// Remove the local user so only the one above is displayed.
|
||||
MultiplayerClient.RemoveUser(API.LocalUser.Value);
|
||||
Id = 2,
|
||||
Statistics = { GlobalRank = 1234 }
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMultipleUsers()
|
||||
{
|
||||
AddStep("add users", () =>
|
||||
{
|
||||
MultiplayerClient.AddUser(new APIUser
|
||||
setupRoomWithUsers(
|
||||
new APIUser
|
||||
{
|
||||
Id = 2,
|
||||
Statistics = { GlobalRank = 1234 }
|
||||
});
|
||||
|
||||
MultiplayerClient.AddUser(new APIUser
|
||||
},
|
||||
new APIUser
|
||||
{
|
||||
Id = 3,
|
||||
Statistics = { GlobalRank = 3333 }
|
||||
});
|
||||
|
||||
MultiplayerClient.AddUser(new APIUser
|
||||
},
|
||||
new APIUser
|
||||
{
|
||||
Id = 4,
|
||||
Statistics = { GlobalRank = 4321 }
|
||||
});
|
||||
|
||||
// Remove the local user so only the ones above are displayed.
|
||||
MultiplayerClient.RemoveUser(API.LocalUser.Value);
|
||||
});
|
||||
}
|
||||
|
||||
[TestCase(1, 10)]
|
||||
@ -73,22 +74,29 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
[TestCase(1000000, 10000000)]
|
||||
public void TestRange(int min, int max)
|
||||
{
|
||||
AddStep("add users", () =>
|
||||
{
|
||||
MultiplayerClient.AddUser(new APIUser
|
||||
setupRoomWithUsers(
|
||||
new APIUser
|
||||
{
|
||||
Id = 2,
|
||||
Statistics = { GlobalRank = min }
|
||||
});
|
||||
|
||||
MultiplayerClient.AddUser(new APIUser
|
||||
},
|
||||
new APIUser
|
||||
{
|
||||
Id = 3,
|
||||
Statistics = { GlobalRank = max }
|
||||
});
|
||||
}
|
||||
|
||||
// Remove the local user so only the ones above are displayed.
|
||||
MultiplayerClient.RemoveUser(API.LocalUser.Value);
|
||||
private void setupRoomWithUsers(params APIUser[] users)
|
||||
{
|
||||
AddStep("setup room", () =>
|
||||
{
|
||||
multiplayerClient.SetupGet(m => m.Room).Returns(new MultiplayerRoom(0)
|
||||
{
|
||||
Users = new List<MultiplayerRoomUser>(users.Select(apiUser => new MultiplayerRoomUser(apiUser.Id) { User = apiUser }))
|
||||
});
|
||||
|
||||
multiplayerClient.Raise(m => m.RoomUpdated -= null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user