// Fill out your copyright notice in the Description page of Project Settings.

#include "Ammo.h"

// Paper2D plugin headers.
#include "PaperFlipbook.h"
#include "PaperFlipbookComponent.h"

FSingleRound::FSingleRound()
{
	RoundColor = EAmmoColour::Red;
	Spread = false;
}

EAmmoColour FSingleRound::GetRoundColor()
{
	return RoundColor;
}

void FSingleRound::SetRoundColor(EAmmoColour NewColor)
{
	RoundColor = NewColor;
}

bool FSingleRound::GetSpread()
{
	return Spread;
}

void FSingleRound::SetSpread(bool NewSpread)
{
	Spread = NewSpread;
}

FString FSingleRound::ToString()
{
	return UEnum::GetValueAsString<EAmmoColour>(RoundColor);
}

/// struct SingleRound

AAmmo::AAmmo() : LeftRound(), RightRound(), ObjectName(GetName())
{
	PrimaryActorTick.bCanEverTick = true;

	RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));

	

	LeftPaperFlipbook = CreateDefaultSubobject<UPaperFlipbookComponent>(TEXT("LeftPaperFlipbook"));
	LeftPaperFlipbook->SetupAttachment(RootComponent);
	

	RightPaperFlipbook = CreateDefaultSubobject<UPaperFlipbookComponent>(TEXT("RightPaperFlipbook"));
	RightPaperFlipbook->SetupAttachment(RootComponent);
	
}

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

	FVector AmmoLocation = GetActorLocation();
	LeftPaperFlipbook->SetWorldLocation(FVector(AmmoLocation.X, AmmoLocation.Y - 225, AmmoLocation.Z));
	RightPaperFlipbook->SetWorldLocation(FVector(AmmoLocation.X, AmmoLocation.Y + 225, AmmoLocation.Z));
}

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

}

FString AAmmo::ToString()
{
	return "{" + LeftRound.ToString() + "|" + RightRound.ToString() + "}";
}

FSingleRound* AAmmo::GetLeftRound()
{
	return &LeftRound;
}

FSingleRound* AAmmo::GetRightRound() 
{
	return &RightRound;
}

UPaperFlipbookComponent* AAmmo::GetLeftPaperFlipbook()
{
	return LeftPaperFlipbook;
}

UPaperFlipbookComponent* AAmmo::GetRightPaperFlipbook()
{
	return RightPaperFlipbook;
}
