1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 15:02:56 +08:00
osu-lazer/osu.Game.Rulesets.Mania.Tests/TestSceneTimingBasedNoteColouring.cs

120 lines
4.4 KiB
C#
Raw Normal View History

// 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.
2021-09-12 23:48:08 +08:00
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Tests.Visual;
using osu.Framework.Timing;
using osu.Game.Rulesets.Mania.Objects;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Configuration;
using osu.Framework.Bindables;
2021-09-12 23:41:50 +08:00
using osu.Framework.Testing;
2021-09-12 23:48:08 +08:00
using osu.Framework.Utils;
using osu.Game.Rulesets.Mania.Objects.Drawables;
using osu.Game.Rulesets.Mania.UI;
namespace osu.Game.Rulesets.Mania.Tests
{
[TestFixture]
public class TestSceneTimingBasedNoteColouring : OsuTestScene
{
[Resolved]
private RulesetConfigCache configCache { get; set; }
2021-04-27 19:25:46 +08:00
2021-09-12 23:41:50 +08:00
private Bindable<bool> configTimingBasedNoteColouring;
2021-09-12 23:41:50 +08:00
private ManualClock clock;
2021-09-12 23:48:08 +08:00
private DrawableManiaRuleset drawableRuleset;
2021-09-12 23:41:50 +08:00
[SetUpSteps]
public void SetUpSteps()
{
2021-09-12 23:41:50 +08:00
AddStep("setup hierarchy", () => Child = new Container
{
Clock = new FramedClock(clock = new ManualClock()),
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Children = new[]
{
2021-09-12 23:48:08 +08:00
drawableRuleset = (DrawableManiaRuleset)Ruleset.Value.CreateInstance().CreateDrawableRulesetWith(createTestBeatmap())
2021-09-12 23:41:50 +08:00
}
});
AddStep("retrieve config bindable", () =>
{
var config = (ManiaRulesetConfigManager)configCache.GetConfigFor(Ruleset.Value.CreateInstance());
configTimingBasedNoteColouring = config.GetBindable<bool>(ManiaRulesetSetting.TimingBasedNoteColouring);
});
}
2021-09-12 23:41:50 +08:00
[Test]
public void TestSimple()
{
AddStep("enable", () => configTimingBasedNoteColouring.Value = true);
AddStep("disable", () => configTimingBasedNoteColouring.Value = false);
}
2021-09-12 23:48:08 +08:00
[Test]
public void TestToggleOffScreen()
{
AddStep("enable", () => configTimingBasedNoteColouring.Value = true);
seekTo(10000);
AddStep("disable", () => configTimingBasedNoteColouring.Value = false);
seekTo(0);
AddAssert("all notes not coloured", () => this.ChildrenOfType<DrawableNote>().All(note => note.Colour == Colour4.White));
seekTo(10000);
AddStep("enable again", () => configTimingBasedNoteColouring.Value = true);
seekTo(0);
AddAssert("some notes coloured", () => this.ChildrenOfType<DrawableNote>().Any(note => note.Colour != Colour4.White));
}
private void seekTo(double time)
{
AddStep($"seek to {time}", () => clock.CurrentTime = time);
AddUntilStep("wait for seek", () => Precision.AlmostEquals(drawableRuleset.FrameStableClock.CurrentTime, time, 1));
}
2021-09-12 23:41:50 +08:00
private ManiaBeatmap createTestBeatmap()
{
const double beat_length = 500;
var beatmap = new ManiaBeatmap(new StageDefinition { Columns = 1 })
{
2021-04-27 19:25:46 +08:00
HitObjects =
{
new Note { StartTime = 0 },
2021-04-27 19:25:46 +08:00
new Note { StartTime = beat_length / 16 },
new Note { StartTime = beat_length / 12 },
new Note { StartTime = beat_length / 8 },
new Note { StartTime = beat_length / 6 },
new Note { StartTime = beat_length / 4 },
new Note { StartTime = beat_length / 3 },
new Note { StartTime = beat_length / 2 },
new Note { StartTime = beat_length }
},
ControlPointInfo = new ControlPointInfo(),
2021-09-12 23:41:50 +08:00
BeatmapInfo = { Ruleset = Ruleset.Value },
};
foreach (var note in beatmap.HitObjects)
{
note.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty());
}
2021-04-27 19:25:46 +08:00
beatmap.ControlPointInfo.Add(0, new TimingControlPoint
2021-05-01 15:00:18 +08:00
{
BeatLength = beat_length
});
2021-09-12 23:41:50 +08:00
return beatmap;
}
}
}