1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 13:22:55 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Tests/TestCaseHitCircle.cs

116 lines
4.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 16:34:07 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Objects.Drawables;
2017-12-27 16:34:07 +08:00
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Tests.Visual;
using OpenTK;
using OpenTK.Graphics;
using osu.Game.Rulesets.Osu.Judgements;
2017-12-30 00:44:38 +08:00
using System.Collections.Generic;
using System;
2018-01-01 18:55:24 +08:00
using osu.Game.Rulesets.Mods;
using System.Linq;
using osu.Game.Rulesets.Scoring;
2017-12-27 16:34:07 +08:00
namespace osu.Game.Rulesets.Osu.Tests
{
public class TestCaseHitCircle : OsuTestCase
{
2017-12-30 00:44:38 +08:00
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(DrawableHitCircle)
};
2017-12-27 16:34:07 +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 16:34:07 +08:00
public TestCaseHitCircle()
{
base.Content.Add(content = new OsuInputManager(new RulesetInfo { ID = 0 }));
2018-01-01 18:55:24 +08:00
AddStep("Miss Big Single", () => testSingle(2));
AddStep("Miss Medium Single", () => testSingle(5));
AddStep("Miss Small Single", () => testSingle(7));
AddStep("Hit Big Single", () => testSingle(2, true));
AddStep("Hit Medium Single", () => testSingle(5, true));
AddStep("Hit Small Single", () => testSingle(7, true));
AddStep("Miss Big Stream", () => testStream(2));
AddStep("Miss Medium Stream", () => testStream(5));
AddStep("Miss Small Stream", () => testStream(7));
AddStep("Hit Big Stream", () => testStream(2, true));
AddStep("Hit Medium Stream", () => testStream(5, true));
AddStep("Hit Small Stream", () => testStream(7, true));
2017-12-27 16:34:07 +08:00
}
2018-01-01 18:55:24 +08:00
private void testSingle(float circleSize, bool auto = false, double timeOffset = 0, Vector2? positionOffset = null)
2017-12-27 16:34:07 +08:00
{
positionOffset = positionOffset ?? Vector2.Zero;
var circle = new HitCircle
{
StartTime = Time.Current + 1000 + timeOffset,
Position = positionOffset.Value,
ComboColour = Color4.LightSeaGreen
};
circle.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = circleSize });
2017-12-27 16:34:07 +08:00
var drawable = new TestDrawableHitCircle(circle, auto)
{
Anchor = Anchor.Centre,
Depth = depthIndex++
};
2018-01-01 18:55:24 +08:00
foreach (var mod in Mods.OfType<IApplicableToDrawableHitObjects>())
mod.ApplyToDrawableHitObjects(new[] { drawable });
Add(drawable);
2017-12-27 16:34:07 +08:00
}
2018-01-01 18:55:24 +08:00
private void testStream(float circleSize, bool auto = false)
2017-12-27 16:34:07 +08:00
{
2018-01-01 18:55:24 +08:00
Vector2 pos = new Vector2(-250, 0);
2017-12-27 16:34:07 +08:00
for (int i = 0; i <= 1000; i += 100)
2017-12-27 16:34:07 +08:00
{
2018-01-01 18:55:24 +08:00
testSingle(circleSize, auto, i, pos);
pos.X += 50;
2017-12-27 16:34:07 +08:00
}
}
private class TestDrawableHitCircle : DrawableHitCircle
{
private readonly bool auto;
2017-12-30 14:38:10 +08:00
public TestDrawableHitCircle(HitCircle h, bool auto) : base(h)
{
this.auto = auto;
}
protected override void CheckForJudgements(bool userTriggered, double timeOffset)
{
if (auto && !userTriggered && timeOffset > 0)
{
2018-01-01 18:55:24 +08:00
// force success
AddJudgement(new OsuJudgement
{
2018-01-01 18:55:24 +08:00
Result = HitResult.Great
});
2018-01-01 18:55:24 +08:00
State.Value = ArmedState.Hit;
}
2018-01-01 18:55:24 +08:00
else
base.CheckForJudgements(userTriggered, timeOffset);
}
}
2017-12-27 16:34:07 +08:00
}
}