2019-05-10 06:39:25 +00: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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2021-07-01 07:55:33 +00:00
|
|
|
using System;
|
2020-03-05 02:25:07 +00:00
|
|
|
using System.Collections.Generic;
|
2021-06-01 06:39:02 +00:00
|
|
|
using System.Linq;
|
2020-03-05 02:25:07 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2021-07-01 07:55:33 +00:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.Rooms;
|
2022-08-09 06:05:05 +00:00
|
|
|
using osu.Game.Online.Spectator;
|
2020-03-05 02:25:07 +00:00
|
|
|
using osu.Game.Rulesets.Judgements;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-08-28 10:57:17 +00:00
|
|
|
using osu.Game.Rulesets.UI;
|
2021-07-01 07:55:33 +00:00
|
|
|
using osu.Game.Scoring;
|
2019-05-10 06:39:25 +00:00
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2020-03-05 02:25:07 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A player that exposes many components that would otherwise not be available, for testing purposes.
|
|
|
|
/// </summary>
|
2021-07-01 07:55:33 +00:00
|
|
|
public class TestPlayer : SoloPlayer
|
2019-05-10 06:39:25 +00:00
|
|
|
{
|
2019-12-11 06:24:06 +00:00
|
|
|
protected override bool PauseOnFocusLost { get; }
|
2019-05-10 06:39:25 +00:00
|
|
|
|
2019-08-28 10:57:17 +00:00
|
|
|
public new DrawableRuleset DrawableRuleset => base.DrawableRuleset;
|
|
|
|
|
2020-03-05 02:25:07 +00:00
|
|
|
public new Bindable<IReadOnlyList<Mod>> Mods => base.Mods;
|
|
|
|
|
|
|
|
public new HUDOverlay HUDOverlay => base.HUDOverlay;
|
|
|
|
|
2019-12-11 06:24:06 +00:00
|
|
|
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
|
|
|
|
|
2020-03-05 02:25:07 +00:00
|
|
|
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
|
|
|
|
|
|
|
|
public new HealthProcessor HealthProcessor => base.HealthProcessor;
|
|
|
|
|
2021-07-01 07:55:33 +00:00
|
|
|
public bool TokenCreationRequested { get; private set; }
|
2021-07-01 08:38:28 +00:00
|
|
|
|
|
|
|
public Score SubmittedScore { get; private set; }
|
2021-07-01 07:55:33 +00:00
|
|
|
|
2021-02-19 08:42:30 +00:00
|
|
|
public new bool PauseCooldownActive => base.PauseCooldownActive;
|
|
|
|
|
2020-03-05 02:25:07 +00:00
|
|
|
public readonly List<JudgementResult> Results = new List<JudgementResult>();
|
|
|
|
|
2022-08-09 06:05:05 +00:00
|
|
|
[Resolved]
|
|
|
|
private SpectatorClient spectatorClient { get; set; }
|
|
|
|
|
2019-12-11 06:24:06 +00:00
|
|
|
public TestPlayer(bool allowPause = true, bool showResults = true, bool pauseOnFocusLost = false)
|
2020-12-23 08:39:08 +00:00
|
|
|
: base(new PlayerConfiguration
|
|
|
|
{
|
|
|
|
AllowPause = allowPause,
|
|
|
|
ShowResults = showResults
|
|
|
|
})
|
2019-05-10 06:39:25 +00:00
|
|
|
{
|
2019-12-11 06:24:06 +00:00
|
|
|
PauseOnFocusLost = pauseOnFocusLost;
|
2019-05-10 06:39:25 +00:00
|
|
|
}
|
2020-03-05 02:25:07 +00:00
|
|
|
|
2021-07-01 07:55:33 +00:00
|
|
|
protected override bool HandleTokenRetrievalFailure(Exception exception) => false;
|
|
|
|
|
|
|
|
protected override APIRequest<APIScoreToken> CreateTokenRequest()
|
|
|
|
{
|
|
|
|
TokenCreationRequested = true;
|
|
|
|
return base.CreateTokenRequest();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override APIRequest<MultiplayerScore> CreateSubmissionRequest(Score score, long token)
|
|
|
|
{
|
2021-07-01 08:38:28 +00:00
|
|
|
SubmittedScore = score;
|
2021-07-01 07:55:33 +00:00
|
|
|
return base.CreateSubmissionRequest(score, token);
|
|
|
|
}
|
|
|
|
|
2021-06-01 06:39:02 +00:00
|
|
|
protected override void PrepareReplay()
|
|
|
|
{
|
2021-06-02 02:10:02 +00:00
|
|
|
// Generally, replay generation is handled by whatever is constructing the player.
|
|
|
|
// This is implemented locally here to ease migration of test scenes that have some executions
|
|
|
|
// running with autoplay and some not, but are not written in a way that lends to instantiating
|
|
|
|
// different `Player` types.
|
|
|
|
//
|
|
|
|
// Eventually we will want to remove this and update all test usages which rely on autoplay to use
|
|
|
|
// a `TestReplayPlayer`.
|
2021-06-01 07:24:38 +00:00
|
|
|
var autoplayMod = Mods.Value.OfType<ModAutoplay>().FirstOrDefault();
|
2021-06-01 06:39:02 +00:00
|
|
|
|
2021-06-01 07:24:38 +00:00
|
|
|
if (autoplayMod != null)
|
2021-06-01 06:39:02 +00:00
|
|
|
{
|
2022-03-29 07:45:21 +00:00
|
|
|
DrawableRuleset?.SetReplayScore(autoplayMod.CreateScoreFromReplayData(GameplayState.Beatmap, Mods.Value));
|
2021-06-01 06:39:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
base.PrepareReplay();
|
|
|
|
}
|
|
|
|
|
2020-03-05 02:25:07 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2022-01-11 09:33:35 +00:00
|
|
|
if (!LoadedBeatmapSuccessfully)
|
|
|
|
return;
|
|
|
|
|
2020-03-05 02:25:07 +00:00
|
|
|
ScoreProcessor.NewJudgement += r => Results.Add(r);
|
|
|
|
}
|
2022-08-09 06:05:05 +00:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
// Specific to tests, the player can be disposed without OnExiting() ever being called.
|
|
|
|
// We should make sure that the gameplay session has finished even in this case.
|
|
|
|
if (LoadedBeatmapSuccessfully)
|
2022-08-09 09:15:50 +00:00
|
|
|
spectatorClient?.EndPlaying(GameplayState);
|
2022-08-09 06:05:05 +00:00
|
|
|
}
|
2019-05-10 06:39:25 +00:00
|
|
|
}
|
|
|
|
}
|