1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 18:07:23 +08:00

Merge pull request #8584 from ThereGoesMySanity/getdecoder-fix

Fix GetDecoder getting fallback decoder too often
This commit is contained in:
Dan Balasescu 2020-04-03 12:36:44 +09:00 committed by GitHub
commit 4e061ceabc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -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 memStream = new MemoryStream())
using (var memWriter = new StreamWriter(memStream))
using (var memReader = new LineBufferedReader(memStream))
{
memWriter.Write(legacyDecoded.Serialize());
memWriter.Flush();
memStream.Position = 0;
decoder = Decoder.GetDecoder<Beatmap>(memReader);
}
}
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"/>.

View File

@ -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)).Select(d => d.Value).FirstOrDefault();
// 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)