2017-03-22 18:15:32 +08:00
|
|
|
|
// 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;
|
2017-03-22 17:54:07 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2017-03-22 18:50:48 +08:00
|
|
|
|
internal class DatabaseWorkingBeatmap : WorkingBeatmap
|
2017-03-22 17:54:07 +08:00
|
|
|
|
{
|
2017-03-22 18:50:48 +08:00
|
|
|
|
private readonly BeatmapDatabase database;
|
2017-03-22 17:54:07 +08:00
|
|
|
|
|
2017-05-01 21:29:57 +08:00
|
|
|
|
public DatabaseWorkingBeatmap(BeatmapDatabase database, BeatmapInfo beatmapInfo, BeatmapSetInfo beatmapSetInfo = null, BeatmapMetadata metadata = null, bool withStoryboard = false)
|
|
|
|
|
: base(beatmapInfo, beatmapSetInfo, metadata, withStoryboard)
|
2017-03-22 18:50:48 +08:00
|
|
|
|
{
|
|
|
|
|
this.database = database;
|
|
|
|
|
}
|
2017-03-22 17:54:07 +08:00
|
|
|
|
|
2017-03-22 18:50:48 +08:00
|
|
|
|
private ArchiveReader getReader() => database?.GetReader(BeatmapSetInfo);
|
2017-03-23 09:07:26 +08:00
|
|
|
|
|
2017-03-22 18:50:48 +08:00
|
|
|
|
protected override Beatmap GetBeatmap()
|
|
|
|
|
{
|
|
|
|
|
try
|
2017-03-22 17:54:07 +08:00
|
|
|
|
{
|
2017-03-23 09:07:26 +08:00
|
|
|
|
Beatmap beatmap;
|
|
|
|
|
|
2017-03-22 18:50:48 +08:00
|
|
|
|
using (var reader = getReader())
|
2017-03-22 17:54:07 +08:00
|
|
|
|
{
|
2017-03-22 18:50:48 +08:00
|
|
|
|
BeatmapDecoder decoder;
|
|
|
|
|
using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path)))
|
2017-03-22 17:54:07 +08:00
|
|
|
|
{
|
2017-03-22 18:50:48 +08:00
|
|
|
|
decoder = BeatmapDecoder.GetDecoder(stream);
|
2017-04-03 19:26:46 +08:00
|
|
|
|
beatmap = decoder.Decode(stream);
|
2017-03-22 17:54:07 +08:00
|
|
|
|
}
|
2017-03-22 18:50:48 +08:00
|
|
|
|
|
2017-04-03 19:26:46 +08:00
|
|
|
|
if (beatmap == null || !WithStoryboard || BeatmapSetInfo.StoryboardFile == null)
|
|
|
|
|
return beatmap;
|
|
|
|
|
|
|
|
|
|
using (var stream = new StreamReader(reader.GetStream(BeatmapSetInfo.StoryboardFile)))
|
|
|
|
|
decoder.Decode(stream, beatmap);
|
2017-03-22 17:54:07 +08:00
|
|
|
|
}
|
2017-03-23 09:07:26 +08:00
|
|
|
|
|
|
|
|
|
return beatmap;
|
2017-03-22 17:54:07 +08:00
|
|
|
|
}
|
2017-03-22 18:50:48 +08:00
|
|
|
|
catch { return null; }
|
|
|
|
|
}
|
2017-03-23 09:07:26 +08:00
|
|
|
|
|
2017-03-22 18:50:48 +08:00
|
|
|
|
protected override Texture GetBackground()
|
|
|
|
|
{
|
|
|
|
|
if (BeatmapInfo?.Metadata?.BackgroundFile == null)
|
|
|
|
|
return null;
|
2017-03-23 09:07:26 +08:00
|
|
|
|
|
2017-03-22 18:50:48 +08:00
|
|
|
|
try
|
2017-03-22 17:54:07 +08:00
|
|
|
|
{
|
2017-03-22 18:50:48 +08:00
|
|
|
|
using (var reader = getReader())
|
2017-03-23 09:07:26 +08:00
|
|
|
|
return new TextureStore(new RawTextureLoaderStore(reader), false).Get(BeatmapInfo.Metadata.BackgroundFile);
|
2017-03-22 17:54:07 +08:00
|
|
|
|
}
|
2017-03-22 18:50:48 +08:00
|
|
|
|
catch { return null; }
|
|
|
|
|
}
|
2017-03-22 17:54:07 +08:00
|
|
|
|
|
2017-03-22 18:50:48 +08:00
|
|
|
|
protected override Track GetTrack()
|
|
|
|
|
{
|
|
|
|
|
try
|
2017-03-22 17:54:07 +08:00
|
|
|
|
{
|
2017-03-23 09:07:26 +08:00
|
|
|
|
var trackData = getReader()?.GetStream(BeatmapInfo.Metadata.AudioFile);
|
|
|
|
|
return trackData == null ? null : new TrackBass(trackData);
|
2017-03-22 17:54:07 +08:00
|
|
|
|
}
|
2017-03-22 18:50:48 +08:00
|
|
|
|
catch { return null; }
|
2017-03-22 17:54:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|