1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 15:22:55 +08:00

Change storyboard parsing logic to not completely fail if only .osb read fails

Changes to allow the storyboard to exist if only the `.osu` is
available. Reads better IMO.
This commit is contained in:
Dean Herbert 2022-07-07 14:33:17 +09:00
parent c4b6893709
commit e81cebf27d

View File

@ -248,37 +248,37 @@ namespace osu.Game.Beatmaps
try try
{ {
string fileStorePath = BeatmapSetInfo.GetPathForFile(BeatmapInfo.Path); string fileStorePath = BeatmapSetInfo.GetPathForFile(BeatmapInfo.Path);
var stream = GetStream(fileStorePath); var beatmapFileStream = GetStream(fileStorePath);
if (stream == null) if (beatmapFileStream == null)
{ {
Logger.Log($"Beatmap failed to load (file {BeatmapInfo.Path} not found on disk at expected location {fileStorePath})", level: LogLevel.Error); Logger.Log($"Beatmap failed to load (file {BeatmapInfo.Path} not found on disk at expected location {fileStorePath})", level: LogLevel.Error);
return null; return null;
} }
using (var reader = new LineBufferedReader(stream)) using (var reader = new LineBufferedReader(beatmapFileStream))
{ {
var decoder = Decoder.GetDecoder<Storyboard>(reader); var decoder = Decoder.GetDecoder<Storyboard>(reader);
string storyboardFilename = BeatmapSetInfo?.Files.FirstOrDefault(f => f.Filename.EndsWith(".osb", StringComparison.OrdinalIgnoreCase))?.Filename; Stream storyboardFileStream = null;
// todo: support loading from both set-wide storyboard *and* beatmap specific. if (BeatmapSetInfo?.Files.FirstOrDefault(f => f.Filename.EndsWith(".osb", StringComparison.OrdinalIgnoreCase))?.Filename is string storyboardFilename)
if (string.IsNullOrEmpty(storyboardFilename))
storyboard = decoder.Decode(reader);
else
{ {
string storyboardFileStorePath = BeatmapSetInfo.GetPathForFile(storyboardFilename); string storyboardFileStorePath = BeatmapSetInfo?.GetPathForFile(storyboardFilename);
var secondaryStream = GetStream(storyboardFileStorePath); storyboardFileStream = GetStream(storyboardFileStorePath);
if (secondaryStream == null) if (storyboardFileStream == null)
{ Logger.Log($"Storyboard failed to load (file {storyboardFilename} not found on disk at expected location {storyboardFileStorePath})", level: LogLevel.Error);
Logger.Log($"Storyboard failed to load (file {storyboardFilename} not found on disk at expected location {fileStorePath})", level: LogLevel.Error); }
return null;
}
using (var secondaryReader = new LineBufferedReader(secondaryStream)) if (storyboardFileStream != null)
{
// Stand-alone storyboard was found, so parse in addition to the beatmap's local storyboard.
using (var secondaryReader = new LineBufferedReader(storyboardFileStream))
storyboard = decoder.Decode(reader, secondaryReader); storyboard = decoder.Decode(reader, secondaryReader);
} }
else
storyboard = decoder.Decode(reader);
} }
} }
catch (Exception e) catch (Exception e)