// Project Lab - NHTV Igad

#include "UnrealProject.h"
#include "FixupUtility.h"
#include "AbilityInfo.h"
#include "AssetRegistryInterface.h"
#include "AssetRegistryModule.h"
#include "SpawnerBase.h"

void UFixupUtility::FixupAbilityInfos()
{
	FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
	TArray<FAssetData> AssetData;
	FARFilter Filter;
	Filter.ClassNames.Add(UAbilityInfo::StaticClass()->GetFName());
	//Filter.PackagePaths.Add("/Content/Assets/Abilities");
	AssetRegistryModule.Get().GetAssets(Filter, AssetData);

	for(auto& d : AssetData)
	{
		UAbilityInfo* info = Cast<UAbilityInfo>(d.GetAsset());
		if(info)
		{
			GPRINT("Fixing up " + info->GetName());
			//info->actionType = info->isToggleAbility ? EAbilityActionType::Toggle : EAbilityActionType::Normal;
			//info->abilityCategory = EAbilityCategory::Unassigned;
			//info->Modify();
		}
	}
}
void UFixupUtility::FixAICastRanges(const FString& filter, float setRange, bool evenIfNotZero)
{
	FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
	TArray<FAssetData> AssetData;
	FARFilter Filter;
	Filter.ClassNames.Add(UAbilityInfo::StaticClass()->GetFName());
	//Filter.PackagePaths.Add("/Content/Assets/Abilities/Boss");
	if(filter.Len() > 0)
	{
		Filter.PackagePaths.Add(*filter);
	}
	AssetRegistryModule.Get().GetAssets(Filter, AssetData);

	for(auto& d : AssetData)
	{
		UAbilityInfo* info = Cast<UAbilityInfo>(d.GetAsset());
		if(info)
		{
			GPRINT("Fixing up AIRange on " + info->GetName());
			if(info->AICastRange == 0 || evenIfNotZero)
			{
				info->AICastRange = setRange;
				info->Modify();
			}
		}
	}
}
void UFixupUtility::FixupSpawners()
{
	UWorld* world = GEngine->GetWorld();
	if(world)
	{
		for(TActorIterator<ASpawnerBase> it(world); it; ++it)
		{
			ASpawnerBase* sp = *it;
			sp->displayMesh->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
		}
	}
}
void UFixupUtility::CrashTheEditor()
{
	uint32* funPointer = (uint32*)0x1;
	GPRINT(*funPointer);
}
