From d2dc7c8937dfe1901494c01c81c4459ef40e86ab Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 6 Dec 2017 00:38:12 +0900 Subject: [PATCH] Add OsuJsonDecoder --- osu.Game/Beatmaps/Formats/BeatmapDecoder.cs | 12 +++++++++- osu.Game/Beatmaps/Formats/OsuJsonDecoder.cs | 25 +++++++++++++++++++++ osu.Game/osu.Game.csproj | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Beatmaps/Formats/OsuJsonDecoder.cs diff --git a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs index 7e1a87085c..31869e207e 100644 --- a/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs +++ b/osu.Game/Beatmaps/Formats/BeatmapDecoder.cs @@ -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(string magic) where T : BeatmapDecoder diff --git a/osu.Game/Beatmaps/Formats/OsuJsonDecoder.cs b/osu.Game/Beatmaps/Formats/OsuJsonDecoder.cs new file mode 100644 index 0000000000..392f1b4890 --- /dev/null +++ b/osu.Game/Beatmaps/Formats/OsuJsonDecoder.cs @@ -0,0 +1,25 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// 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("{"); + } + + protected override void ParseFile(StreamReader stream, Beatmap beatmap) + { + stream.BaseStream.Position = 0; + stream.DiscardBufferedData(); + + string fullText = stream.ReadToEnd(); + fullText.DeserializeInto(beatmap); + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index f50e87b074..9e5d4291ce 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -266,6 +266,7 @@ +