using System; using Engine.Serialization.DTOs; using Syntriax.Engine.Core; using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Factory; namespace Engine.Serialization; public static class Serialization { private static readonly ISerializer defaultSerializer = new YamlSerializer(); public static string SerializeGameObject(IGameObject gameObject) => Serialize(gameObject.ToDTO(), defaultSerializer); public static T DeserializeGameObject(string serializedString) where T : class, IGameObject { GameObjectDTO gameObjectDTO = Deserialize(serializedString, defaultSerializer); Type gameObjectType = (gameObjectDTO.ClassType is not null) ? TypeFactory.Get(gameObjectDTO.ClassType) : typeof(GameObject); T t = new GameObjectFactory().Instantiate(gameObjectType); return t; } public static string Serialize(T @object) => Serialize(@object, defaultSerializer); public static string Serialize(T @object, ISerializer serializer) => serializer.Serialize(@object); public static T Deserialize(string serializedString) => Deserialize(serializedString, defaultSerializer); public static T Deserialize(string serializedString, ISerializer serializer) => serializer.Deserialize(serializedString); }