Files
AssetStudio/AssetStudioUtility/CubismLive2DExtractor/CubismJsonConverters/MyJsonConverterBool.cs
T
VaDiM 7b7907f2eb Migrate to System.Text.Json in Live2D exporter
- [exp3.json] Fixed format of Blend values (there should be strings according to the official specification)
- Fixed BlendType enum
2026-06-19 21:11:55 +03:00

26 lines
874 B
C#

using System;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace CubismLive2DExtractor.CubismJsonConverters
{
public sealed class MyJsonConverterBool : JsonConverter<bool>
{
public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
switch(reader.TokenType)
{
case JsonTokenType.True: return true;
case JsonTokenType.False: return false;
case JsonTokenType.Number: return reader.GetByte() == 1;
default: throw new JsonException($"Unable to convert \"{reader.TokenType}\" token to boolean.");
}
}
public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options)
{
writer.WriteBooleanValue(value);
}
}
}