// Oleg Petruny proprietary.

#include "CameraModeBase.h"

#include "Camera/CameraComponent.h"
#include "EnhancedInputSubsystems.h"
#include "GameFramework/Character.h"
#include "GameFramework/PawnMovementComponent.h"
#include "InputMappingContext.h"
#include "Kismet/GameplayStatics.h"

#include "CustomGameSettings.h"
#include "CustomPlayerController.h"
#include "MainGameModeBase.h"

ACameraModeBase::ACameraModeBase()
{
    static ConstructorHelpers::FObjectFinder<UInputMappingContext> asset{ TEXT("/Script/EnhancedInput.InputMappingContext'/Game/Input/IMC_CameraMode.IMC_CameraMode'") };
    context = asset.Object;
    ACustomPlayerController::AppendInputContext(context);

    PrimaryActorTick.bCanEverTick = true;
}

void ACameraModeBase::BeginPlay()
{
    Super::BeginPlay();

    auto world = GetWorld();

    if(auto gameSettings = UCustomGameSettings::Get())
    {
        if(auto camera = FindComponentByClass<UCameraComponent>())
        {
            camera->PostProcessSettings.MotionBlurAmount = gameSettings->bUseMotionBlur ? 1.0f : 0.0f;
        }
    }
}

void ACameraModeBase::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    // stabilize move speed by fps
    AddActorLocalOffset(ConsumeMovementInputVector() * DeltaTime);
}

void ACameraModeBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);
}

void ACameraModeBase::SwitchToPlayerPawn()
{
    if(auto gamemode = AMainGameModeBase::Get())
        gamemode->SwitchCameraMode();
}

void ACameraModeBase::ElevatePawn(float value)
{
    AddMovementInput(FVector::UpVector, value);
}

void ACameraModeBase::SwitchRun(bool run)
{
    //if(run)
    //    GetMovement()->MaxWalkSpeed = moveSpeed * runSpeedMultiplier;
    //else
    //    GetCharacterMovement()->MaxWalkSpeed = moveSpeed;
}