···11+// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22+// See the LICENCE file in the repository root for full licence text.
33+44+using System;
55+using Newtonsoft.Json;
66+using Newtonsoft.Json.Linq;
77+using osuTK;
88+99+namespace osu.Framework.IO.Serialization
1010+{
1111+ /// <summary>
1212+ /// A type of <see cref="JsonConverter"/> that serializes only the X and Y coordinates of a <see cref="Vector2"/>.
1313+ /// </summary>
1414+ public class Vector2Converter : JsonConverter<Vector2>
1515+ {
1616+ public override Vector2 ReadJson(JsonReader reader, Type objectType, Vector2 existingValue, bool hasExistingValue, JsonSerializer serializer)
1717+ {
1818+ var obj = JObject.Load(reader);
1919+ return new Vector2((float)obj["x"], (float)obj["y"]);
2020+ }
2121+2222+ public override void WriteJson(JsonWriter writer, Vector2 value, JsonSerializer serializer)
2323+ {
2424+ writer.WriteStartObject();
2525+2626+ writer.WritePropertyName("x");
2727+ writer.WriteValue(value.X);
2828+ writer.WritePropertyName("y");
2929+ writer.WriteValue(value.Y);
3030+3131+ writer.WriteEndObject();
3232+ }
3333+ }
3434+}