2019-05-10 14:39:25 +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.
|
|
|
|
|
2020-03-05 10:25:07 +08:00
|
|
|
using System.Collections.Generic;
|
2021-06-01 14:39:02 +08:00
|
|
|
using System.Linq;
|
2020-03-05 10:25:07 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-08-28 18:57:17 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
2019-05-10 14:39:25 +08:00
|
|
|
using osu.Game.Screens.Play;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2020-03-05 10:25:07 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A player that exposes many components that would otherwise not be available, for testing purposes.
|
|
|
|
/// </summary>
|
2019-05-10 14:39:25 +08:00
|
|
|
public class TestPlayer : Player
|
|
|
|
{
|
2019-12-11 14:24:06 +08:00
|
|
|
protected override bool PauseOnFocusLost { get; }
|
2019-05-10 14:39:25 +08:00
|
|
|
|
2019-08-28 18:57:17 +08:00
|
|
|
public new DrawableRuleset DrawableRuleset => base.DrawableRuleset;
|
|
|
|
|
2020-03-05 10:25:07 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Mods from *player* (not OsuScreen).
|
|
|
|
/// </summary>
|
|
|
|
public new Bindable<IReadOnlyList<Mod>> Mods => base.Mods;
|
|
|
|
|
|
|
|
public new HUDOverlay HUDOverlay => base.HUDOverlay;
|
|
|
|
|
2019-12-11 14:24:06 +08:00
|
|
|
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
|
|
|
|
|
2020-03-05 10:25:07 +08:00
|
|
|
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
|
|
|
|
|
|
|
|
public new HealthProcessor HealthProcessor => base.HealthProcessor;
|
|
|
|
|
2021-02-19 16:42:30 +08:00
|
|
|
public new bool PauseCooldownActive => base.PauseCooldownActive;
|
|
|
|
|
2020-03-05 10:25:07 +08:00
|
|
|
public readonly List<JudgementResult> Results = new List<JudgementResult>();
|
|
|
|
|
2019-12-11 14:24:06 +08:00
|
|
|
public TestPlayer(bool allowPause = true, bool showResults = true, bool pauseOnFocusLost = false)
|
2020-12-23 16:39:08 +08:00
|
|
|
: base(new PlayerConfiguration
|
|
|
|
{
|
|
|
|
AllowPause = allowPause,
|
|
|
|
ShowResults = showResults
|
|
|
|
})
|
2019-05-10 14:39:25 +08:00
|
|
|
{
|
2019-12-11 14:24:06 +08:00
|
|
|
PauseOnFocusLost = pauseOnFocusLost;
|
2019-05-10 14:39:25 +08:00
|
|
|
}
|
2020-03-05 10:25:07 +08:00
|
|
|
|
2021-06-01 14:39:02 +08:00
|
|
|
protected override void PrepareReplay()
|
|
|
|
{
|
2021-06-01 15:24:38 +08:00
|
|
|
var autoplayMod = Mods.Value.OfType<ModAutoplay>().FirstOrDefault();
|
2021-06-01 14:39:02 +08:00
|
|
|
|
2021-06-01 15:24:38 +08:00
|
|
|
// This logic should really not exist (and tests should be instantiating a ReplayPlayer), but a lot of base work is required to make that happen.
|
|
|
|
if (autoplayMod != null)
|
2021-06-01 14:39:02 +08:00
|
|
|
{
|
2021-06-01 15:24:38 +08:00
|
|
|
var replayScore = autoplayMod.CreateReplayScore(GameplayBeatmap.PlayableBeatmap, Mods.Value);
|
|
|
|
|
|
|
|
DrawableRuleset?.SetReplayScore(replayScore);
|
|
|
|
|
|
|
|
ScoreProcessor.NewJudgement += result => ScoreProcessor.PopulateScore(replayScore.ScoreInfo);
|
2021-06-01 14:39:02 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
base.PrepareReplay();
|
|
|
|
}
|
|
|
|
|
2020-03-05 10:25:07 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
ScoreProcessor.NewJudgement += r => Results.Add(r);
|
|
|
|
}
|
2019-05-10 14:39:25 +08:00
|
|
|
}
|
|
|
|
}
|