Add the concept of a "WorkingBeatmap" and make player load beatmaps and audio from SongSelect.

This commit is contained in:
Dean Herbert
2016-10-28 14:14:45 +09:00
parent 2cdda98b47
commit feccb7286c
5 changed files with 138 additions and 28 deletions

View File

@ -130,43 +130,46 @@ namespace osu.Game.Database
{
return ArchiveReader.GetReader(storage, beatmapSet.Path);
}
public BeatmapSetInfo GetBeatmapSet(int id)
{
return Query<BeatmapSetInfo>().Where(s => s.BeatmapSetID == id).FirstOrDefault();
}
public WorkingBeatmap GetBeatmapData(BeatmapInfo beatmapInfo)
{
var beatmapSet = Query<BeatmapSetInfo>().Where(s => s.BeatmapSetID == beatmapInfo.BeatmapSetID).FirstOrDefault();
if (beatmapSet == null)
throw new InvalidOperationException($@"Beatmap set {beatmapInfo.BeatmapSetID} is not in the local database.");
var reader = GetReader(beatmapSet);
using (var stream = new StreamReader(reader.ReadFile(beatmapInfo.Path)))
return new WorkingBeatmap(BeatmapDecoder.GetDecoder(stream)?.Decode(stream), reader);
}
public Beatmap GetBeatmap(BeatmapInfo beatmapInfo)
{
var beatmapSet = Query<BeatmapSetInfo>()
.Where(s => s.BeatmapSetID == beatmapInfo.BeatmapSetID).FirstOrDefault();
if (beatmapSet == null)
throw new InvalidOperationException(
$@"Beatmap set {beatmapInfo.BeatmapSetID} is not in the local database.");
using (var reader = GetReader(beatmapSet))
using (var stream = new StreamReader(reader.ReadFile(beatmapInfo.Path)))
{
var decoder = BeatmapDecoder.GetDecoder(stream);
return decoder.Decode(stream);
}
using (WorkingBeatmap data = GetBeatmapData(beatmapInfo))
return data.Beatmap;
}
public TableQuery<T> Query<T>() where T : class
{
return connection.Table<T>();
}
public T GetWithChildren<T>(object id) where T : class
{
return connection.GetWithChildren<T>(id);
}
public List<T> GetAllWithChildren<T>(Expression<Func<T, bool>> filter = null,
bool recursive = true) where T : class
{
return connection.GetAllWithChildren<T>(filter, recursive);
}
public T GetChildren<T>(T item, bool recursive = true)
{
if (item == null) return default(T);