// Copyright 2020 Phyronnaz #include "VoxelGenerators/VoxelGenerator.h" #include "VoxelGenerators/VoxelGeneratorInstance.h" #include "VoxelGenerators/VoxelGeneratorParameters.h" #include "VoxelMessages.h" #include "UObject/Package.h" #include "UObject/MetaData.h" #include "UObject/PropertyPortFlags.h" void UVoxelGenerator::ApplyParameters(const TMap& Parameters) { ApplyParametersInternal(Parameters); } void UVoxelGenerator::GetParameters(TArray& OutParameters) const { VOXEL_FUNCTION_COUNTER(); TSet AllIds; int32 Priority = 0; for (TFieldIterator It(GetClass()); It; ++It) { auto* Property = *It; if (!Property->HasAnyPropertyFlags(CPF_Edit) || Property->HasAnyPropertyFlags(CPF_EditConst)) { continue; } const FName Id = Property->GetFName(); FString Name; FString Category; FString ToolTip; TMap MetaData; #if WITH_EDITOR Name = Property->GetDisplayNameText().ToString(); Category = Property->GetMetaDataText(TEXT("Category")).ToString(); ToolTip = Property->GetToolTipText().ToString(); if (Property->GetMetaDataMap()) { MetaData = *Property->GetMetaDataMap(); } #else Name = Property->GetName(); #endif const auto Type = FVoxelGeneratorParameterType(*Property); FString DefaultValue; Property->ExportTextItem(DefaultValue, Property->ContainerPtrToValuePtr(this), nullptr, nullptr, PPF_None); OutParameters.Add(FVoxelGeneratorParameter(Id, Type, Name, Category, ToolTip, Priority++, MetaData, DefaultValue)); bool bIsInSet = false; AllIds.Add(Id, &bIsInSet); ensureMsgf(!bIsInSet, TEXT("%s"), *Id.ToString()); } } TVoxelSharedRef UVoxelGenerator::GetInstance(const TMap& Parameters) { const auto Backup = ApplyParametersInternal(Parameters); const auto Result = GetInstance(); ApplyParametersInternal(Backup); return Result; } TVoxelSharedRef UVoxelGenerator::GetInstance() { unimplemented(); return TVoxelSharedPtr().ToSharedRef(); } TMap UVoxelGenerator::ApplyParametersInternal(const TMap& Parameters) { TMap ParametersBackup; for (auto& It : Parameters) { auto* Property = FindFProperty (GetClass(), It.Key); if (!Property) { continue; } void* PropertyData = Property->ContainerPtrToValuePtr(this); // Export backup Property->ExportTextItem(ParametersBackup.Add(It.Key), PropertyData, nullptr, nullptr, PPF_None); // Import new value Property->ImportText(*It.Value, PropertyData, PPF_None, this); } return ParametersBackup; } /////////////////////////////////////////////////////////////////////////////// TVoxelSharedRef UVoxelTransformableGenerator::GetTransformableInstance(const TMap& Parameters) { const auto Backup = ApplyParametersInternal(Parameters); const auto Result = GetTransformableInstance(); ApplyParametersInternal(Backup); return Result; } TVoxelSharedRef UVoxelTransformableGenerator::GetTransformableInstance() { unimplemented(); return TVoxelSharedPtr().ToSharedRef(); } TVoxelSharedRef UVoxelTransformableGenerator::GetInstance(const TMap& Parameters) { return GetTransformableInstance(Parameters); } TVoxelSharedRef UVoxelTransformableGenerator::GetInstance() { return GetTransformableInstance(); } /////////////////////////////////////////////////////////////////////////////// FVoxelIntBox UVoxelTransformableGeneratorWithBounds::GetBounds() const { unimplemented(); return {}; }