mirror of
https://github.com/ppy/osu
synced 2025-01-10 16:19:47 +00:00
refactor song progress test scene
This commit is contained in:
parent
1e013bd4e9
commit
6af6f03e29
@ -7,23 +7,20 @@ using System.Collections.Generic;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Shapes;
|
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Utils;
|
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
using osu.Game.Screens.Play.HUD;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Gameplay
|
namespace osu.Game.Tests.Visual.Gameplay
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneSongProgress : OsuTestScene
|
public class TestSceneSongProgress : SkinnableHUDComponentTestScene
|
||||||
{
|
{
|
||||||
private DefaultSongProgress progress;
|
private DefaultSongProgress progress;
|
||||||
private TestSongProgressGraph graph;
|
private readonly List<SongProgress> progresses = new List<SongProgress>();
|
||||||
private readonly Container progressContainer;
|
|
||||||
|
|
||||||
private readonly StopwatchClock clock;
|
private readonly StopwatchClock clock;
|
||||||
private readonly FramedClock framedClock;
|
private readonly FramedClock framedClock;
|
||||||
@ -35,77 +32,18 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
{
|
{
|
||||||
clock = new StopwatchClock();
|
clock = new StopwatchClock();
|
||||||
gameplayClock = new GameplayClock(framedClock = new FramedClock(clock));
|
gameplayClock = new GameplayClock(framedClock = new FramedClock(clock));
|
||||||
|
|
||||||
Add(progressContainer = new Container
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Anchor = Anchor.BottomCentre,
|
|
||||||
Origin = Anchor.BottomCentre,
|
|
||||||
Height = 100,
|
|
||||||
Y = -100,
|
|
||||||
Child = new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Colour = OsuColour.Gray(1),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[SetUpSteps]
|
[SetUpSteps]
|
||||||
public void SetupSteps()
|
public void SetupSteps()
|
||||||
{
|
{
|
||||||
AddStep("add new song progress", () =>
|
|
||||||
{
|
|
||||||
if (progress != null)
|
|
||||||
{
|
|
||||||
progress.Expire();
|
|
||||||
progress = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
progressContainer.Add(progress = new DefaultSongProgress
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Anchor = Anchor.BottomLeft,
|
|
||||||
Origin = Anchor.BottomLeft,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep("add new big graph", () =>
|
|
||||||
{
|
|
||||||
if (graph != null)
|
|
||||||
{
|
|
||||||
graph.Expire();
|
|
||||||
graph = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Add(graph = new TestSongProgressGraph
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
Height = 200,
|
|
||||||
Anchor = Anchor.TopLeft,
|
|
||||||
Origin = Anchor.TopLeft,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep("reset clock", clock.Reset);
|
AddStep("reset clock", clock.Reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestGraphRecreation()
|
|
||||||
{
|
|
||||||
AddAssert("ensure not created", () => graph.CreationCount == 0);
|
|
||||||
AddStep("display values", displayRandomValues);
|
|
||||||
AddUntilStep("wait for creation count", () => graph.CreationCount == 1);
|
|
||||||
AddRepeatStep("new values", displayRandomValues, 5);
|
|
||||||
AddWaitStep("wait some", 5);
|
|
||||||
AddAssert("ensure recreation debounced", () => graph.CreationCount == 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestDisplay()
|
public void TestDisplay()
|
||||||
{
|
{
|
||||||
AddStep("display max values", displayMaxValues);
|
AddStep("display max values", displayMaxValues);
|
||||||
AddUntilStep("wait for graph", () => graph.CreationCount == 1);
|
|
||||||
AddStep("start", clock.Start);
|
AddStep("start", clock.Start);
|
||||||
AddStep("allow seeking", () => progress.AllowSeeking.Value = true);
|
AddStep("allow seeking", () => progress.AllowSeeking.Value = true);
|
||||||
AddStep("hide graph", () => progress.ShowGraph.Value = false);
|
AddStep("hide graph", () => progress.ShowGraph.Value = false);
|
||||||
@ -115,15 +53,6 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
AddStep("stop", clock.Stop);
|
AddStep("stop", clock.Stop);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void displayRandomValues()
|
|
||||||
{
|
|
||||||
var objects = new List<HitObject>();
|
|
||||||
for (double i = 0; i < 5000; i += RNG.NextDouble() * 10 + i / 1000)
|
|
||||||
objects.Add(new HitObject { StartTime = i });
|
|
||||||
|
|
||||||
replaceObjects(objects);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displayMaxValues()
|
private void displayMaxValues()
|
||||||
{
|
{
|
||||||
var objects = new List<HitObject>();
|
var objects = new List<HitObject>();
|
||||||
@ -135,10 +64,12 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
private void replaceObjects(List<HitObject> objects)
|
private void replaceObjects(List<HitObject> objects)
|
||||||
{
|
{
|
||||||
progress.Objects = objects;
|
|
||||||
graph.Objects = objects;
|
|
||||||
|
|
||||||
progress.RequestSeek = pos => clock.Seek(pos);
|
progress.RequestSeek = pos => clock.Seek(pos);
|
||||||
|
|
||||||
|
foreach (var progress in progresses)
|
||||||
|
{
|
||||||
|
progress.Objects = objects;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
@ -147,15 +78,29 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
framedClock.ProcessFrame();
|
framedClock.ProcessFrame();
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestSongProgressGraph : SongProgressGraph
|
protected override Drawable CreateDefaultImplementation()
|
||||||
{
|
{
|
||||||
public int CreationCount { get; private set; }
|
progress = new DefaultSongProgress
|
||||||
|
|
||||||
protected override void RecreateGraph()
|
|
||||||
{
|
{
|
||||||
base.RecreateGraph();
|
RelativeSizeAxes = Axes.X,
|
||||||
CreationCount++;
|
Anchor = Anchor.BottomLeft,
|
||||||
}
|
Origin = Anchor.BottomLeft,
|
||||||
|
};
|
||||||
|
|
||||||
|
progresses.Add(progress);
|
||||||
|
return progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Drawable CreateLegacyImplementation()
|
||||||
|
{
|
||||||
|
var progress = new LegacySongProgress
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
};
|
||||||
|
|
||||||
|
progresses.Add(progress);
|
||||||
|
return progress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user