1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 09:37:42 +08:00
osu-lazer/osu.Game/Database/DatabaseWorkingBeatmap.cs

75 lines
2.4 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.IO;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Formats;
using osu.Game.Beatmaps.IO;
namespace osu.Game.Database
{
internal class DatabaseWorkingBeatmap : WorkingBeatmap
{
private readonly BeatmapDatabase database;
public DatabaseWorkingBeatmap(BeatmapDatabase database, BeatmapInfo beatmapInfo, bool withStoryboard = false)
: base(beatmapInfo, withStoryboard)
{
this.database = database;
}
private ArchiveReader getReader() => database?.GetReader(BeatmapSetInfo);
2017-03-23 09:07:26 +08:00
protected override Beatmap GetBeatmap()
{
try
{
2017-03-23 09:07:26 +08:00
Beatmap beatmap;
using (var reader = getReader())
{
BeatmapDecoder decoder;
using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path)))
{
decoder = BeatmapDecoder.GetDecoder(stream);
beatmap = decoder.Decode(stream);
}
if (beatmap == null || !WithStoryboard || BeatmapSetInfo.StoryboardFile == null)
return beatmap;
using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile)))
decoder.Decode(stream, beatmap);
}
2017-03-23 09:07:26 +08:00
return beatmap;
}
catch { return null; }
}
2017-03-23 09:07:26 +08:00
protected override Texture GetBackground()
{
2017-05-06 14:03:08 +08:00
if (Metadata?.BackgroundFile == null)
return null;
2017-03-23 09:07:26 +08:00
try
{
using (var reader = getReader())
2017-05-06 14:03:08 +08:00
return new TextureStore(new RawTextureLoaderStore(reader), false).Get(Metadata.BackgroundFile);
}
catch { return null; }
}
protected override Track GetTrack()
{
try
{
2017-05-06 14:03:08 +08:00
var trackData = getReader()?.GetStream(Metadata.AudioFile);
2017-03-23 09:07:26 +08:00
return trackData == null ? null : new TrackBass(trackData);
}
catch { return null; }
}
}
}