1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-24 06:47:36 +08:00
osu-lazer/osu.Desktop.VisualTests/Tests/TestCaseTaikoPlayfield.cs

221 lines
7.3 KiB
C#
Raw Normal View History

2017-03-21 14:09:54 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2017-04-10 13:28:28 +08:00
using OpenTK;
2017-03-28 10:18:12 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2017-03-21 14:54:57 +08:00
using osu.Framework.MathUtils;
2017-03-28 20:03:34 +08:00
using osu.Framework.Testing;
2017-04-05 08:57:22 +08:00
using osu.Framework.Timing;
2017-04-18 15:05:58 +08:00
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Judgements;
using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
using osu.Game.Rulesets.Taiko.UI;
2017-04-10 13:28:28 +08:00
using System;
2017-03-21 14:09:54 +08:00
namespace osu.Desktop.VisualTests.Tests
{
internal class TestCaseTaikoPlayfield : TestCase
{
2017-04-10 13:28:28 +08:00
private const double default_duration = 300;
private const float scroll_time = 1000;
2017-03-21 14:09:54 +08:00
2017-04-10 13:28:28 +08:00
public override string Description => "Taiko playfield";
2017-03-21 14:54:57 +08:00
2017-04-05 12:53:29 +08:00
protected override double TimePerAction => default_duration * 2;
2017-04-10 13:28:28 +08:00
private readonly Random rng = new Random(1337);
private TaikoPlayfield playfield;
private Container playfieldContainer;
2017-03-21 14:09:54 +08:00
public override void Reset()
{
base.Reset();
2017-03-31 16:55:07 +08:00
AddStep("Hit!", addHitJudgement);
AddStep("Miss :(", addMissJudgement);
AddStep("DrumRoll", () => addDrumRoll(false));
AddStep("Strong DrumRoll", () => addDrumRoll(true));
2017-04-05 12:53:29 +08:00
AddStep("Swell", () => addSwell());
2017-03-31 16:55:07 +08:00
AddStep("Centre", () => addCentreHit(false));
AddStep("Strong Centre", () => addCentreHit(true));
AddStep("Rim", () => addRimHit(false));
AddStep("Strong Rim", () => addRimHit(true));
2017-04-03 09:04:13 +08:00
AddStep("Add bar line", () => addBarLine(false));
AddStep("Add major bar line", () => addBarLine(true));
2017-04-10 13:28:28 +08:00
AddStep("Height test 1", () => changePlayfieldSize(1));
AddStep("Height test 2", () => changePlayfieldSize(2));
AddStep("Height test 3", () => changePlayfieldSize(3));
AddStep("Height test 4", () => changePlayfieldSize(4));
AddStep("Height test 5", () => changePlayfieldSize(5));
AddStep("Reset height", () => changePlayfieldSize(6));
2017-04-05 08:57:22 +08:00
var rateAdjustClock = new StopwatchClock(true) { Rate = 1 };
Add(playfieldContainer = new Container
2017-03-21 14:09:54 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2017-03-28 10:18:12 +08:00
RelativeSizeAxes = Axes.X,
Height = TaikoPlayfield.DEFAULT_PLAYFIELD_HEIGHT,
Clock = new FramedClock(rateAdjustClock),
2017-03-28 10:18:12 +08:00
Children = new[]
{
playfield = new TaikoPlayfield()
2017-03-28 10:18:12 +08:00
}
2017-03-21 14:09:54 +08:00
});
}
2017-03-21 14:54:57 +08:00
2017-04-10 13:28:28 +08:00
private void changePlayfieldSize(int step)
{
// Add new hits
2017-04-10 13:28:28 +08:00
switch (step)
{
case 1:
addCentreHit(false);
break;
case 2:
addCentreHit(true);
break;
case 3:
addDrumRoll(false);
break;
case 4:
addDrumRoll(true);
break;
case 5:
addSwell(1000);
playfieldContainer.Delay(scroll_time - 100);
2017-04-10 13:28:28 +08:00
break;
}
// Tween playfield height
switch (step)
{
default:
playfieldContainer.ResizeTo(new Vector2(1, rng.Next(25, 400)), 500);
break;
case 6:
playfieldContainer.ResizeTo(new Vector2(1, TaikoPlayfield.DEFAULT_PLAYFIELD_HEIGHT), 500);
break;
}
2017-04-10 13:28:28 +08:00
}
2017-03-21 14:54:57 +08:00
private void addHitJudgement()
{
2017-03-22 00:42:40 +08:00
TaikoHitResult hitResult = RNG.Next(2) == 0 ? TaikoHitResult.Good : TaikoHitResult.Great;
2017-03-21 14:54:57 +08:00
2017-04-10 04:08:05 +08:00
var h = new DrawableTestHit(new Hit())
2017-03-21 14:54:57 +08:00
{
2017-03-22 00:42:40 +08:00
X = RNG.NextSingle(hitResult == TaikoHitResult.Good ? -0.1f : -0.05f, hitResult == TaikoHitResult.Good ? 0.1f : 0.05f),
Judgement = new TaikoJudgement
2017-03-21 14:54:57 +08:00
{
Result = HitResult.Hit,
2017-03-22 00:42:40 +08:00
TaikoResult = hitResult,
2017-04-10 04:08:05 +08:00
TimeOffset = 0
2017-03-21 14:54:57 +08:00
}
2017-04-10 04:08:05 +08:00
};
playfield.OnJudgement(h);
if (RNG.Next(10) == 0)
{
h.Judgement.SecondHit = true;
playfield.OnJudgement(h);
}
2017-03-21 14:54:57 +08:00
}
private void addMissJudgement()
{
2017-03-23 15:56:42 +08:00
playfield.OnJudgement(new DrawableTestHit(new Hit())
2017-03-21 14:54:57 +08:00
{
Judgement = new TaikoJudgement
2017-03-21 14:54:57 +08:00
{
Result = HitResult.Miss,
TimeOffset = 0
2017-03-21 14:54:57 +08:00
}
});
}
2017-04-05 12:53:29 +08:00
private void addBarLine(bool major, double delay = scroll_time)
2017-03-21 20:27:20 +08:00
{
BarLine bl = new BarLine
{
2017-04-05 12:53:29 +08:00
StartTime = playfield.Time.Current + delay,
ScrollTime = scroll_time
2017-03-21 20:27:20 +08:00
};
2017-04-05 09:37:49 +08:00
playfield.AddBarLine(major ? new DrawableBarLineMajor(bl) : new DrawableBarLine(bl));
2017-03-21 20:27:20 +08:00
}
2017-04-05 12:53:29 +08:00
private void addSwell(double duration = default_duration)
2017-03-28 14:05:45 +08:00
{
playfield.Add(new DrawableSwell(new Swell
{
2017-04-05 12:53:29 +08:00
StartTime = playfield.Time.Current + scroll_time,
Duration = duration,
ScrollTime = scroll_time
2017-03-28 14:05:45 +08:00
}));
}
2017-04-05 12:53:29 +08:00
private void addDrumRoll(bool strong, double duration = default_duration)
2017-03-28 15:50:06 +08:00
{
2017-04-05 12:53:29 +08:00
addBarLine(true);
addBarLine(true, scroll_time + duration);
2017-03-28 15:50:06 +08:00
var d = new DrumRoll
{
2017-04-05 12:53:29 +08:00
StartTime = playfield.Time.Current + scroll_time,
IsStrong = strong,
2017-04-05 12:53:29 +08:00
Duration = duration,
ScrollTime = scroll_time,
2017-03-28 15:50:06 +08:00
};
playfield.Add(new DrawableDrumRoll(d));
2017-03-28 15:50:06 +08:00
}
2017-03-28 14:05:45 +08:00
2017-03-28 10:18:12 +08:00
private void addCentreHit(bool strong)
{
Hit h = new Hit
{
2017-04-05 12:53:29 +08:00
StartTime = playfield.Time.Current + scroll_time,
ScrollTime = scroll_time
2017-03-28 10:18:12 +08:00
};
if (strong)
2017-04-05 09:37:49 +08:00
playfield.Add(new DrawableCentreHitStrong(h));
2017-03-28 10:18:12 +08:00
else
playfield.Add(new DrawableCentreHit(h));
}
private void addRimHit(bool strong)
{
Hit h = new Hit
{
2017-04-05 12:53:29 +08:00
StartTime = playfield.Time.Current + scroll_time,
ScrollTime = scroll_time
2017-03-28 10:18:12 +08:00
};
if (strong)
2017-04-05 09:37:49 +08:00
playfield.Add(new DrawableRimHitStrong(h));
2017-03-28 10:18:12 +08:00
else
playfield.Add(new DrawableRimHit(h));
}
private class DrawableTestHit : DrawableHitObject<TaikoHitObject, TaikoJudgement>
2017-03-21 14:54:57 +08:00
{
public DrawableTestHit(TaikoHitObject hitObject)
: base(hitObject)
{
}
protected override TaikoJudgement CreateJudgement() => new TaikoJudgement();
2017-03-21 14:54:57 +08:00
protected override void UpdateState(ArmedState state)
{
}
}
2017-03-21 14:09:54 +08:00
}
}