osu/osu.Game.Rulesets.Taiko/Replays/TaikoAutoGenerator.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

129 lines
4.6 KiB
C#
Raw Normal View History

// 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 09:19:50 +00:00
2017-03-29 07:20:54 +00:00
using System;
using System.Linq;
2022-07-02 11:48:32 +00:00
using osu.Framework.Extensions.ObjectExtensions;
2017-03-31 07:20:31 +00:00
using osu.Game.Beatmaps;
2017-04-18 07:05:58 +00:00
using osu.Game.Rulesets.Taiko.Objects;
using osu.Game.Rulesets.Replays;
2019-03-07 09:30:31 +00:00
using osu.Game.Rulesets.Taiko.Beatmaps;
2019-08-19 14:18:25 +00:00
using osu.Game.Rulesets.Objects;
2018-04-13 09:19:50 +00:00
2017-04-18 07:05:58 +00:00
namespace osu.Game.Rulesets.Taiko.Replays
2017-03-24 05:24:10 +00:00
{
public class TaikoAutoGenerator : AutoGenerator<TaikoReplayFrame>
2017-03-24 05:24:10 +00:00
{
2019-03-07 09:30:31 +00:00
public new TaikoBeatmap Beatmap => (TaikoBeatmap)base.Beatmap;
2017-04-26 07:28:53 +00:00
private const double swell_hit_speed = 50;
2018-04-13 09:19:50 +00:00
2019-03-07 09:30:31 +00:00
public TaikoAutoGenerator(IBeatmap beatmap)
: base(beatmap)
2017-03-24 05:24:10 +00:00
{
}
2018-04-13 09:19:50 +00:00
protected override void GenerateFrames()
2017-03-24 05:24:10 +00:00
{
if (Beatmap.HitObjects.Count == 0)
return;
2017-03-24 05:24:10 +00:00
bool hitButton = true;
2018-04-13 09:19:50 +00:00
Frames.Add(new TaikoReplayFrame(Beatmap.HitObjects[0].StartTime - 1000));
2018-04-13 09:19:50 +00:00
for (int i = 0; i < Beatmap.HitObjects.Count; i++)
2017-03-24 05:24:10 +00:00
{
TaikoHitObject h = Beatmap.HitObjects[i];
2019-12-14 10:02:56 +00:00
double endTime = h.GetEndTime();
2018-04-13 09:19:50 +00:00
2019-11-12 10:16:51 +00:00
switch (h)
2017-03-24 05:24:10 +00:00
{
2019-11-12 10:16:51 +00:00
case Swell swell:
2017-03-24 05:24:10 +00:00
{
2019-11-12 10:16:51 +00:00
int d = 0;
int count = 0;
int req = swell.RequiredHits;
double hitRate = Math.Min(swell_hit_speed, swell.Duration / req);
2018-04-13 09:19:50 +00:00
2019-11-12 10:16:51 +00:00
for (double j = h.StartTime; j < endTime; j += hitRate)
2017-03-24 05:24:10 +00:00
{
2019-11-12 10:16:51 +00:00
TaikoAction action;
switch (d)
{
default:
case 0:
action = TaikoAction.LeftCentre;
break;
case 1:
action = TaikoAction.LeftRim;
break;
case 2:
action = TaikoAction.RightCentre;
break;
case 3:
action = TaikoAction.RightRim;
break;
}
Frames.Add(new TaikoReplayFrame(j, action));
d = (d + 1) % 4;
if (++count == req)
2017-03-24 05:24:10 +00:00
break;
}
2018-04-13 09:19:50 +00:00
2019-11-12 10:16:51 +00:00
break;
2017-03-24 05:24:10 +00:00
}
2018-04-13 09:19:50 +00:00
2019-11-12 10:16:51 +00:00
case DrumRoll drumRoll:
2017-03-24 05:24:10 +00:00
{
2019-11-12 10:16:51 +00:00
foreach (var tick in drumRoll.NestedHitObjects.OfType<DrumRollTick>())
{
Frames.Add(new TaikoReplayFrame(tick.StartTime, hitButton ? TaikoAction.LeftCentre : TaikoAction.RightCentre));
hitButton = !hitButton;
}
break;
2017-03-24 05:24:10 +00:00
}
2019-11-12 10:16:51 +00:00
case Hit hit:
2017-03-24 05:24:10 +00:00
{
2019-11-12 10:16:51 +00:00
TaikoAction[] actions;
if (hit.Type == HitType.Centre)
2019-11-12 10:16:51 +00:00
{
actions = hit.IsStrong
2019-11-12 10:16:51 +00:00
? new[] { TaikoAction.LeftCentre, TaikoAction.RightCentre }
: new[] { hitButton ? TaikoAction.LeftCentre : TaikoAction.RightCentre };
}
else
{
actions = hit.IsStrong
2019-11-12 10:16:51 +00:00
? new[] { TaikoAction.LeftRim, TaikoAction.RightRim }
: new[] { hitButton ? TaikoAction.LeftRim : TaikoAction.RightRim };
}
Frames.Add(new TaikoReplayFrame(h.StartTime, actions));
break;
2017-03-24 05:24:10 +00:00
}
2018-04-13 09:19:50 +00:00
2019-11-12 10:16:51 +00:00
default:
throw new InvalidOperationException("Unknown hit object type.");
2017-03-24 05:24:10 +00:00
}
2018-04-13 09:19:50 +00:00
2019-08-19 18:45:23 +00:00
var nextHitObject = GetNextObject(i); // Get the next object that requires pressing the same button
bool canDelayKeyUp = nextHitObject == null || nextHitObject.StartTime > endTime + KEY_UP_DELAY;
2022-07-02 11:48:32 +00:00
double calculatedDelay = canDelayKeyUp ? KEY_UP_DELAY : (nextHitObject.AsNonNull().StartTime - endTime) * 0.9;
2019-08-19 14:18:25 +00:00
Frames.Add(new TaikoReplayFrame(endTime + calculatedDelay));
2017-03-24 05:24:10 +00:00
hitButton = !hitButton;
}
}
}
}