11 #include "Dom/JsonObject.h"    12 #include "Misc/FileHelper.h"    13 #include "Serialization/JsonReader.h"    14 #include "Serialization/JsonSerializer.h"    17   static const FString 
PATH = FPaths::ProjectContentDir();
    18   static const FString 
DEFAULT = TEXT(
"/Carla/Config/Default");
    24   static const FString 
NAME = TEXT(
"name");
    26   static const FString 
SIZE = TEXT(
"size");
    31   const UEnum *ptr = FindObject<UEnum>(ANY_PACKAGE, TEXT(
"EPropSize"), 
true);
    34     return FString(
"unknown");
    36   return ptr->GetNameStringByIndex(static_cast<int32>(PropSizeType));
    41   const UEnum *EnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT(
"EPropSize"), 
true);
    44     return (
EPropSize) EnumPtr->GetIndexByName(FName(*PropSize));
    46   return EPropSize::INVALID;
    51   TArray<TSharedPtr<FJsonValue>> ResultPropJsonArray;
    57   FFileHelper::LoadFileToString(JsonString, *DefaultPropFilePath);
    59   TSharedPtr<FJsonObject> JsonObject = MakeShareable(
new FJsonObject());
    60   TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(JsonString);
    63   TMap<FString, int> PropIndexes;
    64   if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
    67     for (int32 i = 0; i < ResultPropJsonArray.Num(); ++i)
    69       TSharedPtr<FJsonObject> PropJsonObject = ResultPropJsonArray[i]->AsObject();
    73       PropIndexes.Add(Name, i);
    78   for (
auto &PropParameter : PropParametersArray)
    80     TSharedPtr<FJsonObject> PropJsonObject;
    83     int *PropIndex = PropIndexes.Find(PropParameter.Name);
    86       PropJsonObject = ResultPropJsonArray[*PropIndex]->AsObject();
    90       PropJsonObject = MakeShareable(
new FJsonObject);
    99     TSharedRef<FJsonValue> PropJsonValue = MakeShareable(
new FJsonValueObject(PropJsonObject));
   102       ResultPropJsonArray[*PropIndex] = PropJsonValue;
   106       ResultPropJsonArray.Add(PropJsonValue);
   108       PropIndexes.Add(PropParameter.Name, ResultPropJsonArray.Num() - 1);
   116   FString OutputString;
   117   TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&OutputString);
   118   FJsonSerializer::Serialize(JsonObject.ToSharedRef(), Writer);
   121   FFileHelper::SaveStringToFile(OutputString, *DefaultPropFilePath);
   131   TArray<FString> PropFileNames;
   140   PropFileNames.Sort();
   141   FString DefaultFileName;
   142   for (int32 i = 0; i < PropFileNames.Num() && DefaultFileName.IsEmpty(); ++i)
   146       DefaultFileName = PropFileNames[i];
   147       PropFileNames.RemoveAt(i);
   150   if (!DefaultFileName.IsEmpty())
   152     PropFileNames.Insert(DefaultFileName, 0);
   157   TMap<FString, int> PropIndexes;
   159   for (int32 i = 0; i < PropFileNames.Num(); ++i)
   161     FString FileJsonContent;
   162     if (FFileHelper::LoadFileToString(FileJsonContent, *PropFileNames[i]))
   164       TSharedPtr<FJsonObject> JsonParsed;
   165       TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(FileJsonContent);
   166       if (FJsonSerializer::Deserialize(JsonReader, JsonParsed))
   170         for (
auto &PropJsonValue : PropJsonArray)
   173           TSharedPtr<FJsonObject> PropJsonObject = PropJsonValue->AsObject();
   180           UStaticMesh *PropMesh = LoadObject<UStaticMesh>(
nullptr, *PropMeshPath);
   185           if (PropIndexes.Contains(PropName))
   187             PropParametersArray[PropIndexes[PropName]] = Params;
   191             PropParametersArray.Add(Params);
   192             PropIndexes.Add(Params.Name, PropParametersArray.Num() - 1);
 static void AddToCarlaBlueprintRegistry(const TArray< FPropParameters > &PropParametersArray)
 
static const FString PATH
 
static const FString MESH_PATH
 
static EPropSize StringToPropSizeType(FString PropSize)
 
static const FString SIZE
 
static T Get(carla::rpc::Response< T > &response)
 
static const FString REGISTRY_FORMAT
 
static void LoadPropDefinitions(TArray< FPropParameters > &PropParametersArray)
 
static const FString NAME
 
static const FString DEFAULT
 
static const FString DEFINITIONS
 
static FString PropSizeTypeToString(EPropSize PropSizeType)