2024-02-04 17:47:36 +01:00
|
|
|
|
using CShocker.Shockers.Abstract;
|
2024-01-29 15:37:19 +01:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
|
|
namespace CShocker.Shockers.Additional;
|
|
|
|
|
|
|
|
|
|
public class ShockerJsonConverter : JsonConverter
|
|
|
|
|
{
|
|
|
|
|
public override bool CanConvert(Type objectType)
|
|
|
|
|
{
|
2024-02-01 23:03:28 +01:00
|
|
|
|
return (objectType == typeof(Shocker));
|
2024-01-29 15:37:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override object ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
|
|
|
|
{
|
|
|
|
|
JObject jo = JObject.Load(reader);
|
2024-02-15 23:11:56 +01:00
|
|
|
|
if (jo.ContainsKey("Model")) //OpenShockShocker
|
2024-01-29 15:37:19 +01:00
|
|
|
|
{
|
2024-02-04 17:47:36 +01:00
|
|
|
|
return jo.ToObject<OpenShockShocker>(serializer)!;
|
2024-01-29 15:37:19 +01:00
|
|
|
|
}
|
|
|
|
|
else //PiShockShocker
|
|
|
|
|
{
|
2024-02-04 17:47:36 +01:00
|
|
|
|
return jo.ToObject<PiShockShocker>(serializer)!;
|
2024-01-29 15:37:19 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool CanWrite => false;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Don't call this
|
|
|
|
|
/// </summary>
|
|
|
|
|
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
|
|
|
|
{
|
2024-02-12 02:01:31 +01:00
|
|
|
|
throw new NotImplementedException("Dont call this");
|
2024-01-29 15:37:19 +01:00
|
|
|
|
}
|
|
|
|
|
}
|