mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Improve beatmap loading and hydration
This commit is contained in:
@ -17,7 +17,7 @@ namespace osu.Game.Beatmaps
|
||||
[NotNull, Indexed]
|
||||
public int BeatmapMetadataID { get; set; }
|
||||
[Ignore]
|
||||
public List<Beatmap> Beatmaps { get; protected set; }
|
||||
public List<Beatmap> Beatmaps { get; protected set; } = new List<Beatmap>();
|
||||
[Ignore]
|
||||
public BeatmapMetadata Metadata { get; set; }
|
||||
[Ignore]
|
||||
|
@ -20,6 +20,6 @@ namespace osu.Game.Beatmaps.Formats
|
||||
{
|
||||
decoders[magic] = typeof(T);
|
||||
}
|
||||
|
||||
|
||||
public abstract void Decode(TextReader stream, Beatmap beatmap);
|
||||
}
|
@ -202,16 +202,16 @@ namespace osu.Game.Beatmaps.Formats
|
||||
});
|
||||
}
|
||||
|
||||
public override Beatmap Decode(TextReader stream)
|
||||
public override void Decode(TextReader stream, Beatmap beatmap)
|
||||
{
|
||||
var beatmap = new Beatmap
|
||||
{
|
||||
Metadata = new BeatmapMetadata(),
|
||||
BaseDifficulty = new BaseDifficulty(),
|
||||
HitObjects = new List<HitObject>(),
|
||||
ControlPoints = new List<ControlPoint>(),
|
||||
ComboColors = new List<Color4>(),
|
||||
};
|
||||
// We don't overwrite these two because they're DB bound
|
||||
if (beatmap.Metadata == null) beatmap.Metadata = new BeatmapMetadata();
|
||||
if (beatmap.BaseDifficulty == null) beatmap.BaseDifficulty = new BaseDifficulty();
|
||||
// These are fine though
|
||||
beatmap.HitObjects = new List<HitObject>();
|
||||
beatmap.ControlPoints = new List<ControlPoint>();
|
||||
beatmap.ComboColors = new List<Color4>();
|
||||
|
||||
var section = Section.None;
|
||||
string line;
|
||||
while (true)
|
||||
@ -266,7 +266,6 @@ namespace osu.Game.Beatmaps.Formats
|
||||
break;
|
||||
}
|
||||
}
|
||||
return beatmap;
|
||||
}
|
||||
}
|
||||
}
|
@ -33,7 +33,8 @@ namespace osu.Game.Beatmaps.IO
|
||||
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
|
||||
{
|
||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||
firstMap = decoder.Decode(stream);
|
||||
firstMap = new Beatmap();
|
||||
decoder.Decode(stream, firstMap);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user