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

124 lines
3.9 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.Online.Multiplayer;
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
{
2018-12-27 14:30:02 +08:00
public class TestCaseMatchResults : OsuTestCase
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);
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
{
private readonly Room room;
2018-12-26 19:05:57 +08:00
public TestMatchResults(ScoreInfo score)
2018-12-27 14:30:02 +08:00
: this(score, new Room
{
RoomID = { Value = 1 },
Name = { Value = "an awesome room" }
})
2018-12-21 17:37:33 +08:00
{
}
2018-12-26 19:05:57 +08:00
public TestMatchResults(ScoreInfo score, Room room)
2018-12-21 17:37:33 +08:00
: base(score, room)
{
this.room = room;
}
2018-12-22 15:26:27 +08:00
protected override IEnumerable<IResultPageInfo> CreateResultPages() => new[] { new TestRoomLeaderboardPageInfo(Score, Beatmap, 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;
private readonly Room room;
2018-12-22 15:26:27 +08:00
public TestRoomLeaderboardPageInfo(ScoreInfo score, WorkingBeatmap beatmap, Room room)
2018-12-21 17:37:33 +08:00
: base(score, beatmap, room)
{
this.score = score;
this.beatmap = beatmap;
this.room = room;
}
2018-12-27 14:30:02 +08:00
public override ResultsPage CreatePage() => new TestRoomLeaderboardPage(score, beatmap, room);
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
{
2018-12-27 14:30:02 +08:00
public TestRoomLeaderboardPage(ScoreInfo score, WorkingBeatmap beatmap, Room room)
2018-12-21 17:37:33 +08:00
: base(score, beatmap, room)
{
}
protected override MatchLeaderboard CreateLeaderboard(Room room) => new TestMatchLeaderboard(room);
}
2018-12-27 14:30:02 +08:00
private class TestMatchLeaderboard : RoomLeaderboardPage.ResultsMatchLeaderboard
2018-12-21 17:37:33 +08:00
{
public TestMatchLeaderboard(Room room)
: base(room)
{
}
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
}
}
}