using System; using Engine.Core; using YamlDotNet.Core; using YamlDotNet.Core.Events; using YamlDotNet.Serialization; namespace Engine.Serializers.Yaml; public class Matrix4x4Converter : EngineTypeYamlSerializerBase { private static readonly int SUBSTRING_START_LENGTH = nameof(Matrix4x4).Length + 1; public override Matrix4x4 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 Matrix4x4( float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]), float.Parse(values[3]), float.Parse(values[4]), float.Parse(values[5]), float.Parse(values[6]), float.Parse(values[7]), float.Parse(values[8]), float.Parse(values[9]), float.Parse(values[10]), float.Parse(values[11]), float.Parse(values[12]), float.Parse(values[13]), float.Parse(values[14]), float.Parse(values[15]) ); } public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer) { Matrix4x4 m = (Matrix4x4)value!; emitter.Emit(new Scalar($"{nameof(Matrix4x4)}({m.M11}, {m.M12}, {m.M13}, {m.M14},{m.M21}, {m.M22}, {m.M23}, {m.M24},{m.M31}, {m.M32}, {m.M33}, {m.M34},{m.M41}, {m.M42}, {m.M43}, {m.M44})")); } }