64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "Integration.h"
|
|
#include "Common.h"
|
|
#include "Modules/ModuleManager.h"
|
|
|
|
#if WITH_EDITOR
|
|
#include "Engine/Blueprint.h"
|
|
#include "UObject/SavePackage.h"
|
|
#include "UObject/ObjectSaveContext.h"
|
|
#include "EdGraph/EdGraph.h"
|
|
#include "BlueprintExporter.h"
|
|
#include "Misc/FileHelper.h"
|
|
#endif
|
|
|
|
IMPLEMENT_PRIMARY_GAME_MODULE(FlxIntegrationModuleImpl, Integration, "Integration");
|
|
|
|
void FlxIntegrationModuleImpl::StartupModule()
|
|
{
|
|
#if WITH_EDITOR
|
|
OnAssetSavedHandle = UPackage::PackageSavedWithContextEvent.AddRaw(
|
|
this, &FlxIntegrationModuleImpl::OnAssetSaved);
|
|
#endif
|
|
}
|
|
|
|
void FlxIntegrationModuleImpl::ShutdownModule()
|
|
{
|
|
#if WITH_EDITOR
|
|
UPackage::PackageSavedWithContextEvent.Remove(OnAssetSavedHandle);
|
|
#endif
|
|
}
|
|
|
|
#if WITH_EDITOR
|
|
void FlxIntegrationModuleImpl::OnAssetSaved(const FString& PackageFilename, UPackage* Package, FObjectPostSaveContext Context)
|
|
{
|
|
if (!Package) return;
|
|
|
|
ForEachObjectWithPackage(Package, [&](UObject* Object)
|
|
{
|
|
if (UBlueprint* BP = Cast<UBlueprint>(Object))
|
|
{
|
|
FString BPDir = FPaths::ProjectDir() / TEXT("Saved") / TEXT("BlueprintExports") / BP->GetName();
|
|
|
|
IFileManager::Get().DeleteDirectory(*BPDir, false, true);
|
|
|
|
TArray<UEdGraph*> AllGraphs;
|
|
BP->GetAllGraphs(AllGraphs);
|
|
|
|
for (UEdGraph* Graph : AllGraphs)
|
|
{
|
|
FlxBlueprintExporter Exporter(Graph);
|
|
|
|
FString FilePath = BPDir / Graph->GetName() + TEXT(".txt");
|
|
FString DetailsPath = BPDir / TEXT("DETAILS") / Graph->GetName() + TEXT(".txt");
|
|
FFileHelper::SaveStringToFile(Exporter.GetOutput(), *FilePath);
|
|
FFileHelper::SaveStringToFile(Exporter.GetDetails(), *DetailsPath);
|
|
UE_LOG(LogLuprexIntegration, Warning, TEXT("Blueprint export: %s"), *FilePath);
|
|
}
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
#endif
|