mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 05:02:55 +08:00
Add OsuJsonDecoder
This commit is contained in:
parent
b584178e85
commit
d2dc7c8937
@ -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
|
||||
|
25
osu.Game/Beatmaps/Formats/OsuJsonDecoder.cs
Normal file
25
osu.Game/Beatmaps/Formats/OsuJsonDecoder.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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" />
|
||||
|
Loading…
Reference in New Issue
Block a user