2017-08-07 17:03:44 +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
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2017-08-22 15:05:12 +08:00
|
|
|
using NUnit.Framework;
|
2017-08-07 17:03:44 +08:00
|
|
|
using OpenTK;
|
|
|
|
using osu.Desktop.Tests.Beatmaps;
|
2017-08-22 15:05:12 +08:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2017-08-07 17:03:44 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-08-21 11:31:21 +08:00
|
|
|
using osu.Framework.Input;
|
2017-08-07 17:03:44 +08:00
|
|
|
using osu.Framework.Timing;
|
|
|
|
using osu.Game.Beatmaps;
|
2017-08-22 15:05:12 +08:00
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2017-08-07 17:03:44 +08:00
|
|
|
using osu.Game.Rulesets.Beatmaps;
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2017-08-22 15:05:12 +08:00
|
|
|
using osu.Game.Rulesets.Timing;
|
2017-08-07 17:03:44 +08:00
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
|
|
|
namespace osu.Desktop.Tests.Visual
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The most minimal implementation of a playfield with scrolling hit objects.
|
|
|
|
/// </summary>
|
2017-08-22 15:05:12 +08:00
|
|
|
[TestFixture]
|
2017-08-07 17:11:45 +08:00
|
|
|
public class TestCaseScrollingPlayfield : OsuTestCase
|
2017-08-07 17:03:44 +08:00
|
|
|
{
|
|
|
|
public TestCaseScrollingPlayfield()
|
|
|
|
{
|
|
|
|
Clock = new FramedClock();
|
|
|
|
|
|
|
|
var objects = new List<HitObject>();
|
|
|
|
|
|
|
|
int time = 1500;
|
|
|
|
for (int i = 0; i < 50; i++)
|
|
|
|
{
|
|
|
|
objects.Add(new TestHitObject { StartTime = time });
|
|
|
|
|
|
|
|
time += 500;
|
|
|
|
}
|
|
|
|
|
|
|
|
Beatmap b = new Beatmap
|
|
|
|
{
|
|
|
|
HitObjects = objects,
|
|
|
|
BeatmapInfo = new BeatmapInfo
|
|
|
|
{
|
|
|
|
Difficulty = new BeatmapDifficulty(),
|
|
|
|
Metadata = new BeatmapMetadata()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
WorkingBeatmap beatmap = new TestWorkingBeatmap(b);
|
|
|
|
|
2017-08-09 14:04:19 +08:00
|
|
|
TestRulesetContainer horizontalRulesetContainer;
|
|
|
|
Add(horizontalRulesetContainer = new TestRulesetContainer(Axes.X, beatmap, true));
|
2017-08-08 11:59:50 +08:00
|
|
|
|
2017-08-09 14:04:19 +08:00
|
|
|
TestRulesetContainer verticalRulesetContainer;
|
|
|
|
Add(verticalRulesetContainer = new TestRulesetContainer(Axes.Y, beatmap, true));
|
2017-08-09 13:24:29 +08:00
|
|
|
|
|
|
|
AddStep("Reverse direction", () =>
|
|
|
|
{
|
2017-08-09 14:04:19 +08:00
|
|
|
horizontalRulesetContainer.Playfield.Reversed.Toggle();
|
|
|
|
verticalRulesetContainer.Playfield.Reversed.Toggle();
|
2017-08-09 13:24:29 +08:00
|
|
|
});
|
2017-08-07 17:03:44 +08:00
|
|
|
}
|
|
|
|
|
2017-08-22 15:05:12 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSpeedAdjustmentOrdering()
|
|
|
|
{
|
|
|
|
var hitObjectContainer = new ScrollingPlayfield<TestHitObject, TestJudgement>.ScrollingHitObjectContainer(Axes.X);
|
|
|
|
|
|
|
|
var speedAdjustments = new[]
|
|
|
|
{
|
|
|
|
new SpeedAdjustmentContainer(new MultiplierControlPoint()),
|
|
|
|
new SpeedAdjustmentContainer(new MultiplierControlPoint(1000)
|
|
|
|
{
|
|
|
|
TimingPoint = new TimingControlPoint { BeatLength = 500 }
|
|
|
|
}),
|
|
|
|
new SpeedAdjustmentContainer(new MultiplierControlPoint(2000)
|
|
|
|
{
|
|
|
|
TimingPoint = new TimingControlPoint { BeatLength = 1000 },
|
|
|
|
DifficultyPoint = new DifficultyControlPoint { SpeedMultiplier = 2}
|
|
|
|
}),
|
|
|
|
new SpeedAdjustmentContainer(new MultiplierControlPoint(3000)
|
|
|
|
{
|
|
|
|
TimingPoint = new TimingControlPoint { BeatLength = 1000 },
|
|
|
|
DifficultyPoint = new DifficultyControlPoint { SpeedMultiplier = 1}
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
var hitObjects = new[]
|
|
|
|
{
|
|
|
|
new DrawableTestHitObject(Axes.X, new TestHitObject { StartTime = -1000 }),
|
|
|
|
new DrawableTestHitObject(Axes.X, new TestHitObject()),
|
|
|
|
new DrawableTestHitObject(Axes.X, new TestHitObject { StartTime = 1000 }),
|
|
|
|
new DrawableTestHitObject(Axes.X, new TestHitObject { StartTime = 2000 }),
|
|
|
|
new DrawableTestHitObject(Axes.X, new TestHitObject { StartTime = 3000 }),
|
|
|
|
new DrawableTestHitObject(Axes.X, new TestHitObject { StartTime = 4000 }),
|
|
|
|
};
|
|
|
|
|
|
|
|
hitObjects.ForEach(h => hitObjectContainer.Add(h));
|
|
|
|
speedAdjustments.ForEach(hitObjectContainer.AddSpeedAdjustment);
|
|
|
|
|
|
|
|
// The 0th index in hitObjectContainer.SpeedAdjustments is the "default" control point
|
|
|
|
// Check multiplier of the default speed adjustment
|
|
|
|
Assert.AreEqual(1, hitObjectContainer.SpeedAdjustments[0].ControlPoint.Multiplier);
|
|
|
|
Assert.AreEqual(1, speedAdjustments[0].ControlPoint.Multiplier);
|
|
|
|
Assert.AreEqual(2, speedAdjustments[1].ControlPoint.Multiplier);
|
|
|
|
Assert.AreEqual(2, speedAdjustments[2].ControlPoint.Multiplier);
|
|
|
|
Assert.AreEqual(1, speedAdjustments[3].ControlPoint.Multiplier);
|
|
|
|
|
|
|
|
// Check insertion of hit objects
|
|
|
|
Assert.IsTrue(hitObjectContainer.SpeedAdjustments[0].Contains(hitObjects[0]));
|
|
|
|
Assert.IsTrue(speedAdjustments[0].Contains(hitObjects[1]));
|
|
|
|
Assert.IsTrue(speedAdjustments[1].Contains(hitObjects[2]));
|
|
|
|
Assert.IsTrue(speedAdjustments[2].Contains(hitObjects[3]));
|
|
|
|
Assert.IsTrue(speedAdjustments[3].Contains(hitObjects[4]));
|
|
|
|
Assert.IsTrue(speedAdjustments[3].Contains(hitObjects[5]));
|
|
|
|
|
|
|
|
hitObjectContainer.RemoveSpeedAdjustment(speedAdjustments[1]);
|
|
|
|
|
|
|
|
// The hit object contained in this speed adjustment should be resorted into the previous one
|
|
|
|
|
|
|
|
Assert.IsTrue(speedAdjustments[0].Contains(hitObjects[2]));
|
|
|
|
}
|
|
|
|
|
2017-08-09 12:28:29 +08:00
|
|
|
private class TestRulesetContainer : ScrollingRulesetContainer<TestPlayfield, TestHitObject, TestJudgement>
|
2017-08-07 17:03:44 +08:00
|
|
|
{
|
2017-08-09 13:24:29 +08:00
|
|
|
private readonly Axes scrollingAxes;
|
|
|
|
|
2017-08-09 14:04:19 +08:00
|
|
|
public TestRulesetContainer(Axes scrollingAxes, WorkingBeatmap beatmap, bool isForCurrentRuleset)
|
2017-08-09 12:04:11 +08:00
|
|
|
: base(null, beatmap, isForCurrentRuleset)
|
2017-08-07 17:03:44 +08:00
|
|
|
{
|
2017-08-09 13:24:29 +08:00
|
|
|
this.scrollingAxes = scrollingAxes;
|
2017-08-07 17:03:44 +08:00
|
|
|
}
|
|
|
|
|
2017-08-08 11:59:50 +08:00
|
|
|
public new TestPlayfield Playfield => base.Playfield;
|
|
|
|
|
2017-08-07 17:03:44 +08:00
|
|
|
public override ScoreProcessor CreateScoreProcessor() => new TestScoreProcessor();
|
|
|
|
|
2017-08-21 11:31:21 +08:00
|
|
|
public override PassThroughInputManager CreateInputManager() => new PassThroughInputManager();
|
|
|
|
|
2017-08-07 17:03:44 +08:00
|
|
|
protected override BeatmapConverter<TestHitObject> CreateBeatmapConverter() => new TestBeatmapConverter();
|
|
|
|
|
2017-08-09 13:24:29 +08:00
|
|
|
protected override Playfield<TestHitObject, TestJudgement> CreatePlayfield() => new TestPlayfield(scrollingAxes);
|
2017-08-07 17:03:44 +08:00
|
|
|
|
2017-08-09 13:24:29 +08:00
|
|
|
protected override DrawableHitObject<TestHitObject, TestJudgement> GetVisualRepresentation(TestHitObject h) => new DrawableTestHitObject(scrollingAxes, h);
|
2017-08-07 17:03:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private class TestScoreProcessor : ScoreProcessor<TestHitObject, TestJudgement>
|
|
|
|
{
|
|
|
|
protected override void OnNewJudgement(TestJudgement judgement)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestBeatmapConverter : BeatmapConverter<TestHitObject>
|
|
|
|
{
|
|
|
|
protected override IEnumerable<Type> ValidConversionTypes => new[] { typeof(HitObject) };
|
|
|
|
|
|
|
|
protected override IEnumerable<TestHitObject> ConvertHitObject(HitObject original, Beatmap beatmap)
|
|
|
|
{
|
|
|
|
yield return original as TestHitObject;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class DrawableTestHitObject : DrawableScrollingHitObject<TestHitObject, TestJudgement>
|
|
|
|
{
|
2017-08-09 13:24:29 +08:00
|
|
|
public DrawableTestHitObject(Axes scrollingAxes, TestHitObject hitObject)
|
2017-08-07 17:03:44 +08:00
|
|
|
: base(hitObject)
|
|
|
|
{
|
2017-08-09 13:51:00 +08:00
|
|
|
Anchor = scrollingAxes == Axes.Y ? Anchor.TopCentre : Anchor.CentreLeft;
|
2017-08-07 17:03:44 +08:00
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
Add(new Circle
|
|
|
|
{
|
|
|
|
Size = new Vector2(50)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override TestJudgement CreateJudgement() => new TestJudgement();
|
|
|
|
|
|
|
|
protected override void UpdateState(ArmedState state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestPlayfield : ScrollingPlayfield<TestHitObject, TestJudgement>
|
|
|
|
{
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
private readonly Container<Drawable> content;
|
|
|
|
|
2017-08-09 13:24:29 +08:00
|
|
|
public TestPlayfield(Axes scrollingAxes)
|
|
|
|
: base(scrollingAxes)
|
2017-08-07 17:03:44 +08:00
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0.2f
|
|
|
|
},
|
|
|
|
content = new Container { RelativeSizeAxes = Axes.Both }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class TestHitObject : HitObject
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TestJudgement : Judgement
|
|
|
|
{
|
|
|
|
public override string ResultString { get { throw new NotImplementedException(); } }
|
|
|
|
public override string MaxResultString { get { throw new NotImplementedException(); } }
|
|
|
|
}
|
|
|
|
}
|
2017-08-22 15:05:12 +08:00
|
|
|
}
|