1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 12:47:25 +08:00
osu-lazer/osu.Game.Tests/Visual/Gameplay/TestSceneLeadIn.cs

84 lines
2.7 KiB
C#
Raw Normal View History

2019-03-26 15:13:58 +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 NUnit.Framework;
2019-11-21 14:56:08 +08:00
using osu.Framework.MathUtils;
2019-03-26 15:13:58 +08:00
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
2019-11-15 13:47:28 +08:00
using osu.Game.Rulesets.Osu;
2019-03-26 15:13:58 +08:00
using osu.Game.Screens.Play;
using osu.Game.Tests.Beatmaps;
namespace osu.Game.Tests.Visual.Gameplay
{
2019-11-15 13:15:09 +08:00
public class TestSceneLeadIn : RateAdjustedBeatmapTestScene
2019-03-26 15:13:58 +08:00
{
private LeadInPlayer player;
2019-11-15 13:47:28 +08:00
[Test]
public void TestShortLeadIn()
2019-03-26 15:13:58 +08:00
{
2019-11-15 13:47:28 +08:00
loadPlayerWithBeatmap(new TestBeatmap(new OsuRuleset().RulesetInfo)
2019-03-26 15:13:58 +08:00
{
2019-11-15 13:47:28 +08:00
BeatmapInfo = { AudioLeadIn = 1000 }
2019-03-26 15:13:58 +08:00
});
2019-11-21 14:56:08 +08:00
AddAssert("correct lead-in", () => Precision.AlmostEquals(player.FirstFrameClockTime.Value, 0, 100));
2019-03-26 15:13:58 +08:00
}
[Test]
public void TestLongLeadIn()
{
2019-11-15 13:47:28 +08:00
loadPlayerWithBeatmap(new TestBeatmap(new OsuRuleset().RulesetInfo)
{
BeatmapInfo = { AudioLeadIn = 10000 }
});
2019-11-21 14:56:08 +08:00
AddAssert("correct lead-in", () => Precision.AlmostEquals(player.FirstFrameClockTime.Value, player.GameplayStartTime - 10000, 100));
2019-03-26 15:13:58 +08:00
}
private void loadPlayerWithBeatmap(IBeatmap beatmap)
{
2019-11-15 13:47:28 +08:00
AddStep("create player", () =>
{
Beatmap.Value = CreateWorkingBeatmap(beatmap);
LoadScreen(player = new LeadInPlayer());
});
2019-03-26 15:13:58 +08:00
2019-11-15 13:47:28 +08:00
AddUntilStep("player loaded", () => player.IsLoaded && player.Alpha == 1);
2019-03-26 15:13:58 +08:00
}
2019-11-15 13:47:28 +08:00
private class LeadInPlayer : TestPlayer
2019-03-26 15:13:58 +08:00
{
2019-05-31 14:58:46 +08:00
public LeadInPlayer()
: base(false, false)
{
}
2019-03-26 15:13:58 +08:00
public double? FirstFrameClockTime;
public new GameplayClockContainer GameplayClockContainer => base.GameplayClockContainer;
public double GameplayStartTime => DrawableRuleset.GameplayStartTime;
public double GameplayClockTime => GameplayClockContainer.GameplayClock.CurrentTime;
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
2019-05-31 14:58:46 +08:00
2019-03-26 15:13:58 +08:00
if (!FirstFrameClockTime.HasValue)
{
FirstFrameClockTime = GameplayClockContainer.GameplayClock.CurrentTime;
AddInternal(new OsuSpriteText
{
Text = $"GameplayStartTime: {DrawableRuleset.GameplayStartTime} "
+ $"LeadInTime: {Beatmap.Value.BeatmapInfo.AudioLeadIn} "
+ $"FirstFrameClockTime: {FirstFrameClockTime}"
});
}
}
}
}
}