mirror of
https://github.com/ppy/osu.git
synced 2025-02-01 02:03:19 +08:00
Simplify linq from beatmap conversion
This commit is contained in:
parent
ec9f23ab73
commit
fb1760f580
@ -55,39 +55,38 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
beatmap.BeatmapInfo = original.BeatmapInfo;
|
beatmap.BeatmapInfo = original.BeatmapInfo;
|
||||||
beatmap.ControlPointInfo = original.ControlPointInfo;
|
beatmap.ControlPointInfo = original.ControlPointInfo;
|
||||||
beatmap.HitObjects = original.HitObjects.SelectMany(h => convert(h, original)).ToList();
|
beatmap.HitObjects = convertHitObjects(original.HitObjects, original);
|
||||||
beatmap.Breaks = original.Breaks;
|
beatmap.Breaks = original.Breaks;
|
||||||
|
|
||||||
return beatmap;
|
return beatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private List<T> convertHitObjects(IReadOnlyList<HitObject> hitObjects, IBeatmap beatmap)
|
||||||
/// 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)
|
|
||||||
{
|
{
|
||||||
// Check if the hitobject is already the converted type
|
var result = new List<T>(hitObjects.Count);
|
||||||
T tObject = original as T;
|
|
||||||
if (tObject != null)
|
|
||||||
{
|
|
||||||
yield return tObject;
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
|
|
||||||
var converted = ConvertHitObject(original, beatmap).ToList();
|
// ReSharper disable once ForCanBeConvertedToForeach
|
||||||
ObjectConverted?.Invoke(original, converted);
|
foreach (var obj in hitObjects)
|
||||||
|
|
||||||
// Convert the hit object
|
|
||||||
foreach (var obj in converted)
|
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj is T tObj)
|
||||||
|
{
|
||||||
|
result.Add(tObj);
|
||||||
continue;
|
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>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user