1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-19 14:23:14 +08:00

Simplify linq from beatmap conversion

This commit is contained in:
smoogipoo 2018-10-11 20:29:26 +09:00
parent ec9f23ab73
commit fb1760f580

View File

@ -55,39 +55,38 @@ namespace osu.Game.Beatmaps
beatmap.BeatmapInfo = original.BeatmapInfo;
beatmap.ControlPointInfo = original.ControlPointInfo;
beatmap.HitObjects = original.HitObjects.SelectMany(h => convert(h, original)).ToList();
beatmap.HitObjects = convertHitObjects(original.HitObjects, original);
beatmap.Breaks = original.Breaks;
return beatmap;
}
/// <summary>
/// Converts a hit object.
/// </summary>
/// <param name="original">The hit object to convert.</param>
/// <param name="beatmap">The un-converted Beatmap.</param>
/// <returns>The converted hit object.</returns>
private IEnumerable<T> convert(HitObject original, IBeatmap beatmap)
private List<T> convertHitObjects(IReadOnlyList<HitObject> hitObjects, IBeatmap beatmap)
{
// Check if the hitobject is already the converted type
T tObject = original as T;
if (tObject != null)
{
yield return tObject;
yield break;
}
var result = new List<T>(hitObjects.Count);
var converted = ConvertHitObject(original, beatmap).ToList();
ObjectConverted?.Invoke(original, converted);
// Convert the hit object
foreach (var obj in converted)
// ReSharper disable once ForCanBeConvertedToForeach
foreach (var obj in hitObjects)
{
if (obj == null)
if (obj is T tObj)
{
result.Add(tObj);
continue;
}
yield return obj;
var converted = ConvertHitObject(obj, beatmap);
// Note: This will not perform .ToList() if ObjectConverted is null
ObjectConverted?.Invoke(obj, converted.ToList());
foreach (var c in converted)
{
if (c != null)
result.Add(c);
}
}
return result;
}
/// <summary>