4#include "Misc/FileHelper.h"
5#include "UObject/EnumProperty.h"
20 bool bInDontWriteEmptyContainer) :
21 ComplexNamePrefix(InComplexNamePrefix),
22 bDontWriteEmptyContainer(bInDontWriteEmptyContainer)
36 const FString& PreString,
37 const FString& PostString,
40 if (StructDefinition ==
nullptr)
46 TArray<const FNYProperty*> Primitives;
47 TArray<const FNYProperty*> PrimitiveContainers;
48 TArray<const FNYProperty*> ComplexElements;
49 TArray<const FNYProperty*> ComplexContainers;
51 constexpr int32 PropCategoryNum = 4;
52 TArray<const FNYProperty*>* PropCategory[PropCategoryNum] = { &Primitives, &PrimitiveContainers, &ComplexElements, &ComplexContainers };
55 if (StructDefinition->IsA<UClass>())
58 if (!UnrealObject->IsValidLowLevelFast())
63 StructDefinition = UnrealObject->GetClass();
65 if (!StructDefinition->IsValidLowLevelFast())
71 for (TFieldIterator<FNYProperty> It(StructDefinition); It; ++It)
73 const auto* Property = *It;
76 Primitives.Add(Property);
82 PrimitiveContainers.Add(Property);
86 ComplexContainers.Add(Property);
91 ComplexElements.Add(Property);
95 constexpr bool bContainerElement =
false;
96 for (int32 i = 0; i < PropCategoryNum; ++i)
98 for (
const auto* Prop : *PropCategory[i])
109 bool bContainerElement,
110 const FString& PreString,
111 const FString& PostString,
164 const FString& PostS,
168 if (WritePrimitiveElementToStringTemplated<FNYBoolProperty, bool>(Property,
Object, bInContainer,
BoolToString, PreS, PostS, Target))
172 if (WritePrimitiveElementToStringTemplated<FNYIntProperty, int32>(Property,
Object, bInContainer,
IntToString, PreS, PostS, Target))
176 if (WritePrimitiveElementToStringTemplated<FNYInt64Property, int64>(Property,
Object, bInContainer,
IntToString, PreS, PostS, Target))
180 if (WritePrimitiveElementToStringTemplated<FNYFloatProperty, float>(Property,
Object, bInContainer,
FloatToString, PreS, PostS, Target))
184 if (WritePrimitiveElementToStringTemplated<FNYStrProperty, FString>(Property,
Object, bInContainer,
StringToString, PreS, PostS, Target))
188 if (WritePrimitiveElementToStringTemplated<FNYNameProperty, FName>(Property,
Object, bInContainer,
NameToString, PreS, PostS, Target))
192 if (WritePrimitiveElementToStringTemplated<FNYTextProperty, FText>(Property,
Object, bInContainer,
TextToString, PreS, PostS, Target))
200 const auto* EnumProp = FNYReflectionHelper::CastProperty<FNYEnumProperty>(Property);
201 if (EnumProp !=
nullptr)
203 const void* Value = EnumProp->ContainerPtrToValuePtr<uint8>(
Object);
204 const FName EnumName = EnumProp->GetEnum()->GetNameByIndex(EnumProp->GetUnderlyingProperty()->GetSignedIntPropertyValue(Value));
205 Target += PreS + Property->GetName() +
" " +
NameToString(EnumName) + PostS;
216 const FString& PreString,
217 const FString& PostString,
220 const auto* ArrayProp = FNYReflectionHelper::CastProperty<FNYArrayProperty>(Property);
221 if (ArrayProp ==
nullptr)
227 if (WritePrimitiveArrayToStringTemplated<FNYBoolProperty, bool>(ArrayProp,
Object,
BoolToString, PreString, PostString, Target))
231 if (WritePrimitiveArrayToStringTemplated<FNYIntProperty, int32>(ArrayProp,
Object,
IntToString, PreString, PostString, Target))
235 if (WritePrimitiveArrayToStringTemplated<FNYInt64Property, int64>(ArrayProp,
Object,
IntToString, PreString, PostString, Target))
239 if (WritePrimitiveArrayToStringTemplated<FNYFloatProperty, float>(ArrayProp,
Object,
FloatToString, PreString, PostString, Target))
243 if (WritePrimitiveArrayToStringTemplated<FNYStrProperty, FString>(ArrayProp,
Object,
StringToString, PreString, PostString, Target))
247 if (WritePrimitiveArrayToStringTemplated<FNYNameProperty, FName>(ArrayProp,
Object,
NameToString, PreString, PostString, Target))
251 if (WritePrimitiveArrayToStringTemplated<FNYTextProperty, FText>(ArrayProp,
Object,
TextToString, PreString, PostString, Target))
262 bool bContainerElement,
263 const FString& PreString,
264 const FString& PostString,
268 if (Property ==
nullptr)
274 if (
const auto* StructProperty = FNYReflectionHelper::CastProperty<FNYStructProperty>(Property))
276 const void* StructObject = StructProperty->ContainerPtrToValuePtr<
void>(
Object, 0);
277 if (StructObject ==
nullptr)
294 if (
const auto* ObjectProperty = FNYReflectionHelper::CastProperty<FNYObjectProperty>(Property))
297 const FString Path = *ObjPtrPtr !=
nullptr ? (*ObjPtrPtr)->GetPathName() :
"";
298 auto WritePathName = [&]()
300 if (bContainerElement)
302 Target += PreString +
"\"" + Path +
"\"" + PostString;
306 Target += PreString + Property->GetName() +
" \"" + Path +
"\"" + PostString;
317 if (*ObjPtrPtr ==
nullptr || ObjectProperty->PropertyClass ==
nullptr)
342 const FString& PreString,
343 const FString& PostString,
344 bool bContainerElement,
354 if (bWriteType && !UnrealObject->IsValidLowLevelFast())
363 if (bContainerElement)
365 if (TypeString.Len() > 0)
367 Target += PreString + TypeString + (bLinePerMember ?
EOL + PreString +
"{" +
EOL :
"{ ");
371 Target += PreString + (bLinePerMember ?
"{" +
EOL_String :
"{ ");
376 Target += PreString + TypeString + Property->GetName() + (bLinePerMember ?
EOL + PreString +
"{" +
EOL :
" { ");
384 Target += PreString +
"}" + PostString;
388 Target +=
" }" + PostString;
395 const FString& PreString,
396 const FString& PostString,
399 const auto* ArrayProp = FNYReflectionHelper::CastProperty<FNYArrayProperty>(Property);
400 if (ArrayProp ==
nullptr)
404 if (FNYReflectionHelper::CastProperty<FNYStructProperty>(ArrayProp->Inner) ==
nullptr
405 && FNYReflectionHelper::CastProperty<FNYObjectProperty>(ArrayProp->Inner) ==
nullptr)
418 FString TypeText =
"";
419 auto* ObjProp = FNYReflectionHelper::CastProperty<FNYObjectProperty>(ArrayProp->Inner);
420 if (ObjProp !=
nullptr && ObjProp->PropertyClass !=
nullptr)
427 Target += PreString + TypeText + ArrayProp->Inner->GetName() +
" {";
428 for (int32 i = 0; i < Helper.Num(); ++i)
432 Target +=
" }" + PostString;
436 Target += PreString + TypeText + ArrayProp->Inner->GetName() +
EOL;
437 Target += PreString +
"{" +
EOL;
438 for (int32 i = 0; i < Helper.Num(); ++i)
442 Target += PreString +
"\t// " + FString::FromInt(i) +
EOL;
446 Target += PreString +
"}" +
EOL;
455 const FString& PreString,
456 const FString& PostString,
459 const auto* MapProp = FNYReflectionHelper::CastProperty<FNYMapProperty>(Property);
460 if (MapProp ==
nullptr)
476 Target += PreString + MapProp->GetName() +
" { ";
480 for (int32 i = 0; i < Helper.GetMaxIndex(); ++i)
482 if (!Helper.IsValidIndex(i))
490 Target +=
"}" + PostString;
495 Target += PreString + MapProp->GetName() +
EOL;
496 Target += PreString +
"{" +
EOL;
500 for (int32 i = 0; i < Helper.GetMaxIndex(); ++i)
502 if (!Helper.IsValidIndex(i))
510 Target += PreString +
"}" +
EOL;
519 const FString& PreString,
520 const FString& PostString,
523 const auto* SetProp = FNYReflectionHelper::CastProperty<FNYSetProperty>(Property);
524 if (SetProp ==
nullptr)
530 const FScriptSetHelper Helper(SetProp, SetProp->ContainerPtrToValuePtr<uint8>(
Object));
542 FString SubPreString = PreString;
543 for (int32 i = 0; i < SetProp->GetName().Len() + 3; ++i)
549 Target += PreString + SetProp->GetName() +
" {";
558 for (int32 i = 0; i < Helper.GetMaxIndex(); ++i)
560 if (!Helper.IsValidIndex(i))
576 Target += (bLinePerItem ?
" " :
"") + FString(
"}") + PostString;
580 UE_LOG(LogDlgConfigWriter,
Warning, TEXT(
"Set not exported: unsuported set member (%s)"), *SetProp->ElementProp->GetName());
589 return FNYReflectionHelper::CastProperty<FNYBoolProperty>(Property) !=
nullptr ||
590 FNYReflectionHelper::CastProperty<FNYIntProperty>(Property) !=
nullptr ||
591 FNYReflectionHelper::CastProperty<FNYInt64Property>(Property) !=
nullptr ||
592 FNYReflectionHelper::CastProperty<FNYFloatProperty>(Property) !=
nullptr ||
593 FNYReflectionHelper::CastProperty<FNYStrProperty>(Property) !=
nullptr ||
594 FNYReflectionHelper::CastProperty<FNYNameProperty>(Property) !=
nullptr ||
595 FNYReflectionHelper::CastProperty<FNYTextProperty>(Property) !=
nullptr ||
596 FNYReflectionHelper::CastProperty<FNYEnumProperty>(Property) !=
nullptr;
601 return FNYReflectionHelper::CastProperty<FNYArrayProperty>(Property) !=
nullptr ||
602 FNYReflectionHelper::CastProperty<FNYMapProperty>(Property) !=
nullptr ||
603 FNYReflectionHelper::CastProperty<FNYSetProperty>(Property) !=
nullptr;
609 if (FNYReflectionHelper::CastProperty<FNYArrayProperty>(Property) !=
nullptr
610 &&
IsPrimitive(FNYReflectionHelper::CastProperty<FNYArrayProperty>(Property)->Inner))
616 if (FNYReflectionHelper::CastProperty<FNYMapProperty>(Property) !=
nullptr &&
617 IsPrimitive(FNYReflectionHelper::CastProperty<FNYMapProperty>(Property)->KeyProp) &&
618 IsPrimitive(FNYReflectionHelper::CastProperty<FNYMapProperty>(Property)->ValueProp))
624 if (FNYReflectionHelper::CastProperty<FNYSetProperty>(Property) !=
nullptr
625 &&
IsPrimitive(FNYReflectionHelper::CastProperty<FNYSetProperty>(Property)->ElementProp))
635 if (
const auto* StructProperty = FNYReflectionHelper::CastProperty<FNYStructProperty>(Property))
637 return StructProperty->Struct;
640 if (
const auto* ObjectProperty = FNYReflectionHelper::CastProperty<FNYObjectProperty>(Property))
642 return ObjectProperty->PropertyClass;
650 if (StructDefinition ==
nullptr || Owner ==
nullptr)
655 for (TFieldIterator<const FNYProperty> It(StructDefinition); It; ++It)
657 const auto* Property = *It;
668 if (
const auto* MapProperty = FNYReflectionHelper::CastProperty<FNYMapProperty>(Property))
670 const FScriptMapHelper Helper(MapProperty, Property->ContainerPtrToValuePtr<uint8>(Owner));
671 if (Helper.Num() > 0)
678 if (
const auto* ArrayProperty = FNYReflectionHelper::CastProperty<FNYArrayProperty>(Property))
680 const FScriptArrayHelper Helper(ArrayProperty, Property->ContainerPtrToValuePtr<uint8>(Owner));
681 if (Helper.Num() > 0)
688 if (
const auto* SetProperty = FNYReflectionHelper::CastProperty<FNYSetProperty>(Property))
690 const FScriptSetHelper Helper(SetProperty, Property->ContainerPtrToValuePtr<uint8>(Owner));
691 if (Helper.Num() > 0)
699 if (FNYReflectionHelper::CastProperty<FNYStructProperty>(Property) !=
nullptr)
704 if (
const auto* ObjectProperty = FNYReflectionHelper::CastProperty<FNYObjectProperty>(Property))
706 UObject** ObjPtrPtr = ((
UObject**)ObjectProperty->ContainerPtrToValuePtr<
void>(Owner, 0));
719 if (
const auto* StructProperty = FNYReflectionHelper::CastProperty<FNYStructProperty>(Property))
724 if (
const auto* ObjectProperty = FNYReflectionHelper::CastProperty<FNYObjectProperty>(Property))
727 if (ObjectPtr ==
nullptr)
732 if (ObjectPtr->GetClass())
743 int32 Count =
String.Len();
749 return String.Right(Count);
DEFINE_LOG_CATEGORY(LogDlgConfigWriter)
bool WriteMapToString(const FNYProperty *Property, const void *Object, const FString &PreString, const FString &PostString, FString &Target)
const std::function< FString(const FString &) StringToString)
static const FString EOL_String
FDlgConfigWriter(const FString InComplexNamePrefix="", bool bInDontWriteEmptyContainer=true)
const std::function< FString(const float &) FloatToString)
const std::function< FString(const int64 &) IntToString)
const std::function< FString(const bool &) BoolToString)
const bool bDontWriteEmptyContainer
const std::function< FString(const FName &) NameToString)
bool WritePrimitiveArrayToString(const FNYProperty *Property, const void *Object, const FString &PreString, const FString &PostString, FString &Target)
const void * TopLevelObjectPtr
void Write(const UStruct *StructDefinition, const void *Object) override
bool WriteSetToString(const FNYProperty *Property, const void *Object, const FString &PreString, const FString &PostString, FString &Target)
bool IsContainer(const FNYProperty *Property)
bool IsPrimitiveContainer(const FNYProperty *Property)
static const TCHAR * EOL_LF
void WriteComplexToString(const UStruct *StructDefinition, const FNYProperty *Property, const void *Object, const FString &PreString, const FString &PostString, bool bContainerElement, bool bWriteType, FString &Target)
bool WriteComplexArrayToString(const FNYProperty *Property, const void *Object, const FString &PreString, const FString &PostString, FString &Target)
bool WouldWriteNonPrimitive(const UStruct *StructDefinition, const void *Owner)
bool WriteComplexElementToString(const FNYProperty *Property, const void *Object, bool bContainerElement, const FString &PreString, const FString &PostString, bool bPointerAsRef, FString &Target)
const std::function< FString(const FText &) TextToString)
bool WritePrimitiveElementToString(const FNYProperty *Property, const void *Object, bool bContainerElement, const FString &PreString, const FString &PostString, FString &Target)
FString GetStringWithoutPrefix(const FString &String)
bool IsPrimitive(const FNYProperty *Property)
const FString ComplexNamePrefix
static const TCHAR * EOL_CRLF
void WriteComplexMembersToString(const UStruct *StructDefinition, const void *Object, const FString &PreString, const FString &PostString, FString &Target)
const UStruct * GetComplexType(const FNYProperty *Property)
FString GetNameWithoutPrefix(const FNYProperty *StructDefinition, const UObject *ObjectPtr=nullptr)
bool WritePropertyToString(const FNYProperty *Property, const void *Object, bool bContainerElement, const FString &PreString, const FString &PostString, bool bPointerAsRef, FString &Target)
FORCEINLINE const uint8 * GetConstRawPtr(int32 Index=0) const
virtual bool CanSaveAsReference(const FNYProperty *Property, const UObject *Object)
static bool CanWriteOneLinePerItem(const FNYProperty *Property)
static bool CanSkipProperty(const FNYProperty *Property)
static bool CanWriteIndex(const FNYProperty *Property)