chore: moved primitive converters under subfolder
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using Syntriax.Engine.Core;
|
||||
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Core.Events;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Syntriax.Engine.Serialization;
|
||||
|
||||
public class QuaternionConverter : IEngineTypeYamlConverter
|
||||
{
|
||||
private static readonly int SUBSTRING_START_LENGTH = nameof(Quaternion).Length + 1;
|
||||
|
||||
public bool Accepts(Type type) => type == typeof(Quaternion);
|
||||
|
||||
public object? ReadYaml(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 Quaternion(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]), float.Parse(values[3]));
|
||||
}
|
||||
|
||||
public void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
|
||||
{
|
||||
Quaternion quaternion = (Quaternion)value!;
|
||||
emitter.Emit(new Scalar($"{nameof(Quaternion)}({quaternion.X}, {quaternion.Y}, {quaternion.Z}, {quaternion.W})"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user