1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Do Split and Parse before checking HitObjects

This commit is contained in:
ratinfx 2023-11-12 14:58:46 +01:00
parent c367697559
commit 4e7c40f1d7
2 changed files with 18 additions and 29 deletions

View File

@ -60,33 +60,27 @@ namespace osu.Game.Rulesets.Mania.Edit
return;
List<ManiaHitObject> remainingHitObjects = EditorBeatmap.HitObjects.Cast<ManiaHitObject>().Where(h => h.StartTime >= timestamp).ToList();
string[] split = objectDescription.Split(',').ToArray();
string[] splitDescription = objectDescription.Split(',').ToArray();
for (int i = 0; i < split.Length; i++)
for (int i = 0; i < splitDescription.Length; i++)
{
ManiaHitObject current = remainingHitObjects.FirstOrDefault(h => shouldBeSelected(h, split[i]));
string[] split = splitDescription[i].Split('|').ToArray();
if (split.Length != 2)
continue;
if (!double.TryParse(split[0], out double time) || !int.TryParse(split[1], out int column))
continue;
ManiaHitObject current = remainingHitObjects.FirstOrDefault(h => h.StartTime == time && h.Column == column);
if (current == null)
continue;
EditorBeatmap.SelectedHitObjects.Add(current);
if (i < split.Length - 1)
if (i < splitDescription.Length - 1)
remainingHitObjects = remainingHitObjects.Where(h => h != current && h.StartTime >= current.StartTime).ToList();
}
}
private bool shouldBeSelected(ManiaHitObject hitObject, string objectInfo)
{
string[] split = objectInfo.Split('|').ToArray();
if (split.Length != 2)
return false;
if (!double.TryParse(split[0], out double time) || !int.TryParse(split[1], out int column))
return false;
return hitObject.StartTime == time
&& hitObject.Column == column;
}
}
}

View File

@ -115,30 +115,25 @@ namespace osu.Game.Rulesets.Osu.Edit
return;
List<OsuHitObject> remainingHitObjects = EditorBeatmap.HitObjects.Cast<OsuHitObject>().Where(h => h.StartTime >= timestamp).ToList();
string[] split = objectDescription.Split(',').ToArray();
string[] splitDescription = objectDescription.Split(',').ToArray();
for (int i = 0; i < split.Length; i++)
for (int i = 0; i < splitDescription.Length; i++)
{
OsuHitObject current = remainingHitObjects.FirstOrDefault(h => shouldBeSelected(h, split[i]));
if (!int.TryParse(splitDescription[i], out int combo) || combo < 1)
continue;
OsuHitObject current = remainingHitObjects.FirstOrDefault(h => h.IndexInCurrentCombo + 1 == combo);
if (current == null)
continue;
EditorBeatmap.SelectedHitObjects.Add(current);
if (i < split.Length - 1)
if (i < splitDescription.Length - 1)
remainingHitObjects = remainingHitObjects.Where(h => h != current && h.StartTime >= current.StartTime).ToList();
}
}
private bool shouldBeSelected(OsuHitObject hitObject, string objectInfo)
{
if (!int.TryParse(objectInfo, out int combo) || combo < 1)
return false;
return hitObject.IndexInCurrentCombo + 1 == combo;
}
private DistanceSnapGrid distanceSnapGrid;
private Container distanceSnapGridContainer;