Fixed file transfer file paths

This commit is contained in:
Axel 2021-07-27 11:33:56 +02:00 committed by bernat
parent fb30cbafac
commit daf269dd94
4 changed files with 20 additions and 11 deletions

View File

@ -50,11 +50,19 @@ ACarlaGameModeBase::ACarlaGameModeBase(const FObjectInitializer& ObjectInitializ
CarlaSettingsDelegate = CreateDefaultSubobject<UCarlaSettingsDelegate>(TEXT("CarlaSettingsDelegate"));
}
const FString ACarlaGameModeBase::GetMapPath() const
const FString ACarlaGameModeBase::GetRelativeMapPath() const
{
UWorld* World = GetWorld();
TSoftObjectPtr<UWorld> AssetPtr (World);
return AssetPtr.GetLongPackageName();
FString Path = FPaths::GetPath(AssetPtr.GetLongPackageName());
Path.RemoveFromStart("/Game/");
return Path;
}
const FString ACarlaGameModeBase::GetFullMapPath() const
{
FString Path = GetRelativeMapPath();
return FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()) + Path;
}
void ACarlaGameModeBase::InitGame(

View File

@ -48,7 +48,10 @@ public:
return Map;
}
const FString GetMapPath() const;
const FString GetFullMapPath() const;
// get path relative to Content folder
const FString GetRelativeMapPath() const;
UFUNCTION(Exec, Category = "CARLA Game Mode")
void DebugShowSignals(bool enable);

View File

@ -70,9 +70,7 @@ FString UOpenDrive::GetXODR(const UWorld *World)
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(World);
auto RelativePath = FPaths::GetPath(GameMode->GetMapPath());
RelativePath.RemoveFromStart("/Game/");
auto MapDir = FPaths::ProjectContentDir() + RelativePath;
auto MapDir = GameMode->GetFullMapPath();
const auto FolderDir = MapDir + "/OpenDrive/";
const auto FileName = MapDir.EndsWith(MapName) ? "*" : MapName;

View File

@ -343,7 +343,7 @@ void FCarlaServer::FPimpl::BindActions()
REQUIRE_CARLA_EPISODE();
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
const auto &SpawnPoints = Episode->GetRecommendedSpawnPoints();
FString FullMapPath = FPaths::GetPath(GameMode->GetMapPath());
FString FullMapPath = GameMode->GetFullMapPath();
FString MapDir = FullMapPath.RightChop(FullMapPath.Find("Content/", ESearchCase::CaseSensitive) + 8);
MapDir += "/" + Episode->GetMapName();
return cr::MapInfo{
@ -378,14 +378,14 @@ void FCarlaServer::FPimpl::BindActions()
// Get the map's folder absolute path and check if it's in its own folder
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
const auto mapDir = FPaths::GetPath(GameMode->GetMapPath());
const auto folderDir = mapDir + "/" + folder.c_str();
const auto mapDir = GameMode->GetFullMapPath();
const auto folderDir = mapDir + folder.c_str();
const auto fileName = mapDir.EndsWith(Episode->GetMapName()) ? "*" : Episode->GetMapName();
// Find all the xodr and bin files from the map
TArray<FString> Files;
IFileManager::Get().FindFilesRecursive(Files, *folderDir, *FString(fileName + ".xodr"), true, false, false);
IFileManager::Get().FindFilesRecursive(Files, *folderDir, *FString(fileName + ".bin"), true, false, false);
IFileManager::Get().FindFilesRecursive(Files, *folderDir, *(fileName + ".xodr"), true, false, false);
IFileManager::Get().FindFilesRecursive(Files, *folderDir, *(fileName + ".bin"), true, false, false);
// Remove the start of the path until the content folder and put each file in the result
std::vector<std::string> result;