Files
MonoGame.Extended/Source/MonoGame.Extended.Gui/Serialization/GuiJsonSerializer.cs
T
vividosandDylan Wilson e4538dedd1 Gui System fixes (#588)
* added serializer for Size type

* updated type names of Gui classes

* throw more specific FormatException when deserializing json elements fails

* fixed Control deserializer
2019-11-14 10:43:12 +10:00

29 lines
1.3 KiB
C#

using System;
using Microsoft.Xna.Framework.Content;
using MonoGame.Extended.BitmapFonts;
using MonoGame.Extended.Serialization;
using Newtonsoft.Json;
namespace MonoGame.Extended.Gui.Serialization
{
public sealed class GuiJsonSerializer : JsonSerializer
{
public GuiJsonSerializer(ContentManager contentManager, params Type[] customControlTypes)
{
var textureRegionService = new GuiTextureRegionService();
Converters.Add(new Vector2JsonConverter());
Converters.Add(new SizeJsonConverter());
Converters.Add(new Size2JsonConverter());
Converters.Add(new ColorJsonConverter());
Converters.Add(new ThicknessJsonConverter());
Converters.Add(new ContentManagerJsonConverter<BitmapFont>(contentManager, font => font.Name));
Converters.Add(new ControlStyleJsonConverter(customControlTypes));
Converters.Add(new GuiTextureAtlasJsonConverter(contentManager, textureRegionService));
Converters.Add(new GuiNinePatchRegion2DJsonConverter(textureRegionService));
Converters.Add(new TextureRegion2DJsonConverter(textureRegionService));
Converters.Add(new AlignmentConverter());
ContractResolver = new ShortNameJsonContractResolver();
Formatting = Formatting.Indented;
}
}
}