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;
|
2024-09-04 10:28:07 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2024-09-04 09:35:27 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Testing;
|
2024-09-03 05:38:54 +00:00
|
|
|
|
using osu.Game.Replays;
|
2024-09-04 10:28:07 +00:00
|
|
|
|
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!;
|
2024-09-04 10:28:07 +00:00
|
|
|
|
private ReplayAnalysisSettings settings = null!;
|
|
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
|
private OsuRulesetConfigManager config = new OsuRulesetConfigManager(null, new OsuRuleset().RulesetInfo);
|
2024-09-03 05:38:54 +00:00
|
|
|
|
|
2024-09-04 09:35:27 +00:00
|
|
|
|
[SetUpSteps]
|
|
|
|
|
public void SetUpSteps()
|
2024-09-03 05:38:54 +00:00
|
|
|
|
{
|
2024-09-04 09:35:27 +00:00
|
|
|
|
AddStep("create analysis container", () =>
|
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2024-09-04 10:50:45 +00:00
|
|
|
|
new OsuPlayfieldAdjustmentContainer
|
|
|
|
|
{
|
|
|
|
|
Child = analysisContainer = new TestReplayAnalysisOverlay(fabricateReplay()),
|
|
|
|
|
},
|
2024-09-04 10:28:07 +00:00
|
|
|
|
settings = new ReplayAnalysisSettings(config),
|
2024-09-04 09:35:27 +00:00
|
|
|
|
};
|
2024-09-04 10:50:45 +00:00
|
|
|
|
|
2024-09-05 06:15:15 +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", () =>
|
|
|
|
|
{
|
2024-09-05 06:15:15 +00:00
|
|
|
|
settings.ShowClickMarkers.Value = true;
|
|
|
|
|
settings.ShowAimMarkers.Value = true;
|
|
|
|
|
settings.ShowCursorPath.Value = true;
|
2024-09-04 09:35:27 +00:00
|
|
|
|
});
|
2024-09-03 05:38:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestHitMarkers()
|
|
|
|
|
{
|
2024-09-05 06:15:15 +00:00
|
|
|
|
AddStep("enable hit markers", () => settings.ShowClickMarkers.Value = true);
|
2024-09-05 07:45:37 +00:00
|
|
|
|
AddUntilStep("hit markers visible", () => analysisContainer.HitMarkersVisible);
|
2024-09-05 06:15:15 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2024-09-05 06:15:15 +00:00
|
|
|
|
AddStep("enable aim markers", () => settings.ShowAimMarkers.Value = true);
|
2024-09-05 07:45:37 +00:00
|
|
|
|
AddUntilStep("aim markers visible", () => analysisContainer.AimMarkersVisible);
|
2024-09-05 06:15:15 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2024-09-05 06:15:15 +00:00
|
|
|
|
AddStep("enable aim lines", () => settings.ShowCursorPath.Value = true);
|
2024-09-05 07:45:37 +00:00
|
|
|
|
AddUntilStep("aim lines visible", () => analysisContainer.AimLinesVisible);
|
2024-09-05 06:15:15 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2024-09-04 09:35:27 +00:00
|
|
|
|
private Replay fabricateReplay()
|
2024-09-03 05:38:54 +00:00
|
|
|
|
{
|
2024-09-04 09:35:27 +00:00
|
|
|
|
var frames = new List<ReplayFrame>();
|
|
|
|
|
var random = new Random();
|
|
|
|
|
int posX = 250;
|
|
|
|
|
int posY = 250;
|
2024-09-05 06:12:16 +00:00
|
|
|
|
|
|
|
|
|
var actions = new HashSet<OsuAction>();
|
2024-09-03 05:38:54 +00:00
|
|
|
|
|
2024-09-04 09:35:27 +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
|
|
|
|
|
2024-09-05 06:12:16 +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
|
|
|
|
{
|
2024-09-05 06:12:16 +00:00
|
|
|
|
actions.Remove(random.NextDouble() > 0.5 ? OsuAction.LeftButton : OsuAction.RightButton);
|
2024-09-04 09:35:27 +00:00
|
|
|
|
}
|
2024-09-03 05:38:54 +00:00
|
|
|
|
|
2024-09-04 09:35:27 +00:00
|
|
|
|
frames.Add(new OsuReplayFrame
|
|
|
|
|
{
|
|
|
|
|
Time = Time.Current + i * 15,
|
|
|
|
|
Position = new Vector2(posX, posY),
|
2024-09-05 06:12:16 +00:00
|
|
|
|
Actions = actions.ToList(),
|
2024-09-04 09:35:27 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2024-09-03 05:38:54 +00:00
|
|
|
|
|
2024-09-04 09:35:27 +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
|
2024-09-04 09:35:27 +00:00
|
|
|
|
{
|
2024-09-04 10:28:07 +00:00
|
|
|
|
public TestReplayAnalysisOverlay(Replay replay)
|
|
|
|
|
: base(replay)
|
2024-09-04 09:35:27 +00:00
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|