Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix editor test play not marking hit objects before its start time as judged #26465

Merged
merged 13 commits into from
Jun 28, 2024
Merged
18 changes: 18 additions & 0 deletions osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@ public void TestGameplayTestWhenTrackRunning()
AddAssert("sample playback re-enabled", () => !Editor.SamplePlaybackDisabled.Value);
}

[Test]
public void TestGameplayTestAtEndOfBeatmap()
{
AddStep("seek to last 2 seconds", () => EditorClock.Seek(importedBeatmapSet.MaxLength - 2000));
AddStep("click test gameplay button", () =>
{
var button = Editor.ChildrenOfType<TestGameplayButton>().Single();

InputManager.MoveMouseTo(button);
InputManager.Click(MouseButton.Left);
});

AddUntilStep("player pushed", () => Stack.CurrentScreen is EditorPlayer);

AddWaitStep("wait some", 5);
AddAssert("current screen is editor", () => Stack.CurrentScreen is Editor);
}

[Test]
public void TestCancelGameplayTestWithUnsavedChanges()
{
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Edit/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public void TestGameplay()
pushEditorPlayer();
}

void pushEditorPlayer() => this.Push(new EditorPlayerLoader(this));
void pushEditorPlayer() => this.Push(new EditorPlayerLoader(this, playableBeatmap));
}

/// <summary>
Expand Down
34 changes: 33 additions & 1 deletion osu.Game/Screens/Edit/GameplayTest/EditorPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Online.Spectator;
using osu.Game.Overlays;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Users;

Expand All @@ -15,17 +21,19 @@ public partial class EditorPlayer : Player
{
private readonly Editor editor;
private readonly EditorState editorState;
private readonly IBeatmap playableBeatmap;

protected override UserActivity InitialActivity => new UserActivity.TestingBeatmap(Beatmap.Value.BeatmapInfo, Ruleset.Value);

[Resolved]
private MusicController musicController { get; set; } = null!;

public EditorPlayer(Editor editor)
public EditorPlayer(Editor editor, IBeatmap playableBeatmap)
: base(new PlayerConfiguration { ShowResults = false })
{
this.editor = editor;
editorState = editor.GetState();
this.playableBeatmap = playableBeatmap;
}

protected override GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart)
Expand All @@ -43,6 +51,19 @@ protected override GameplayClockContainer CreateGameplayClockContainer(WorkingBe
protected override void LoadComplete()
{
base.LoadComplete();

var frame = new ReplayFrame { Header = new FrameHeader(new ScoreInfo(), new ScoreProcessorStatistics()) };

foreach (var hitObject in enumerateHitObjects(playableBeatmap.HitObjects.Where(h => h.StartTime < editorState.Time)))
peppy marked this conversation as resolved.
Show resolved Hide resolved
{
var judgement = hitObject.CreateJudgement();
frame.Header.Statistics.TryAdd(judgement.MaxResult, 0);
frame.Header.Statistics[judgement.MaxResult]++;
}

HealthProcessor.ResetFromReplayFrame(frame);
ScoreProcessor.ResetFromReplayFrame(frame);

ScoreProcessor.HasCompleted.BindValueChanged(completed =>
{
if (completed.NewValue)
Expand All @@ -54,6 +75,17 @@ protected override void LoadComplete()
}, RESULTS_DISPLAY_DELAY);
}
});

static IEnumerable<HitObject> enumerateHitObjects(IEnumerable<HitObject> hitObjects)
{
foreach (var hitObject in hitObjects)
{
foreach (var nested in enumerateHitObjects(hitObject.NestedHitObjects))
yield return nested;

yield return hitObject;
}
}
}

protected override void PrepareReplay()
Expand Down
5 changes: 3 additions & 2 deletions osu.Game/Screens/Edit/GameplayTest/EditorPlayerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Screens.Menu;
using osu.Game.Screens.Play;

Expand All @@ -14,8 +15,8 @@ public partial class EditorPlayerLoader : PlayerLoader
[Resolved]
private OsuLogo osuLogo { get; set; } = null!;

public EditorPlayerLoader(Editor editor)
: base(() => new EditorPlayer(editor))
public EditorPlayerLoader(Editor editor, IBeatmap playableBeatmap)
: base(() => new EditorPlayer(editor, playableBeatmap))
{
}

Expand Down
Loading