mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 16:43:03 +08:00
Fix GetDecoder getting fallback decoder too often
This commit is contained in:
parent
aa74b3193e
commit
c042e709a5
@ -127,6 +127,31 @@ namespace osu.Game.Tests.Beatmaps.Formats
|
||||
.Assert();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestGetJsonDecoder()
|
||||
{
|
||||
Decoder<Beatmap> decoder;
|
||||
|
||||
using (var stream = TestResources.OpenResource(normal))
|
||||
using (var sr = new LineBufferedReader(stream))
|
||||
{
|
||||
var legacyDecoded = new LegacyBeatmapDecoder { ApplyOffsets = false }.Decode(sr);
|
||||
|
||||
using (var ms = new MemoryStream())
|
||||
using (var sw = new StreamWriter(ms))
|
||||
using (var sr2 = new LineBufferedReader(ms))
|
||||
{
|
||||
sw.Write(legacyDecoded.Serialize());
|
||||
sw.Flush();
|
||||
|
||||
ms.Position = 0;
|
||||
decoder = Decoder.GetDecoder<Beatmap>(sr2);
|
||||
}
|
||||
}
|
||||
|
||||
Assert.IsInstanceOf(typeof(JsonBeatmapDecoder), decoder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a .osu file first with a <see cref="LegacyBeatmapDecoder"/>, serializes the resulting <see cref="Beatmap"/> to JSON
|
||||
/// and then deserializes the result back into a <see cref="Beatmap"/> through an <see cref="JsonBeatmapDecoder"/>.
|
||||
|
@ -63,7 +63,7 @@ namespace osu.Game.Beatmaps.Formats
|
||||
if (line == null)
|
||||
throw new IOException("Unknown file format (null)");
|
||||
|
||||
var decoder = typedDecoders.Select(d => line.StartsWith(d.Key, StringComparison.InvariantCulture) ? d.Value : null).FirstOrDefault();
|
||||
var decoder = typedDecoders.Where(d => line.StartsWith(d.Key, StringComparison.InvariantCulture)).FirstOrDefault().Value;
|
||||
|
||||
// it's important the magic does NOT get consumed here, since sometimes it's part of the structure
|
||||
// (see JsonBeatmapDecoder - the magic string is the opening brace)
|
||||
|
Loading…
Reference in New Issue
Block a user