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

@ -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]

View File

@ -20,6 +20,6 @@ namespace osu.Game.Beatmaps.Formats
{
decoders[magic] = typeof(T);
}
public abstract void Decode(TextReader stream, Beatmap beatmap);
}

View File

@ -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;
}
}
}

View File

@ -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);
}
}