defmodule Manganese.SerializationKit.Structs.UnityComponent do @moduledoc """ """ alias Manganese.SerializationKit.Structs alias Manganese.SerializationKit.Enumerations @typedoc """ """ @type id :: pos_integer @typedoc """ """ @type t :: %Structs.UnityComponent{ id: id, type: Enumerations.UnityComponentType.t } defstruct [ :id, :type ] # Deserialization @doc """ """ @spec from_map(t_external) :: t def from_map(%{ "id" => id, "type" => type } = params) do type = Enumerations.UnityComponentType.from_integer type case type do :transform -> Structs.UnityTransformComponent.from_map params :box_collider -> Structs.UnityBoxColliderComponent.from_map params _ -> %Structs.UnityComponent{ id: id, type: type } end end # Serialization @type t_external :: map @doc """ """ @spec to_map(t) :: t_external def to_map(%Structs.UnityComponent{ id: id, type: type }) do %{ "id" => id, "type" => Enumerations.UnityComponentType.to_integer(type) } end def to_map(unity_component) do case unity_component.type do :transform -> Structs.UnityTransformComponent.to_map unity_component :box_collider -> Structs.UnityBoxColliderComponent.to_map unity_component end end end