1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 20:07:25 +08:00
osu-lazer/osu.Game.Rulesets.Osu.Tests/TestCaseSpinner.cs

89 lines
3.0 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-12-27 19:01:20 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-12-30 00:44:38 +08:00
using System;
using System.Collections.Generic;
2018-01-01 18:55:24 +08:00
using System.Linq;
2018-03-02 14:34:31 +08:00
using NUnit.Framework;
2017-12-27 19:01:20 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
2018-01-01 18:55:24 +08:00
using osu.Game.Rulesets.Mods;
2017-12-27 19:01:20 +08:00
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
2018-01-03 00:04:00 +08:00
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
2017-12-27 19:01:20 +08:00
using osu.Game.Tests.Visual;
namespace osu.Game.Rulesets.Osu.Tests
{
2018-03-02 14:34:31 +08:00
[TestFixture]
2017-12-27 19:01:20 +08:00
public class TestCaseSpinner : OsuTestCase
{
2017-12-30 00:44:38 +08:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
2018-01-03 00:04:00 +08:00
typeof(SpinnerDisc),
typeof(DrawableSpinner),
typeof(DrawableOsuHitObject)
2017-12-30 00:44:38 +08:00
};
2017-12-27 19:01:20 +08:00
private readonly Container content;
protected override Container<Drawable> Content => content;
private int depthIndex;
2018-01-01 18:55:24 +08:00
protected readonly List<Mod> Mods = new List<Mod>();
2017-12-27 19:01:20 +08:00
public TestCaseSpinner()
{
base.Content.Add(content = new OsuInputManager(new RulesetInfo { ID = 0 }));
2018-01-01 18:55:24 +08:00
AddStep("Miss Big", () => testSingle(2));
AddStep("Miss Medium", () => testSingle(5));
AddStep("Miss Small", () => testSingle(7));
AddStep("Hit Big", () => testSingle(2, true));
AddStep("Hit Medium", () => testSingle(5, true));
AddStep("Hit Small", () => testSingle(7, true));
2017-12-27 19:01:20 +08:00
}
2018-01-01 18:55:24 +08:00
private void testSingle(float circleSize, bool auto = false)
2017-12-27 19:01:20 +08:00
{
var spinner = new Spinner { StartTime = Time.Current + 1000, EndTime = Time.Current + 4000 };
spinner.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = circleSize });
2017-12-27 19:01:20 +08:00
2018-01-01 18:55:24 +08:00
var drawable = new TestDrawableSpinner(spinner, auto)
2017-12-27 19:01:20 +08:00
{
Anchor = Anchor.Centre,
Depth = depthIndex++
};
2018-01-01 18:55:24 +08:00
foreach (var mod in Mods.OfType<IApplicableToDrawableHitObjects>())
mod.ApplyToDrawableHitObjects(new[] { drawable });
2017-12-27 19:01:20 +08:00
Add(drawable);
}
2018-01-01 18:55:24 +08:00
private class TestDrawableSpinner : DrawableSpinner
{
private bool auto;
public TestDrawableSpinner(Spinner s, bool auto) : base(s)
{
this.auto = auto;
}
protected override void CheckForJudgements(bool userTriggered, double timeOffset)
{
if (auto && !userTriggered && Time.Current > Spinner.StartTime + Spinner.Duration / 2 && Progress < 1)
{
// force completion only once to not break human interaction
Disc.RotationAbsolute = Spinner.SpinsRequired * 360;
auto = false;
}
base.CheckForJudgements(userTriggered, timeOffset);
}
}
2017-12-27 19:01:20 +08:00
}
}