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

#include "LightInteractionComponent.h"

namespace JamSpook {

LightInteractionComponent::LightInteractionComponent(mat4 transform,
                                                     shared_ptr<BroadcastObservable<shared_ptr<Message> > > entity,
                                                     weak_ptr<InteractionSystem> interactionSystem):
        InteractionComponent(transform, entity, interactionSystem),
        oldDirection(vec3(0))
{}

LightInteractionComponent::~LightInteractionComponent()
{}

void LightInteractionComponent::onInputDeviceStateChange(const InputDeviceState inputDeviceState)
{
    Log::write(LogLevel::debug, "PlayerInteractionComponent - onInputDeviceStateChange");

    vec3 accumulatedDirection = vec3(0);

    // Handle controls
    if (inputDeviceState.left == ButtonState::pressed)
    {
        accumulatedDirection += vec3(-1.0f, 0, 0);
        mTransform = translate(mTransform, accumulatedDirection);
    }
    if (inputDeviceState.right == ButtonState::pressed)
    {
        accumulatedDirection += vec3(1.0f, 0, 0);
        mTransform = translate(mTransform, accumulatedDirection);
    }
    if (inputDeviceState.up == ButtonState::pressed)
    {
        accumulatedDirection += vec3(0, 1.0f, 0);
    }
    if (inputDeviceState.down == ButtonState::pressed)
    {
        accumulatedDirection += vec3(0, -1.0f, 0);
    }
    if (inputDeviceState.action == ButtonState::pressed)
    {
        accumulatedDirection += vec3(0, 0.0f, 1.0f);
    }
//
//    if (inputDeviceState.up == ButtonState::released ||
//        inputDeviceState.down == ButtonState::released ||
//        inputDeviceState.left == ButtonState::released ||
//        inputDeviceState.right == ButtonState::released)
//    {
//        accumulatedDirection = vec3(0);
//    }

//    mTransform = translate(mTransform, accumulatedDirection);
    ICCBroadcast(dynamic_pointer_cast<Message>(make_shared<TransformChangeMessage>(mTransform)));

//    ICCBroadcast(dynamic_pointer_cast<Message>(make_shared<messages::DirectionChangeMessage>(getTranslation(mTransform),
//                                                                                             oldDirection,
//                                                                                             accumulatedDirection)));
//    oldDirection = accumulatedDirection;
}

void LightInteractionComponent::onICCMessage(shared_ptr<Message> message)
{
    InteractionComponent::onICCMessage(message);
}

} // namespace JamSpook
