mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 19:33:20 +08:00
Always apply beatmap converter/processor
This commit is contained in:
parent
e9a2e92adf
commit
9713d90388
@ -1,14 +1,21 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Audio.Track;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
using osu.Game.IO;
|
using osu.Game.IO;
|
||||||
using osu.Game.IO.Serialization;
|
using osu.Game.IO.Serialization;
|
||||||
|
using osu.Game.Rulesets.Catch;
|
||||||
|
using osu.Game.Rulesets.Mania;
|
||||||
|
using osu.Game.Rulesets.Osu;
|
||||||
|
using osu.Game.Rulesets.Taiko;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Beatmaps.Formats
|
namespace osu.Game.Tests.Beatmaps.Formats
|
||||||
@ -29,26 +36,68 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
|||||||
Assert.That(encoded.Serialize(), Is.EqualTo(decoded.Serialize()));
|
Assert.That(encoded.Serialize(), Is.EqualTo(decoded.Serialize()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Beatmap decode(string filename, out Beatmap encoded)
|
private IBeatmap decode(string filename, out IBeatmap encoded)
|
||||||
{
|
{
|
||||||
using (var stream = TestResources.OpenResource(filename))
|
using (var stream = TestResources.GetStore().GetStream(filename))
|
||||||
using (var sr = new LineBufferedReader(stream))
|
using (var sr = new LineBufferedReader(stream))
|
||||||
{
|
{
|
||||||
var legacyDecoded = new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr);
|
var legacyDecoded = convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr));
|
||||||
|
|
||||||
using (var ms = new MemoryStream())
|
using (var ms = new MemoryStream())
|
||||||
using (var sw = new StreamWriter(ms))
|
using (var sw = new StreamWriter(ms))
|
||||||
using (var sr2 = new LineBufferedReader(ms))
|
using (var sr2 = new LineBufferedReader(ms, true))
|
||||||
{
|
{
|
||||||
new LegacyBeatmapEncoder(legacyDecoded).Encode(sw);
|
new LegacyBeatmapEncoder(legacyDecoded).Encode(sw);
|
||||||
sw.Flush();
|
|
||||||
|
|
||||||
|
sw.Flush();
|
||||||
ms.Position = 0;
|
ms.Position = 0;
|
||||||
|
|
||||||
encoded = new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr2);
|
encoded = convert(new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr2));
|
||||||
|
|
||||||
return legacyDecoded;
|
return legacyDecoded;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IBeatmap convert(IBeatmap beatmap)
|
||||||
|
{
|
||||||
|
switch (beatmap.BeatmapInfo.RulesetID)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
beatmap.BeatmapInfo.Ruleset = new OsuRuleset().RulesetInfo;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
beatmap.BeatmapInfo.Ruleset = new TaikoRuleset().RulesetInfo;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
beatmap.BeatmapInfo.Ruleset = new CatchRuleset().RulesetInfo;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
beatmap.BeatmapInfo.Ruleset = new ManiaRuleset().RulesetInfo;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TestWorkingBeatmap(beatmap).GetPlayableBeatmap(beatmap.BeatmapInfo.Ruleset);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TestWorkingBeatmap : WorkingBeatmap
|
||||||
|
{
|
||||||
|
private readonly IBeatmap beatmap;
|
||||||
|
|
||||||
|
public TestWorkingBeatmap(IBeatmap beatmap)
|
||||||
|
: base(beatmap.BeatmapInfo, null)
|
||||||
|
{
|
||||||
|
this.beatmap = beatmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override IBeatmap GetBeatmap() => beatmap;
|
||||||
|
|
||||||
|
protected override Texture GetBackground() => throw new NotImplementedException();
|
||||||
|
|
||||||
|
protected override Track GetTrack() => throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user