A game framework written with osu! in mind.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add support for osuTK Vector2 json serialisation

To be used by `TabletHandler`. Taken from osu! and applied globally.

+44
+34
osu.Framework/IO/Serialization/Vector2Converter.cs
··· 1 + // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2 + // See the LICENCE file in the repository root for full licence text. 3 + 4 + using System; 5 + using Newtonsoft.Json; 6 + using Newtonsoft.Json.Linq; 7 + using osuTK; 8 + 9 + namespace osu.Framework.IO.Serialization 10 + { 11 + /// <summary> 12 + /// A type of <see cref="JsonConverter"/> that serializes only the X and Y coordinates of a <see cref="Vector2"/>. 13 + /// </summary> 14 + public class Vector2Converter : JsonConverter<Vector2> 15 + { 16 + public override Vector2 ReadJson(JsonReader reader, Type objectType, Vector2 existingValue, bool hasExistingValue, JsonSerializer serializer) 17 + { 18 + var obj = JObject.Load(reader); 19 + return new Vector2((float)obj["x"], (float)obj["y"]); 20 + } 21 + 22 + public override void WriteJson(JsonWriter writer, Vector2 value, JsonSerializer serializer) 23 + { 24 + writer.WriteStartObject(); 25 + 26 + writer.WritePropertyName("x"); 27 + writer.WriteValue(value.X); 28 + writer.WritePropertyName("y"); 29 + writer.WriteValue(value.Y); 30 + 31 + writer.WriteEndObject(); 32 + } 33 + } 34 + }
+10
osu.Framework/Platform/GameHost.cs
··· 13 13 using System.Runtime.InteropServices; 14 14 using System.Threading; 15 15 using System.Threading.Tasks; 16 + using Newtonsoft.Json; 16 17 using osuTK; 17 18 using osuTK.Graphics; 18 19 using osuTK.Graphics.ES30; ··· 36 37 using SixLabors.ImageSharp.Processing; 37 38 using osu.Framework.Graphics.Textures; 38 39 using osu.Framework.Graphics.Video; 40 + using osu.Framework.IO.Serialization; 39 41 using osu.Framework.IO.Stores; 40 42 using SixLabors.ImageSharp.Memory; 41 43 using Image = SixLabors.ImageSharp.Image; ··· 225 227 protected GameHost(string gameName = @"") 226 228 { 227 229 Name = gameName; 230 + 231 + JsonConvert.DefaultSettings = () => new JsonSerializerSettings() 232 + { 233 + Converters = new List<JsonConverter>() 234 + { 235 + new Vector2Converter() 236 + } 237 + }; 228 238 } 229 239 230 240 /// <summary>