32 lines
974 B
C#
32 lines
974 B
C#
using System;
|
|
using GameCore;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
namespace EventSmash.Converter
|
|
{
|
|
public class ItemDataIgnoreCurCountConverter : JsonConverter<ItemData>
|
|
{
|
|
public override void WriteJson(JsonWriter writer, ItemData value, JsonSerializer serializer)
|
|
{
|
|
writer.WriteStartObject();
|
|
writer.WritePropertyName("id");
|
|
writer.WriteValue(value.id);
|
|
writer.WritePropertyName("count");
|
|
writer.WriteValue(value.count);
|
|
writer.WriteEndObject();
|
|
}
|
|
|
|
public override ItemData ReadJson(JsonReader reader, Type objectType, ItemData existingValue,
|
|
bool hasExistingValue, JsonSerializer serializer)
|
|
{
|
|
var obj = JObject.Load(reader);
|
|
return new ItemData
|
|
{
|
|
id = obj["id"]?.Value<int>() ?? 0,
|
|
count = obj["count"]?.Value<int>() ?? 0
|
|
};
|
|
}
|
|
}
|
|
}
|