2021-05-07 17:04:38 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-05-06 23:31:12 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using JetBrains.Annotations;
|
2017-04-29 02:08:48 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-11-28 16:20:37 +08:00
|
|
|
|
using osu.Game.Replays;
|
2019-08-19 22:18:25 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-04-29 02:08:48 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Replays
|
|
|
|
|
{
|
2021-05-06 20:43:30 +08:00
|
|
|
|
public abstract class AutoGenerator
|
2017-04-29 02:08:48 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2021-05-06 20:43:30 +08:00
|
|
|
|
/// The default duration of a key press in milliseconds.
|
2017-04-29 02:08:48 +08:00
|
|
|
|
/// </summary>
|
2021-05-06 20:43:30 +08:00
|
|
|
|
public const double KEY_UP_DELAY = 50;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-04-29 02:08:48 +08:00
|
|
|
|
/// <summary>
|
2021-05-06 20:43:30 +08:00
|
|
|
|
/// The beatmap the autoplay is generated for.
|
2017-04-29 02:08:48 +08:00
|
|
|
|
/// </summary>
|
2021-05-06 20:43:30 +08:00
|
|
|
|
protected IBeatmap Beatmap { get; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-07 17:30:31 +08:00
|
|
|
|
protected AutoGenerator(IBeatmap beatmap)
|
2017-04-29 02:08:48 +08:00
|
|
|
|
{
|
|
|
|
|
Beatmap = beatmap;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-05-06 20:43:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generate the replay of the autoplay.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract Replay Generate();
|
2019-08-19 22:18:25 +08:00
|
|
|
|
|
|
|
|
|
protected virtual HitObject GetNextObject(int currentIndex)
|
|
|
|
|
{
|
|
|
|
|
if (currentIndex >= Beatmap.HitObjects.Count - 1)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return Beatmap.HitObjects[currentIndex + 1];
|
|
|
|
|
}
|
2017-04-29 02:08:48 +08:00
|
|
|
|
}
|
2021-05-06 23:31:12 +08:00
|
|
|
|
|
|
|
|
|
public abstract class AutoGenerator<TFrame> : AutoGenerator
|
|
|
|
|
where TFrame : ReplayFrame
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The replay frames of the autoplay.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly List<TFrame> Frames = new List<TFrame>();
|
|
|
|
|
|
|
|
|
|
[CanBeNull]
|
|
|
|
|
protected TFrame LastFrame => Frames.Count == 0 ? null : Frames[^1];
|
|
|
|
|
|
|
|
|
|
protected AutoGenerator(IBeatmap beatmap)
|
|
|
|
|
: base(beatmap)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sealed override Replay Generate()
|
|
|
|
|
{
|
|
|
|
|
Frames.Clear();
|
|
|
|
|
GenerateFrames();
|
|
|
|
|
|
|
|
|
|
return new Replay
|
|
|
|
|
{
|
|
|
|
|
Frames = Frames.OrderBy(frame => frame.Time).Cast<ReplayFrame>().ToList()
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generate the replay frames of the autoplay and populate <see cref="Frames"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected abstract void GenerateFrames();
|
|
|
|
|
}
|
2017-04-29 02:08:48 +08:00
|
|
|
|
}
|