Files
MonoGame.Extended/source/MonoGame.Extended.Gui/Serialization/GuiTextureAtlasJsonConverter.cs
T
Christopher WhitleyandGitHub 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

32 lines
1.0 KiB
C#

using System;
using System.Text.Json;
using Microsoft.Xna.Framework.Content;
using MonoGame.Extended.Serialization;
using MonoGame.Extended.TextureAtlases;
namespace MonoGame.Extended.Gui.Serialization
{
public class GuiTextureAtlasJsonConverter : ContentManagerJsonConverter<TextureAtlas>
{
private readonly IGuiTextureRegionService _textureRegionService;
public GuiTextureAtlasJsonConverter(ContentManager contentManager, IGuiTextureRegionService textureRegionService)
: base(contentManager, atlas => atlas.Name)
{
_textureRegionService = textureRegionService;
}
/// <inheritdoc />
public override TextureAtlas Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var textureAtlas = base.Read(ref reader, typeToConvert, options);
if (textureAtlas is not null)
{
_textureRegionService.TextureAtlases.Add(textureAtlas);
}
return textureAtlas;
}
}
}