BREAKING CHANGE: moved yaml serialization from Engine.Serialization to Engine.Integration
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
|
||||
using Engine.Core;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Engine.Serializers.Yaml;
|
||||
|
||||
public class Vector2DConverter : EngineTypeYamlSerializerBase<Vector2D>
|
||||
{
|
||||
private static readonly int SUBSTRING_START_LENGTH = nameof(Vector2D).Length + 1;
|
||||
|
||||
public override Vector2D Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
|
||||
{
|
||||
string value = parser.Consume<Scalar>().Value;
|
||||
string insideParenthesis = value[SUBSTRING_START_LENGTH..^1];
|
||||
string[] values = insideParenthesis.Split(", ");
|
||||
return new Vector2D(float.Parse(values[0]), float.Parse(values[1]));
|
||||
}
|
||||
|
||||
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
Vector2D vector2D = (Vector2D)value!;
|
||||
emitter.Emit(new Scalar($"{nameof(Vector2D)}({vector2D.X}, {vector2D.Y})"));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user