using System; using Engine.Core; using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Serialization; namespace Engine.Serializers.Yaml; public class Vector2DIntConverter : EngineTypeYamlSerializerBase { private static readonly int SUBSTRING_START_LENGTH = nameof(Vector2DInt).Length + 1; public override Vector2DInt Read(IParser parser, Type type, ObjectDeserializer rootDeserializer) { string value = parser.Consume().Value; string insideParenthesis = value[SUBSTRING_START_LENGTH..^1]; string[] values = insideParenthesis.Split(", "); return new Vector2DInt(int.Parse(values[0]), int.Parse(values[1])); } public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer) { Vector2DInt vector2DInt = (Vector2DInt)value!; emitter.Emit(new Scalar($"{nameof(Vector2DInt)}({vector2DInt.X}, {vector2DInt.Y})")); } }