Commandlet iterates over all tiles of the map.

This commit is contained in:
JoseMartinez 2024-02-19 18:47:27 +01:00
parent 2566839481
commit 5011f248da
2 changed files with 47 additions and 26 deletions

View File

@ -16,6 +16,8 @@
#include "EditorLevelLibrary.h" #include "EditorLevelLibrary.h"
#include "MapGen/LargeMapManager.h" #include "MapGen/LargeMapManager.h"
DEFINE_LOG_CATEGORY(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet); DEFINE_LOG_CATEGORY(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet);
@ -42,41 +44,33 @@ int32 USetProperPositionForWorldPartitionCommandlet::Main(const FString &Params)
ParseCommandLine(*Params, Tokens, Switches, ParamsMap ); ParseCommandLine(*Params, Tokens, Switches, ParamsMap );
FString BaseLevelName = ParamsMap["BaseLevelName"]; FString BaseLevelName = ParamsMap["BaseLevelName"];
FIntVector CurrentTilesInXY = FIntVector(FCString::Atof(*ParamsMap["CTileX"]),FCString::Atof(*ParamsMap["CTileY"]), 0);
UEditorLevelLibrary::LoadLevel(*BaseLevelName); UEditorLevelLibrary::LoadLevel(*BaseLevelName);
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Valid Map loaded")); UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Valid Map loaded, MapName %s"), *BaseLevelName);
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("MapName %s"), *BaseLevelName);
AActor* QueryActor = UGameplayStatics::GetActorOfClass( GEditor->GetEditorWorldContext().World(), ALargeMapManager::StaticClass()); AActor* QueryActor = UGameplayStatics::GetActorOfClass( GEditor->GetEditorWorldContext().World(), ALargeMapManager::StaticClass());
if (QueryActor != nullptr) { if (QueryActor != nullptr) {
ALargeMapManager* LmManager = Cast<ALargeMapManager>(QueryActor); ALargeMapManager* LmManager = Cast<ALargeMapManager>(QueryActor);
FIntVector NumTilesInXY = LmManager->GetNumTilesInXY();
float TileSize = LmManager->GetTileSize(); const FIntVector NumTilesInXY = LmManager->GetNumTilesInXY();
FVector Tile0Offset = LmManager->GetTile0Offset(); const float TileSize = LmManager->GetTileSize();
FCarlaMapTile& CarlaTile = LmManager->GetCarlaMapTile(CurrentTilesInXY);
UEditorLevelLibrary::SaveCurrentLevel();
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Current Tile is %s"), *(CurrentTilesInXY.ToString()));
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("NumTilesInXY is %s"), *(NumTilesInXY.ToString())); UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("NumTilesInXY is %s"), *(NumTilesInXY.ToString()));
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("TileSize is %f"), (TileSize)); UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("TileSize is %f"), (TileSize));
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Tile0Offset is %s"), *(Tile0Offset.ToString()));
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Tile Name is %s"), *(CarlaTile.Name)); UEditorLevelLibrary::SaveCurrentLevel();
UEditorLevelLibrary::LoadLevel(CarlaTile.Name); for(int TileX = 0; TileX < NumTilesInXY.X; TileX++)
FVector MinPosition = FVector(CurrentTilesInXY.X * TileSize, CurrentTilesInXY.Y * -TileSize, 0.0f);
FVector MaxPosition = FVector((CurrentTilesInXY.X + 1.0f) * TileSize, (CurrentTilesInXY.Y + 1.0f) * -TileSize, 0.0f);
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GEditor->GetEditorWorldContext().World(), AActor::StaticClass(), FoundActors);
for (AActor* CA : FoundActors)
{ {
CA->AddActorWorldOffset(MinPosition, false, nullptr, ETeleportType::ResetPhysics); for(int TileY = 0; TileY < NumTilesInXY.Y; TileY++)
{
if(TileX != 0 || TileY != 0)
{
UEditorLevelLibrary::LoadLevel(*BaseLevelName);
UEditorLevelLibrary::SaveCurrentLevel();
ProcessTile(FIntVector(TileX, TileY, 0), TileSize);
}
}
} }
} }
else { else {
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Error, TEXT("Largemapmanager not found ")); UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Error, TEXT("Largemapmanager not found "));
@ -88,4 +82,29 @@ int32 USetProperPositionForWorldPartitionCommandlet::Main(const FString &Params)
return 0; return 0;
} }
void USetProperPositionForWorldPartitionCommandlet::ProcessTile(const FIntVector CurrentTilesInXY, const float TileSize)
{
AActor* QueryActor = UGameplayStatics::GetActorOfClass( GEditor->GetEditorWorldContext().World(), ALargeMapManager::StaticClass());
if (QueryActor != nullptr)
{
ALargeMapManager* LmManager = Cast<ALargeMapManager>(QueryActor);
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Current Tile is %s"), *(CurrentTilesInXY.ToString()));
const FCarlaMapTile& CarlaTile = LmManager->GetCarlaMapTile(CurrentTilesInXY);
UE_LOG(LogCarlaToolsMapSetProperPositionForWorldPartitionCommandlet, Warning, TEXT("Tile Name is %s"), *(CarlaTile.Name));
UEditorLevelLibrary::LoadLevel(CarlaTile.Name);
const FVector MinPosition = FVector(CurrentTilesInXY.X * TileSize, CurrentTilesInXY.Y * -TileSize, 0.0f);
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GEditor->GetEditorWorldContext().World(), AActor::StaticClass(), FoundActors);
for (AActor* CA : FoundActors)
{
CA->AddActorWorldOffset(MinPosition, false, nullptr, ETeleportType::ResetPhysics);
}
UEditorLevelLibrary::SaveCurrentLevel();
}
}
#endif #endif

View File

@ -38,5 +38,7 @@ public:
virtual int32 Main(const FString &Params) override; virtual int32 Main(const FString &Params) override;
void ProcessTile(const FIntVector CurrentTilesInXY, const float TileSize);
#endif // WITH_EDITORONLY_DATA #endif // WITH_EDITORONLY_DATA
}; };