10#include "Dom/JsonObject.h"
11#include "Misc/FileHelper.h"
12#include "Serialization/JsonReader.h"
13#include "Serialization/JsonSerializer.h"
17 static const FString
PATH = FPaths::ProjectContentDir();
18 static const FString
DEFAULT = TEXT(
"/Carla/Config/Default");
25 static const FString
NAME = TEXT(
"name");
27 static const FString
SIZE = TEXT(
"size");
33 const UEnum *ptr = FindObject<UEnum>(ANY_PACKAGE, TEXT(
"EPropSize"),
true);
36 return FString(
"unknown");
38 return ptr->GetNameStringByIndex(
static_cast<int32
>(PropSizeType));
44 const UEnum *EnumPtr = FindObject<UEnum>(ANY_PACKAGE, TEXT(
"EPropSize"),
true);
47 return (
EPropSize)EnumPtr->GetIndexByName(FName(*PropSize));
49 return EPropSize::INVALID;
55 TArray<TSharedPtr<FJsonValue>> ResultPropJsonArray;
60 FFileHelper::LoadFileToString(JsonString, *DefaultPropFilePath);
61 TSharedPtr<FJsonObject> JsonObject = MakeShareable(
new FJsonObject());
62 TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(JsonString);
64 TMap<FString, int> PropIndexes;
65 if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
71 for (int32 i = 0; i < ResultPropJsonArray.Num(); ++i)
73 TSharedPtr<FJsonObject> PropJsonObject = ResultPropJsonArray[i]->AsObject();
75 PropIndexes.Add(Name, i);
79 for (
auto &PropParameter : PropParametersArray)
81 TSharedPtr<FJsonObject> PropJsonObject;
83 int *PropIndex = PropIndexes.Find(PropParameter.Name);
86 PropJsonObject = ResultPropJsonArray[*PropIndex]->AsObject();
90 PropJsonObject = MakeShareable(
new FJsonObject);
97 TSharedRef<FJsonValue> PropJsonValue = MakeShareable(
new FJsonValueObject(PropJsonObject));
100 ResultPropJsonArray[*PropIndex] = PropJsonValue;
104 ResultPropJsonArray.Add(PropJsonValue);
105 PropIndexes.Add(PropParameter.Name, ResultPropJsonArray.Num() - 1);
113 FJsonSerializer::Serialize(JsonObject.ToSharedRef(),
Writer);
115 FFileHelper::SaveStringToFile(
OutputString, *DefaultPropFilePath);
121 TArray<FString> PropFileNames;
122 IFileManager::Get().FindFilesRecursive(PropFileNames,
129 PropFileNames.Sort();
130 FString DefaultFileName;
131 for (int32 i = 0; i < PropFileNames.Num() && DefaultFileName.IsEmpty(); ++i)
135 DefaultFileName = PropFileNames[i];
136 PropFileNames.RemoveAt(i);
139 if (!DefaultFileName.IsEmpty())
141 PropFileNames.Insert(DefaultFileName, 0);
145 TMap<FString, int> PropIndexes;
146 for (int32 i = 0; i < PropFileNames.Num(); ++i)
148 FString FileJsonContent;
149 if (FFileHelper::LoadFileToString(FileJsonContent, *PropFileNames[i]))
151 TSharedPtr<FJsonObject> JsonParsed;
152 TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(FileJsonContent);
153 if (FJsonSerializer::Deserialize(JsonReader, JsonParsed))
156 for (
auto &PropJsonValue : PropJsonArray)
159 TSharedPtr<FJsonObject> PropJsonObject = PropJsonValue->AsObject();
164 UStaticMesh *PropMesh = LoadObject<UStaticMesh>(
nullptr, *PropMeshPath);
168 if (PropIndexes.Contains(PropName))
170 PropParametersArray[PropIndexes[PropName]] = Params;
174 PropParametersArray.Add(Params);
175 PropIndexes.Add(Params.Name, PropParametersArray.Num() - 1);
static EPropSize StringToPropSizeType(FString PropSize)
TSharedRef< TJsonWriter<> > Writer
static FString PropSizeTypeToString(EPropSize PropSizeType)
static void AddToCarlaBlueprintRegistry(const TArray< FPropParameters > &PropParametersArray)
static void LoadPropDefinitions(TArray< FPropParameters > &PropParametersArray)
static const FString DEFINITIONS
static const FString DEFAULT
static const FString PATH
static const FString SIZE
static const FString MESH_PATH
static const FString NAME
static const FString REGISTRY_FORMAT