From 58e65397b06b43973c52babef2e520520fc2e94e Mon Sep 17 00:00:00 2001 From: Damnae Date: Tue, 12 Sep 2017 10:13:55 +0200 Subject: [PATCH] Add support for storyboards using numerical values. --- osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs | 53 +++++++++++++++++-- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index e436a43989..adf366cdea 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -287,8 +287,8 @@ namespace osu.Game.Beatmaps.Formats break; case EventType.Sprite: { - var layer = split[1]; - var origin = (Anchor)Enum.Parse(typeof(Anchor), split[2]); + var layer = parseLayer(split[1]); + var origin = parseOrigin(split[2]); var path = cleanFilename(split[3]); var x = float.Parse(split[4], NumberFormatInfo.InvariantInfo); var y = float.Parse(split[5], NumberFormatInfo.InvariantInfo); @@ -298,8 +298,8 @@ namespace osu.Game.Beatmaps.Formats break; case EventType.Animation: { - var layer = split[1]; - var origin = (Anchor)Enum.Parse(typeof(Anchor), split[2]); + var layer = parseLayer(split[1]); + var origin = parseOrigin(split[2]); var path = cleanFilename(split[3]); var x = float.Parse(split[4], NumberFormatInfo.InvariantInfo); var y = float.Parse(split[5], NumberFormatInfo.InvariantInfo); @@ -313,7 +313,7 @@ namespace osu.Game.Beatmaps.Formats case EventType.Sample: { var time = double.Parse(split[1], CultureInfo.InvariantCulture); - var layer = split[2]; + var layer = parseLayer(split[2]); var path = cleanFilename(split[3]); var volume = split.Length > 4 ? float.Parse(split[4], CultureInfo.InvariantCulture) : 100; beatmap.Storyboard.GetLayer(layer).Add(new SampleDefinition(path, time, volume)); @@ -446,6 +446,27 @@ namespace osu.Game.Beatmaps.Formats private static string cleanFilename(string path) => FileSafety.PathStandardise(path.Trim('\"')); + private static Anchor parseOrigin(string value) + { + var origin = (LegacyOrigins)Enum.Parse(typeof(LegacyOrigins), value); + switch (origin) + { + case LegacyOrigins.TopLeft: return Anchor.TopLeft; + case LegacyOrigins.TopCentre: return Anchor.TopCentre; + case LegacyOrigins.TopRight: return Anchor.TopRight; + case LegacyOrigins.CentreLeft: return Anchor.CentreLeft; + case LegacyOrigins.Centre: return Anchor.Centre; + case LegacyOrigins.CentreRight: return Anchor.CentreRight; + case LegacyOrigins.BottomLeft: return Anchor.BottomLeft; + case LegacyOrigins.BottomCentre: return Anchor.BottomCentre; + case LegacyOrigins.BottomRight: return Anchor.BottomRight; + } + throw new InvalidDataException($@"Unknown origin: {value}"); + } + + private static string parseLayer(string value) + => Enum.Parse(typeof(StoryLayer), value).ToString(); + private void handleTimingPoints(Beatmap beatmap, string line) { string[] split = line.Split(','); @@ -683,5 +704,27 @@ namespace osu.Game.Beatmaps.Formats Sample = 5, Animation = 6 } + + internal enum LegacyOrigins + { + TopLeft, + Centre, + CentreLeft, + TopRight, + BottomCentre, + TopCentre, + Custom, + CentreRight, + BottomLeft, + BottomRight + }; + + internal enum StoryLayer + { + Background = 0, + Fail = 1, + Pass = 2, + Foreground = 3 + } } }