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

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

134 lines
4.8 KiB
C#
Raw Permalink 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.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
2024-09-03 05:38:54 +00:00
using osu.Game.Replays;
using osu.Game.Rulesets.Osu.Configuration;
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;
using osu.Game.Tests.Visual;
using osuTK;
namespace osu.Game.Rulesets.Osu.Tests
{
public partial class TestSceneOsuAnalysisContainer : OsuTestScene
{
2024-09-04 09:43:33 +00:00
private TestReplayAnalysisOverlay analysisContainer = null!;
private ReplayAnalysisSettings settings = null!;
[Cached]
private OsuRulesetConfigManager config = new OsuRulesetConfigManager(null, new OsuRuleset().RulesetInfo);
2024-09-03 05:38:54 +00:00
[SetUpSteps]
public void SetUpSteps()
2024-09-03 05:38:54 +00:00
{
AddStep("create analysis container", () =>
{
Children = new Drawable[]
{
2024-09-04 10:50:45 +00:00
new OsuPlayfieldAdjustmentContainer
{
Child = analysisContainer = new TestReplayAnalysisOverlay(fabricateReplay()),
},
settings = new ReplayAnalysisSettings(config),
};
2024-09-04 10:50:45 +00:00
settings.ShowClickMarkers.Value = false;
settings.ShowAimMarkers.Value = false;
settings.ShowCursorPath.Value = false;
2024-09-04 10:50:45 +00:00
});
}
[Test]
public void TestEverythingOn()
{
AddStep("enable everything", () =>
{
settings.ShowClickMarkers.Value = true;
settings.ShowAimMarkers.Value = true;
settings.ShowCursorPath.Value = true;
});
2024-09-03 05:38:54 +00:00
}
[Test]
public void TestHitMarkers()
{
AddStep("enable hit markers", () => settings.ShowClickMarkers.Value = true);
2024-09-05 07:45:37 +00:00
AddUntilStep("hit markers visible", () => analysisContainer.HitMarkersVisible);
AddStep("disable hit markers", () => settings.ShowClickMarkers.Value = false);
2024-09-05 07:45:37 +00:00
AddUntilStep("hit markers not visible", () => !analysisContainer.HitMarkersVisible);
2024-09-03 05:38:54 +00:00
}
[Test]
public void TestAimMarker()
{
AddStep("enable aim markers", () => settings.ShowAimMarkers.Value = true);
2024-09-05 07:45:37 +00:00
AddUntilStep("aim markers visible", () => analysisContainer.AimMarkersVisible);
AddStep("disable aim markers", () => settings.ShowAimMarkers.Value = false);
2024-09-05 07:45:37 +00:00
AddUntilStep("aim markers not visible", () => !analysisContainer.AimMarkersVisible);
2024-09-03 05:38:54 +00:00
}
[Test]
public void TestAimLines()
{
AddStep("enable aim lines", () => settings.ShowCursorPath.Value = true);
2024-09-05 07:45:37 +00:00
AddUntilStep("aim lines visible", () => analysisContainer.AimLinesVisible);
AddStep("disable aim lines", () => settings.ShowCursorPath.Value = false);
2024-09-05 07:45:37 +00:00
AddUntilStep("aim lines not visible", () => !analysisContainer.AimLinesVisible);
2024-09-03 05:38:54 +00:00
}
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;
var actions = new HashSet<OsuAction>();
2024-09-03 05:38:54 +00:00
for (int i = 0; i < 1000; i++)
2024-09-03 05:38:54 +00:00
{
2024-09-05 04:07:49 +00:00
posX = Math.Clamp(posX + random.Next(-20, 21), -100, 600);
posY = Math.Clamp(posY + random.Next(-20, 21), -100, 600);
2024-09-03 05:38:54 +00:00
if (random.NextDouble() > (actions.Count == 0 ? 0.9 : 0.95))
{
actions.Add(random.NextDouble() > 0.5 ? OsuAction.LeftButton : OsuAction.RightButton);
}
else if (random.NextDouble() > 0.7)
2024-09-03 05:38:54 +00:00
{
actions.Remove(random.NextDouble() > 0.5 ? OsuAction.LeftButton : OsuAction.RightButton);
}
2024-09-03 05:38:54 +00:00
frames.Add(new OsuReplayFrame
{
Time = Time.Current + i * 15,
Position = new Vector2(posX, posY),
Actions = actions.ToList(),
});
}
2024-09-03 05:38:54 +00:00
return new Replay { Frames = frames };
}
2024-09-03 05:38:54 +00:00
2024-09-04 09:43:33 +00:00
private partial class TestReplayAnalysisOverlay : ReplayAnalysisOverlay
{
public TestReplayAnalysisOverlay(Replay replay)
: base(replay)
{
2024-09-03 05:38:54 +00:00
}
2024-09-05 07:45:34 +00:00
public bool HitMarkersVisible => ClickMarkers?.Alpha > 0 && ClickMarkers.Entries.Any();
public bool AimMarkersVisible => FrameMarkers?.Alpha > 0 && FrameMarkers.Entries.Any();
public bool AimLinesVisible => CursorPath?.Alpha > 0 && CursorPath.Vertices.Count > 1;
2024-09-03 05:38:54 +00:00
}
}
}