/*
 * LightPhysicsComponent.cpp
 *
 *  Created on: Oct 9, 2019
 *      Author: fredrick
 */

#include "LightPhysicsComponent.h"

namespace JamSpook {

LightPhysicsComponent::LightPhysicsComponent(mat4 transform,
                                             shared_ptr<BroadcastObservable<shared_ptr<Message> > > entity,
                                             weak_ptr<BroadcastObservable<const milliseconds> > physicsSystem,
                                             weak_ptr<BroadcastObservable<shared_ptr<CollisionStateChangeMessage> > > physicsCollisionSubSystem,
                                             weak_ptr<BroadcastObservable<shared_ptr<ColliderQueryMessage> > > physicsColliderQuerySubSystem,
                                             shared_ptr<Collider> collider):
        PhysicsComponent(transform,
                         entity,
                         physicsSystem,
                         physicsCollisionSubSystem,
                         physicsColliderQuerySubSystem,
                         collider)
{}

LightPhysicsComponent::~LightPhysicsComponent()
{}

void LightPhysicsComponent::update(const milliseconds dtms)
{
//    Log::write(LogLevel::trace, "CollectablePhysicsComponent - update");
    PhysicsComponent::update(dtms);
}

void LightPhysicsComponent::onICCMessage(shared_ptr<Message> message)
{
    PhysicsComponent::onICCMessage(message);

    // DirectionChangeMessage
    if (message->getMessageType() == IDCache::get("DirectionChangeMessage"))
    {
        Log::write(LogLevel::debug, "PlayerPhysicsComponent - onICCMessage - DirectionChangeMessage");

        shared_ptr<messages::DirectionChangeMessage> msg = dynamic_pointer_cast<messages::DirectionChangeMessage>(message);
        if (msg->getNewDirection() != vec3(0,0,0))
        {
            mDirection = msg->getNewDirection();

            mCollider->setLinearVelocity(msg->getNewDirection()*4.0f);

//            Log::write(LogLevel::trace, "PlayerPhysicsComponent - onICCMessage - DirectionChangeMessage - " + glm::to_string(msg->getNewDirection()*4.0f));
//            BroadcastObservable<const vec3, const vec3>::broadcast(msg->getPosition(), msg->getNewDirection());
        }
    }
}

void LightPhysicsComponent::onCollision(const string& tag)
{
    // nothing
}

} // namespace JamSpook
