2020-12-16 12:00:19 +08:00
|
|
|
// 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;
|
2020-12-16 14:26:03 +08:00
|
|
|
using System.Collections.Generic;
|
2020-12-16 15:05:46 +08:00
|
|
|
using System.Linq;
|
2020-12-16 12:00:19 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2021-06-25 16:37:02 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2020-12-16 12:00:19 +08:00
|
|
|
using osu.Framework.Graphics;
|
2020-12-17 15:02:06 +08:00
|
|
|
using osu.Framework.Testing;
|
2020-12-16 14:26:03 +08:00
|
|
|
using osu.Framework.Utils;
|
2021-04-12 21:03:45 +08:00
|
|
|
using osu.Game.Configuration;
|
2021-02-19 14:15:31 +08:00
|
|
|
using osu.Game.Online.API;
|
2021-08-12 10:05:31 +08:00
|
|
|
using osu.Game.Online.Multiplayer;
|
2020-12-16 12:00:19 +08:00
|
|
|
using osu.Game.Online.Spectator;
|
2020-12-16 14:26:03 +08:00
|
|
|
using osu.Game.Replays.Legacy;
|
2020-12-16 12:00:19 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Scoring;
|
2020-12-16 14:26:03 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Scoring;
|
2020-12-16 12:00:19 +08:00
|
|
|
using osu.Game.Screens.Play.HUD;
|
2021-06-25 14:30:23 +08:00
|
|
|
using osu.Game.Tests.Visual.OnlinePlay;
|
2021-05-12 13:19:36 +08:00
|
|
|
using osu.Game.Tests.Visual.Spectator;
|
2021-08-09 15:44:50 +08:00
|
|
|
using osu.Game.Users;
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-28 19:31:08 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
2020-12-16 12:00:19 +08:00
|
|
|
{
|
2020-12-26 10:34:05 +08:00
|
|
|
public class TestSceneMultiplayerGameplayLeaderboard : MultiplayerTestScene
|
2020-12-16 12:00:19 +08:00
|
|
|
{
|
2021-06-25 16:37:02 +08:00
|
|
|
private static IEnumerable<int> users => Enumerable.Range(0, 16);
|
2020-12-26 11:11:19 +08:00
|
|
|
|
2021-06-25 17:07:47 +08:00
|
|
|
public new TestMultiplayerSpectatorClient SpectatorClient => (TestMultiplayerSpectatorClient)OnlinePlayDependencies?.SpectatorClient;
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2021-06-25 14:30:23 +08:00
|
|
|
private MultiplayerGameplayLeaderboard leaderboard;
|
2021-04-12 21:03:45 +08:00
|
|
|
private OsuConfigManager config;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
Dependencies.Cache(config = new OsuConfigManager(LocalStorage));
|
|
|
|
}
|
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
[SetUpSteps]
|
2020-12-26 10:34:05 +08:00
|
|
|
public override void SetUpSteps()
|
2020-12-17 15:02:06 +08:00
|
|
|
{
|
2021-06-25 14:30:23 +08:00
|
|
|
AddStep("set local user", () => ((DummyAPIAccess)API).LocalUser.Value = LookupCache.GetUserAsync(1).Result);
|
2021-02-19 14:15:31 +08:00
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
AddStep("create leaderboard", () =>
|
|
|
|
{
|
2020-12-26 16:55:24 +08:00
|
|
|
leaderboard?.Expire();
|
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
OsuScoreProcessor scoreProcessor;
|
|
|
|
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
|
|
|
|
|
2021-08-12 10:05:31 +08:00
|
|
|
var playableBeatmap = Beatmap.Value.GetPlayableBeatmap(Ruleset.Value);
|
|
|
|
var multiplayerUsers = new List<MultiplayerRoomUser>();
|
2020-12-16 14:26:03 +08:00
|
|
|
|
2021-06-25 16:37:02 +08:00
|
|
|
foreach (var user in users)
|
2021-08-09 15:44:50 +08:00
|
|
|
{
|
2021-06-25 16:37:02 +08:00
|
|
|
SpectatorClient.StartPlay(user, Beatmap.Value.BeatmapInfo.OnlineBeatmapID ?? 0);
|
2021-08-12 10:05:31 +08:00
|
|
|
multiplayerUsers.Add(OnlinePlayDependencies.Client.AddUser(new User { Id = user }, true));
|
2021-08-09 15:44:50 +08:00
|
|
|
}
|
2020-12-16 14:26:03 +08:00
|
|
|
|
2020-12-17 15:02:06 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
scoreProcessor = new OsuScoreProcessor(),
|
|
|
|
};
|
2020-12-16 14:26:03 +08:00
|
|
|
|
2021-08-12 10:05:31 +08:00
|
|
|
scoreProcessor.ApplyBeatmap(playableBeatmap);
|
2020-12-17 15:02:06 +08:00
|
|
|
|
2021-08-12 10:05:31 +08:00
|
|
|
LoadComponentAsync(leaderboard = new MultiplayerGameplayLeaderboard(scoreProcessor, multiplayerUsers.ToArray())
|
2020-12-17 15:02:06 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
}, Add);
|
|
|
|
});
|
|
|
|
|
|
|
|
AddUntilStep("wait for load", () => leaderboard.IsLoaded);
|
2021-05-27 18:57:19 +08:00
|
|
|
AddUntilStep("wait for user population", () => Client.CurrentMatchPlayingUserIds.Count > 0);
|
2020-12-17 15:02:06 +08:00
|
|
|
}
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-16 14:26:03 +08:00
|
|
|
[Test]
|
|
|
|
public void TestScoreUpdates()
|
|
|
|
{
|
2021-06-25 14:30:23 +08:00
|
|
|
AddRepeatStep("update state", () => SpectatorClient.RandomlyUpdateState(), 100);
|
2021-02-19 14:09:41 +08:00
|
|
|
AddToggleStep("switch compact mode", expanded => leaderboard.Expanded.Value = expanded);
|
2020-12-16 14:26:03 +08:00
|
|
|
}
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-26 11:11:19 +08:00
|
|
|
[Test]
|
|
|
|
public void TestUserQuit()
|
|
|
|
{
|
2021-06-25 16:37:02 +08:00
|
|
|
foreach (var user in users)
|
|
|
|
AddStep($"mark user {user} quit", () => Client.RemoveUser(LookupCache.GetUserAsync(user).Result.AsNonNull()));
|
2020-12-26 11:11:19 +08:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:03:45 +08:00
|
|
|
[Test]
|
|
|
|
public void TestChangeScoringMode()
|
|
|
|
{
|
2021-06-25 14:30:23 +08:00
|
|
|
AddRepeatStep("update state", () => SpectatorClient.RandomlyUpdateState(), 5);
|
2021-04-12 21:03:45 +08:00
|
|
|
AddStep("change to classic", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Classic));
|
|
|
|
AddStep("change to standardised", () => config.SetValue(OsuSetting.ScoreDisplayMode, ScoringMode.Standardised));
|
|
|
|
}
|
|
|
|
|
2021-06-25 19:11:38 +08:00
|
|
|
protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new TestDependencies();
|
2021-06-25 14:30:23 +08:00
|
|
|
|
2021-06-25 19:11:38 +08:00
|
|
|
protected class TestDependencies : MultiplayerTestSceneDependencies
|
2021-06-25 14:30:23 +08:00
|
|
|
{
|
2021-06-25 16:55:16 +08:00
|
|
|
protected override TestSpectatorClient CreateSpectatorClient() => new TestMultiplayerSpectatorClient();
|
2021-06-25 14:30:23 +08:00
|
|
|
}
|
|
|
|
|
2021-05-20 14:55:07 +08:00
|
|
|
public class TestMultiplayerSpectatorClient : TestSpectatorClient
|
2020-12-16 12:00:19 +08:00
|
|
|
{
|
2020-12-16 14:26:03 +08:00
|
|
|
private readonly Dictionary<int, FrameHeader> lastHeaders = new Dictionary<int, FrameHeader>();
|
2020-12-16 12:00:19 +08:00
|
|
|
|
2020-12-16 14:26:03 +08:00
|
|
|
public void RandomlyUpdateState()
|
2020-12-16 12:00:19 +08:00
|
|
|
{
|
2020-12-16 14:26:03 +08:00
|
|
|
foreach (var userId in PlayingUsers)
|
|
|
|
{
|
2020-12-20 04:25:04 +08:00
|
|
|
if (RNG.NextBool())
|
2020-12-16 14:26:03 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!lastHeaders.TryGetValue(userId, out var header))
|
|
|
|
{
|
|
|
|
lastHeaders[userId] = header = new FrameHeader(new ScoreInfo
|
|
|
|
{
|
2020-12-20 04:26:40 +08:00
|
|
|
Statistics = new Dictionary<HitResult, int>
|
2020-12-16 14:26:03 +08:00
|
|
|
{
|
2020-12-20 04:26:40 +08:00
|
|
|
[HitResult.Miss] = 0,
|
|
|
|
[HitResult.Meh] = 0,
|
|
|
|
[HitResult.Great] = 0
|
|
|
|
}
|
2020-12-16 14:26:03 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-04-12 21:00:27 +08:00
|
|
|
((ISpectatorClient)this).UserSentFrames(userId, new FrameDataBundle(header, new[] { new LegacyReplayFrame(Time.Current, 0, 0, ReplayButtonState.None) }));
|
2020-12-16 14:26:03 +08:00
|
|
|
}
|
2020-12-16 12:00:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|