96 lines
3.3 KiB
C++
96 lines
3.3 KiB
C++
|
|
// Copyright (c) Samuel Kahn (samuel@kahncode.com). All Rights Reserved.
|
||
|
|
|
||
|
|
#include "K2Node_JsonToStruct.h"
|
||
|
|
|
||
|
|
#include "BlobFunctionLibrary.h"
|
||
|
|
#include "BlueprintActionDatabaseRegistrar.h"
|
||
|
|
#include "BlueprintFieldNodeSpawner.h"
|
||
|
|
#include "EdGraphSchema_K2.h"
|
||
|
|
#include "EdGraphUtilities.h"
|
||
|
|
#include "EditorCategoryUtils.h"
|
||
|
|
#include "K2Node_CallFunction.h"
|
||
|
|
#include "KismetCompiler.h"
|
||
|
|
|
||
|
|
#define LOCTEXT_NAMESPACE "K2Node_JsonToStruct"
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////////////////////////////
|
||
|
|
// UK2Node_JsonToStruct
|
||
|
|
|
||
|
|
void UK2Node_JsonToStruct::AllocateDefaultPins()
|
||
|
|
{
|
||
|
|
Super::AllocateDefaultPins();
|
||
|
|
|
||
|
|
UEdGraphNode::FCreatePinParams StringPinParams;
|
||
|
|
StringPinParams.bIsConst = true;
|
||
|
|
StringPinParams.bIsReference = true;
|
||
|
|
CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_String, FName(TEXT("JsonString")), StringPinParams);
|
||
|
|
|
||
|
|
UEdGraphNode::FCreatePinParams StructPinParams;
|
||
|
|
StructPinParams.bIsConst = false;
|
||
|
|
StructPinParams.bIsReference = true;
|
||
|
|
CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Wildcard, FName(TEXT("Struct")), StructPinParams);
|
||
|
|
}
|
||
|
|
|
||
|
|
FText UK2Node_JsonToStruct::GetNodeTitle(ENodeTitleType::Type aTitleType) const
|
||
|
|
{
|
||
|
|
if (CachedNodeTitle.IsOutOfDate(this))
|
||
|
|
{
|
||
|
|
CachedNodeTitle.SetCachedText(LOCTEXT("JsonToStruct_Title", "Json To Struct"), this);
|
||
|
|
}
|
||
|
|
return CachedNodeTitle;
|
||
|
|
}
|
||
|
|
|
||
|
|
FText UK2Node_JsonToStruct::GetTooltipText() const
|
||
|
|
{
|
||
|
|
if (CachedTooltip.IsOutOfDate(this))
|
||
|
|
{
|
||
|
|
CachedTooltip.SetCachedText(LOCTEXT("JsonToStruct_Tooltip", "Writes a json string into a struct (passed by reference)"), this);
|
||
|
|
}
|
||
|
|
return CachedTooltip;
|
||
|
|
}
|
||
|
|
|
||
|
|
FSlateIcon UK2Node_JsonToStruct::GetIconAndTint(FLinearColor& outColor) const
|
||
|
|
{
|
||
|
|
static FSlateIcon Icon("EditorStyle", "GraphEditor.BreakStruct_16x");
|
||
|
|
return Icon;
|
||
|
|
}
|
||
|
|
|
||
|
|
void UK2Node_JsonToStruct::ExpandNode(class FKismetCompilerContext& CompilerContext, UEdGraph* SourceGraph)
|
||
|
|
{
|
||
|
|
// This is where the node is implemented, calls UBinaryBlobFunctionLibrary::JsonToStruct
|
||
|
|
|
||
|
|
Super::ExpandNode(CompilerContext, SourceGraph);
|
||
|
|
|
||
|
|
if (StructType)
|
||
|
|
{
|
||
|
|
UEdGraphPin* InJsonStringPin = FindPin(TEXT("JsonString"));
|
||
|
|
UEdGraphPin* InStructPin = GetStructPin();
|
||
|
|
|
||
|
|
UK2Node_CallFunction* PinCallFunction = CompilerContext.SpawnIntermediateNode<UK2Node_CallFunction>(this, SourceGraph);
|
||
|
|
const UFunction* Function = UBlobFunctionLibrary::StaticClass()->FindFunctionByName(
|
||
|
|
GET_FUNCTION_NAME_CHECKED(UBlobFunctionLibrary, JsonToStruct));
|
||
|
|
PinCallFunction->SetFromFunction(Function);
|
||
|
|
PinCallFunction->AllocateDefaultPins();
|
||
|
|
|
||
|
|
UEdGraphPin* JsonStringPin = PinCallFunction->FindPinChecked(TEXT("JsonString"));
|
||
|
|
CompilerContext.MovePinLinksToIntermediate(*InJsonStringPin, *JsonStringPin);
|
||
|
|
|
||
|
|
UEdGraphPin* StructPin = PinCallFunction->FindPinChecked(TEXT("OutStruct"));
|
||
|
|
|
||
|
|
// Set the type of the OutRow pin on this expanded mode to match original
|
||
|
|
StructPin->PinType = InStructPin->PinType;
|
||
|
|
StructPin->PinType.PinSubCategoryObject = InStructPin->PinType.PinSubCategoryObject;
|
||
|
|
|
||
|
|
CompilerContext.MovePinLinksToIntermediate(*InStructPin, *StructPin); // struct pin out is not recognized properly
|
||
|
|
|
||
|
|
// Move execution pin links
|
||
|
|
CompilerContext.MovePinLinksToIntermediate(*GetThenPin(), *(PinCallFunction->GetThenPin()));
|
||
|
|
CompilerContext.MovePinLinksToIntermediate(*GetExecPin(), *(PinCallFunction->GetExecPin()));
|
||
|
|
}
|
||
|
|
|
||
|
|
// Break any links to the expanded node
|
||
|
|
BreakAllNodeLinks();
|
||
|
|
}
|
||
|
|
|
||
|
|
#undef LOCTEXT_NAMESPACE
|