From cc76c58f5f250151bb85ad5efa3f6ce008f0cbb0 Mon Sep 17 00:00:00 2001 From: Aergwyn Date: Sat, 2 Dec 2017 16:05:39 +0100 Subject: [PATCH] fall back to .osu file for storyboard if no .osb file is present + CI fixes --- .../Beatmaps/Formats/LegacyStoryboardDecoderTest.cs | 9 +++++---- osu.Game/Beatmaps/BeatmapManager.cs | 6 ++++-- osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs | 7 +++++++ osu.Game/Beatmaps/Formats/LegacyDecoder.cs | 12 ++++++++---- osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs | 6 +++--- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/osu.Game.Tests/Beatmaps/Formats/LegacyStoryboardDecoderTest.cs b/osu.Game.Tests/Beatmaps/Formats/LegacyStoryboardDecoderTest.cs index a42318883c..839932c640 100644 --- a/osu.Game.Tests/Beatmaps/Formats/LegacyStoryboardDecoderTest.cs +++ b/osu.Game.Tests/Beatmaps/Formats/LegacyStoryboardDecoderTest.cs @@ -1,7 +1,6 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; using System.IO; using System.Linq; using NUnit.Framework; @@ -56,9 +55,9 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.IsTrue(foreground.EnabledWhenPassing); Assert.AreEqual("Foreground", foreground.Name); - int spriteCount = background.Elements.Where(x => x.GetType() == typeof(StoryboardSprite)).Count(); - int animationCount = background.Elements.Where(x => x.GetType() == typeof(StoryboardAnimation)).Count(); - int sampleCount = background.Elements.Where(x => x.GetType() == typeof(StoryboardSample)).Count(); + int spriteCount = background.Elements.Count(x => x.GetType() == typeof(StoryboardSprite)); + int animationCount = background.Elements.Count(x => x.GetType() == typeof(StoryboardAnimation)); + int sampleCount = background.Elements.Count(x => x.GetType() == typeof(StoryboardSample)); Assert.AreEqual(15, spriteCount); Assert.AreEqual(1, animationCount); @@ -66,6 +65,7 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.AreEqual(background.Elements.Count(), spriteCount + animationCount + sampleCount); var sprite = background.Elements.ElementAt(0) as StoryboardSprite; + Assert.NotNull(sprite); Assert.IsTrue(sprite.HasCommands); Assert.AreEqual(new Vector2(320, 240), sprite.InitialPosition); Assert.IsTrue(sprite.IsDrawable); @@ -73,6 +73,7 @@ namespace osu.Game.Tests.Beatmaps.Formats Assert.AreEqual("SB/lyric/ja-21.png", sprite.Path); var animation = background.Elements.ElementAt(12) as StoryboardAnimation; + Assert.NotNull(animation); Assert.AreEqual(141175, animation.EndTime); Assert.AreEqual(10, animation.FrameCount); Assert.AreEqual(30, animation.FrameDelay); diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index 00182d5d85..d97cc6a7bf 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -615,7 +615,7 @@ namespace osu.Game.Beatmaps protected override Storyboard GetStoryboard() { - if (BeatmapSetInfo?.StoryboardFile == null) + if (BeatmapInfo?.Path == null && BeatmapSetInfo?.StoryboardFile == null) return new Storyboard(); try @@ -624,7 +624,9 @@ namespace osu.Game.Beatmaps using (var stream = new StreamReader(store.GetStream(getPathForFile(BeatmapInfo.Path)))) decoder = Decoder.GetDecoder(stream); - using (var stream = new StreamReader(store.GetStream(getPathForFile(BeatmapSetInfo.StoryboardFile)))) + // try for .osb first and fall back to .osu + string storyboardFile = BeatmapSetInfo.StoryboardFile ?? BeatmapInfo.Path; + using (var stream = new StreamReader(store.GetStream(getPathForFile(storyboardFile)))) return decoder.GetStoryboardDecoder().DecodeStoryboard(stream); } catch diff --git a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs index 29cf7dd913..b7004dd3eb 100644 --- a/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyBeatmapDecoder.cs @@ -47,6 +47,13 @@ namespace osu.Game.Beatmaps.Formats hitObject.ApplyDefaults(this.beatmap.ControlPointInfo, this.beatmap.BeatmapInfo.BaseDifficulty); } + protected override bool ShouldSkipLine(string line) + { + if (base.ShouldSkipLine(line) || line.StartsWith(" ") || line.StartsWith("_")) + return true; + return false; + } + protected override void ProcessSection(Section section, string line) { switch (section) diff --git a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs index 85d77d93bc..96747a870d 100644 --- a/osu.Game/Beatmaps/Formats/LegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyDecoder.cs @@ -52,10 +52,7 @@ namespace osu.Game.Beatmaps.Formats string line; while ((line = stream.ReadLine()) != null) { - if (string.IsNullOrWhiteSpace(line)) - continue; - - if (line.StartsWith("//")) + if (ShouldSkipLine(line)) continue; // It's already set in ParseBeatmap... why do it again? @@ -76,6 +73,13 @@ namespace osu.Game.Beatmaps.Formats } } + protected virtual bool ShouldSkipLine(string line) + { + if (string.IsNullOrWhiteSpace(line) || line.StartsWith("//")) + return true; + return false; + } + protected abstract void ProcessSection(Section section, string line); /// diff --git a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs index aca92f3969..8da6a0cefb 100644 --- a/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs +++ b/osu.Game/Beatmaps/Formats/LegacyStoryboardDecoder.cs @@ -237,9 +237,9 @@ namespace osu.Game.Beatmaps.Formats } } - private static string parseLayer(string value) => Enum.Parse(typeof(StoryLayer), value).ToString(); + private string parseLayer(string value) => Enum.Parse(typeof(StoryLayer), value).ToString(); - private static Anchor parseOrigin(string value) + private Anchor parseOrigin(string value) { var origin = (LegacyOrigins)Enum.Parse(typeof(LegacyOrigins), value); switch (origin) @@ -266,6 +266,6 @@ namespace osu.Game.Beatmaps.Formats throw new InvalidDataException($@"Unknown origin: {value}"); } - private static string cleanFilename(string path) => FileSafety.PathStandardise(path.Trim('\"')); + private string cleanFilename(string path) => FileSafety.PathStandardise(path.Trim('\"')); } }