2021-11-11 06:11:25 +08: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.
|
|
|
|
|
2024-01-10 15:19:38 +08:00
|
|
|
using System.Collections.Generic;
|
2022-11-17 11:32:35 +08:00
|
|
|
using System.Linq;
|
2021-11-11 22:45:10 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-11-11 22:25:58 +08:00
|
|
|
using osu.Framework.Screens;
|
2021-11-12 19:50:38 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2021-11-11 22:45:10 +08:00
|
|
|
using osu.Game.Overlays;
|
2024-05-29 22:28:37 +08:00
|
|
|
using osu.Game.Rulesets.Judgements;
|
2024-01-10 15:19:38 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-11-11 06:11:25 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2023-02-13 05:04:12 +08:00
|
|
|
using osu.Game.Users;
|
2021-11-11 06:11:25 +08:00
|
|
|
|
2021-11-12 19:07:38 +08:00
|
|
|
namespace osu.Game.Screens.Edit.GameplayTest
|
2021-11-11 06:11:25 +08:00
|
|
|
{
|
2022-11-17 06:32:54 +08:00
|
|
|
public partial class EditorPlayer : Player
|
2021-11-11 06:11:25 +08:00
|
|
|
{
|
2021-11-12 20:12:25 +08:00
|
|
|
private readonly Editor editor;
|
2021-11-12 19:50:38 +08:00
|
|
|
private readonly EditorState editorState;
|
|
|
|
|
2024-03-01 20:28:52 +08:00
|
|
|
protected override UserActivity InitialActivity => new UserActivity.TestingBeatmap(Beatmap.Value.BeatmapInfo);
|
2023-02-13 05:04:12 +08:00
|
|
|
|
2021-11-12 19:50:38 +08:00
|
|
|
[Resolved]
|
2022-11-16 16:54:49 +08:00
|
|
|
private MusicController musicController { get; set; } = null!;
|
|
|
|
|
2024-05-29 20:32:52 +08:00
|
|
|
public EditorPlayer(Editor editor)
|
2021-11-11 06:11:25 +08:00
|
|
|
: base(new PlayerConfiguration { ShowResults = false })
|
|
|
|
{
|
2021-11-12 20:12:25 +08:00
|
|
|
this.editor = editor;
|
|
|
|
editorState = editor.GetState();
|
2021-11-11 06:11:25 +08:00
|
|
|
}
|
|
|
|
|
2021-11-12 19:50:38 +08:00
|
|
|
protected override GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart)
|
2022-08-22 13:11:06 +08:00
|
|
|
{
|
|
|
|
var masterGameplayClockContainer = new MasterGameplayClockContainer(beatmap, gameplayStart);
|
2022-11-17 11:32:35 +08:00
|
|
|
|
|
|
|
// Only reset the time to the current point if the editor is later than the normal start time (and the first object).
|
|
|
|
// This allows more sane test playing from the start of the beatmap (ie. correctly adding lead-in time).
|
|
|
|
if (editorState.Time > gameplayStart && editorState.Time > DrawableRuleset.Objects.FirstOrDefault()?.StartTime)
|
|
|
|
masterGameplayClockContainer.Reset(editorState.Time);
|
|
|
|
|
2022-08-22 13:11:06 +08:00
|
|
|
return masterGameplayClockContainer;
|
|
|
|
}
|
2021-11-11 22:45:10 +08:00
|
|
|
|
2021-11-11 22:25:58 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2024-01-10 15:19:38 +08:00
|
|
|
|
2024-05-29 20:32:52 +08:00
|
|
|
markPreviousObjectsHit();
|
2024-06-28 15:37:10 +08:00
|
|
|
markVisibleDrawableObjectsHit();
|
2024-01-10 15:19:38 +08:00
|
|
|
|
2021-11-11 22:25:58 +08:00
|
|
|
ScoreProcessor.HasCompleted.BindValueChanged(completed =>
|
|
|
|
{
|
|
|
|
if (completed.NewValue)
|
2022-07-13 23:58:32 +08:00
|
|
|
{
|
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
if (this.IsCurrentScreen())
|
|
|
|
this.Exit();
|
|
|
|
}, RESULTS_DISPLAY_DELAY);
|
|
|
|
}
|
2021-11-11 22:25:58 +08:00
|
|
|
});
|
2024-05-29 20:32:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void markPreviousObjectsHit()
|
|
|
|
{
|
2024-05-29 21:57:17 +08:00
|
|
|
foreach (var hitObject in enumerateHitObjects(DrawableRuleset.Objects, editorState.Time))
|
2024-05-29 20:32:52 +08:00
|
|
|
{
|
2024-05-29 21:57:17 +08:00
|
|
|
var judgement = hitObject.Judgement;
|
2024-06-28 15:37:10 +08:00
|
|
|
var result = new JudgementResult(hitObject, judgement) { Type = judgement.MaxResult };
|
2024-05-29 20:32:52 +08:00
|
|
|
|
2024-06-28 15:37:10 +08:00
|
|
|
HealthProcessor.ApplyResult(result);
|
|
|
|
ScoreProcessor.ApplyResult(result);
|
2024-05-29 20:32:52 +08:00
|
|
|
}
|
|
|
|
|
2024-05-29 21:57:17 +08:00
|
|
|
static IEnumerable<HitObject> enumerateHitObjects(IEnumerable<HitObject> hitObjects, double cutoffTime)
|
2024-01-10 15:19:38 +08:00
|
|
|
{
|
2024-05-29 22:30:47 +08:00
|
|
|
foreach (var hitObject in hitObjects)
|
2024-01-10 15:19:38 +08:00
|
|
|
{
|
2024-05-29 21:57:17 +08:00
|
|
|
foreach (var nested in enumerateHitObjects(hitObject.NestedHitObjects, cutoffTime))
|
2024-05-29 22:30:47 +08:00
|
|
|
{
|
|
|
|
if (nested.GetEndTime() < cutoffTime)
|
|
|
|
yield return nested;
|
|
|
|
}
|
2024-01-10 15:19:38 +08:00
|
|
|
|
2024-05-29 22:30:47 +08:00
|
|
|
if (hitObject.GetEndTime() < cutoffTime)
|
|
|
|
yield return hitObject;
|
2024-01-10 15:19:38 +08:00
|
|
|
}
|
|
|
|
}
|
2021-11-11 22:25:58 +08:00
|
|
|
}
|
|
|
|
|
2024-06-28 15:37:10 +08:00
|
|
|
private void markVisibleDrawableObjectsHit()
|
|
|
|
{
|
|
|
|
if (!DrawableRuleset.Playfield.IsLoaded)
|
|
|
|
{
|
|
|
|
Schedule(markVisibleDrawableObjectsHit);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var drawableObjectEntry in enumerateDrawableEntries(
|
|
|
|
DrawableRuleset.Playfield.AllHitObjects
|
|
|
|
.Select(ho => ho.Entry)
|
|
|
|
.Where(e => e != null)
|
|
|
|
.Cast<HitObjectLifetimeEntry>(), editorState.Time))
|
|
|
|
{
|
|
|
|
drawableObjectEntry.Result = new JudgementResult(drawableObjectEntry.HitObject, drawableObjectEntry.HitObject.Judgement)
|
2024-06-28 15:45:45 +08:00
|
|
|
{
|
|
|
|
Type = drawableObjectEntry.HitObject.Judgement.MaxResult
|
|
|
|
};
|
2024-06-28 15:37:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static IEnumerable<HitObjectLifetimeEntry> enumerateDrawableEntries(IEnumerable<HitObjectLifetimeEntry> entries, double cutoffTime)
|
|
|
|
{
|
|
|
|
foreach (var entry in entries)
|
|
|
|
{
|
|
|
|
foreach (var nested in enumerateDrawableEntries(entry.NestedEntries, cutoffTime))
|
|
|
|
{
|
|
|
|
if (nested.HitObject.GetEndTime() < cutoffTime)
|
|
|
|
yield return nested;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entry.HitObject.GetEndTime() < cutoffTime)
|
|
|
|
yield return entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-11 06:11:25 +08:00
|
|
|
protected override void PrepareReplay()
|
|
|
|
{
|
|
|
|
// don't record replays.
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool CheckModsAllowFailure() => false; // never fail.
|
2021-11-11 22:45:10 +08:00
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
public override void OnEntering(ScreenTransitionEvent e)
|
2021-11-12 20:51:02 +08:00
|
|
|
{
|
2022-04-21 23:52:44 +08:00
|
|
|
base.OnEntering(e);
|
2021-11-12 20:51:02 +08:00
|
|
|
|
|
|
|
// finish alpha transforms on entering to avoid gameplay starting in a half-hidden state.
|
|
|
|
// the finish calls are purposefully not propagated to children to avoid messing up their state.
|
|
|
|
FinishTransforms();
|
|
|
|
GameplayClockContainer.FinishTransforms(false, nameof(Alpha));
|
|
|
|
}
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2021-11-11 22:45:10 +08:00
|
|
|
{
|
|
|
|
musicController.Stop();
|
2021-11-12 20:12:25 +08:00
|
|
|
|
|
|
|
editor.RestoreState(editorState);
|
2022-04-21 23:52:44 +08:00
|
|
|
return base.OnExiting(e);
|
2021-11-11 22:45:10 +08:00
|
|
|
}
|
2021-11-11 06:11:25 +08:00
|
|
|
}
|
|
|
|
}
|