Better error handling in 'Call a Lua Function' k2node
This commit is contained in:
@@ -49,6 +49,7 @@ const FName UK2Node_LuaCall::FunctionPinName(TEXT("Lua Function Prototype"));
|
||||
const FName UK2Node_LuaCall::InvokeOrProbePinName(TEXT("Invoke or Probe"));
|
||||
const FName UK2Node_LuaCall::PlacePinName(TEXT("Place Tangible"));
|
||||
const FName UK2Node_LuaCall::ExtraResultsPinName(TEXT("Extra Results"));
|
||||
const FName UK2Node_LuaCall::ErrorPinName(TEXT("Lua Error"));
|
||||
|
||||
bool UK2Node_LuaCall::IsPrefix(const UEdGraphPin *Pin, char Prefix)
|
||||
{
|
||||
@@ -131,6 +132,8 @@ void UK2Node_LuaCall::AllocateDefaultPins()
|
||||
|
||||
void UK2Node_LuaCall::CreateCorrectPins()
|
||||
{
|
||||
UEnum *IPEnum = StaticEnum<ElxInvokeOrProbe>();
|
||||
|
||||
if (LuaFunctionPrototype.IsEmpty())
|
||||
{
|
||||
LuaFunctionPrototype = TEXT("class.func(int arg1, int arg2) : int ret1, int ret2");
|
||||
@@ -177,17 +180,22 @@ void UK2Node_LuaCall::CreateCorrectPins()
|
||||
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Then);
|
||||
}
|
||||
|
||||
if (InvokeOrProbe == TEXT("Probe"))
|
||||
{
|
||||
if (!KeepPin(ErrorPinName))
|
||||
{
|
||||
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, ErrorPinName);
|
||||
}
|
||||
}
|
||||
|
||||
if (!KeepPin(FunctionPinName))
|
||||
{
|
||||
UEdGraphPin *P = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_String, FunctionPinName);
|
||||
P->DefaultValue = LuaFunctionPrototype;
|
||||
}
|
||||
|
||||
if (!KeepPin(InvokeOrProbePinName))
|
||||
{
|
||||
UEdGraphPin *P = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Byte, StaticEnum<ElxInvokeOrProbe>(), InvokeOrProbePinName);
|
||||
P->DefaultValue = TEXT("Probe");
|
||||
P->AutogeneratedDefaultValue = P->DefaultValue;
|
||||
UEdGraphPin *P = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Byte, IPEnum, InvokeOrProbePinName);
|
||||
}
|
||||
|
||||
if (!KeepPin(PlacePinName))
|
||||
@@ -195,6 +203,12 @@ void UK2Node_LuaCall::CreateCorrectPins()
|
||||
UEdGraphPin *P = CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Object, AActor::StaticClass(), PlacePinName);
|
||||
}
|
||||
|
||||
// Copy the property names into the pins.
|
||||
UEdGraphPin *FunctionPin = FindPinChecked(FunctionPinName);
|
||||
UEdGraphPin *InvokeOrProbePin = FindPinChecked(InvokeOrProbePinName);
|
||||
FunctionPin->DefaultValue = LuaFunctionPrototype;
|
||||
InvokeOrProbePin->DefaultValue = InvokeOrProbe;
|
||||
|
||||
// Create Argument pins in the correct order, reusing old pins where possible.
|
||||
for (const FlxParsedProto::Pin & Pin : ParsedProto.Arguments)
|
||||
{
|
||||
@@ -257,7 +271,7 @@ FText UK2Node_LuaCall::GetNodeTitle(ENodeTitleType::Type TitleType) const
|
||||
FText UK2Node_LuaCall::GetPinDisplayName(const UEdGraphPin* Pin) const
|
||||
{
|
||||
// The exec pins don't need labels.
|
||||
if (Pin->PinType.PinCategory == UEdGraphSchema_K2::PC_Exec)
|
||||
if ((Pin->PinName == UEdGraphSchema_K2::PN_Execute) || (Pin->PinName == UEdGraphSchema_K2::PN_Then))
|
||||
{
|
||||
return FText::GetEmpty();
|
||||
}
|
||||
@@ -306,6 +320,12 @@ void UK2Node_LuaCall::PinDefaultValueChanged(UEdGraphPin* Pin)
|
||||
CreateCorrectPins();
|
||||
GetGraph()->NotifyNodeChanged(this);
|
||||
}
|
||||
else if (Pin->PinName == InvokeOrProbePinName)
|
||||
{
|
||||
InvokeOrProbe = Pin->DefaultValue;
|
||||
CreateCorrectPins();
|
||||
GetGraph()->NotifyNodeChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
FText UK2Node_LuaCall::GetTooltipText() const
|
||||
@@ -342,8 +362,8 @@ void UK2Node_LuaCall::ExpandNode(class FKismetCompilerContext& CompilerContext,
|
||||
UK2Node_CallFunction* BeginNode = MakeCallFunctionNode(LuaCallLibraryFunction(LuaCallBegin));
|
||||
Schema->TrySetDefaultValue(*BeginNode->FindPinChecked(TEXT("ClassName")), ParsedProto.ClassName);
|
||||
Schema->TrySetDefaultValue(*BeginNode->FindPinChecked(TEXT("FunctionName")), ParsedProto.FunctionName);
|
||||
UK2Node_CallFunction* PrevNode = BeginNode;
|
||||
|
||||
UEdGraphPin *ThenPin = BeginNode->GetThenPin();
|
||||
|
||||
// Add Packing operations for all argument pins.
|
||||
for (const FlxParsedProto::Pin &PinInfo : ParsedProto.Arguments)
|
||||
{
|
||||
@@ -357,17 +377,26 @@ void UK2Node_LuaCall::ExpandNode(class FKismetCompilerContext& CompilerContext,
|
||||
}
|
||||
UK2Node_CallFunction *PackNode = MakeCallFunctionNode(PackingFunc);
|
||||
CompilerContext.MovePinLinksToIntermediate(*Pin, *PackNode->FindPinChecked(TEXT("Value")));
|
||||
PrevNode->GetThenPin()->MakeLinkTo(PackNode->GetExecPin());
|
||||
PrevNode = PackNode;
|
||||
ThenPin->MakeLinkTo(PackNode->GetExecPin());
|
||||
ThenPin = PackNode->GetThenPin();
|
||||
}
|
||||
|
||||
// Add the invoke or probe node.
|
||||
bool IsInvoke = (FindPinChecked(InvokeOrProbePinName, EGPD_Input)->DefaultValue == TEXT("Invoke"));
|
||||
UFunction *Action = IsInvoke ? LuaCallLibraryFunction(LuaCallInvoke) : LuaCallLibraryFunction(LuaCallProbe);
|
||||
UK2Node_CallFunction* ActionNode = MakeCallFunctionNode(Action);
|
||||
CompilerContext.MovePinLinksToIntermediate(*FindPin(PlacePinName, EGPD_Input), *ActionNode->FindPinChecked(TEXT("Place")));
|
||||
PrevNode->GetThenPin()->MakeLinkTo(ActionNode->GetExecPin());
|
||||
PrevNode = ActionNode;
|
||||
if (InvokeOrProbe == TEXT("Probe"))
|
||||
{
|
||||
UK2Node_CallFunction* ActionNode = MakeCallFunctionNode(LuaCallLibraryFunction(LuaCallProbe));
|
||||
CompilerContext.MovePinLinksToIntermediate(*FindPinChecked(PlacePinName, EGPD_Input), *ActionNode->FindPinChecked(TEXT("Place")));
|
||||
CompilerContext.MovePinLinksToIntermediate(*FindPinChecked(ErrorPinName, EGPD_Output), *ActionNode->FindPinChecked(TEXT("False")));
|
||||
ThenPin->MakeLinkTo(ActionNode->GetExecPin());
|
||||
ThenPin = ActionNode->FindPinChecked(TEXT("True"));
|
||||
}
|
||||
else
|
||||
{
|
||||
UK2Node_CallFunction* ActionNode = MakeCallFunctionNode(LuaCallLibraryFunction(LuaCallInvoke));
|
||||
CompilerContext.MovePinLinksToIntermediate(*FindPinChecked(PlacePinName, EGPD_Input), *ActionNode->FindPinChecked(TEXT("Place")));
|
||||
ThenPin->MakeLinkTo(ActionNode->GetExecPin());
|
||||
ThenPin = ActionNode->GetThenPin();
|
||||
}
|
||||
|
||||
// Add Unpacking operations for all return value pins.
|
||||
for (const FlxParsedProto::Pin &PinInfo : ParsedProto.ReturnValues)
|
||||
@@ -382,8 +411,8 @@ void UK2Node_LuaCall::ExpandNode(class FKismetCompilerContext& CompilerContext,
|
||||
}
|
||||
UK2Node_CallFunction *UnpackNode = MakeCallFunctionNode(UnpackingFunc);
|
||||
CompilerContext.MovePinLinksToIntermediate(*Pin, *UnpackNode->FindPinChecked(UEdGraphSchema_K2::PN_ReturnValue));
|
||||
PrevNode->GetThenPin()->MakeLinkTo(UnpackNode->GetExecPin());
|
||||
PrevNode = UnpackNode;
|
||||
ThenPin->MakeLinkTo(UnpackNode->GetExecPin());
|
||||
ThenPin = UnpackNode->GetThenPin();
|
||||
}
|
||||
|
||||
// If there is an extra results pin, hook it up.
|
||||
@@ -392,16 +421,16 @@ void UK2Node_LuaCall::ExpandNode(class FKismetCompilerContext& CompilerContext,
|
||||
UEdGraphPin *Pin = FindPinChecked(ExtraResultsPinName);
|
||||
UK2Node_CallFunction *UnpackNode = MakeCallFunctionNode(LuaCallLibraryFunction(LuaCallGetRest));
|
||||
CompilerContext.MovePinLinksToIntermediate(*Pin, *UnpackNode->FindPinChecked(UEdGraphSchema_K2::PN_ReturnValue));
|
||||
PrevNode->GetThenPin()->MakeLinkTo(UnpackNode->GetExecPin());
|
||||
PrevNode = UnpackNode;
|
||||
ThenPin->MakeLinkTo(UnpackNode->GetExecPin());
|
||||
ThenPin = UnpackNode->GetThenPin();
|
||||
}
|
||||
|
||||
// Link up the Exec pins.
|
||||
CompilerContext.MovePinLinksToIntermediate(*GetExecPin(), *BeginNode->GetExecPin());
|
||||
CompilerContext.MovePinLinksToIntermediate(*GetThenPin(), *PrevNode->GetThenPin());
|
||||
CompilerContext.MovePinLinksToIntermediate(*GetThenPin(), *ThenPin);
|
||||
|
||||
// Make sure we didn't have return values for an invoke.
|
||||
if (IsInvoke && ((ParsedProto.ReturnValues.Num() > 0) || (ParsedProto.ExtraReturnValues)))
|
||||
if ((InvokeOrProbe != TEXT("Probe")) && ((ParsedProto.ReturnValues.Num() > 0) || (ParsedProto.ExtraReturnValues)))
|
||||
{
|
||||
CompilerContext.MessageLog.Error(TEXT("Lua Call in Invoke mode does not support return values"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user