Syntriax.Engine/Engine.Serialization/InternalExtensions.cs

37 lines
1.8 KiB
C#

using System.Collections.Generic;
using Engine.Serialization.DTOs;
using Syntriax.Engine.Core.Abstract;
namespace Engine.Serialization;
internal static class InternalExtensions
{
public static TransformDTO ToDTO(this ITransform transform)
=> new(transform.GetType().FullName ?? throw new System.Exception(), transform.Parent?.GameObject.Id, transform.Position, transform.Scale, transform.Rotation);
public static GameObjectDTO ToDTO(this IGameObject gameObject)
=> new(gameObject.GetType().FullName ?? throw new System.Exception(), gameObject.Id, gameObject.Name, gameObject.Transform.ToDTO(), gameObject.BehaviourController.ToDTO(), gameObject.StateEnable.ToDTO());
public static GameManagerDTO ToDTO(this IGameManager gameManager)
{
List<GameObjectDTO> dtos = [];
foreach (var gameObject in gameManager)
dtos.Add(gameObject.ToDTO());
return new(gameManager.GetType().FullName ?? throw new System.Exception(), dtos);
}
public static StateEnableDTO ToDTO(this IStateEnable stateEnable)
=> new(stateEnable.GetType().FullName ?? throw new System.Exception(), stateEnable.Enabled);
public static BehaviourControllerDTO ToDTO(this IBehaviourController behaviourController)
{
List<BehaviourDTO> dtos = [];
foreach (var behaviour in behaviourController)
dtos.Add(new(behaviour.GetType().FullName ?? throw new System.Exception(), behaviour.Priority, behaviour.StateEnable.ToDTO()));
return new(behaviourController.GetType().FullName ?? throw new System.Exception(), dtos);
}
public static BehaviourDTO ToDTO(this IBehaviour behaviour)
=> new(behaviour.GetType().FullName ?? throw new System.Exception(), behaviour.Priority, behaviour.StateEnable.ToDTO());
}