Add patcher support for breaks

This commit is contained in:
Bartłomiej Dach 2024-06-19 10:22:14 +02:00
parent 4022a8b06c
commit 58701b17f8
No known key found for this signature in database
1 changed files with 22 additions and 0 deletions

View File

@ -45,6 +45,7 @@ public void Patch(byte[] currentState, byte[] newState)
editorBeatmap.BeginChange();
processHitObjects(result, () => newBeatmap ??= readBeatmap(newState));
processTimingPoints(() => newBeatmap ??= readBeatmap(newState));
processBreaks(() => newBeatmap ??= readBeatmap(newState));
processHitObjectLocalData(() => newBeatmap ??= readBeatmap(newState));
editorBeatmap.EndChange();
}
@ -75,6 +76,27 @@ private void processTimingPoints(Func<IBeatmap> getNewBeatmap)
}
}
private void processBreaks(Func<IBeatmap> getNewBeatmap)
{
var newBreaks = getNewBeatmap().Breaks.ToArray();
foreach (var oldBreak in editorBeatmap.Breaks.ToArray())
{
if (newBreaks.Any(b => b.Equals(oldBreak)))
continue;
editorBeatmap.Breaks.Remove(oldBreak);
}
foreach (var newBreak in newBreaks)
{
if (editorBeatmap.Breaks.Any(b => b.Equals(newBreak)))
continue;
editorBeatmap.Breaks.Add(newBreak);
}
}
private void processHitObjects(DiffResult result, Func<IBeatmap> getNewBeatmap)
{
findChangedIndices(result, LegacyDecoder<Beatmap>.Section.HitObjects, out var removedIndices, out var addedIndices);