Files
AssetStudio/AssetStudioUtility/CubismLive2DExtractor/CubismJsonConverters/MyJsonConverterFloatList.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

44 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace CubismLive2DExtractor.CubismJsonConverters
{
public class MyJsonConverterFloatList : JsonConverter<List<float>>
{
public override List<float> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return JsonSerializer.Deserialize<List<float>>(ref reader, new JsonSerializerOptions
{
NumberHandling = options.NumberHandling
});
}
public override void Write(Utf8JsonWriter writer, List<float> value, JsonSerializerOptions options)
{
writer.WriteStartArray();
foreach (var n in value)
{
if (float.IsNaN(n) || float.IsInfinity(n))
{
if (options.NumberHandling == JsonNumberHandling.AllowNamedFloatingPointLiterals)
{
writer.WriteStringValue($"{n.ToString(CultureInfo.InvariantCulture)}");
}
else
{
writer.WriteStringValue(JsonSerializer.Serialize(value));
}
}
else
{
writer.WriteNumberValue(MathF.Round(n, 3));
}
}
writer.WriteEndArray();
}
}
}