Syntriax.Engine/Engine.Serialization/InternalExtensions.cs

37 lines
1.8 KiB
C#
Raw Normal View History

2024-02-09 17:50:39 +03:00
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)
2024-02-10 17:10:02 +03:00
=> new(transform.GetType().FullName ?? throw new System.Exception(), transform.Parent?.GameObject.Id, transform.Position, transform.Scale, transform.Rotation);
2024-02-09 17:50:39 +03:00
public static GameObjectDTO ToDTO(this IGameObject gameObject)
2024-02-10 17:10:02 +03:00
=> new(gameObject.GetType().FullName ?? throw new System.Exception(), gameObject.Id, gameObject.Name, gameObject.Transform.ToDTO(), gameObject.BehaviourController.ToDTO(), gameObject.StateEnable.ToDTO());
2024-02-09 17:50:39 +03:00
2024-02-10 20:02:38 +03:00
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);
}
2024-02-09 17:50:39 +03:00
public static StateEnableDTO ToDTO(this IStateEnable stateEnable)
=> new(stateEnable.GetType().FullName ?? throw new System.Exception(), stateEnable.Enabled);
2024-02-10 17:10:02 +03:00
public static BehaviourControllerDTO ToDTO(this IBehaviourController behaviourController)
2024-02-09 17:50:39 +03:00
{
List<BehaviourDTO> dtos = [];
foreach (var behaviour in behaviourController)
dtos.Add(new(behaviour.GetType().FullName ?? throw new System.Exception(), behaviour.Priority, behaviour.StateEnable.ToDTO()));
2024-02-10 17:10:02 +03:00
return new(behaviourController.GetType().FullName ?? throw new System.Exception(), dtos);
2024-02-09 17:50:39 +03:00
}
2024-02-10 17:10:02 +03:00
public static BehaviourDTO ToDTO(this IBehaviour behaviour)
=> new(behaviour.GetType().FullName ?? throw new System.Exception(), behaviour.Priority, behaviour.StateEnable.ToDTO());
2024-02-09 17:50:39 +03:00
}