1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:07:24 +08:00

Preserve storyboard events when saving a beatmap in the editor

Until we have full encoding support for storyboards, this stop-gap
measure ensures that storyboards don't just disappear from existence.
This commit is contained in:
Dean Herbert 2024-04-29 22:26:44 +08:00
parent 0c45a482eb
commit fd3f4a9e7b
No known key found for this signature in database
9 changed files with 46 additions and 0 deletions

View File

@ -37,6 +37,21 @@ namespace osu.Game.Tests.Beatmaps.Formats
private static IEnumerable<string> allBeatmaps = beatmaps_resource_store.GetAvailableResources().Where(res => res.EndsWith(".osu", StringComparison.Ordinal));
[Test]
public void TestUnsupportedStoryboardEvents()
{
const string name = "Resources/storyboard_only_video.osu";
var decoded = decodeFromLegacy(beatmaps_resource_store.GetStream(name), name);
var decodedAfterEncode = decodeFromLegacy(encodeToLegacy(decoded), name);
Assert.That(decoded.beatmap.UnhandledEventLines.Count, Is.EqualTo(1));
Assert.That(decoded.beatmap.UnhandledEventLines.Single(), Is.EqualTo("Video,0,\"video.avi\""));
Assert.That(decodedAfterEncode.beatmap.UnhandledEventLines.Count, Is.EqualTo(1));
Assert.That(decodedAfterEncode.beatmap.UnhandledEventLines.Single(), Is.EqualTo("Video,0,\"video.avi\""));
}
[TestCaseSource(nameof(allBeatmaps))]
public void TestEncodeDecodeStability(string name)
{

View File

@ -63,6 +63,8 @@ namespace osu.Game.Beatmaps
public List<BreakPeriod> Breaks { get; set; } = new List<BreakPeriod>();
public List<string> UnhandledEventLines { get; set; } = new List<string>();
[JsonIgnore]
public double TotalBreakTime => Breaks.Sum(b => b.Duration);

View File

@ -66,6 +66,7 @@ namespace osu.Game.Beatmaps
beatmap.ControlPointInfo = original.ControlPointInfo;
beatmap.HitObjects = convertHitObjects(original.HitObjects, original, cancellationToken).OrderBy(s => s.StartTime).ToList();
beatmap.Breaks = original.Breaks;
beatmap.UnhandledEventLines = original.UnhandledEventLines;
return beatmap;
}

View File

@ -420,6 +420,10 @@ namespace osu.Game.Beatmaps.Formats
if (!Enum.TryParse(split[0], out LegacyEventType type))
throw new InvalidDataException($@"Unknown event type: {split[0]}");
// Until we have full storyboard encoder coverage, let's track any lines which aren't handled
// and store them to a temporary location such that they aren't lost on editor save / export.
bool lineSupportedByEncoder = false;
switch (type)
{
case LegacyEventType.Sprite:
@ -427,7 +431,11 @@ namespace osu.Game.Beatmaps.Formats
// In some older beatmaps, it is not present and replaced by a storyboard-level background instead.
// Allow the first sprite (by file order) to act as the background in such cases.
if (string.IsNullOrEmpty(beatmap.BeatmapInfo.Metadata.BackgroundFile))
{
beatmap.BeatmapInfo.Metadata.BackgroundFile = CleanFilename(split[3]);
lineSupportedByEncoder = true;
}
break;
case LegacyEventType.Video:
@ -439,12 +447,14 @@ namespace osu.Game.Beatmaps.Formats
if (!OsuGameBase.VIDEO_EXTENSIONS.Contains(Path.GetExtension(filename).ToLowerInvariant()))
{
beatmap.BeatmapInfo.Metadata.BackgroundFile = filename;
lineSupportedByEncoder = true;
}
break;
case LegacyEventType.Background:
beatmap.BeatmapInfo.Metadata.BackgroundFile = CleanFilename(split[2]);
lineSupportedByEncoder = true;
break;
case LegacyEventType.Break:
@ -452,8 +462,12 @@ namespace osu.Game.Beatmaps.Formats
double end = Math.Max(start, getOffsetTime(Parsing.ParseDouble(split[2])));
beatmap.Breaks.Add(new BreakPeriod(start, end));
lineSupportedByEncoder = true;
break;
}
if (!lineSupportedByEncoder)
beatmap.UnhandledEventLines.Add(line);
}
private void handleTimingPoint(string line)

View File

@ -156,6 +156,9 @@ namespace osu.Game.Beatmaps.Formats
foreach (var b in beatmap.Breaks)
writer.WriteLine(FormattableString.Invariant($"{(int)LegacyEventType.Break},{b.StartTime},{b.EndTime}"));
foreach (string l in beatmap.UnhandledEventLines)
writer.WriteLine(l);
}
private void handleControlPoints(TextWriter writer)

View File

@ -42,6 +42,12 @@ namespace osu.Game.Beatmaps
/// </summary>
List<BreakPeriod> Breaks { get; }
/// <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.
/// </summary>
List<string> UnhandledEventLines { get; }
/// <summary>
/// Total amount of break time in the beatmap.
/// </summary>

View File

@ -330,6 +330,8 @@ namespace osu.Game.Rulesets.Difficulty
}
public List<BreakPeriod> Breaks => baseBeatmap.Breaks;
public List<string> UnhandledEventLines => baseBeatmap.UnhandledEventLines;
public double TotalBreakTime => baseBeatmap.TotalBreakTime;
public IEnumerable<BeatmapStatistic> GetStatistics() => baseBeatmap.GetStatistics();
public double GetMostCommonBeatLength() => baseBeatmap.GetMostCommonBeatLength();

View File

@ -174,6 +174,8 @@ namespace osu.Game.Screens.Edit
public List<BreakPeriod> Breaks => PlayableBeatmap.Breaks;
public List<string> UnhandledEventLines => PlayableBeatmap.UnhandledEventLines;
public double TotalBreakTime => PlayableBeatmap.TotalBreakTime;
public IReadOnlyList<HitObject> HitObjects => PlayableBeatmap.HitObjects;

View File

@ -27,6 +27,7 @@ namespace osu.Game.Tests.Beatmaps
BeatmapInfo = baseBeatmap.BeatmapInfo;
ControlPointInfo = baseBeatmap.ControlPointInfo;
Breaks = baseBeatmap.Breaks;
UnhandledEventLines = baseBeatmap.UnhandledEventLines;
if (withHitObjects)
HitObjects = baseBeatmap.HitObjects;