1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 15:32:55 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneGameplayRewinding.cs

118 lines
4.0 KiB
C#
Raw Normal View History

2019-06-13 13:41:10 +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.
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
2019-06-14 18:35:31 +08:00
using osu.Framework.Audio.Track;
2020-01-09 12:43:44 +08:00
using osu.Framework.Utils;
2019-06-13 13:41:10 +08:00
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Objects;
2019-09-12 17:10:50 +08:00
using osu.Game.Rulesets.Scoring;
2019-06-13 13:41:10 +08:00
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play;
2019-11-21 17:50:54 +08:00
using osu.Game.Storyboards;
2019-06-13 13:41:10 +08:00
using osuTK;
namespace osu.Game.Tests.Visual.Gameplay
{
public class TestSceneGameplayRewinding : PlayerTestScene
{
private RulesetExposingPlayer player => (RulesetExposingPlayer)Player;
[Resolved]
private AudioManager audioManager { get; set; }
public TestSceneGameplayRewinding()
: base(new OsuRuleset())
{
}
2019-06-14 18:35:31 +08:00
private Track track;
2019-11-21 17:50:54 +08:00
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap, Storyboard storyboard = null)
2019-06-14 18:35:31 +08:00
{
2019-11-21 17:50:54 +08:00
var working = new ClockBackedTestWorkingBeatmap(beatmap, storyboard, new FramedClock(new ManualClock { Rate = 1 }), audioManager);
2019-06-14 18:35:31 +08:00
track = working.Track;
return working;
}
2019-06-13 13:41:10 +08:00
[Test]
2019-06-14 18:35:47 +08:00
public void TestNoJudgementsOnRewind()
2019-06-13 13:41:10 +08:00
{
AddUntilStep("wait for track to start running", () => track.IsRunning);
2019-06-13 13:41:10 +08:00
addSeekStep(3000);
AddAssert("all judged", () => player.DrawableRuleset.Playfield.AllHitObjects.All(h => h.Judged));
2019-09-12 17:10:50 +08:00
AddUntilStep("key counter counted keys", () => player.HUDOverlay.KeyCounter.Children.All(kc => kc.CountPresses >= 7));
2019-06-13 13:41:10 +08:00
AddStep("clear results", () => player.AppliedResults.Clear());
addSeekStep(0);
AddAssert("none judged", () => player.DrawableRuleset.Playfield.AllHitObjects.All(h => !h.Judged));
2019-09-12 17:10:50 +08:00
AddUntilStep("key counters reset", () => player.HUDOverlay.KeyCounter.Children.All(kc => kc.CountPresses == 0));
2019-06-13 13:41:10 +08:00
AddAssert("no results triggered", () => player.AppliedResults.Count == 0);
}
private void addSeekStep(double time)
{
2019-06-14 18:35:31 +08:00
AddStep($"seek to {time}", () => track.Seek(time));
2019-06-13 13:41:10 +08:00
2019-06-13 14:47:21 +08:00
// Allow a few frames of lenience
AddUntilStep("wait for seek to finish", () => Precision.AlmostEquals(time, player.DrawableRuleset.FrameStableClock.CurrentTime, 100));
2019-06-13 13:41:10 +08:00
}
protected override Player CreatePlayer(Ruleset ruleset)
{
2019-12-13 20:45:38 +08:00
SelectedMods.Value = SelectedMods.Value.Concat(new[] { ruleset.GetAutoplayMod() }).ToArray();
2019-06-13 13:41:10 +08:00
return new RulesetExposingPlayer();
}
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset)
{
var beatmap = new Beatmap
{
BeatmapInfo = { BaseDifficulty = { ApproachRate = 9 } },
};
for (int i = 0; i < 15; i++)
{
beatmap.HitObjects.Add(new HitCircle
{
Position = new Vector2(256, 192),
StartTime = 1000 + 30 * i
});
}
return beatmap;
}
private class RulesetExposingPlayer : Player
{
public readonly List<JudgementResult> AppliedResults = new List<JudgementResult>();
2019-09-12 17:10:50 +08:00
public new ScoreProcessor ScoreProcessor => base.ScoreProcessor;
public new HUDOverlay HUDOverlay => base.HUDOverlay;
2019-06-13 13:41:10 +08:00
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
public new DrawableRuleset DrawableRuleset => base.DrawableRuleset;
public RulesetExposingPlayer()
: base(false, false)
{
}
[BackgroundDependencyLoader]
private void load()
{
ScoreProcessor.NewJudgement += r => AppliedResults.Add(r);
}
}
}
}