Files
UnrealEngineUWP/Engine/Plugins/Runtime/StateTree/Source/StateTreeEditorModule/Public/StateTreePropertyBindingCompiler.h
mieszko zielinski 31a5065342 Moved GameplayBehaviors out of restricted folder over to Experimental
Moved SmartObjects out of restricted folder
Moved StateTree out of restricted folder
Moved ZoneGraph out of restricted folder
Moved ZoneGraphAnnotations out of restricted folder

#jira UE-115297

#ROBOMERGE-OWNER: mieszko.zielinski
#ROBOMERGE-AUTHOR: mieszko.zielinski
#ROBOMERGE-SOURCE: CL 17648223 via CL 17648246 via CL 17648261 via CL 17648385 via CL 17648390
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v875-17642767)
#ROBOMERGE-CONFLICT from-shelf
#ROBOMERGE[STARSHIP]: UE5-Main

[CL 17648742 by mieszko zielinski in ue5-release-engine-test branch]
2021-09-28 13:33:00 -04:00

99 lines
4.2 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Misc/Guid.h"
#include "InstancedStruct.h"
#include "UObject/Interface.h"
#include "IPropertyAccessEditor.h"
#include "StateTreeEditorPropertyBindings.h"
#include "StateTreePropertyBindings.h"
#include "StateTreePropertyBindingCompiler.generated.h"
/**
* Helper class to compile editor representation of property bindings into runtime representation.
* TODO: Better error reporting, something that can be shown in the UI.
*/
USTRUCT()
struct STATETREEEDITORMODULE_API FStateTreePropertyBindingCompiler
{
GENERATED_BODY()
/**
* Initializes the compiler to compile copies to specified Property Bindings.
* @param PropertyBindings - Reference to the Property Bindings where all the batches will be stored.
* @return true on success.
*/
bool Init(FStateTreePropertyBindings& InPropertyBindings);
/**
* Compiles a batch of property copies.
* @param TargetStruct - Description of the structs which contains the target properties.
* @param PropertyBindings - Array of bindings to compile, all bindings that point to TargetStructs will be added to the batch.
* @param OutBatchIndex - Resulting batch index, if index is INDEX_NONE, no bindings were found and no batch was generated.
* @return True on success, false on failure.
*/
bool CompileBatch(const FStateTreeBindableStructDesc& TargetStruct, TConstArrayView<FStateTreeEditorPropertyBinding> EditorPropertyBindings, int32& OutBatchIndex);
/** Finalizes compilation, should be called once all batches are compiled. */
void Finalize();
/**
* Adds source struct. When compiling a batch, the bindings can be between any of the defined source structs, and the target struct.
* Source structs can be added between calls to Compilebatch().
* @param SourceStruct - Description of the source struct to add.
* @return Source struct index.
*/
int32 AddSourceStruct(const FStateTreeBindableStructDesc& SourceStruct);
/** @return Index of a source struct by specified ID, or INDEX_NONE if not found. */
int32 GetSourceStructIndexByID(const FGuid& ID) const;
/** @return Reference to a source struct based on ID. */
const FStateTreeBindableStructDesc& GetSourceStructDesc(const int32 Index) const
{
return SourceStructs[Index];
}
/**
* Resolves a string based property path in specified struct into segments of property names and access types.
* @param InStructDesc Description of the struct in which the property path is valid.
* @param InPath The property path in string format.
* @param OutSegments The resolved property access path as segments.
* @param OutLeafProperty The leaf property of the resolved path.
* @param OutLeafArrayIndex The left array index (or INDEX_NONE if not applicable) of the resolved path.
* @param bLogErrors Set to true to log errors during resolve into the console.
* @return True of the property was solved successfully.
*/
static bool ResolvePropertyPath(const FStateTreeBindableStructDesc& InStructDesc, const FStateTreeEditorPropertyPath& InPath,
TArray<FStateTreePropertySegment>& OutSegments, FProperty*& OutLeafProperty, int32& OutLeafArrayIndex, const bool bLogErrors = false);
/**
* Checks if two property types can are compatible for copying.
* @param InPropertyA First property used in the check.
* @param InPropertyB Second property used in the check.
* @return Incompatible if the properties cannot be copied, Compatible if they are trivially copyable, or Promotable if numeric values can be promoted to another numeric type.
*/
static EPropertyAccessCompatibility GetPropertyCompatibility(const FProperty* InPropertyA, const FProperty* InPropertyB);
protected:
void StoreSourceStructs();
UPROPERTY()
TArray<FStateTreeBindableStructDesc> SourceStructs;
FStateTreePropertyBindings* PropertyBindings = nullptr;
struct FResolvedPathResult
{
int32 PathIndex = INDEX_NONE;
FProperty* LeafProperty = nullptr;
int32 LeafArrayIndex = INDEX_NONE;
};
EStateTreePropertyCopyType GetCopyType(FProperty* SourceProperty, int32 SourceArrayIndex, FProperty* TargetProperty, int32 TargetArrayIndex);
bool ResolvePropertyPath(const FStateTreeBindableStructDesc& InStructDesc, const FStateTreeEditorPropertyPath& InPath, FResolvedPathResult& OutResult);
};