// Copyright (c) 2024 Codemongous LLC. All Rights Reserved.

#include "SCW_AActor.h"
#include "GameFramework/Actor.h"
#include "SourcifyCoreUEWrapperModule.h"

using namespace Sourcify;

SCW_AActor::SCW_AActor(AActor* InActor) : SCW_UObject(InActor), Actor(InActor)
{

}

void SCW_AActor::Destroy()
{
	Actor->Destroy();
}

void SCW_AActor::GetComponents(vector<ISCW_UActorComponentPtr>& OutComponents, bool bIncludeFromChildActors/* = false*/) const
{
	// Gathering pointers so safe to call UE native function then wrap those results
	TArray<UActorComponent*> UEComponents;
	Actor->GetComponents(UEComponents, bIncludeFromChildActors);

	// Wrap results
	OutComponents.clear();
	OutComponents.reserve(UEComponents.Num());
	for (UActorComponent* UEComponent : UEComponents)
	{
		OutComponents.push_back(FSourcifyCoreUEWrapper::Get().Wrap(*UEComponent));
	}
}

ISCW_USceneComponentPtr SCW_AActor::GetRootComponent() const
{
	return FSourcifyCoreUEWrapper::Get().Wrap(*Actor->GetRootComponent());
}

void SCW_AActor::PostEditMove(bool bFinished)
{
	Actor->PostEditMove(bFinished);
}

void SCW_AActor::RerunConstructionScripts() const
{
	Actor->RerunConstructionScripts();
}

AActor* SCW_AActor::ToAActor() const
{
	return Actor;
}

ISCW_AActorPtr SCW_AActor::ToAActorPtr()
{
	return GetSharedThisAs<SCW_AActor>();
}

ISCW_AActorConstPtr SCW_AActor::ToAActorPtr() const
{
	return GetSharedThisAs<SCW_AActor>();
}

