1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 05:02:55 +08:00

Add OsuJsonDecoder

This commit is contained in:
smoogipoo 2017-12-06 00:38:12 +09:00
parent b584178e85
commit d2dc7c8937
3 changed files with 37 additions and 1 deletions

View File

@ -14,6 +14,7 @@ namespace osu.Game.Beatmaps.Formats
static BeatmapDecoder()
{
OsuLegacyDecoder.Register();
OsuJsonDecoder.Register();
}
public static BeatmapDecoder GetDecoder(StreamReader stream)
@ -27,7 +28,16 @@ namespace osu.Game.Beatmaps.Formats
if (line == null || !decoders.ContainsKey(line))
throw new IOException(@"Unknown file format");
return (BeatmapDecoder)Activator.CreateInstance(decoders[line], line);
try
{
return (BeatmapDecoder)Activator.CreateInstance(decoders[line], line);
}
catch
{
// As a default case, try a parameterless constructor
return (BeatmapDecoder)Activator.CreateInstance(decoders[line]);
}
}
protected static void AddDecoder<T>(string magic) where T : BeatmapDecoder

View File

@ -0,0 +1,25 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.IO;
using osu.Game.IO.Serialization;
namespace osu.Game.Beatmaps.Formats
{
public class OsuJsonDecoder : BeatmapDecoder
{
public static void Register()
{
AddDecoder<OsuJsonDecoder>("{");
}
protected override void ParseFile(StreamReader stream, Beatmap beatmap)
{
stream.BaseStream.Position = 0;
stream.DiscardBufferedData();
string fullText = stream.ReadToEnd();
fullText.DeserializeInto(beatmap);
}
}
}

View File

@ -266,6 +266,7 @@
<Compile Include="Beatmaps\Drawables\BeatmapPanel.cs" />
<Compile Include="Beatmaps\Drawables\BeatmapSetCover.cs" />
<Compile Include="Beatmaps\Drawables\BeatmapSetHeader.cs" />
<Compile Include="Beatmaps\Formats\OsuJsonDecoder.cs" />
<Compile Include="Database\DatabaseContextFactory.cs" />
<Compile Include="Database\IHasPrimaryKey.cs" />
<Compile Include="Graphics\UserInterface\HoverClickSounds.cs" />