2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-09-12 14:52:18 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
using System.Collections.Generic;
|
2017-09-12 14:52:18 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
|
using osu.Game.Rulesets.Replays;
|
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mania.Replays
|
|
|
|
|
{
|
|
|
|
|
internal class ManiaAutoGenerator : AutoGenerator<ManiaHitObject>
|
|
|
|
|
{
|
2017-11-28 14:17:02 +08:00
|
|
|
|
public const double RELEASE_DELAY = 20;
|
2017-09-12 15:09:28 +08:00
|
|
|
|
|
2017-11-28 18:07:00 +08:00
|
|
|
|
public ManiaAutoGenerator(Beatmap<ManiaHitObject> beatmap)
|
2017-09-12 14:52:18 +08:00
|
|
|
|
: base(beatmap)
|
|
|
|
|
{
|
|
|
|
|
Replay = new Replay { User = new User { Username = @"Autoplay" } };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Replay Replay;
|
|
|
|
|
|
|
|
|
|
public override Replay Generate()
|
|
|
|
|
{
|
2017-09-12 15:10:31 +08:00
|
|
|
|
// Todo: Realistically this shouldn't be needed, but the first frame is skipped with the way replays are currently handled
|
2017-11-29 14:47:10 +08:00
|
|
|
|
Replay.Frames.Add(new ManiaReplayFrame(-100000, 0));
|
2017-09-12 15:10:31 +08:00
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
var pointGroups = generateActionPoints().GroupBy(a => a.Time).OrderBy(g => g.First().Time);
|
2017-09-12 14:52:18 +08:00
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
int activeColumns = 0;
|
|
|
|
|
foreach (var group in pointGroups)
|
2017-09-12 14:52:18 +08:00
|
|
|
|
{
|
2017-11-28 14:17:02 +08:00
|
|
|
|
foreach (var point in group)
|
2017-09-12 14:52:18 +08:00
|
|
|
|
{
|
2017-11-28 14:17:02 +08:00
|
|
|
|
if (point is HitPoint)
|
|
|
|
|
activeColumns |= 1 << point.Column;
|
|
|
|
|
if (point is ReleasePoint)
|
|
|
|
|
activeColumns ^= 1 << point.Column;
|
2017-09-12 14:52:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 17:42:54 +08:00
|
|
|
|
Replay.Frames.Add(new ManiaReplayFrame(group.First().Time, activeColumns));
|
2017-09-12 14:52:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Replay;
|
|
|
|
|
}
|
2017-09-12 15:10:31 +08:00
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
private IEnumerable<IActionPoint> generateActionPoints()
|
2017-09-12 15:10:31 +08:00
|
|
|
|
{
|
2017-11-28 14:17:02 +08:00
|
|
|
|
foreach (var obj in Beatmap.HitObjects)
|
2017-09-12 15:10:31 +08:00
|
|
|
|
{
|
2017-11-28 14:17:02 +08:00
|
|
|
|
yield return new HitPoint { Time = obj.StartTime, Column = obj.Column };
|
|
|
|
|
yield return new ReleasePoint { Time = ((obj as IHasEndTime)?.EndTime ?? obj.StartTime) + RELEASE_DELAY, Column = obj.Column };
|
2017-09-12 15:10:31 +08:00
|
|
|
|
}
|
2017-11-28 14:17:02 +08:00
|
|
|
|
}
|
2017-09-12 15:10:31 +08:00
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
private interface IActionPoint
|
|
|
|
|
{
|
|
|
|
|
double Time { get; set; }
|
|
|
|
|
int Column { get; set; }
|
2017-09-12 15:10:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
private struct HitPoint : IActionPoint
|
2017-09-12 15:10:31 +08:00
|
|
|
|
{
|
2017-11-28 14:17:02 +08:00
|
|
|
|
public double Time { get; set; }
|
|
|
|
|
public int Column { get; set; }
|
|
|
|
|
}
|
2017-09-12 15:10:31 +08:00
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
private struct ReleasePoint : IActionPoint
|
|
|
|
|
{
|
|
|
|
|
public double Time { get; set; }
|
|
|
|
|
public int Column { get; set; }
|
2017-09-12 15:10:31 +08:00
|
|
|
|
}
|
2017-09-12 14:52:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|