2
0
mirror of https://github.com/9ParsonsB/Pulsar.git synced 2025-04-05 17:39:39 -04:00
pulsar/ObservatoryFramework/Files/Converters/ThargoidWarRemainingTimeConverter.cs
Ben Parsons bd811c861c Update Journal File Handling
Now Correctly deserializes Journal events
2024-05-12 14:24:53 +10:00

28 lines
762 B
C#

using System.Text.Json;
using System.Text.Json.Serialization;
namespace Observatory.Framework.Files.Converters;
class ThargoidWarRemainingTimeConverter : JsonConverter<int>
{
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
var value = reader.GetString();
var dayCount = int.TryParse(value.Split(' ')[0], out var days)
? days
: 0;
return dayCount;
}
return reader.GetInt32();
}
public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
writer.WriteStringValue(value + " Days");
}
}