mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 14:53:01 +08:00
Improve beatmap loading and hydration
This commit is contained in:
parent
fd10e6e582
commit
25d08c8e2c
@ -31,7 +31,8 @@ namespace osu.Desktop.Beatmaps.IO
|
|||||||
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
|
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
|
||||||
{
|
{
|
||||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
firstMap = decoder.Decode(stream);
|
firstMap = new Beatmap();
|
||||||
|
decoder.Decode(stream, firstMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ using System.IO;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
using osu.Game.Beatmaps.Objects.Osu;
|
using osu.Game.Beatmaps.Objects.Osu;
|
||||||
using osu.Game.Beatmaps.Samples;
|
using osu.Game.Beatmaps.Samples;
|
||||||
@ -25,7 +26,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
var decoder = new OsuLegacyDecoder();
|
var decoder = new OsuLegacyDecoder();
|
||||||
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
||||||
{
|
{
|
||||||
var beatmap = decoder.Decode(new StreamReader(stream));
|
Beatmap beatmap = new Beatmap();
|
||||||
|
decoder.Decode(new StreamReader(stream), beatmap);
|
||||||
var meta = beatmap.Metadata;
|
var meta = beatmap.Metadata;
|
||||||
Assert.AreEqual(241526, meta.BeatmapSetID);
|
Assert.AreEqual(241526, meta.BeatmapSetID);
|
||||||
Assert.AreEqual("Soleily", meta.Artist);
|
Assert.AreEqual("Soleily", meta.Artist);
|
||||||
@ -47,7 +49,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
var decoder = new OsuLegacyDecoder();
|
var decoder = new OsuLegacyDecoder();
|
||||||
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
||||||
{
|
{
|
||||||
var beatmap = decoder.Decode(new StreamReader(stream));
|
Beatmap beatmap = new Beatmap();
|
||||||
|
decoder.Decode(new StreamReader(stream), beatmap);
|
||||||
Assert.AreEqual(0, beatmap.AudioLeadIn);
|
Assert.AreEqual(0, beatmap.AudioLeadIn);
|
||||||
Assert.AreEqual(false, beatmap.Countdown);
|
Assert.AreEqual(false, beatmap.Countdown);
|
||||||
Assert.AreEqual(SampleSet.Soft, beatmap.SampleSet);
|
Assert.AreEqual(SampleSet.Soft, beatmap.SampleSet);
|
||||||
@ -65,7 +68,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
var decoder = new OsuLegacyDecoder();
|
var decoder = new OsuLegacyDecoder();
|
||||||
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
||||||
{
|
{
|
||||||
var beatmap = decoder.Decode(new StreamReader(stream));
|
Beatmap beatmap = new Beatmap();
|
||||||
|
decoder.Decode(new StreamReader(stream), beatmap);
|
||||||
int[] expectedBookmarks =
|
int[] expectedBookmarks =
|
||||||
{
|
{
|
||||||
11505, 22054, 32604, 43153, 53703, 64252, 74802, 85351,
|
11505, 22054, 32604, 43153, 53703, 64252, 74802, 85351,
|
||||||
@ -88,7 +92,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
var decoder = new OsuLegacyDecoder();
|
var decoder = new OsuLegacyDecoder();
|
||||||
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
||||||
{
|
{
|
||||||
var beatmap = decoder.Decode(new StreamReader(stream));
|
Beatmap beatmap = new Beatmap();
|
||||||
|
decoder.Decode(new StreamReader(stream), beatmap);
|
||||||
var difficulty = beatmap.BaseDifficulty;
|
var difficulty = beatmap.BaseDifficulty;
|
||||||
Assert.AreEqual(6.5f, difficulty.DrainRate);
|
Assert.AreEqual(6.5f, difficulty.DrainRate);
|
||||||
Assert.AreEqual(4, difficulty.CircleSize);
|
Assert.AreEqual(4, difficulty.CircleSize);
|
||||||
@ -105,7 +110,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
var decoder = new OsuLegacyDecoder();
|
var decoder = new OsuLegacyDecoder();
|
||||||
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
||||||
{
|
{
|
||||||
var beatmap = decoder.Decode(new StreamReader(stream));
|
Beatmap beatmap = new Beatmap();
|
||||||
|
decoder.Decode(new StreamReader(stream), beatmap);
|
||||||
Color4[] expected =
|
Color4[] expected =
|
||||||
{
|
{
|
||||||
new Color4(142, 199, 255, 255),
|
new Color4(142, 199, 255, 255),
|
||||||
@ -126,7 +132,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
var decoder = new OsuLegacyDecoder();
|
var decoder = new OsuLegacyDecoder();
|
||||||
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
using (var stream = Resource.OpenResource("Soleily - Renatus (Gamu) [Insane].osu"))
|
||||||
{
|
{
|
||||||
var beatmap = decoder.Decode(new StreamReader(stream));
|
Beatmap beatmap = new Beatmap();
|
||||||
|
decoder.Decode(new StreamReader(stream), beatmap);
|
||||||
var slider = beatmap.HitObjects[0] as Slider;
|
var slider = beatmap.HitObjects[0] as Slider;
|
||||||
Assert.IsNotNull(slider);
|
Assert.IsNotNull(slider);
|
||||||
Assert.AreEqual(new Vector2(192, 168), slider.Position);
|
Assert.AreEqual(new Vector2(192, 168), slider.Position);
|
||||||
|
@ -17,7 +17,7 @@ namespace osu.Game.Beatmaps
|
|||||||
[NotNull, Indexed]
|
[NotNull, Indexed]
|
||||||
public int BeatmapMetadataID { get; set; }
|
public int BeatmapMetadataID { get; set; }
|
||||||
[Ignore]
|
[Ignore]
|
||||||
public List<Beatmap> Beatmaps { get; protected set; }
|
public List<Beatmap> Beatmaps { get; protected set; } = new List<Beatmap>();
|
||||||
[Ignore]
|
[Ignore]
|
||||||
public BeatmapMetadata Metadata { get; set; }
|
public BeatmapMetadata Metadata { get; set; }
|
||||||
[Ignore]
|
[Ignore]
|
||||||
|
@ -20,6 +20,6 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
decoders[magic] = typeof(T);
|
decoders[magic] = typeof(T);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract Beatmap Decode(TextReader stream);
|
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
|
// We don't overwrite these two because they're DB bound
|
||||||
{
|
if (beatmap.Metadata == null) beatmap.Metadata = new BeatmapMetadata();
|
||||||
Metadata = new BeatmapMetadata(),
|
if (beatmap.BaseDifficulty == null) beatmap.BaseDifficulty = new BaseDifficulty();
|
||||||
BaseDifficulty = new BaseDifficulty(),
|
// These are fine though
|
||||||
HitObjects = new List<HitObject>(),
|
beatmap.HitObjects = new List<HitObject>();
|
||||||
ControlPoints = new List<ControlPoint>(),
|
beatmap.ControlPoints = new List<ControlPoint>();
|
||||||
ComboColors = new List<Color4>(),
|
beatmap.ComboColors = new List<Color4>();
|
||||||
};
|
|
||||||
var section = Section.None;
|
var section = Section.None;
|
||||||
string line;
|
string line;
|
||||||
while (true)
|
while (true)
|
||||||
@ -266,7 +266,6 @@ namespace osu.Game.Beatmaps.Formats
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return beatmap;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -33,7 +33,8 @@ namespace osu.Game.Beatmaps.IO
|
|||||||
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
|
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
|
||||||
{
|
{
|
||||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
firstMap = decoder.Decode(stream);
|
firstMap = new Beatmap();
|
||||||
|
decoder.Decode(stream, firstMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ namespace osu.Game.Database
|
|||||||
reader = ArchiveReader.GetReader(storage, path);
|
reader = ArchiveReader.GetReader(storage, path);
|
||||||
var metadata = reader.ReadMetadata();
|
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;
|
return; // TODO: Update this beatmap instead
|
||||||
string[] mapNames = reader.ReadBeatmaps();
|
string[] mapNames = reader.ReadBeatmaps();
|
||||||
var beatmapSet = new BeatmapSet
|
var beatmapSet = new BeatmapSet
|
||||||
{
|
{
|
||||||
@ -62,7 +62,8 @@ namespace osu.Game.Database
|
|||||||
using (var stream = new StreamReader(reader.ReadFile(name)))
|
using (var stream = new StreamReader(reader.ReadFile(name)))
|
||||||
{
|
{
|
||||||
var decoder = BeatmapDecoder.GetDecoder(stream);
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
var beatmap = decoder.Decode(stream);
|
Beatmap beatmap = new Beatmap();
|
||||||
|
decoder.Decode(stream, beatmap);
|
||||||
maps.Add(beatmap);
|
maps.Add(beatmap);
|
||||||
beatmap.BaseDifficultyID = connection.Insert(beatmap.BaseDifficulty);
|
beatmap.BaseDifficultyID = connection.Insert(beatmap.BaseDifficulty);
|
||||||
}
|
}
|
||||||
@ -71,12 +72,29 @@ namespace osu.Game.Database
|
|||||||
connection.Insert(beatmapSet);
|
connection.Insert(beatmapSet);
|
||||||
connection.InsertAll(maps);
|
connection.InsertAll(maps);
|
||||||
}
|
}
|
||||||
|
public ArchiveReader GetReader(BeatmapSet beatmapSet)
|
||||||
|
{
|
||||||
|
return ArchiveReader.GetReader(storage, beatmapSet.Path);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Given a BeatmapSet pulled from the database, loads the rest of its data from disk.
|
/// Given a BeatmapSet pulled from the database, loads the rest of its data from disk.
|
||||||
/// </summary>
public void PopulateBeatmap(BeatmapSet beatmap)
|
/// </summary>
public void PopulateBeatmap(BeatmapSet beatmapSet)
|
||||||
{
|
{
|
||||||
// TODO
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user