#include "LightComponent.h"

LightComponent::LightComponent(Object* owner)
    : Component(owner) {}

void LightComponent::Save(YAML::Emitter& out) const
{
    out << YAML::BeginMap;
    out << YAML::Key << "type"     << YAML::Value << "LightComponent";
    out << YAML::Key << "color"    << YAML::Value << std::vector<float>{ m_Color.r, m_Color.g, m_Color.b };
    out << YAML::Key << "intensity" << YAML::Value << m_Intensity;
    out << YAML::Key << "radius"    << YAML::Value << m_Radius;
    out << YAML::Key << "falloff"   << YAML::Value << m_Falloff;
    out << YAML::Key << "type"   << YAML::Value << m_type;

    out << YAML::EndMap;
}


void LightComponent::Load(const YAML::Node& node)
{
    if (node["color"])
    {
        auto vec = node["color"].as<std::vector<float>>();
        if (vec.size() == 3)
            m_Color = glm::vec3(vec[0], vec[1], vec[2]);
    }
    if (node["intensity"]) m_Intensity = node["intensity"].as<float>();
    if (node["radius"])    m_Radius = node["radius"].as<float>();
    if (node["falloff"])   m_Falloff = node["falloff"].as<float>();
    if (node["light_type"])m_type = node["light_type"].as<int>();

}
