10 #include "Misc/FileHelper.h" 12 #include "GenericPlatform/GenericPlatformProcess.h" 14 #include "Runtime/Core/Public/HAL/FileManagerGeneric.h" 15 #include "Misc/FileHelper.h" 19 FString MapName = InMapName;
25 FString CorrectedMapName = MapName;
26 constexpr
auto PIEPrefix = TEXT(
"UEDPIE_0_");
27 CorrectedMapName.RemoveFromStart(PIEPrefix);
28 MapName = CorrectedMapName;
32 MapName += TEXT(
".xodr");
34 const FString DefaultFilePath =
35 FPaths::ProjectContentDir() +
36 TEXT(
"Carla/Maps/OpenDrive/") +
41 if (FileManager.FileExists(*DefaultFilePath))
43 return DefaultFilePath;
46 TArray<FString> FilesFound;
47 FileManager.FindFilesRecursive(
49 *FPaths::ProjectContentDir(),
55 return FilesFound.Num() > 0 ? FilesFound[0u] : FString{};
60 auto MapName = World->GetMapName();
66 FString CorrectedMapName = MapName;
67 constexpr
auto PIEPrefix = TEXT(
"UEDPIE_0_");
68 CorrectedMapName.RemoveFromStart(PIEPrefix);
69 MapName = CorrectedMapName;
76 const auto FolderDir = MapDir +
"/OpenDrive/";
77 const auto FileName = MapDir.EndsWith(MapName) ?
"*" : MapName;
80 TArray<FString> Files;
81 IFileManager::Get().FindFilesRecursive(Files, *FolderDir, *FString(FileName +
".xodr"),
true,
false,
false);
87 UE_LOG(LogTemp, Error, TEXT(
"Failed to find OpenDrive file for map '%s'"), *MapName);
89 else if (FFileHelper::LoadFileToString(Content, *Files[0]))
91 UE_LOG(LogTemp, Log, TEXT(
"Loaded OpenDrive file '%s'"), *Files[0]);
95 UE_LOG(LogTemp, Error, TEXT(
"Failed to load OpenDrive file '%s'"), *Files[0]);
107 if (FilePath.IsEmpty())
109 UE_LOG(LogTemp, Error, TEXT(
"Failed to find OpenDrive file for map '%s'"), *MapName);
111 else if (FFileHelper::LoadFileToString(Content, *FilePath))
113 UE_LOG(LogTemp, Log, TEXT(
"Loaded OpenDrive file '%s'"), *FilePath);
117 UE_LOG(LogTemp, Error, TEXT(
"Failed to load OpenDrive file '%s'"), *FilePath);
129 FString CorrectedMapName = MapName;
130 constexpr
auto PIEPrefix = TEXT(
"UEDPIE_0_");
131 CorrectedMapName.RemoveFromStart(PIEPrefix);
132 MapName = CorrectedMapName;
134 #endif // WITH_EDITOR 136 FString FileName = XODRPath.EndsWith(MapName) ?
"*" : MapName;
137 FString FolderDir = XODRPath;
138 FolderDir.RemoveFromEnd(MapName +
".xodr");
141 TArray<FString> Files;
142 IFileManager::Get().FindFilesRecursive(Files, *FolderDir, *FString(FileName +
".xodr"),
true,
false,
false);
148 UE_LOG(LogTemp, Error, TEXT(
"Failed to find OpenDrive file for map '%s'"), *MapName);
150 else if (FFileHelper::LoadFileToString(Content, *Files[0]))
152 UE_LOG(LogTemp, Log, TEXT(
"Loaded OpenDrive file '%s'"), *Files[0]);
161 auto XODRContent =
LoadXODR(MapName);
162 if (!XODRContent.IsEmpty())
164 Map = NewObject<UOpenDriveMap>();
165 Map->
Load(XODRContent);
172 UWorld *World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
173 return World !=
nullptr ?
static FString LoadXODR(const FString &MapName)
static FString FindPathToXODRFile(const FString &InMapName)
static T Get(carla::rpc::Response< T > &response)
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
static FString GetXODRByPath(FString XODRPath, FString MapName)
Return the OpenDrive XML associated to MapName, or empty if the file is not found.
Helper class for exposing CARLA OpenDrive API to blueprints.
static FString GetXODR(const UWorld *World)
Return the OpenDrive XML associated to MapName, or empty if the file is not found.
static UOpenDriveMap * LoadOpenDriveMap(const FString &MapName)
Load OpenDriveMap associated to the given MapName.
Base class for the CARLA Game Mode.
bool Load(const FString &XODRContent)
Load this map with an OpenDrive (XODR) file.
const FString GetFullMapPath() const
static UOpenDriveMap * LoadCurrentOpenDriveMap(const UObject *WorldContextObject)
Load OpenDriveMap associated to the currently loaded map.