29 lines
		
	
	
		
			1009 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			1009 B
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
 | 
						|
using Engine.Core;
 | 
						|
 | 
						|
using YamlDotNet.Core;
 | 
						|
using YamlDotNet.Core.Events;
 | 
						|
using YamlDotNet.Serialization;
 | 
						|
 | 
						|
namespace Engine.Serializers.Yaml;
 | 
						|
 | 
						|
public class Vector3DIntConverter : EngineTypeYamlSerializerBase<Vector3DInt>
 | 
						|
{
 | 
						|
    private static readonly int SUBSTRING_START_LENGTH = nameof(Vector3DInt).Length + 1;
 | 
						|
 | 
						|
    public override Vector3DInt 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 Vector3DInt(int.Parse(values[0]), int.Parse(values[1]), int.Parse(values[2]));
 | 
						|
    }
 | 
						|
 | 
						|
    public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
 | 
						|
    {
 | 
						|
        Vector3DInt vector3DInt = (Vector3DInt)value!;
 | 
						|
        emitter.Emit(new Scalar($"{nameof(Vector3DInt)}({vector3DInt.X}, {vector3DInt.Y}, {vector3DInt.Z})"));
 | 
						|
    }
 | 
						|
}
 |