From 4ee7c80448217a4603d56a42297b8224219cc36e Mon Sep 17 00:00:00 2001 From: nsubiron Date: Thu, 26 Jul 2018 22:31:37 +0200 Subject: [PATCH] Helpers for building vehicle definitions --- .../Actor/ActorBlueprintFunctionLibrary.cpp | 65 +++++++++++++++++++ .../Actor/ActorBlueprintFunctionLibrary.h | 33 ++++++++++ 2 files changed, 98 insertions(+) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp index 658f1ad0b..221a5f147 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp @@ -149,6 +149,20 @@ private: FScopedStack Stack; }; +template +static FString JoinStrings(const FString &Separator, ARGS && ... Args) { + return FString::Join(TArray{std::forward(Args)...}, *Separator); +} + +static FString ColorToFString(const FColor &Color) +{ + return JoinStrings( + TEXT(","), + FString::FromInt(Color.R), + FString::FromInt(Color.G), + FString::FromInt(Color.B)); +} + bool UActorBlueprintFunctionLibrary::CheckActorDefinition(const FActorDefinition &ActorDefinition) { FActorDefinitionValidator Validator; @@ -160,3 +174,54 @@ bool UActorBlueprintFunctionLibrary::CheckActorDefinitions(const TArray +static void FillActorDefinitionArray( + const TArray &ParameterArray, + TArray &Definitions, + Functor Maker) +{ + for (auto &Item : ParameterArray) + { + FActorDefinition Definition; + bool Success = false; + Maker(Item, Success, Definition); + if (Success) + { + Definitions.Emplace(std::move(Definition)); + } + } +} + +void UActorBlueprintFunctionLibrary::MakeVehicleDefinitions( + const TArray &ParameterArray, + TArray &Definitions) +{ + FillActorDefinitionArray(ParameterArray, Definitions, &MakeVehicleDefinition); +} diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.h index bbdfb3d5b..b0afa1780 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.h @@ -7,11 +7,33 @@ #pragma once #include "Carla/Actor/ActorDefinition.h" +#include "Carla/Vehicle/CarlaWheeledVehicle.h" #include "Kismet/BlueprintFunctionLibrary.h" #include "ActorBlueprintFunctionLibrary.generated.h" +USTRUCT(BlueprintType) +struct CARLA_API FVehicleParameters +{ + GENERATED_BODY() + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString Make; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + FString Model; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + TSubclassOf Class; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + int32 NumberOfWheels = 4; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + TArray RecommendedColors; +}; + UCLASS() class UActorBlueprintFunctionLibrary : public UBlueprintFunctionLibrary { @@ -27,5 +49,16 @@ public: /// errors found. UFUNCTION(Category = "Carla Actor", BlueprintCallable) static bool CheckActorDefinitions(const TArray &ActorDefinitions); + + UFUNCTION(Category = "Carla Actor", BlueprintCallable) + static void MakeVehicleDefinition( + const FVehicleParameters &Parameters, + bool &Success, + FActorDefinition &Definition); + + UFUNCTION(Category = "Carla Actor", BlueprintCallable) + static void MakeVehicleDefinitions( + const TArray &ParameterArray, + TArray &Definitions); };