1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-19 17:52:58 +08:00
osu-lazer/osu.Game.Rulesets.Catch/Beatmaps/CatchBeatmapProcessor.cs

73 lines
2.6 KiB
C#
Raw Normal View History

2018-01-05 19:21:19 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-09-18 11:48:33 +08:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
2017-11-28 20:22:57 +08:00
using System.Collections.Generic;
using System.Linq;
2017-09-18 11:48:33 +08:00
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Rulesets.Catch.UI;
using osu.Game.Rulesets.Objects.Types;
using OpenTK;
namespace osu.Game.Rulesets.Catch.Beatmaps
{
public class CatchBeatmapProcessor : BeatmapProcessor<CatchHitObject>
{
public override void PostProcess(Beatmap<CatchHitObject> beatmap)
{
initialiseHyperDash(beatmap.HitObjects);
2017-11-28 20:22:57 +08:00
base.PostProcess(beatmap);
int index = 0;
foreach (var obj in beatmap.HitObjects)
obj.IndexInBeatmap = index++;
}
2017-11-28 20:22:57 +08:00
private void initialiseHyperDash(List<CatchHitObject> objects)
2017-11-28 20:22:57 +08:00
{
// todo: add difficulty adjust.
double halfCatcherWidth = CatcherArea.CATCHER_SIZE * (objects.FirstOrDefault()?.Scale ?? 1) / CatchPlayfield.BASE_WIDTH / 2;
2017-11-28 20:22:57 +08:00
int lastDirection = 0;
double lastExcess = halfCatcherWidth;
int objCount = objects.Count;
for (int i = 0; i < objCount - 1; i++)
{
CatchHitObject currentObject = objects[i];
// not needed?
// if (currentObject is TinyDroplet) continue;
CatchHitObject nextObject = objects[i + 1];
// while (nextObject is TinyDroplet)
// {
// if (++i == objCount - 1) break;
// nextObject = objects[i + 1];
// }
int thisDirection = nextObject.X > currentObject.X ? 1 : -1;
double timeToNext = nextObject.StartTime - ((currentObject as IHasEndTime)?.EndTime ?? currentObject.StartTime) - 4;
double distanceToNext = Math.Abs(nextObject.X - currentObject.X) - (lastDirection == thisDirection ? lastExcess : halfCatcherWidth);
if (timeToNext * CatcherArea.Catcher.BASE_SPEED < distanceToNext)
{
currentObject.HyperDashTarget = nextObject;
lastExcess = halfCatcherWidth;
}
else
{
//currentObject.DistanceToHyperDash = timeToNext - distanceToNext;
lastExcess = MathHelper.Clamp(timeToNext - distanceToNext, 0, halfCatcherWidth);
}
lastDirection = thisDirection;
}
2017-11-28 20:22:57 +08:00
}
}
}