Preserve the beatmap's version

This commit is contained in:
smoogipoo 2018-10-23 14:38:27 +09:00
parent d210383d8f
commit 8a2a6a3ecb
4 changed files with 28 additions and 2 deletions

View File

@ -8,11 +8,13 @@
using osu.Game.Tests.Resources;
using System.Linq;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Beatmaps.Formats;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Catch.Beatmaps;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Skinning;
@ -21,6 +23,25 @@ namespace osu.Game.Tests.Beatmaps.Formats
[TestFixture]
public class LegacyBeatmapDecoderTest
{
[Test]
public void TestDecodeBeatmapVersion()
{
using (var resStream = Resource.OpenResource("beatmap-version.osu"))
using (var stream = new StreamReader(resStream))
{
var decoder = Decoder.GetDecoder<Beatmap>(stream);
stream.BaseStream.Position = 0;
stream.DiscardBufferedData();
var working = new TestWorkingBeatmap(decoder.Decode(stream));
Assert.AreEqual(6, working.BeatmapInfo.BeatmapVersion);
Assert.AreEqual(6, working.Beatmap.BeatmapInfo.BeatmapVersion);
Assert.AreEqual(6, working.GetPlayableBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo.BeatmapVersion);
}
}
[Test]
public void TestDecodeBeatmapGeneral()
{

View File

@ -0,0 +1 @@
osu file format v6

View File

@ -19,7 +19,6 @@ public class BeatmapInfo : IEquatable<BeatmapInfo>, IJsonSerializable, IHasPrima
[JsonIgnore]
public int ID { get; set; }
//TODO: should be in database
public int BeatmapVersion;
private int? onlineBeatmapID;

View File

@ -41,8 +41,13 @@ protected WorkingBeatmap(BeatmapInfo beatmapInfo)
beatmap = new RecyclableLazy<IBeatmap>(() =>
{
var b = GetBeatmap() ?? new Beatmap();
// use the database-backed info.
// The original beatmap version needs to be preserved as the database doesn't contain it
BeatmapInfo.BeatmapVersion = b.BeatmapInfo.BeatmapVersion;
// Use the database-backed info for more up-to-date values (beatmap id, ranked status, etc)
b.BeatmapInfo = BeatmapInfo;
return b;
});