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

37 lines
1.1 KiB
C#

using System.Text.Json;
using System.Text.Json.Serialization;
using Observatory.Framework.Files.ParameterTypes;
namespace Observatory.Framework.Files.Converters;
public class MissionEffectConverter : JsonConverter<MissionEffect>
{
public override MissionEffect Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var effect = reader.GetString();
//TODO: Find out all possible values
switch (effect)
{
case "+":
effect = "Low";
break;
case "++":
effect = "Med";
break;
case "+++":
case "++++":
case "+++++":
effect = "High";
break;
}
var missionEffect = (MissionEffect)Enum.Parse(typeof(MissionEffect), effect, true);
return missionEffect;
}
public override void Write(Utf8JsonWriter writer, MissionEffect value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value, options);
}
}