1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 16:02:55 +08:00

Use autoplay mod rather than local replay provider

This commit is contained in:
Dean Herbert 2020-03-05 11:33:30 +09:00
parent 77fddcd2c2
commit 26ce0d05d6
3 changed files with 21 additions and 66 deletions

View File

@ -3,8 +3,6 @@
using NUnit.Framework;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Osu.Tests.Mods
@ -17,11 +15,11 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
}
[Test]
public void TestNoAdjustment() => CreateModTest(new ModTestData()
public void TestNoAdjustment() => CreateModTest(new ModTestData
{
Mod = new OsuModDifficultyAdjust(),
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
PassCondition = () => Player.ScoreProcessor.JudgedHits >= 2
});
[Test]
@ -29,7 +27,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
{
Mod = new OsuModDifficultyAdjust { CircleSize = { Value = 10 } },
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
PassCondition = () => Player.ScoreProcessor.JudgedHits >= 2
});
[Test]
@ -37,19 +35,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods
{
Mod = new OsuModDifficultyAdjust { ApproachRate = { Value = 10 } },
Autoplay = true,
PassCondition = () => ((ScoreAccessibleTestPlayer)Player).ScoreProcessor.JudgedHits >= 2
PassCondition = () => Player.ScoreProcessor.JudgedHits >= 2
});
protected override TestPlayer CreateReplayPlayer(Score score, bool allowFail) => new ScoreAccessibleTestPlayer(score, allowFail);
private class ScoreAccessibleTestPlayer : TestPlayer
{
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
public ScoreAccessibleTestPlayer(Score score, bool allowFail)
: base(score, allowFail)
{
}
}
}
}

View File

@ -3,13 +3,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual
{
@ -27,52 +24,48 @@ namespace osu.Game.Tests.Visual
{
}
private ModTestData currentTest;
private ModTestData currentTestData;
protected void CreateModTest(ModTestData testData) => CreateTest(() =>
{
AddStep("set test data", () => currentTest = testData);
AddStep("set test data", () => currentTestData = testData);
});
public override void TearDownSteps()
{
AddUntilStep("test passed", () =>
{
if (currentTest == null)
if (currentTestData == null)
return true;
return currentTest.PassCondition?.Invoke() ?? false;
return currentTestData.PassCondition?.Invoke() ?? false;
});
base.TearDownSteps();
}
protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTest?.Beatmap ?? base.CreateBeatmap(ruleset);
protected sealed override IBeatmap CreateBeatmap(RulesetInfo ruleset) => currentTestData?.Beatmap ?? base.CreateBeatmap(ruleset);
protected sealed override Player CreatePlayer(Ruleset ruleset)
protected sealed override TestPlayer CreatePlayer(Ruleset ruleset)
{
SelectedMods.Value = SelectedMods.Value.Append(currentTest.Mod).ToArray();
var mods = new List<Mod>(SelectedMods.Value);
var score = currentTest.Autoplay
? ruleset.GetAutoplayMod().CreateReplayScore(Beatmap.Value.GetPlayableBeatmap(ruleset.RulesetInfo, SelectedMods.Value))
: null;
if (currentTestData.Mod != null)
mods.Add(currentTestData.Mod);
if (currentTestData.Autoplay)
mods.Add(ruleset.GetAutoplayMod());
return CreateReplayPlayer(score, AllowFail);
SelectedMods.Value = mods;
return new ModTestPlayer(AllowFail);
}
/// <summary>
/// Creates the <see cref="TestPlayer"/> for a test case.
/// </summary>
/// <param name="score">The <see cref="Score"/>.</param>
/// <param name="allowFail">Whether the player can fail.</param>
protected virtual TestPlayer CreateReplayPlayer(Score score, bool allowFail) => new TestPlayer(score, allowFail);
protected class TestPlayer : TestReplayPlayer
protected class ModTestPlayer : TestPlayer
{
protected override bool AllowFail { get; }
public TestPlayer(Score score, bool allowFail)
: base(score, false, false)
public ModTestPlayer(bool allowFail)
: base(false, false)
{
AllowFail = allowFail;
}

View File

@ -1,24 +0,0 @@
// 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.
using osu.Game.Rulesets.UI;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
namespace osu.Game.Tests.Visual
{
public class TestReplayPlayer : ReplayPlayer
{
protected override bool PauseOnFocusLost { get; }
public new DrawableRuleset DrawableRuleset => base.DrawableRuleset;
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
public TestReplayPlayer(Score score, bool allowPause = true, bool showResults = true, bool pauseOnFocusLost = false)
: base(score, allowPause, showResults)
{
PauseOnFocusLost = pauseOnFocusLost;
}
}
}