1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-18 02:02:54 +08:00
osu-lazer/osu.Game.Modes.Taiko/Beatmaps/TaikoBeatmapConverter.cs

83 lines
2.8 KiB
C#
Raw Normal View History

2017-03-11 23:34:21 +08:00
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Legacy;
using osu.Game.Beatmaps.Samples;
using osu.Game.Modes.Objects;
using osu.Game.Modes.Objects.Types;
2017-03-11 23:34:21 +08:00
using osu.Game.Modes.Taiko.Objects;
using System.Collections.Generic;
using System.Linq;
2017-03-11 23:34:21 +08:00
namespace osu.Game.Modes.Taiko.Beatmaps
{
2017-03-17 12:33:48 +08:00
internal class TaikoBeatmapConverter : IBeatmapConverter<TaikoHitObject>
2017-03-11 23:34:21 +08:00
{
2017-03-17 13:44:48 +08:00
private const float legacy_velocity_scale = 1.4f;
2017-03-17 18:52:24 +08:00
private const float bash_convert_factor = 1.65f;
2017-03-17 13:44:48 +08:00
2017-03-17 12:33:48 +08:00
public Beatmap<TaikoHitObject> Convert(Beatmap original)
2017-03-11 23:34:21 +08:00
{
2017-03-18 17:34:45 +08:00
if (original is LegacyBeatmap)
2017-03-17 13:44:48 +08:00
original.TimingInfo.ControlPoints.ForEach(c => c.VelocityAdjustment /= legacy_velocity_scale);
2017-03-17 12:33:48 +08:00
return new Beatmap<TaikoHitObject>(original)
2017-03-11 23:34:21 +08:00
{
HitObjects = convertHitObjects(original.HitObjects)
};
}
private List<TaikoHitObject> convertHitObjects(List<HitObject> hitObjects)
{
return hitObjects.Select(convertHitObject).ToList();
}
private TaikoHitObject convertHitObject(HitObject original)
{
// Check if this HitObject is already a TaikoHitObject, and return it if so
TaikoHitObject originalTaiko = original as TaikoHitObject;
if (originalTaiko != null)
return originalTaiko;
IHasDistance distanceData = original as IHasDistance;
IHasRepeats repeatsData = original as IHasRepeats;
IHasEndTime endTimeData = original as IHasEndTime;
2017-03-28 09:02:41 +08:00
bool strong = ((original.Sample?.Type ?? SampleType.None) & SampleType.Finish) > 0;
if (distanceData != null)
{
return new DrumRoll
{
StartTime = original.StartTime,
Sample = original.Sample,
2017-03-28 09:02:41 +08:00
IsStrong = strong,
Distance = distanceData.Distance * (repeatsData?.RepeatCount ?? 1)
};
}
if (endTimeData != null)
{
2017-03-17 18:52:24 +08:00
// We compute the end time manually to add in the Bash convert factor
2017-03-25 19:57:49 +08:00
return new Swell
{
StartTime = original.StartTime,
Sample = original.Sample,
2017-03-28 09:02:41 +08:00
IsStrong = strong,
2017-03-17 18:52:24 +08:00
EndTime = original.StartTime + endTimeData.Duration * bash_convert_factor
};
}
2017-03-23 10:25:38 +08:00
return new Hit
{
StartTime = original.StartTime,
Sample = original.Sample,
2017-03-28 09:02:41 +08:00
IsStrong = strong
2017-03-11 23:34:21 +08:00
};
}
}
}