2021-01-06 14:01:38 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "RigVMModel/RigVMFunctionLibrary.h"
|
|
|
|
|
|
|
|
|
|
URigVMFunctionLibrary::URigVMFunctionLibrary()
|
|
|
|
|
: URigVMGraph()
|
|
|
|
|
{
|
2021-03-11 04:40:53 -04:00
|
|
|
|
2021-01-06 14:01:38 -04:00
|
|
|
}
|
|
|
|
|
|
2021-01-14 15:00:40 -04:00
|
|
|
FString URigVMFunctionLibrary::GetNodePath() const
|
|
|
|
|
{
|
|
|
|
|
return FString::Printf(TEXT("FunctionLibrary::%s"), *Super::GetNodePath());
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-11 04:40:53 -04:00
|
|
|
URigVMFunctionLibrary* URigVMFunctionLibrary::GetDefaultFunctionLibrary() const
|
|
|
|
|
{
|
|
|
|
|
if(URigVMFunctionLibrary* DefaultFunctionLibrary = Super::GetDefaultFunctionLibrary())
|
|
|
|
|
{
|
|
|
|
|
return DefaultFunctionLibrary;
|
|
|
|
|
}
|
|
|
|
|
return (URigVMFunctionLibrary*)this;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-06 14:01:38 -04:00
|
|
|
TArray<URigVMLibraryNode*> URigVMFunctionLibrary::GetFunctions() const
|
|
|
|
|
{
|
|
|
|
|
TArray<URigVMLibraryNode*> Functions;
|
|
|
|
|
|
|
|
|
|
for (URigVMNode* Node : GetNodes())
|
|
|
|
|
{
|
|
|
|
|
// we only allow library nodes under a function library graph
|
|
|
|
|
URigVMLibraryNode* LibraryNode = CastChecked<URigVMLibraryNode>(Node);
|
|
|
|
|
Functions.Add(LibraryNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Functions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
URigVMLibraryNode* URigVMFunctionLibrary::FindFunction(const FName& InFunctionName) const
|
|
|
|
|
{
|
2021-01-14 15:00:40 -04:00
|
|
|
FString FunctionNameStr = InFunctionName.ToString();
|
|
|
|
|
if (FunctionNameStr.StartsWith(TEXT("FunctionLibrary::|")))
|
|
|
|
|
{
|
|
|
|
|
FunctionNameStr.RightChopInline(18);
|
|
|
|
|
}
|
|
|
|
|
return Cast<URigVMLibraryNode>(FindNodeByName(*FunctionNameStr));
|
2021-01-06 14:01:38 -04:00
|
|
|
}
|
|
|
|
|
|
2021-04-27 03:19:42 -04:00
|
|
|
URigVMLibraryNode* URigVMFunctionLibrary::FindFunctionForNode(URigVMNode* InNode) const
|
|
|
|
|
{
|
2021-04-29 07:44:28 -04:00
|
|
|
if(InNode == nullptr)
|
2021-04-27 03:19:42 -04:00
|
|
|
{
|
2021-04-29 07:44:28 -04:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UObject* Subject = InNode;
|
|
|
|
|
while (Subject->GetOuter() != this)
|
|
|
|
|
{
|
|
|
|
|
Subject = Subject->GetOuter();
|
2021-04-27 03:19:42 -04:00
|
|
|
if(Subject == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Cast<URigVMLibraryNode>(Subject);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-19 13:37:12 -04:00
|
|
|
TArray< TSoftObjectPtr<URigVMFunctionReferenceNode> > URigVMFunctionLibrary::GetReferencesForFunction(const FName& InFunctionName)
|
|
|
|
|
{
|
|
|
|
|
TArray< TSoftObjectPtr<URigVMFunctionReferenceNode> > Result;
|
|
|
|
|
|
2021-04-27 03:19:42 -04:00
|
|
|
ForEachReferenceSoftPtr(InFunctionName, [&Result](TSoftObjectPtr<URigVMFunctionReferenceNode> Reference)
|
2021-01-19 13:37:12 -04:00
|
|
|
{
|
2021-04-27 03:19:42 -04:00
|
|
|
Result.Add(TSoftObjectPtr<URigVMFunctionReferenceNode>(Reference.GetUniqueID()));
|
|
|
|
|
});
|
2021-01-19 13:37:12 -04:00
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TArray< FString > URigVMFunctionLibrary::GetReferencePathsForFunction(const FName& InFunctionName)
|
|
|
|
|
{
|
|
|
|
|
TArray< FString > Result;
|
|
|
|
|
|
2021-04-27 03:19:42 -04:00
|
|
|
ForEachReferenceSoftPtr(InFunctionName, [&Result](TSoftObjectPtr<URigVMFunctionReferenceNode> Reference)
|
|
|
|
|
{
|
|
|
|
|
Result.Add(Reference.ToString());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void URigVMFunctionLibrary::ForEachReference(const FName& InFunctionName,
|
|
|
|
|
TFunction<void(URigVMFunctionReferenceNode*)> PerReferenceFunction) const
|
|
|
|
|
{
|
2021-01-19 13:37:12 -04:00
|
|
|
if (URigVMLibraryNode* Function = FindFunction(InFunctionName))
|
|
|
|
|
{
|
2021-04-27 03:19:42 -04:00
|
|
|
const FRigVMFunctionReferenceArray* ReferencesEntry = FunctionReferences.Find(Function);
|
2021-01-19 13:37:12 -04:00
|
|
|
if (ReferencesEntry)
|
|
|
|
|
{
|
|
|
|
|
for (int32 ReferenceIndex = 0; ReferenceIndex < ReferencesEntry->Num(); ReferenceIndex++)
|
|
|
|
|
{
|
|
|
|
|
const TSoftObjectPtr<URigVMFunctionReferenceNode>& Reference = ReferencesEntry->operator [](ReferenceIndex);
|
2021-04-27 03:19:42 -04:00
|
|
|
if (!Reference.IsValid())
|
|
|
|
|
{
|
|
|
|
|
Reference.LoadSynchronous();
|
|
|
|
|
}
|
|
|
|
|
if (Reference.IsValid())
|
|
|
|
|
{
|
|
|
|
|
PerReferenceFunction(Reference.Get());
|
|
|
|
|
}
|
2021-01-19 13:37:12 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-27 03:19:42 -04:00
|
|
|
}
|
2021-01-19 13:37:12 -04:00
|
|
|
|
2021-04-27 03:19:42 -04:00
|
|
|
void URigVMFunctionLibrary::ForEachReferenceSoftPtr(const FName& InFunctionName,
|
|
|
|
|
TFunction<void(TSoftObjectPtr<URigVMFunctionReferenceNode>)> PerReferenceFunction) const
|
|
|
|
|
{
|
|
|
|
|
if (URigVMLibraryNode* Function = FindFunction(InFunctionName))
|
|
|
|
|
{
|
|
|
|
|
const FRigVMFunctionReferenceArray* ReferencesEntry = FunctionReferences.Find(Function);
|
|
|
|
|
if (ReferencesEntry)
|
|
|
|
|
{
|
|
|
|
|
for (int32 ReferenceIndex = 0; ReferenceIndex < ReferencesEntry->Num(); ReferenceIndex++)
|
|
|
|
|
{
|
|
|
|
|
const TSoftObjectPtr<URigVMFunctionReferenceNode>& Reference = ReferencesEntry->operator [](ReferenceIndex);
|
|
|
|
|
PerReferenceFunction(Reference);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-19 13:37:12 -04:00
|
|
|
}
|
2021-03-10 05:52:25 -04:00
|
|
|
|
2021-04-15 14:30:33 -04:00
|
|
|
void URigVMFunctionLibrary::UpdateReferencesForReferenceNode(URigVMFunctionReferenceNode* InReferenceNode)
|
|
|
|
|
{
|
|
|
|
|
if(InReferenceNode->GetOutermost() == GetTransientPackage())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(URigVMLibraryNode* Function = InReferenceNode->GetReferencedNode())
|
|
|
|
|
{
|
|
|
|
|
if(Function->GetOuter() == this)
|
|
|
|
|
{
|
|
|
|
|
FRigVMFunctionReferenceArray* ReferencesEntry = FunctionReferences.Find(Function);
|
|
|
|
|
if (ReferencesEntry == nullptr)
|
|
|
|
|
{
|
|
|
|
|
Modify();
|
|
|
|
|
FunctionReferences.Add(Function);
|
|
|
|
|
ReferencesEntry = FunctionReferences.Find(Function);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FString ReferenceNodePathName = InReferenceNode->GetPathName();
|
|
|
|
|
for (int32 ReferenceIndex = 0; ReferenceIndex < ReferencesEntry->Num(); ReferenceIndex++)
|
|
|
|
|
{
|
|
|
|
|
const TSoftObjectPtr<URigVMFunctionReferenceNode>& Reference = ReferencesEntry->operator [](ReferenceIndex);
|
|
|
|
|
if(Reference.ToString() == ReferenceNodePathName)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Modify();
|
|
|
|
|
ReferencesEntry->FunctionReferences.Add(InReferenceNode);
|
|
|
|
|
MarkPackageDirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 05:52:25 -04:00
|
|
|
URigVMLibraryNode* URigVMFunctionLibrary::FindPreviouslyLocalizedFunction(URigVMLibraryNode* InFunctionToLocalize)
|
|
|
|
|
{
|
|
|
|
|
if(InFunctionToLocalize == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FString PathName = InFunctionToLocalize->GetPathName();
|
|
|
|
|
|
|
|
|
|
if(!LocalizedFunctions.Contains((PathName)))
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
URigVMLibraryNode* LocalizedFunction = LocalizedFunctions.FindChecked(PathName);
|
|
|
|
|
|
|
|
|
|
// once we found the function - let's make sure it's notation is right
|
|
|
|
|
if(LocalizedFunction->GetPins().Num() != InFunctionToLocalize->GetPins().Num())
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
for(int32 PinIndex=0; PinIndex < InFunctionToLocalize->GetPins().Num(); PinIndex++)
|
|
|
|
|
{
|
|
|
|
|
URigVMPin* PinA = InFunctionToLocalize->GetPins()[PinIndex];
|
|
|
|
|
URigVMPin* PinB = LocalizedFunction->GetPins()[PinIndex];
|
|
|
|
|
|
|
|
|
|
if((PinA->GetFName() != PinB->GetFName()) ||
|
|
|
|
|
(PinA->GetCPPType() != PinB->GetCPPType()) ||
|
|
|
|
|
(PinA->GetCPPTypeObject() != PinB->GetCPPTypeObject()) ||
|
|
|
|
|
(PinA->IsArray() != PinB->IsArray()))
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return LocalizedFunction;
|
|
|
|
|
}
|