Halfway done with Dispatcher stuff

This commit is contained in:
2026-03-20 16:18:03 -04:00
parent 0ac9a01859
commit ca6b3f9768
6 changed files with 235 additions and 11 deletions

View File

@@ -1,9 +1,11 @@
#include "WingBlueprintVar.h"
#include "WingFunctionArgs.h"
#include "WingJson.h"
#include "WingServer.h"
#include "WingTypes.h"
#include "WingUtils.h"
#include "EdGraphSchema_K2.h"
#include "K2Node_EditablePinBase.h"
#include "Kismet2/BlueprintEditorUtils.h"
FWingBlueprintVar::FWingBlueprintVar(UBlueprint* BP, const FString& VarName)
@@ -11,13 +13,34 @@ FWingBlueprintVar::FWingBlueprintVar(UBlueprint* BP, const FString& VarName)
Desc = WingUtils::FindExactlyOneNamed(VarName, BP->NewVariables);
if (!Desc) return;
// Try to find the default value property on the CDO.
if (BP->GeneratedClass)
if (Desc->VarType.PinCategory == UEdGraphSchema_K2::PC_MCDelegate)
{
UObject* CDO = BP->GeneratedClass->GetDefaultObject();
FProperty* Prop = BP->GeneratedClass->FindPropertyByName(Desc->VarName);
if (CDO && Prop)
DefaultValueProp = FWingProperty(Prop, CDO);
// Find the matching signature graph by name.
for (UEdGraph* Graph : BP->DelegateSignatureGraphs)
{
if (Graph->GetFName() == Desc->VarName)
{
SigGraph = Graph;
break;
}
}
if (!SigGraph)
{
UWingServer::Printf(TEXT("ERROR: Signature graph not found for event dispatcher '%s'\n"), *VarName);
Desc = nullptr;
return;
}
}
else
{
// Try to find the default value property on the CDO.
if (BP->GeneratedClass)
{
UObject* CDO = BP->GeneratedClass->GetDefaultObject();
FProperty* Prop = BP->GeneratedClass->FindPropertyByName(Desc->VarName);
if (CDO && Prop)
DefaultValueProp = FWingProperty(Prop, CDO);
}
}
}
@@ -25,6 +48,7 @@ void FWingBlueprintVar::Dump()
{
LoadFlags();
LoadDefault();
LoadDelegateArgs();
TArray<FWingProperty> Props = MergedProperties();
for (FWingProperty& P : Props)
{
@@ -38,6 +62,7 @@ void FWingBlueprintVar::Dump()
bool FWingBlueprintVar::ApplyJson(const FJsonObject* Json)
{
bool bHasDefault = Json->HasField(TEXT("DefaultValue"));
bool bHasDelegateArgs = Json->HasField(TEXT("DelegateArgs"));
bool bHasType = Json->HasField(TEXT("VarType"));
if (bHasDefault && bHasType)
{
@@ -49,6 +74,7 @@ bool FWingBlueprintVar::ApplyJson(const FJsonObject* Json)
}
LoadFlags();
LoadDelegateArgs();
TArray<FWingProperty> Props = MergedProperties();
if (!WingJson::PopulateFromJson(Props, Json, true))
@@ -56,7 +82,9 @@ bool FWingBlueprintVar::ApplyJson(const FJsonObject* Json)
SaveFlags();
if (bHasDefault)
return SaveDefault();
if (!SaveDefault()) return false;
if (bHasDelegateArgs)
if (!SaveDelegateArgs()) return false;
return true;
}
@@ -82,6 +110,18 @@ void FWingBlueprintVar::LoadDefault()
DefaultValue.Empty();
}
void FWingBlueprintVar::LoadDelegateArgs()
{
if (!SigGraph) return;
TWeakObjectPtr<UK2Node_EditablePinBase> EntryNode;
TWeakObjectPtr<UK2Node_EditablePinBase> ResultNode;
FBlueprintEditorUtils::GetEntryAndResultNodes(SigGraph, EntryNode, ResultNode);
if (EntryNode.IsValid())
DelegateArgs = WingFunctionArgs::GetArgs(EntryNode.Get());
else
DelegateArgs.Empty();
}
void FWingBlueprintVar::SaveFlags()
{
// CPF flags
@@ -125,6 +165,20 @@ bool FWingBlueprintVar::SaveDefault()
return true;
}
bool FWingBlueprintVar::SaveDelegateArgs()
{
if (!SigGraph) return true;
TWeakObjectPtr<UK2Node_EditablePinBase> EntryNode;
TWeakObjectPtr<UK2Node_EditablePinBase> ResultNode;
FBlueprintEditorUtils::GetEntryAndResultNodes(SigGraph, EntryNode, ResultNode);
if (!EntryNode.IsValid())
{
UWingServer::Print(TEXT("ERROR: Entry node not found in delegate signature graph\n"));
return false;
}
return WingFunctionArgs::SetArgs(EntryNode.Get(), DelegateArgs);
}
TArray<FWingProperty> FWingBlueprintVar::MergedProperties()
{
TArray<FWingProperty> Props = FWingProperty::GetAll(
@@ -139,9 +193,20 @@ TArray<FWingProperty> FWingBlueprintVar::MergedProperties()
Props.Append(FWingProperty::GetAll(
FWingBlueprintVar::StaticStruct(), this, (EPropertyFlags)0));
// Remove DefaultValue if we don't have a CDO property to back it.
if (!DefaultValueProp)
if (SigGraph)
{
FWingProperty::Remove(Props, TEXT("VarType"));
FWingProperty::Remove(Props, TEXT("DefaultValue"));
FWingProperty::Remove(Props, TEXT("ExposeOnSpawn"));
FWingProperty::Remove(Props, TEXT("ExposeToCinematics"));
}
else
{
FWingProperty::Remove(Props, TEXT("DelegateArgs"));
// Remove DefaultValue if we don't have a CDO property to back it.
if (!DefaultValueProp)
FWingProperty::Remove(Props, TEXT("DefaultValue"));
}
return Props;
}