diff --git a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs index 9b699a3d76..420141e9a1 100644 --- a/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs +++ b/osu.Desktop/Beatmaps/IO/LegacyFilesystemReader.cs @@ -21,6 +21,7 @@ namespace osu.Desktop.Beatmaps.IO private string basePath { get; set; } private string[] beatmaps { get; set; } + private string storyboard { get; set; } private Beatmap firstMap { get; set; } public LegacyFilesystemReader(string path) @@ -29,6 +30,7 @@ namespace osu.Desktop.Beatmaps.IO beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray(); if (beatmaps.Length == 0) throw new FileNotFoundException(@"This directory contains no beatmaps"); + storyboard = Directory.GetFiles(basePath, @"*.osb").Select(f => Path.GetFileName(f)).FirstOrDefault(); using (var stream = new StreamReader(GetStream(beatmaps[0]))) { var decoder = BeatmapDecoder.GetDecoder(stream); @@ -41,6 +43,11 @@ namespace osu.Desktop.Beatmaps.IO return beatmaps; } + public override string ReadStoryboard() + { + return storyboard; + } + public override Stream GetStream(string name) { return File.OpenRead(Path.Combine(basePath, name)); diff --git a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index ba99b206b5..4846cf376d 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -7,6 +7,8 @@ using System.IO; using osu.Game.Modes.Objects; using OpenTK.Graphics; using osu.Game.Graphics; +using osu.Game.Beatmaps.Timing; +using osu.Game.Database; namespace osu.Game.Beatmaps.Formats { @@ -34,6 +36,11 @@ namespace osu.Game.Beatmaps.Formats return b; } + public virtual void Decode(TextReader stream, Beatmap beatmap) + { + ParseFile(stream, beatmap); + } + public virtual Beatmap Process(Beatmap beatmap) { ApplyColours(beatmap); @@ -41,7 +48,23 @@ namespace osu.Game.Beatmaps.Formats return beatmap; } - protected abstract Beatmap ParseFile(TextReader stream); + protected virtual Beatmap ParseFile(TextReader stream) + { + var beatmap = new Beatmap + { + HitObjects = new List(), + ControlPoints = new List(), + ComboColors = new List(), + BeatmapInfo = new BeatmapInfo + { + Metadata = new BeatmapMetadata(), + BaseDifficulty = new BaseDifficulty(), + }, + }; + ParseFile(stream, beatmap); + return beatmap; + } + protected abstract void ParseFile(TextReader stream, Beatmap beatmap); public virtual void ApplyColours(Beatmap b) { diff --git a/osu.Game/Beatmaps/Formats/ConstructableBeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/ConstructableBeatmapDecoder.cs index 6f81cae00f..f80c673e89 100644 --- a/osu.Game/Beatmaps/Formats/ConstructableBeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/ConstructableBeatmapDecoder.cs @@ -12,7 +12,7 @@ namespace osu.Game.Beatmaps.Formats { public class ConstructableBeatmapDecoder : BeatmapDecoder { - protected override Beatmap ParseFile(TextReader stream) + protected override void ParseFile(TextReader stream, Beatmap beatmap) { throw new NotImplementedException(); } diff --git a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs index 29bb7ca32b..c32c3fe2f1 100644 --- a/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs +++ b/osu.Game/Beatmaps/Formats/OsuLegacyDecoder.cs @@ -233,20 +233,8 @@ namespace osu.Game.Beatmaps.Formats }); } - protected override Beatmap ParseFile(TextReader stream) + protected override void ParseFile(TextReader stream, Beatmap beatmap) { - var beatmap = new Beatmap - { - HitObjects = new List(), - ControlPoints = new List(), - ComboColors = new List(), - BeatmapInfo = new BeatmapInfo - { - Metadata = new BeatmapMetadata(), - BaseDifficulty = new BaseDifficulty(), - }, - }; - HitObjectParser parser = null; var section = Section.None; @@ -309,8 +297,6 @@ namespace osu.Game.Beatmaps.Formats break; } } - - return beatmap; } } } diff --git a/osu.Game/Beatmaps/IO/ArchiveReader.cs b/osu.Game/Beatmaps/IO/ArchiveReader.cs index 8ae495a1fe..a944e7589a 100644 --- a/osu.Game/Beatmaps/IO/ArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/ArchiveReader.cs @@ -44,6 +44,10 @@ namespace osu.Game.Beatmaps.IO /// public abstract string[] ReadBeatmaps(); /// + /// Gets the storyboard file name. + /// + public abstract string ReadStoryboard(); + /// /// Opens a stream for reading a specific file from this archive. /// public abstract Stream GetStream(string name); diff --git a/osu.Game/Beatmaps/IO/OszArchiveReader.cs b/osu.Game/Beatmaps/IO/OszArchiveReader.cs index 4b35805373..f9b7fb2cf8 100644 --- a/osu.Game/Beatmaps/IO/OszArchiveReader.cs +++ b/osu.Game/Beatmaps/IO/OszArchiveReader.cs @@ -26,8 +26,9 @@ namespace osu.Game.Beatmaps.IO private Stream archiveStream; private ZipFile archive; private string[] beatmaps; + private string storyboard; private Beatmap firstMap; - + public OszArchiveReader(Stream archiveStream) { this.archiveStream = archiveStream; @@ -36,6 +37,8 @@ namespace osu.Game.Beatmaps.IO .Select(e => e.FileName).ToArray(); if (beatmaps.Length == 0) throw new FileNotFoundException(@"This directory contains no beatmaps"); + storyboard = archive.Entries.Where(e => e.FileName.EndsWith(@".osb")) + .Select(e => e.FileName).FirstOrDefault(); using (var stream = new StreamReader(GetStream(beatmaps[0]))) { var decoder = BeatmapDecoder.GetDecoder(stream); @@ -48,6 +51,11 @@ namespace osu.Game.Beatmaps.IO return beatmaps; } + public override string ReadStoryboard() + { + return storyboard; + } + public override Stream GetStream(string name) { ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name); diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 019674c3ad..674ab76802 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -18,6 +18,8 @@ namespace osu.Game.Beatmaps public readonly BeatmapSetInfo BeatmapSetInfo; private readonly BeatmapDatabase database; + public readonly bool WithStoryboard; + private ArchiveReader getReader() => database?.GetReader(BeatmapSetInfo); private Texture background; @@ -58,8 +60,18 @@ namespace osu.Game.Beatmaps try { using (var reader = getReader()) - using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path))) - beatmap = BeatmapDecoder.GetDecoder(stream)?.Decode(stream); + { + BeatmapDecoder decoder; + using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path))) + { + decoder = BeatmapDecoder.GetDecoder(stream); + beatmap = decoder?.Decode(stream); + } + + if (WithStoryboard && beatmap != null && BeatmapSetInfo.StoryboardFile != null) + using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile))) + decoder?.Decode(stream, beatmap); + } } catch { } @@ -103,11 +115,12 @@ namespace osu.Game.Beatmaps this.beatmap = beatmap; } - public WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, BeatmapDatabase database) + public WorkingBeatmap(BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo, BeatmapDatabase database, bool withStoryboard = false) { BeatmapInfo = beatmapInfo; BeatmapSetInfo = beatmapSetInfo; this.database = database; + this.WithStoryboard = withStoryboard; } private bool isDisposed; diff --git a/osu.Game/Database/BeatmapDatabase.cs b/osu.Game/Database/BeatmapDatabase.cs index dff76479e8..1b678b2148 100644 --- a/osu.Game/Database/BeatmapDatabase.cs +++ b/osu.Game/Database/BeatmapDatabase.cs @@ -137,6 +137,7 @@ namespace osu.Game.Database beatmapSet.Beatmaps.Add(beatmap.BeatmapInfo); } } + beatmapSet.StoryboardFile = reader.ReadStoryboard(); } Import(new[] { beatmapSet }); @@ -169,7 +170,7 @@ namespace osu.Game.Database return Query().FirstOrDefault(s => s.OnlineBeatmapSetID == id); } - public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, WorkingBeatmap previous = null) + public WorkingBeatmap GetWorkingBeatmap(BeatmapInfo beatmapInfo, WorkingBeatmap previous = null, bool withStoryboard = false) { var beatmapSetInfo = Query().FirstOrDefault(s => s.ID == beatmapInfo.BeatmapSetInfoID); @@ -182,7 +183,7 @@ namespace osu.Game.Database if (beatmapInfo.Metadata == null) beatmapInfo.Metadata = beatmapSetInfo.Metadata; - var working = new WorkingBeatmap(beatmapInfo, beatmapSetInfo, this); + var working = new WorkingBeatmap(beatmapInfo, beatmapSetInfo, this, withStoryboard); previous?.TransferTo(working); diff --git a/osu.Game/Database/BeatmapSetInfo.cs b/osu.Game/Database/BeatmapSetInfo.cs index f556c3546a..a9c3f03a49 100644 --- a/osu.Game/Database/BeatmapSetInfo.cs +++ b/osu.Game/Database/BeatmapSetInfo.cs @@ -27,6 +27,8 @@ namespace osu.Game.Database public string Hash { get; set; } public string Path { get; set; } + + public string StoryboardFile { get; set; } } } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index a9584a1f10..36ea7c5b49 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -74,7 +74,7 @@ namespace osu.Game.Screens.Play try { if (Beatmap == null) - Beatmap = beatmaps.GetWorkingBeatmap(BeatmapInfo); + Beatmap = beatmaps.GetWorkingBeatmap(BeatmapInfo, withStoryboard: true); } catch {