mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 14:12:54 +08:00
9e20a02c0a
Hide database functionality at a lower level in preparation from eventually making it private.
71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
// 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;
|
|
using System.IO;
|
|
using osu.Framework.Audio.Track;
|
|
using osu.Framework.Graphics.Textures;
|
|
using osu.Framework.IO.Stores;
|
|
using osu.Game.Beatmaps.Formats;
|
|
|
|
namespace osu.Game.Beatmaps
|
|
{
|
|
internal class BeatmapStoreWorkingBeatmap : WorkingBeatmap
|
|
{
|
|
private readonly Func<IResourceStore<byte[]>> getStore;
|
|
|
|
public BeatmapStoreWorkingBeatmap(Func<IResourceStore<byte[]>> getStore, BeatmapInfo beatmapInfo)
|
|
: base(beatmapInfo)
|
|
{
|
|
this.getStore = getStore;
|
|
}
|
|
|
|
protected override Beatmap GetBeatmap()
|
|
{
|
|
try
|
|
{
|
|
Beatmap beatmap;
|
|
|
|
BeatmapDecoder decoder;
|
|
using (var stream = new StreamReader(getStore().GetStream(BeatmapInfo.Path)))
|
|
{
|
|
decoder = BeatmapDecoder.GetDecoder(stream);
|
|
beatmap = decoder.Decode(stream);
|
|
}
|
|
|
|
if (beatmap == null || BeatmapSetInfo.StoryboardFile == null)
|
|
return beatmap;
|
|
|
|
using (var stream = new StreamReader(getStore().GetStream(BeatmapSetInfo.StoryboardFile)))
|
|
decoder.Decode(stream, beatmap);
|
|
|
|
|
|
return beatmap;
|
|
}
|
|
catch { return null; }
|
|
}
|
|
|
|
protected override Texture GetBackground()
|
|
{
|
|
if (Metadata?.BackgroundFile == null)
|
|
return null;
|
|
|
|
try
|
|
{
|
|
return new TextureStore(new RawTextureLoaderStore(getStore()), false).Get(Metadata.BackgroundFile);
|
|
}
|
|
catch { return null; }
|
|
}
|
|
|
|
protected override Track GetTrack()
|
|
{
|
|
try
|
|
{
|
|
var trackData = getStore().GetStream(Metadata.AudioFile);
|
|
return trackData == null ? null : new TrackBass(trackData);
|
|
}
|
|
catch { return new TrackVirtual(); }
|
|
}
|
|
}
|
|
}
|