2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
using System.Collections.Generic;
|
2017-09-12 14:52:18 +08:00
|
|
|
|
using System.Linq;
|
2022-07-02 19:48:32 +08:00
|
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2018-02-28 15:34:47 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
2021-03-23 05:38:51 +08:00
|
|
|
|
using osu.Game.Rulesets.Mania.Objects;
|
2019-08-19 22:18:25 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2017-09-12 14:52:18 +08:00
|
|
|
|
using osu.Game.Rulesets.Replays;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-12 14:52:18 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Mania.Replays
|
|
|
|
|
{
|
2021-05-06 23:31:12 +08:00
|
|
|
|
internal class ManiaAutoGenerator : AutoGenerator<ManiaReplayFrame>
|
2017-09-12 14:52:18 +08:00
|
|
|
|
{
|
2017-11-28 14:17:02 +08:00
|
|
|
|
public const double RELEASE_DELAY = 20;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-02-28 15:34:47 +08:00
|
|
|
|
public new ManiaBeatmap Beatmap => (ManiaBeatmap)base.Beatmap;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-02-28 15:34:47 +08:00
|
|
|
|
private readonly ManiaAction[] columnActions;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-02-28 15:34:47 +08:00
|
|
|
|
public ManiaAutoGenerator(ManiaBeatmap beatmap)
|
2017-09-12 14:52:18 +08:00
|
|
|
|
: base(beatmap)
|
|
|
|
|
{
|
2018-02-28 15:34:47 +08:00
|
|
|
|
columnActions = new ManiaAction[Beatmap.TotalColumns];
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-02-28 15:34:47 +08:00
|
|
|
|
var normalAction = ManiaAction.Key1;
|
|
|
|
|
var specialAction = ManiaAction.Special1;
|
|
|
|
|
int totalCounter = 0;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-02-28 15:34:47 +08:00
|
|
|
|
foreach (var stage in Beatmap.Stages)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < stage.Columns; i++)
|
|
|
|
|
{
|
|
|
|
|
if (stage.IsSpecialColumn(i))
|
|
|
|
|
columnActions[totalCounter] = specialAction++;
|
|
|
|
|
else
|
|
|
|
|
columnActions[totalCounter] = normalAction++;
|
|
|
|
|
totalCounter++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-12 14:52:18 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-05-06 20:53:34 +08:00
|
|
|
|
protected override void GenerateFrames()
|
2017-09-12 14:52:18 +08:00
|
|
|
|
{
|
2020-09-28 13:15:26 +08:00
|
|
|
|
if (Beatmap.HitObjects.Count == 0)
|
2021-05-06 20:53:34 +08:00
|
|
|
|
return;
|
2020-09-28 13:15:26 +08:00
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
var pointGroups = generateActionPoints().GroupBy(a => a.Time).OrderBy(g => g.First().Time);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-02-28 15:34:47 +08:00
|
|
|
|
var actions = new List<ManiaAction>();
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
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
|
|
|
|
{
|
2018-07-17 13:35:09 +08:00
|
|
|
|
switch (point)
|
|
|
|
|
{
|
2022-06-24 20:25:23 +08:00
|
|
|
|
case HitPoint:
|
2018-07-17 13:35:09 +08:00
|
|
|
|
actions.Add(columnActions[point.Column]);
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
|
case ReleasePoint:
|
2018-07-17 13:35:09 +08:00
|
|
|
|
actions.Remove(columnActions[point.Column]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-09-12 14:52:18 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-05-06 20:53:34 +08:00
|
|
|
|
Frames.Add(new ManiaReplayFrame(group.First().Time, actions.ToArray()));
|
2017-09-12 14:52:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-11-28 14:17:02 +08:00
|
|
|
|
private IEnumerable<IActionPoint> generateActionPoints()
|
2017-09-12 15:10:31 +08:00
|
|
|
|
{
|
2019-08-16 18:39:54 +08:00
|
|
|
|
for (int i = 0; i < Beatmap.HitObjects.Count; i++)
|
2017-09-12 15:10:31 +08:00
|
|
|
|
{
|
2019-08-16 18:39:54 +08:00
|
|
|
|
var currentObject = Beatmap.HitObjects[i];
|
2019-08-20 02:45:23 +08:00
|
|
|
|
var nextObjectInColumn = GetNextObject(i); // Get the next object that requires pressing the same button
|
2021-10-27 12:04:41 +08:00
|
|
|
|
double releaseTime = calculateReleaseTime(currentObject, nextObjectInColumn);
|
2019-08-16 18:39:54 +08:00
|
|
|
|
|
2021-03-23 05:38:51 +08:00
|
|
|
|
yield return new HitPoint { Time = currentObject.StartTime, Column = currentObject.Column };
|
2019-08-16 18:39:54 +08:00
|
|
|
|
|
2021-03-23 05:38:51 +08:00
|
|
|
|
yield return new ReleasePoint { Time = releaseTime, Column = currentObject.Column };
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-08-16 18:39:54 +08:00
|
|
|
|
|
2022-07-02 13:33:05 +08:00
|
|
|
|
private double calculateReleaseTime(HitObject currentObject, HitObject? nextObject)
|
2021-03-23 05:38:51 +08:00
|
|
|
|
{
|
|
|
|
|
double endTime = currentObject.GetEndTime();
|
2023-12-11 21:06:46 +08:00
|
|
|
|
double releaseDelay = RELEASE_DELAY;
|
2019-08-16 18:39:54 +08:00
|
|
|
|
|
2023-12-11 21:06:46 +08:00
|
|
|
|
if (currentObject is HoldNote hold)
|
|
|
|
|
{
|
|
|
|
|
if (hold.Duration > 0)
|
|
|
|
|
// hold note releases must be timed exactly.
|
|
|
|
|
return endTime;
|
|
|
|
|
|
|
|
|
|
// Special case for super short hold notes
|
|
|
|
|
releaseDelay = 1;
|
|
|
|
|
}
|
2019-08-16 18:39:54 +08:00
|
|
|
|
|
2021-03-23 05:38:51 +08:00
|
|
|
|
bool canDelayKeyUpFully = nextObject == null ||
|
2023-12-11 21:06:46 +08:00
|
|
|
|
nextObject.StartTime > endTime + releaseDelay;
|
2021-03-23 05:38:51 +08:00
|
|
|
|
|
2023-12-11 21:06:46 +08:00
|
|
|
|
return endTime + (canDelayKeyUpFully ? releaseDelay : (nextObject.AsNonNull().StartTime - endTime) * 0.9);
|
2019-08-19 22:18:25 +08:00
|
|
|
|
}
|
2019-08-16 18:39:54 +08:00
|
|
|
|
|
2022-07-02 13:33:05 +08:00
|
|
|
|
protected override HitObject? GetNextObject(int currentIndex)
|
2019-08-19 22:18:25 +08:00
|
|
|
|
{
|
2019-08-26 16:45:12 +08:00
|
|
|
|
int desiredColumn = Beatmap.HitObjects[currentIndex].Column;
|
2019-08-16 18:39:54 +08:00
|
|
|
|
|
2019-08-26 16:45:12 +08:00
|
|
|
|
for (int i = currentIndex + 1; i < Beatmap.HitObjects.Count; i++)
|
2019-08-19 22:18:25 +08:00
|
|
|
|
{
|
2019-08-26 16:45:12 +08:00
|
|
|
|
if (Beatmap.HitObjects[i].Column == desiredColumn)
|
|
|
|
|
return Beatmap.HitObjects[i];
|
2017-09-12 15:10:31 +08:00
|
|
|
|
}
|
2019-08-19 22:18:25 +08:00
|
|
|
|
|
|
|
|
|
return null;
|
2017-11-28 14:17:02 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +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
|
|
|
|
}
|
2018-04-13 17:19:50 +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; }
|
|
|
|
|
}
|
2018-04-13 17:19:50 +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
|
|
|
|
}
|
|
|
|
|
}
|