1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 18:47:27 +08:00
osu-lazer/osu.Game/Beatmaps/BeatmapProcessor.cs

70 lines
2.3 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 17:19:50 +08:00
using System.Linq;
2018-09-18 11:54:07 +08:00
using osu.Game.Rulesets.Objects;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Beatmaps
{
/// <summary>
/// Provides functionality to alter a <see cref="IBeatmap"/> after it has been converted.
2018-04-13 17:19:50 +08:00
/// </summary>
public class BeatmapProcessor : IBeatmapProcessor
2018-04-13 17:19:50 +08:00
{
public IBeatmap Beatmap { get; }
public BeatmapProcessor(IBeatmap beatmap)
{
Beatmap = beatmap;
}
public virtual void PreProcess()
2018-04-13 17:19:50 +08:00
{
IHasComboInformation lastObj = null;
foreach (var obj in Beatmap.HitObjects.OfType<IHasComboInformation>())
2018-04-13 17:19:50 +08:00
{
if (obj.NewCombo)
{
obj.IndexInCurrentCombo = 0;
obj.ComboIndex = (lastObj?.ComboIndex ?? 0) + obj.ComboOffset + 1;
2018-04-13 17:19:50 +08:00
if (lastObj != null)
lastObj.LastInCombo = true;
}
else if (lastObj != null)
{
obj.IndexInCurrentCombo = lastObj.IndexInCurrentCombo + 1;
obj.ComboIndex = lastObj.ComboIndex;
}
lastObj = obj;
}
}
public virtual void PostProcess()
{
2018-09-18 11:54:07 +08:00
void updateNestedCombo(HitObject obj, int comboIndex, int indexInCurrentCombo)
{
2018-09-18 11:54:07 +08:00
if (obj is IHasComboInformation objectComboInfo)
{
objectComboInfo.ComboIndex = comboIndex;
objectComboInfo.IndexInCurrentCombo = indexInCurrentCombo;
2018-09-18 11:54:07 +08:00
foreach (var nestedObject in obj.NestedHitObjects)
updateNestedCombo(nestedObject, comboIndex, indexInCurrentCombo);
}
}
2018-09-18 11:54:07 +08:00
foreach (var hitObject in Beatmap.HitObjects)
2018-09-18 11:54:07 +08:00
{
if (hitObject is IHasComboInformation objectComboInfo)
{
foreach (var nested in hitObject.NestedHitObjects)
2018-09-15 01:52:32 +08:00
updateNestedCombo(nested, objectComboInfo.ComboIndex, objectComboInfo.IndexInCurrentCombo);
}
2018-09-18 11:54:07 +08:00
}
}
2018-04-13 17:19:50 +08:00
}
}