Merge pull request #28689 from smoogipoo/fix-break-conversion

Fix `ManiaModInvert` permanently destroying the beatmap
This commit is contained in:
Bartłomiej Dach 2024-07-02 07:53:16 +02:00 committed by GitHub
commit 3bf3e9133b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 96 additions and 44 deletions

View File

@ -2,6 +2,8 @@
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Mania.Mods;
using osu.Game.Tests.Visual;
@ -17,5 +19,22 @@ public void TestInversion() => CreateModTest(new ModTestData
Mod = new ManiaModInvert(),
PassCondition = () => Player.ScoreProcessor.JudgedHits >= 2
});
[Test]
public void TestBreaksPreservedOnOriginalBeatmap()
{
var beatmap = CreateBeatmap(new ManiaRuleset().RulesetInfo);
beatmap.Breaks.Clear();
beatmap.Breaks.Add(new BreakPeriod(0, 1000));
var workingBeatmap = new FlatWorkingBeatmap(beatmap);
var playableWithInvert = workingBeatmap.GetPlayableBeatmap(new ManiaRuleset().RulesetInfo, new[] { new ManiaModInvert() });
Assert.That(playableWithInvert.Breaks.Count, Is.Zero);
var playableWithoutInvert = workingBeatmap.GetPlayableBeatmap(new ManiaRuleset().RulesetInfo);
Assert.That(playableWithoutInvert.Breaks.Count, Is.Not.Zero);
Assert.That(playableWithoutInvert.Breaks[0], Is.EqualTo(new BreakPeriod(0, 1000)));
}
}
}

View File

@ -21,10 +21,11 @@ public void TestEmptyBeatmap()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
};
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -38,14 +39,15 @@ public void TestSingleObjectBeatmap()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1000 },
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -59,15 +61,16 @@ public void TestTwoObjectsCloseTogether()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1000 },
new HitCircle { StartTime = 2000 },
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -81,14 +84,15 @@ public void TestHoldNote()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new ManiaRuleset().RulesetInfo },
HitObjects =
{
new HoldNote { StartTime = 1000, Duration = 10000 },
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new ManiaRuleset());
beatmapProcessor.PreProcess();
@ -102,16 +106,17 @@ public void TestHoldNoteWithOverlappingNote()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new ManiaRuleset().RulesetInfo },
HitObjects =
{
new HoldNote { StartTime = 1000, Duration = 10000 },
new Note { StartTime = 2000 },
new Note { StartTime = 12000 },
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new ManiaRuleset());
beatmapProcessor.PreProcess();
@ -125,15 +130,16 @@ public void TestTwoObjectsFarApart()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1000 },
new HitCircle { StartTime = 5000 },
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -152,9 +158,10 @@ public void TestBreaksAreFused()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1000 },
@ -165,7 +172,7 @@ public void TestBreaksAreFused()
new BreakPeriod(1200, 4000),
new BreakPeriod(5200, 8000),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -184,9 +191,10 @@ public void TestBreaksAreSplit()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1000 },
@ -197,7 +205,7 @@ public void TestBreaksAreSplit()
{
new BreakPeriod(1200, 8000),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -218,9 +226,10 @@ public void TestBreaksAreNudged()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1100 },
@ -230,7 +239,7 @@ public void TestBreaksAreNudged()
{
new BreakPeriod(1200, 8000),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -249,9 +258,10 @@ public void TestManualBreaksAreNotFused()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1000 },
@ -262,7 +272,7 @@ public void TestManualBreaksAreNotFused()
new ManualBreakPeriod(1200, 4000),
new ManualBreakPeriod(5200, 8000),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -283,9 +293,10 @@ public void TestManualBreaksAreSplit()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1000 },
@ -296,7 +307,7 @@ public void TestManualBreaksAreSplit()
{
new ManualBreakPeriod(1200, 8000),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -317,9 +328,10 @@ public void TestManualBreaksAreNotNudged()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1000 },
@ -329,7 +341,7 @@ public void TestManualBreaksAreNotNudged()
{
new ManualBreakPeriod(1200, 8800),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -348,9 +360,10 @@ public void TestBreaksAtEndOfBeatmapAreRemoved()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1000 },
@ -360,7 +373,7 @@ public void TestBreaksAtEndOfBeatmapAreRemoved()
{
new BreakPeriod(10000, 15000),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -374,9 +387,10 @@ public void TestManualBreaksAtEndOfBeatmapAreRemoved()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 1000 },
@ -386,7 +400,7 @@ public void TestManualBreaksAtEndOfBeatmapAreRemoved()
{
new ManualBreakPeriod(10000, 15000),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -400,9 +414,10 @@ public void TestManualBreaksAtEndOfBeatmapAreRemovedCorrectlyEvenWithConcurrentO
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HoldNote { StartTime = 1000, EndTime = 20000 },
@ -412,7 +427,7 @@ public void TestManualBreaksAtEndOfBeatmapAreRemovedCorrectlyEvenWithConcurrentO
{
new ManualBreakPeriod(10000, 15000),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -426,9 +441,10 @@ public void TestBreaksAtStartOfBeatmapAreRemoved()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 10000 },
@ -438,7 +454,7 @@ public void TestBreaksAtStartOfBeatmapAreRemoved()
{
new BreakPeriod(0, 9000),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();
@ -452,9 +468,10 @@ public void TestManualBreaksAtStartOfBeatmapAreRemoved()
{
var controlPoints = new ControlPointInfo();
controlPoints.Add(0, new TimingControlPoint { BeatLength = 500 });
var beatmap = new Beatmap
var beatmap = new EditorBeatmap(new Beatmap
{
ControlPointInfo = controlPoints,
BeatmapInfo = { Ruleset = new OsuRuleset().RulesetInfo },
HitObjects =
{
new HitCircle { StartTime = 10000 },
@ -464,7 +481,7 @@ public void TestManualBreaksAtStartOfBeatmapAreRemoved()
{
new ManualBreakPeriod(0, 9000),
}
};
});
var beatmapProcessor = new EditorBeatmapProcessor(beatmap, new OsuRuleset());
beatmapProcessor.PreProcess();

View File

@ -8,7 +8,6 @@
using System.Linq;
using osu.Game.Beatmaps.ControlPoints;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.IO.Serialization.Converters;
namespace osu.Game.Beatmaps
@ -62,7 +61,7 @@ public Beatmap()
public ControlPointInfo ControlPointInfo { get; set; } = new ControlPointInfo();
public BindableList<BreakPeriod> Breaks { get; set; } = new BindableList<BreakPeriod>();
public List<BreakPeriod> Breaks { get; set; } = new List<BreakPeriod>();
public List<string> UnhandledEventLines { get; set; } = new List<string>();

View File

@ -49,6 +49,9 @@ public IBeatmap Convert(CancellationToken cancellationToken = default)
original.BeatmapInfo = original.BeatmapInfo.Clone();
original.ControlPointInfo = original.ControlPointInfo.DeepClone();
// Used in osu!mania conversion.
original.Breaks = original.Breaks.ToList();
return ConvertBeatmap(original, cancellationToken);
}

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Objects;
@ -41,11 +40,11 @@ public interface IBeatmap
/// <summary>
/// The breaks in this beatmap.
/// </summary>
BindableList<BreakPeriod> Breaks { get; }
List<BreakPeriod> Breaks { get; set; }
/// <summary>
/// All lines from the [Events] section which aren't handled in the encoding process yet.
/// These lines shoule be written out to the beatmap file on save or export.
/// These lines should be written out to the beatmap file on save or export.
/// </summary>
List<string> UnhandledEventLines { get; }

View File

@ -9,7 +9,6 @@
using System.Threading;
using JetBrains.Annotations;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
@ -328,7 +327,12 @@ public BeatmapDifficulty Difficulty
set => baseBeatmap.Difficulty = value;
}
public BindableList<BreakPeriod> Breaks => baseBeatmap.Breaks;
public List<BreakPeriod> Breaks
{
get => baseBeatmap.Breaks;
set => baseBeatmap.Breaks = value;
}
public List<string> UnhandledEventLines => baseBeatmap.UnhandledEventLines;
public double TotalBreakTime => baseBeatmap.TotalBreakTime;

View File

@ -110,6 +110,9 @@ public EditorBeatmap(IBeatmap playableBeatmap, ISkin beatmapSkin = null, Beatmap
foreach (var obj in HitObjects)
trackStartTime(obj);
Breaks = new BindableList<BreakPeriod>(playableBeatmap.Breaks);
Breaks.BindCollectionChanged((_, _) => playableBeatmap.Breaks = Breaks.ToList());
PreviewTime = new BindableInt(BeatmapInfo.Metadata.PreviewTime);
PreviewTime.BindValueChanged(s =>
{
@ -172,7 +175,13 @@ public ControlPointInfo ControlPointInfo
set => PlayableBeatmap.ControlPointInfo = value;
}
public BindableList<BreakPeriod> Breaks => PlayableBeatmap.Breaks;
public readonly BindableList<BreakPeriod> Breaks;
List<BreakPeriod> IBeatmap.Breaks
{
get => PlayableBeatmap.Breaks;
set => PlayableBeatmap.Breaks = value;
}
public List<string> UnhandledEventLines => PlayableBeatmap.UnhandledEventLines;

View File

@ -12,11 +12,13 @@ namespace osu.Game.Screens.Edit
{
public class EditorBeatmapProcessor : IBeatmapProcessor
{
public IBeatmap Beatmap { get; }
public EditorBeatmap Beatmap { get; }
IBeatmap IBeatmapProcessor.Beatmap => Beatmap;
private readonly IBeatmapProcessor? rulesetBeatmapProcessor;
public EditorBeatmapProcessor(IBeatmap beatmap, Ruleset ruleset)
public EditorBeatmapProcessor(EditorBeatmap beatmap, Ruleset ruleset)
{
Beatmap = beatmap;
rulesetBeatmapProcessor = ruleset.CreateBeatmapProcessor(beatmap);