using YamlDotNet.Serialization; using YamlDotNet.Serialization.NamingConventions; namespace Engine.Serialization; public class YamlSerializer : ISerializer { private readonly YamlDotNet.Serialization.ISerializer serializer = new SerializerBuilder() .WithNamingConvention(CamelCaseNamingConvention.Instance) .WithTypeConverter(new BehaviourYamlConverter()) .WithTypeConverter(new BehaviourControllerYamlConverter()) .WithTypeConverter(new BehaviourDTOListConverter()) .WithTypeConverter(new GameManagerYamlConverter()) .WithTypeConverter(new GameObjectYamlConverter()) .WithTypeConverter(new GameObjectDTOListConverter()) .WithTypeConverter(new StateEnableYamlConverter()) .WithTypeConverter(new TransformYamlConverter()) .WithTypeConverter(new Vector2DYamlConverter()) .Build(); private readonly YamlDotNet.Serialization.IDeserializer deserializer = new DeserializerBuilder() .WithNamingConvention(UnderscoredNamingConvention.Instance) .WithTypeConverter(new BehaviourYamlConverter()) .WithTypeConverter(new BehaviourControllerYamlConverter()) .WithTypeConverter(new BehaviourDTOListConverter()) .WithTypeConverter(new GameManagerYamlConverter()) .WithTypeConverter(new GameObjectYamlConverter()) .WithTypeConverter(new GameObjectDTOListConverter()) .WithTypeConverter(new StateEnableYamlConverter()) .WithTypeConverter(new TransformYamlConverter()) .WithTypeConverter(new Vector2DYamlConverter()) .Build(); public string Serialize(T @object) => serializer.Serialize(@object); public T Deserialize(string serializedString) => deserializer.Deserialize(serializedString); }