Current section

Files

Jump to
manganese_serialization_kit lib structs assets unity_asset.ex
Raw

lib/structs/assets/unity_asset.ex

defmodule Manganese.SerializationKit.Structs.UnityAsset do
@moduledoc """
"""
alias Manganese.SerializationKit.Structs
alias Manganese.SerializationKit.Enumerations
@typedoc """
"""
@type id :: pos_integer
@typedoc """
"""
@type t :: %Structs.UnityAsset{
path: String.t,
id: id,
type: Enumerations.UnityAssetType.t
}
defstruct [
:path,
:id,
:type
]
# Deserialization
@doc """
"""
@spec from_map(t_external) :: t
def from_map(%{ "path" => path, "id" => id, "type" => type } = params) do
case Enumerations.UnityAssetType.from_integer type do
:text_asset -> Structs.UnityTextAsset.from_map params
:game_object -> Structs.UnityGameObjectAsset.from_map params
:material -> Structs.UnityMaterialAsset.from_map params
_ ->
%Structs.UnityAsset{
path: path,
id: id,
type: Enumerations.UnityAssetType.from_integer(type)
}
end
end
# Serialization
@type t_external :: map
@doc """
"""
@spec to_map(t) :: t_external
def to_map(asset) do
case asset.type do
:text_asset -> Structs.UnityTextAsset.to_map asset
:game_object -> Structs.UnityGameObjectAsset.to_map asset
:material -> Structs.UnityMaterialAsset.to_map asset
_ ->
%Structs.UnityAsset{
path: path,
id: id,
type: type
} = asset
%{
"path" => path,
"id" => id,
"type" => Enumerations.UnityAssetType.to_integer(type)
}
end
end
end