Improve beatmap loading and hydration

This commit is contained in:
Drew DeVault
2016-10-13 10:29:30 -04:00
parent fd10e6e582
commit 25d08c8e2c
7 changed files with 50 additions and 24 deletions

View File

@ -48,7 +48,7 @@ namespace osu.Game.Database
else
reader = ArchiveReader.GetReader(storage, path);
var metadata = reader.ReadMetadata();
if (connection.Table<BeatmapSet>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
if (connection.Table<BeatmapSet>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
return; // TODO: Update this beatmap instead
string[] mapNames = reader.ReadBeatmaps();
var beatmapSet = new BeatmapSet
@ -62,7 +62,8 @@ namespace osu.Game.Database
{
using (var stream = new StreamReader(reader.ReadFile(name)))
{
var decoder = BeatmapDecoder.GetDecoder(stream);
var decoder = BeatmapDecoder.GetDecoder(stream);
Beatmap beatmap = new Beatmap();
decoder.Decode(stream, beatmap);
maps.Add(beatmap);
beatmap.BaseDifficultyID = connection.Insert(beatmap.BaseDifficulty);
@ -71,12 +72,29 @@ namespace osu.Game.Database
beatmapSet.BeatmapMetadataID = connection.Insert(metadata);
connection.Insert(beatmapSet);
connection.InsertAll(maps);
}
public ArchiveReader GetReader(BeatmapSet beatmapSet)
{
return ArchiveReader.GetReader(storage, beatmapSet.Path);
}
/// Given a BeatmapSet pulled from the database, loads the rest of its data from disk.
/// <summary>
/// Given a BeatmapSet pulled from the database, loads the rest of its data from disk.
public void PopulateBeatmap(BeatmapSet beatmap)
/// </summary>
public void PopulateBeatmap(BeatmapSet beatmapSet)
{
using (var reader = GetReader(beatmapSet))
{
string[] mapNames = reader.ReadBeatmaps();
foreach (var name in mapNames)
{
using (var stream = new StreamReader(reader.ReadFile(name)))
{
var decoder = BeatmapDecoder.GetDecoder(stream);
Beatmap beatmap = new Beatmap();
decoder.Decode(stream, beatmap);
beatmapSet.Beatmaps.Add(beatmap);
}
}
}