osu/osu.Game.Rulesets.Osu.Tests/TestSceneOsuAnalysisContain...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
4.1 KiB
C#
Raw Normal View History

2024-09-03 05:38:54 +00:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Testing;
2024-09-03 05:38:54 +00:00
using osu.Game.Replays;
2024-09-04 07:38:13 +00:00
using osu.Game.Rulesets.Osu.Beatmaps;
2024-09-03 05:38:54 +00:00
using osu.Game.Rulesets.Osu.Replays;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Replays;
2024-09-04 07:38:13 +00:00
using osu.Game.Rulesets.UI;
2024-09-03 05:38:54 +00:00
using osu.Game.Tests.Visual;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests
{
public partial class TestSceneOsuAnalysisContainer : OsuTestScene
{
private TestOsuAnalysisContainer analysisContainer = null!;
2024-09-03 05:38:54 +00:00
[SetUpSteps]
public void SetUpSteps()
2024-09-03 05:38:54 +00:00
{
AddStep("create analysis container", () =>
{
DrawableOsuRuleset drawableRuleset = new DrawableOsuRuleset(new OsuRuleset(), new OsuBeatmap());
Children = new Drawable[]
{
drawableRuleset,
analysisContainer = new TestOsuAnalysisContainer(fabricateReplay(), drawableRuleset),
};
});
2024-09-03 05:38:54 +00:00
}
[Test]
public void TestHitMarkers()
{
AddStep("enable hit markers", () => analysisContainer.Settings.HitMarkersEnabled.Value = true);
2024-09-03 05:38:54 +00:00
AddAssert("hit markers visible", () => analysisContainer.HitMarkersVisible);
AddStep("disable hit markers", () => analysisContainer.Settings.HitMarkersEnabled.Value = false);
2024-09-03 05:38:54 +00:00
AddAssert("hit markers not visible", () => !analysisContainer.HitMarkersVisible);
}
[Test]
public void TestAimMarker()
{
AddStep("enable aim markers", () => analysisContainer.Settings.AimMarkersEnabled.Value = true);
2024-09-03 05:38:54 +00:00
AddAssert("aim markers visible", () => analysisContainer.AimMarkersVisible);
AddStep("disable aim markers", () => analysisContainer.Settings.AimMarkersEnabled.Value = false);
2024-09-03 05:38:54 +00:00
AddAssert("aim markers not visible", () => !analysisContainer.AimMarkersVisible);
}
[Test]
public void TestAimLines()
{
AddStep("enable aim lines", () => analysisContainer.Settings.AimLinesEnabled.Value = true);
2024-09-03 05:38:54 +00:00
AddAssert("aim lines visible", () => analysisContainer.AimLinesVisible);
AddStep("disable aim lines", () => analysisContainer.Settings.AimLinesEnabled.Value = false);
2024-09-03 05:38:54 +00:00
AddAssert("aim lines not visible", () => !analysisContainer.AimLinesVisible);
}
private Replay fabricateReplay()
2024-09-03 05:38:54 +00:00
{
var frames = new List<ReplayFrame>();
var random = new Random();
int posX = 250;
int posY = 250;
bool leftOrRight = false;
2024-09-03 05:38:54 +00:00
for (int i = 0; i < 1000; i++)
2024-09-03 05:38:54 +00:00
{
posX = Math.Clamp(posX + random.Next(-10, 11), 0, 500);
posY = Math.Clamp(posY + random.Next(-10, 11), 0, 500);
2024-09-03 05:38:54 +00:00
var actions = new List<OsuAction>();
2024-09-03 05:38:54 +00:00
if (i % 20 == 0)
2024-09-03 05:38:54 +00:00
{
actions.Add(leftOrRight ? OsuAction.LeftButton : OsuAction.RightButton);
leftOrRight = !leftOrRight;
}
2024-09-03 05:38:54 +00:00
frames.Add(new OsuReplayFrame
{
Time = Time.Current + i * 15,
Position = new Vector2(posX, posY),
Actions = actions
});
}
2024-09-03 05:38:54 +00:00
return new Replay { Frames = frames };
}
2024-09-03 05:38:54 +00:00
private partial class TestOsuAnalysisContainer : OsuAnalysisContainer
{
public TestOsuAnalysisContainer(Replay replay, DrawableRuleset drawableRuleset)
: base(replay, drawableRuleset)
{
2024-09-03 05:38:54 +00:00
}
public bool HitMarkersVisible => HitMarkers.Alpha > 0 && HitMarkers.Entries.Any();
public bool AimMarkersVisible => AimMarkers.Alpha > 0 && AimMarkers.Entries.Any();
public bool AimLinesVisible => AimLines.Alpha > 0 && AimLines.Vertices.Count > 1;
}
}
}