From fb795f6bfdbb0638c21ae33e2f02e025ca38d780 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 16 Dec 2020 13:00:19 +0900 Subject: [PATCH] Add initial hook-up to spectator backend --- .../Visual/Gameplay/TestSceneSpectator.cs | 2 +- .../TestSceneSpectatorDrivenLeaderboard.cs | 74 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorDrivenLeaderboard.cs diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs index 3e5b561a6f..1fdff99da6 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectator.cs @@ -232,7 +232,7 @@ namespace osu.Game.Tests.Visual.Gameplay public class TestSpectatorStreamingClient : SpectatorStreamingClient { - public readonly User StreamingUser = new User { Id = 1234, Username = "Test user" }; + public readonly User StreamingUser = new User { Id = 55, Username = "Test user" }; public new BindableList PlayingUsers => (BindableList)base.PlayingUsers; diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorDrivenLeaderboard.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorDrivenLeaderboard.cs new file mode 100644 index 0000000000..7211755ba6 --- /dev/null +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSpectatorDrivenLeaderboard.cs @@ -0,0 +1,74 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Framework.Graphics; +using osu.Game.Database; +using osu.Game.Online.API; +using osu.Game.Online.Spectator; +using osu.Game.Rulesets.Osu.Scoring; +using osu.Game.Screens.Play.HUD; + +namespace osu.Game.Tests.Visual.Gameplay +{ + public class TestSceneSpectatorDrivenLeaderboard : OsuTestScene + { + [Cached(typeof(SpectatorStreamingClient))] + private TestSceneSpectator.TestSpectatorStreamingClient testSpectatorStreamingClient = new TestSceneSpectator.TestSpectatorStreamingClient(); + + // used just to show beatmap card for the time being. + protected override bool UseOnlineAPI => true; + + [SetUp] + public void SetUp() => Schedule(() => + { + OsuScoreProcessor scoreProcessor; + + testSpectatorStreamingClient.StartPlay(55); + + Children = new Drawable[] + { + scoreProcessor = new OsuScoreProcessor(), + new MultiplayerGameplayLeaderboard(scoreProcessor) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + } + }; + }); + } + + public class MultiplayerGameplayLeaderboard : GameplayLeaderboard + { + private readonly OsuScoreProcessor scoreProcessor; + + public MultiplayerGameplayLeaderboard(OsuScoreProcessor scoreProcessor) + { + this.scoreProcessor = scoreProcessor; + + AddPlayer(new BindableDouble(), new GuestUser()); + } + + [Resolved] + private SpectatorStreamingClient streamingClient { get; set; } + + [Resolved] + private UserLookupCache userLookupCache { get; set; } + + [BackgroundDependencyLoader] + private void load() + { + Console.WriteLine("got here"); + + foreach (var user in streamingClient.PlayingUsers) + { + streamingClient.WatchUser(user); + var resolvedUser = userLookupCache.GetUserAsync(user).Result; + AddPlayer(new BindableDouble(), resolvedUser); + } + } + } +}