1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 13:57:29 +08:00
osu-lazer/osu.Game.Tests/Visual/TestCaseMatchResults.cs

107 lines
3.4 KiB
C#
Raw Normal View History

// 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.
2018-12-21 17:22:13 +08:00
using System;
using System.Collections.Generic;
2018-12-21 17:37:33 +08:00
using System.Linq;
2018-12-21 17:22:13 +08:00
using osu.Framework.Allocation;
using osu.Game.Beatmaps;
2018-12-21 17:37:33 +08:00
using osu.Game.Online.API;
2018-12-22 14:45:16 +08:00
using osu.Game.Online.API.Requests.Responses;
2018-12-21 17:22:13 +08:00
using osu.Game.Scoring;
2018-12-21 17:37:33 +08:00
using osu.Game.Screens.Multi.Match.Components;
2018-12-21 17:22:13 +08:00
using osu.Game.Screens.Multi.Ranking;
using osu.Game.Screens.Multi.Ranking.Pages;
using osu.Game.Screens.Multi.Ranking.Types;
2018-12-22 15:26:27 +08:00
using osu.Game.Screens.Ranking;
2018-12-21 17:22:13 +08:00
using osu.Game.Users;
namespace osu.Game.Tests.Visual
{
2019-02-05 18:00:01 +08:00
public class TestCaseMatchResults : MultiplayerTestCase
2018-12-21 17:22:13 +08:00
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
2018-12-26 19:05:57 +08:00
typeof(MatchResults),
2018-12-22 15:26:27 +08:00
typeof(RoomLeaderboardPageInfo),
2018-12-27 14:30:02 +08:00
typeof(RoomLeaderboardPage)
2018-12-21 17:22:13 +08:00
};
[Resolved]
private BeatmapManager beatmaps { get; set; }
[BackgroundDependencyLoader]
private void load()
{
var beatmapInfo = beatmaps.QueryBeatmap(b => b.RulesetID == 0);
if (beatmapInfo != null)
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmapInfo);
2019-02-05 18:00:01 +08:00
Room.RoomID.Value = 1;
Room.Name.Value = "an awesome room";
2018-12-26 19:05:57 +08:00
Child = new TestMatchResults(new ScoreInfo
2018-12-21 17:37:33 +08:00
{
User = new User { Id = 10 },
});
}
2018-12-26 19:05:57 +08:00
private class TestMatchResults : MatchResults
2018-12-21 17:37:33 +08:00
{
2018-12-26 19:05:57 +08:00
public TestMatchResults(ScoreInfo score)
2019-02-05 18:00:01 +08:00
: base(score)
2018-12-21 17:37:33 +08:00
{
}
2019-02-01 14:42:15 +08:00
protected override IEnumerable<IResultPageInfo> CreateResultPages() => new[] { new TestRoomLeaderboardPageInfo(Score, Beatmap.Value, room) };
2018-12-21 17:37:33 +08:00
}
2018-12-22 15:26:27 +08:00
private class TestRoomLeaderboardPageInfo : RoomLeaderboardPageInfo
2018-12-21 17:37:33 +08:00
{
private readonly ScoreInfo score;
private readonly WorkingBeatmap beatmap;
2019-02-05 18:00:01 +08:00
public TestRoomLeaderboardPageInfo(ScoreInfo score, WorkingBeatmap beatmap)
: base(score, beatmap)
2018-12-21 17:37:33 +08:00
{
this.score = score;
this.beatmap = beatmap;
}
2019-02-05 18:00:01 +08:00
public override ResultsPage CreatePage() => new TestRoomLeaderboardPage(score, beatmap);
2018-12-21 17:37:33 +08:00
}
2018-12-27 14:30:02 +08:00
private class TestRoomLeaderboardPage : RoomLeaderboardPage
2018-12-21 17:37:33 +08:00
{
2019-02-05 18:00:01 +08:00
public TestRoomLeaderboardPage(ScoreInfo score, WorkingBeatmap beatmap)
: base(score, beatmap)
2018-12-21 17:37:33 +08:00
{
}
2019-02-05 18:00:01 +08:00
protected override MatchLeaderboard CreateLeaderboard() => new TestMatchLeaderboard();
2018-12-21 17:37:33 +08:00
}
2018-12-27 14:30:02 +08:00
private class TestMatchLeaderboard : RoomLeaderboardPage.ResultsMatchLeaderboard
2018-12-21 17:37:33 +08:00
{
2018-12-22 14:45:16 +08:00
protected override APIRequest FetchScores(Action<IEnumerable<APIRoomScoreInfo>> scoresCallback)
2018-12-21 17:37:33 +08:00
{
var scores = Enumerable.Range(0, 50).Select(createRoomScore).ToArray();
scoresCallback?.Invoke(scores);
ScoresLoaded?.Invoke(scores);
return null;
}
2018-12-21 17:22:13 +08:00
2018-12-22 14:45:16 +08:00
private APIRoomScoreInfo createRoomScore(int id) => new APIRoomScoreInfo
2018-12-21 17:22:13 +08:00
{
2018-12-21 17:37:33 +08:00
User = new User { Id = id, Username = $"User {id}" },
Accuracy = 0.98,
TotalScore = 987654,
TotalAttempts = 13,
2018-12-22 14:46:04 +08:00
CompletedBeatmaps = 5
2018-12-21 17:37:33 +08:00
};
2018-12-21 17:22:13 +08:00
}
}
}