Files
MonoGame.Extended/source/MonoGame.Extended.Gui/Serialization/GuiJsonSerializerOptionsProvider.cs
T
Christopher Whitley d008b1bd41 Replace Newtonsoft.Json with System.Text.Json (#869)
* Converted to use `System.Text.Json`

* Remove Newtonsoft.Json Dependency
Newtonsoft.Json dependency has been removed in favor of System.Text.Json

* Treat MGFXO file as binary
2024-05-22 23:23:36 -04:00

39 lines
1.6 KiB
C#

using System;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Xna.Framework.Content;
using MonoGame.Extended.BitmapFonts;
using MonoGame.Extended.Serialization;
namespace MonoGame.Extended.Gui.Serialization;
public static class GuiJsonSerializerOptionsProvider
{
public static JsonSerializerOptions GetOptions(ContentManager contentManager, params Type[] customControlTypes)
{
var options = new JsonSerializerOptions
{
WriteIndented = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
var textureRegionService = new GuiTextureRegionService();
options.Converters.Add(new Vector2JsonConverter());
options.Converters.Add(new SizeJsonConverter());
options.Converters.Add(new Size2JsonConverter());
options.Converters.Add(new ColorJsonConverter());
options.Converters.Add(new ThicknessJsonConverter());
options.Converters.Add(new ContentManagerJsonConverter<BitmapFont>(contentManager, font => font.Name));
options.Converters.Add(new ControlStyleJsonConverter(customControlTypes));
options.Converters.Add(new GuiTextureAtlasJsonConverter(contentManager, textureRegionService));
options.Converters.Add(new GuiNinePatchRegion2DJsonConverter(textureRegionService));
options.Converters.Add(new TextureRegion2DJsonConverter(textureRegionService));
options.Converters.Add(new VerticalAlignmentConverter());
options.Converters.Add(new HorizontalAlignmentConverter());
return options;
}
}