-
-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathN2CNodeTranslator.cpp
More file actions
1804 lines (1577 loc) · 70 KB
/
N2CNodeTranslator.cpp
File metadata and controls
1804 lines (1577 loc) · 70 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2025 Nick McClure (Protospatial). All Rights Reserved.
#include "Core/N2CNodeTranslator.h"
#include "Core/N2CSettings.h"
#include "Utils/N2CLogger.h"
#include "Utils/N2CNodeTypeRegistry.h"
#include "Utils/Validators/N2CBlueprintValidator.h"
#include "UObject/UnrealType.h"
#include "UObject/UObjectBase.h"
#include "UObject/Class.h"
#include "UObject/UnrealTypePrivate.h"
FN2CNodeTranslator& FN2CNodeTranslator::Get()
{
static FN2CNodeTranslator Instance;
return Instance;
}
bool FN2CNodeTranslator::GenerateN2CStruct(const TArray<UK2Node*>& CollectedNodes)
{
// Clear any existing data
N2CBlueprint = FN2CBlueprint();
NodeIDMap.Empty();
PinIDMap.Empty();
ProcessedStructPaths.Empty(); // Clear processed structs set
ProcessedEnumPaths.Empty(); // Clear processed enums set
if (CollectedNodes.Num() == 0)
{
FN2CLogger::Get().LogWarning(TEXT("No nodes provided to translate"));
return false;
}
FN2CLogger::Get().Log(TEXT("Starting node translation"), EN2CLogSeverity::Info);
// Get Blueprint metadata from first node (all nodes are from the same graph)
if (UK2Node* FirstNode = CollectedNodes[0])
{
if (UBlueprint* Blueprint = FirstNode->GetBlueprint())
{
// Set Blueprint name
N2CBlueprint.Metadata.Name = Blueprint->GetName();
// Set Blueprint class
if (UClass* BPClass = FirstNode->GetBlueprintClassFromNode())
{
N2CBlueprint.Metadata.BlueprintClass = GetCleanClassName(BPClass->GetName());
}
// Determine Blueprint type
switch (Blueprint->BlueprintType)
{
case BPTYPE_Const:
N2CBlueprint.Metadata.BlueprintType = EN2CBlueprintType::Const;
break;
case BPTYPE_MacroLibrary:
N2CBlueprint.Metadata.BlueprintType = EN2CBlueprintType::MacroLibrary;
break;
case BPTYPE_Interface:
N2CBlueprint.Metadata.BlueprintType = EN2CBlueprintType::Interface;
break;
case BPTYPE_LevelScript:
N2CBlueprint.Metadata.BlueprintType = EN2CBlueprintType::LevelScript;
break;
case BPTYPE_FunctionLibrary:
N2CBlueprint.Metadata.BlueprintType = EN2CBlueprintType::FunctionLibrary;
break;
default:
N2CBlueprint.Metadata.BlueprintType = EN2CBlueprintType::Normal;
break;
}
// Log Blueprint info
FString Context = FString::Printf(TEXT("Blueprint: %s, Type: %s, Class: %s"),
*N2CBlueprint.Metadata.Name,
*StaticEnum<EN2CBlueprintType>()->GetNameStringByValue(static_cast<int64>(N2CBlueprint.Metadata.BlueprintType)),
*N2CBlueprint.Metadata.BlueprintClass);
FN2CLogger::Get().Log(TEXT("Blueprint metadata collected"), EN2CLogSeverity::Info, Context);
}
}
// Create initial graph for the nodes
FN2CGraph MainGraph;
// Get graph info from first node
if (CollectedNodes.Num() > 0 && CollectedNodes[0])
{
if (UEdGraph* Graph = CollectedNodes[0]->GetGraph())
{
MainGraph.Name = Graph->GetName();
MainGraph.GraphType = DetermineGraphType(Graph);
FString Context = FString::Printf(TEXT("Created graph: %s of type %s"),
*MainGraph.Name,
*StaticEnum<EN2CGraphType>()->GetNameStringByValue(static_cast<int64>(MainGraph.GraphType)));
FN2CLogger::Get().Log(TEXT("Graph info"), EN2CLogSeverity::Debug, Context);
}
}
CurrentGraph = &MainGraph;
// Process each node
for (UK2Node* Node : CollectedNodes)
{
if (!Node)
{
FN2CLogger::Get().LogWarning(TEXT("Null node encountered during translation"));
continue;
}
FN2CNodeDefinition NodeDef;
if (ProcessNode(Node, NodeDef))
{
CurrentGraph->Nodes.Add(NodeDef);
}
}
// Add the main graph to the blueprint
N2CBlueprint.Graphs.Add(MainGraph);
// Process any additional graphs that were discovered
while (AdditionalGraphsToProcess.Num() > 0)
{
FGraphProcessInfo GraphInfo = AdditionalGraphsToProcess.Pop();
if (GraphInfo.Graph)
{
// Set the depth to parent depth before processing
CurrentDepth = GraphInfo.ParentDepth;
ProcessGraph(GraphInfo.Graph, DetermineGraphType(GraphInfo.Graph));
}
}
FString Context = FString::Printf(TEXT("Translated %d nodes in %d graphs"),
MainGraph.Nodes.Num(),
N2CBlueprint.Graphs.Num());
FN2CLogger::Get().Log(TEXT("Node translation complete"), EN2CLogSeverity::Info, Context);
return N2CBlueprint.Graphs.Num() > 0;
}
FString FN2CNodeTranslator::GenerateNodeID()
{
return FString::Printf(TEXT("N%d"), NodeIDMap.Num() + 1);
}
FString FN2CNodeTranslator::GeneratePinID(int32 PinCount)
{
return FString::Printf(TEXT("P%d"), PinCount + 1);
}
bool FN2CNodeTranslator::InitializeNodeProcessing(UK2Node* Node, FN2CNodeDefinition& OutNodeDef)
{
if (!Node)
{
FN2CLogger::Get().LogWarning(TEXT("Attempted to process null node"));
return false;
}
// Skip knot nodes entirely - they're just pass-through connections
if (Node->IsA<UK2Node_Knot>())
{
FN2CLogger::Get().Log(TEXT("Skipping knot node"), EN2CLogSeverity::Debug);
return false;
}
// Check if we already have an ID for this node
FString* ExistingID = NodeIDMap.Find(Node->NodeGuid);
if (ExistingID)
{
OutNodeDef.ID = *ExistingID;
FString Context = FString::Printf(TEXT("Reusing existing node ID %s for node %s"),
*OutNodeDef.ID,
*Node->GetNodeTitle(ENodeTitleType::ListView).ToString());
FN2CLogger::Get().Log(Context, EN2CLogSeverity::Debug);
}
else
{
// Generate and map new node ID
FString NodeID = GenerateNodeID();
NodeIDMap.Add(Node->NodeGuid, NodeID);
OutNodeDef.ID = NodeID;
FString Context = FString::Printf(TEXT("Generated new node ID %s for node %s"),
*NodeID,
*Node->GetNodeTitle(ENodeTitleType::ListView).ToString());
FN2CLogger::Get().Log(Context, EN2CLogSeverity::Debug);
}
return true;
}
bool FN2CNodeTranslator::ProcessNode(UK2Node* Node, FN2CNodeDefinition& OutNodeDef)
{
if (!InitializeNodeProcessing(Node, OutNodeDef))
{
return false;
}
ProcessNodeTypeAndProperties(Node, OutNodeDef);
// Track pin connections for flows
TArray<UEdGraphPin*> ExecInputs;
TArray<UEdGraphPin*> ExecOutputs;
ProcessNodePins(Node, OutNodeDef, ExecInputs, ExecOutputs);
ProcessNodeFlows(Node, ExecInputs, ExecOutputs);
LogNodeDetails(OutNodeDef);
return true;
}
void FN2CNodeTranslator::AddGraphToProcess(UEdGraph* Graph)
{
if (!Graph)
{
return;
}
// Check if we've already processed this graph
for (const FN2CGraph& ExistingGraph : N2CBlueprint.Graphs)
{
if (ExistingGraph.Name == Graph->GetName())
{
return;
}
}
// Check if this is a user-created graph
bool bIsUserCreated = false;
// Check if this is a composite/collapsed graph
if (Cast<UK2Node_Composite>(Graph->GetOuter()))
{
bIsUserCreated = !Graph->GetOuter()->IsA<UK2Node_MathExpression>();
if (bIsUserCreated)
{
FString Context = FString::Printf(TEXT("Found composite graph: %s"), *Graph->GetName());
FN2CLogger::Get().Log(Context, EN2CLogSeverity::Debug);
}
}
// Otherwise check if it's in a user content directory
else if (UBlueprint* OwningBP = Cast<UBlueprint>(Graph->GetOuter()))
{
// Check if the Blueprint is in a user content directory
FString BlueprintPath = OwningBP->GetPathName();
bIsUserCreated = BlueprintPath.Contains(TEXT("/Game/")) ||
BlueprintPath.Contains(TEXT("/Content/"));
// For macros, also check if it's a user-created macro
if (UK2Node_MacroInstance* MacroNode = Cast<UK2Node_MacroInstance>(Graph->GetOuter()))
{
if (UEdGraph* MacroGraph = MacroNode->GetMacroGraph())
{
if (UBlueprint* MacroBP = Cast<UBlueprint>(MacroGraph->GetOuter()))
{
FString MacroPath = MacroBP->GetPathName();
bIsUserCreated = MacroPath.Contains(TEXT("/Game/")) ||
MacroPath.Contains(TEXT("/Content/"));
}
}
}
}
// Only process user-created graphs
if (bIsUserCreated)
{
// Now check recursion depth limit since we know it's a user graph
const UN2CSettings* Settings = GetDefault<UN2CSettings>();
int32 NextDepth = CurrentDepth + 1;
if (Settings && NextDepth > Settings->TranslationDepth)
{
FString Context = FString::Printf(TEXT("Skipping graph '%s' - maximum translation depth reached (%d)"),
*Graph->GetName(), Settings->TranslationDepth);
FN2CLogger::Get().Log(Context, EN2CLogSeverity::Warning);
return;
}
// Check if we already have this graph queued
bool bAlreadyQueued = false;
for (const FGraphProcessInfo& Info : AdditionalGraphsToProcess)
{
if (Info.Graph == Graph)
{
bAlreadyQueued = true;
break;
}
}
if (!bAlreadyQueued)
{
FString Context = FString::Printf(TEXT("Adding user-created graph to process: %s (Parent Depth: %d)"),
*Graph->GetName(), CurrentDepth);
FN2CLogger::Get().Log(Context, EN2CLogSeverity::Debug);
AdditionalGraphsToProcess.Add(FGraphProcessInfo(Graph, CurrentDepth));
}
}
else
{
// Only log at Debug severity since this is expected behavior
FString Context = FString::Printf(TEXT("Skipping engine graph: %s"), *Graph->GetName());
FN2CLogger::Get().Log(Context, EN2CLogSeverity::Debug);
}
}
bool FN2CNodeTranslator::ProcessGraph(UEdGraph* Graph, EN2CGraphType GraphType)
{
if (!Graph)
{
FN2CLogger::Get().LogWarning(TEXT("Attempted to process null graph"));
return false;
}
// Create new graph structure
FN2CGraph NewGraph;
NewGraph.Name = Graph->GetName();
NewGraph.GraphType = GraphType;
CurrentGraph = &NewGraph;
// Collect and process nodes from this graph
TArray<UK2Node*> GraphNodes;
for (UEdGraphNode* Node : Graph->Nodes)
{
if (UK2Node* K2Node = Cast<UK2Node>(Node))
{
FN2CNodeDefinition NodeDef;
if (ProcessNode(K2Node, NodeDef))
{
CurrentGraph->Nodes.Add(NodeDef);
}
}
}
// Add the processed graph to the blueprint if it has nodes
if (CurrentGraph->Nodes.Num() > 0)
{
// Validate all flow references
if (!ValidateFlowReferences(NewGraph))
{
FN2CLogger::Get().LogWarning(FString::Printf(TEXT("Flow validation issues found in graph: %s"), *NewGraph.Name));
}
N2CBlueprint.Graphs.Add(NewGraph);
FString Context = FString::Printf(TEXT("Processed graph: %s with %d nodes"),
*NewGraph.Name,
NewGraph.Nodes.Num());
FN2CLogger::Get().Log(TEXT("Graph processing complete"), EN2CLogSeverity::Info, Context);
return true;
}
return false;
}
EN2CGraphType FN2CNodeTranslator::DetermineGraphType(UEdGraph* Graph) const
{
if (!Graph)
{
return EN2CGraphType::EventGraph;
}
// First check if this is a function graph by looking for function entry node
for (UEdGraphNode* Node : Graph->Nodes)
{
if (Node->IsA<UK2Node_FunctionEntry>())
{
return EN2CGraphType::Function;
}
}
// Check for composite/collapsed graphs
if (Cast<UK2Node_Composite>(Graph->GetOuter()))
{
return EN2CGraphType::Composite;
}
// Check graph name for common patterns
FString GraphName = Graph->GetName().ToLower();
if (GraphName.Contains(TEXT("construction")))
{
return EN2CGraphType::Construction;
}
if (GraphName.Contains(TEXT("macro")))
{
return EN2CGraphType::Macro;
}
if (GraphName.Contains(TEXT("animation")))
{
return EN2CGraphType::Animation;
}
// Default to event graph
return EN2CGraphType::EventGraph;
}
void FN2CNodeTranslator::DetermineNodeType(UK2Node* Node, EN2CNodeType& OutType)
{
OutType = FN2CNodeTypeRegistry::Get().GetNodeType(Node);
}
EN2CPinType FN2CNodeTranslator::DeterminePinType(const UEdGraphPin* Pin) const
{
if (!Pin) return EN2CPinType::Wildcard;
const FName& PinCategory = Pin->PinType.PinCategory;
// Handle execution pins
if (PinCategory == UEdGraphSchema_K2::PC_Exec)
return EN2CPinType::Exec;
// Handle basic types
if (PinCategory == UEdGraphSchema_K2::PC_Boolean)
return EN2CPinType::Boolean;
if (PinCategory == UEdGraphSchema_K2::PC_Byte)
return EN2CPinType::Byte;
if (PinCategory == UEdGraphSchema_K2::PC_Int)
return EN2CPinType::Integer;
if (PinCategory == UEdGraphSchema_K2::PC_Int64)
return EN2CPinType::Integer64;
if (PinCategory == UEdGraphSchema_K2::PC_Float)
return EN2CPinType::Float;
if (PinCategory == UEdGraphSchema_K2::PC_Double)
return EN2CPinType::Double;
if (PinCategory == UEdGraphSchema_K2::PC_Real)
return EN2CPinType::Real;
if (PinCategory == UEdGraphSchema_K2::PC_String)
return EN2CPinType::String;
if (PinCategory == UEdGraphSchema_K2::PC_Name)
return EN2CPinType::Name;
if (PinCategory == UEdGraphSchema_K2::PC_Text)
return EN2CPinType::Text;
// Handle object types
if (PinCategory == UEdGraphSchema_K2::PC_Object)
return EN2CPinType::Object;
if (PinCategory == UEdGraphSchema_K2::PC_Class)
return EN2CPinType::Class;
if (PinCategory == UEdGraphSchema_K2::PC_Interface)
return EN2CPinType::Interface;
if (PinCategory == UEdGraphSchema_K2::PC_Struct)
return EN2CPinType::Struct;
if (PinCategory == UEdGraphSchema_K2::PC_Enum)
return EN2CPinType::Enum;
// Handle delegate types
if (PinCategory == UEdGraphSchema_K2::PC_Delegate)
return EN2CPinType::Delegate;
if (PinCategory == UEdGraphSchema_K2::PC_MCDelegate)
return EN2CPinType::MulticastDelegate;
// Handle field path and special types
if (PinCategory == UEdGraphSchema_K2::PC_FieldPath)
return EN2CPinType::FieldPath;
if (PinCategory == UEdGraphSchema_K2::PC_Wildcard)
return EN2CPinType::Wildcard;
// Handle soft references
if (PinCategory == UEdGraphSchema_K2::PC_SoftObject)
return EN2CPinType::SoftObject;
if (PinCategory == UEdGraphSchema_K2::PC_SoftClass)
return EN2CPinType::SoftClass;
// Handle special subcategories
if (Pin->PinType.PinSubCategory == UEdGraphSchema_K2::PSC_Bitmask)
return EN2CPinType::Bitmask;
if (Pin->PinType.PinSubCategory == UEdGraphSchema_K2::PSC_Self)
return EN2CPinType::Self;
if (Pin->PinType.PinSubCategory == UEdGraphSchema_K2::PSC_Index)
return EN2CPinType::Index;
// Default to wildcard for unknown types
return EN2CPinType::Wildcard;
}
UEdGraphPin* FN2CNodeTranslator::TraceConnectionThroughKnots(UEdGraphPin* StartPin) const
{
if (!StartPin)
{
return nullptr;
}
UEdGraphPin* CurrentPin = StartPin;
TSet<UEdGraphNode*> VisitedNodes; // Prevent infinite loops
while (CurrentPin)
{
UEdGraphNode* OwningNode = CurrentPin->GetOwningNode();
if (!OwningNode)
{
return nullptr;
}
// If we've hit this node before, we have a loop
if (VisitedNodes.Contains(OwningNode))
{
FN2CLogger::Get().LogWarning(TEXT("Detected loop in knot node chain"));
return nullptr;
}
VisitedNodes.Add(OwningNode);
// If this isn't a knot node, we've found our target
if (!OwningNode->IsA<UK2Node_Knot>())
{
return CurrentPin;
}
// For knot nodes, follow to the next connection
// Knots should only have one connection on the opposite side
TArray<UEdGraphPin*>& LinkedPins = (CurrentPin->Direction == EGPD_Input) ?
OwningNode->Pins[1]->LinkedTo : OwningNode->Pins[0]->LinkedTo;
if (LinkedPins.Num() == 0)
{
return nullptr; // Dead end
}
CurrentPin = LinkedPins[0];
}
return nullptr;
}
bool FN2CNodeTranslator::ValidateFlowReferences(FN2CGraph& Graph)
{
// Use the blueprint validator to validate the graph
FN2CBlueprintValidator Validator;
FString ErrorMessage;
return Validator.ValidateFlowReferences(Graph, ErrorMessage);
}
void FN2CNodeTranslator::ProcessNodeTypeAndProperties(UK2Node* Node, FN2CNodeDefinition& OutNodeDef)
{
// Determine node type
DetermineNodeType(Node, OutNodeDef.NodeType);
// Get the appropriate processor for this node type
TSharedPtr<IN2CNodeProcessor> Processor = FN2CNodeProcessorFactory::Get().GetProcessor(OutNodeDef.NodeType);
if (Processor.IsValid())
{
// Process the node using the processor
if (!Processor->Process(Node, OutNodeDef))
{
FString NodeTypeName = StaticEnum<EN2CNodeType>()->GetNameStringByValue(static_cast<int64>(OutNodeDef.NodeType));
FString NodeTitle = Node->GetNodeTitle(ENodeTitleType::ListView).ToString();
FN2CLogger::Get().LogWarning(FString::Printf(TEXT("Node processor failed for node '%s' of type %s"),
*NodeTitle, *NodeTypeName));
// Fall back to the old method if processor fails
FallbackProcessNodeProperties(Node, OutNodeDef);
}
else
{
// Log successful processing
FString NodeTypeName = StaticEnum<EN2CNodeType>()->GetNameStringByValue(static_cast<int64>(OutNodeDef.NodeType));
FN2CLogger::Get().Log(FString::Printf(TEXT("Successfully processed node '%s' using %s processor"),
*OutNodeDef.Name, *NodeTypeName), EN2CLogSeverity::Debug);
}
}
else
{
// Fall back to the old method if no processor is available
FString NodeTypeName = StaticEnum<EN2CNodeType>()->GetNameStringByValue(static_cast<int64>(OutNodeDef.NodeType));
FString NodeTitle = Node->GetNodeTitle(ENodeTitleType::ListView).ToString();
FN2CLogger::Get().LogWarning(FString::Printf(TEXT("No processor available for node '%s' of type %s"),
*NodeTitle, *NodeTypeName));
FallbackProcessNodeProperties(Node, OutNodeDef);
}
// Process any struct or enum types used in this node
ProcessRelatedTypes(Node, OutNodeDef);
// Check for nested graphs that might need processing
if (UK2Node_Composite* CompositeNode = Cast<UK2Node_Composite>(Node))
{
if (UEdGraph* BoundGraph = CompositeNode->BoundGraph)
{
AddGraphToProcess(BoundGraph);
}
}
else if (UK2Node_MacroInstance* MacroNode = Cast<UK2Node_MacroInstance>(Node))
{
if (UEdGraph* MacroGraph = MacroNode->GetMacroGraph())
{
AddGraphToProcess(MacroGraph);
}
}
else if (UK2Node_CallFunction* FuncNode = Cast<UK2Node_CallFunction>(Node))
{
if (UFunction* Function = FuncNode->GetTargetFunction())
{
if (UBlueprintGeneratedClass* BlueprintClass = Cast<UBlueprintGeneratedClass>(Function->GetOwnerClass()))
{
if (UBlueprint* FunctionBlueprint = Cast<UBlueprint>(BlueprintClass->ClassGeneratedBy))
{
// Find and add the function graph
for (UEdGraph* FuncGraph : FunctionBlueprint->FunctionGraphs)
{
if (FuncGraph && FuncGraph->GetFName() == Function->GetFName())
{
AddGraphToProcess(FuncGraph);
break;
}
}
}
}
}
}
else if (UK2Node_CreateDelegate* CreateDelegateNode = Cast<UK2Node_CreateDelegate>(Node))
{
// Try to find and add the function graph
if (UClass* ScopeClass = CreateDelegateNode->GetScopeClass())
{
if (UBlueprint* BP = Cast<UBlueprint>(ScopeClass->ClassGeneratedBy))
{
for (UEdGraph* FuncGraph : BP->FunctionGraphs)
{
if (FuncGraph && FuncGraph->GetFName() == CreateDelegateNode->GetFunctionName())
{
AddGraphToProcess(FuncGraph);
FN2CLogger::Get().Log(
FString::Printf(TEXT("Added delegate function graph to process: %s"), *FuncGraph->GetName()),
EN2CLogSeverity::Debug);
break;
}
}
}
}
else if (UFunction* DelegateSignature = CreateDelegateNode->GetDelegateSignature())
{
if (UBlueprintGeneratedClass* BlueprintClass = Cast<UBlueprintGeneratedClass>(DelegateSignature->GetOwnerClass()))
{
if (UBlueprint* FunctionBlueprint = Cast<UBlueprint>(BlueprintClass->ClassGeneratedBy))
{
// Find and add the function graph
for (UEdGraph* FuncGraph : FunctionBlueprint->FunctionGraphs)
{
if (FuncGraph && FuncGraph->GetFName() == DelegateSignature->GetFName())
{
AddGraphToProcess(FuncGraph);
FN2CLogger::Get().Log(
FString::Printf(TEXT("Added delegate signature graph to process: %s"), *FuncGraph->GetName()),
EN2CLogSeverity::Debug);
break;
}
}
}
}
}
}
}
void FN2CNodeTranslator::FallbackProcessNodeProperties(UK2Node* Node, FN2CNodeDefinition& OutNodeDef)
{
// Set node name
OutNodeDef.Name = Node->GetNodeTitle(ENodeTitleType::MenuTitle).ToString();
// Determine node specific data directly such as
// MemberParent, MemberName, bLatent,
DetermineNodeSpecificProperties(Node, OutNodeDef);
// Extract comments if present
if (Node->NodeComment.Len() > 0) { OutNodeDef.Comment = Node->NodeComment; }
// Set purity from node
OutNodeDef.bPure = Node->IsNodePure();
}
void FN2CNodeTranslator::ProcessNodePins(UK2Node* Node, FN2CNodeDefinition& OutNodeDef, TArray<UEdGraphPin*>& OutExecInputs, TArray<UEdGraphPin*>& OutExecOutputs)
{
// Process input pins
for (UEdGraphPin* Pin : Node->Pins)
{
if (!Pin) continue;
// Skip hidden pins entirely
if (Pin->bHidden)
{
continue;
}
FN2CPinDefinition PinDef;
// Generate and map pin ID (using local counter for this node)
FString PinID = GeneratePinID(OutNodeDef.InputPins.Num() + OutNodeDef.OutputPins.Num());
PinIDMap.Add(Pin->PinId, PinID);
PinDef.ID = PinID;
// Set pin name
PinDef.Name = Pin->GetDisplayName().ToString();
// Determine pin type
PinDef.Type = DeterminePinType(Pin);
// Set pin metadata
PinDef.bConnected = Pin->LinkedTo.Num() > 0;
PinDef.bIsReference = Pin->PinType.bIsReference;
PinDef.bIsConst = Pin->PinType.bIsConst;
PinDef.bIsArray = Pin->PinType.ContainerType == EPinContainerType::Array;
PinDef.bIsMap = Pin->PinType.ContainerType == EPinContainerType::Map;
PinDef.bIsSet = Pin->PinType.ContainerType == EPinContainerType::Set;
// Get default value if any
if (!Pin->DefaultValue.IsEmpty())
{
PinDef.DefaultValue = Pin->DefaultValue;
}
else if (Pin->DefaultObject)
{
PinDef.DefaultValue = Pin->DefaultObject->GetPathName();
}
else if (!Pin->DefaultTextValue.IsEmpty())
{
PinDef.DefaultValue = Pin->DefaultTextValue.ToString();
}
// Set subtype for container/object types
if (UK2Node_CreateDelegate* CreateDelegateNode = Cast<UK2Node_CreateDelegate>(Node))
{
// For delegate output pin on CreateDelegate node, use function name as subtype
if (Pin->Direction == EGPD_Output && Pin->PinType.PinCategory == TEXT("delegate"))
{
PinDef.SubType = GetCleanClassName(CreateDelegateNode->GetFunctionName().ToString());
}
if (Pin->Direction == EGPD_Input && Pin->PinType.PinCategory == TEXT("object"))
{
PinDef.SubType = GetCleanClassName(CreateDelegateNode->GetScopeClass()->GetName());
}
}
else if (Pin->PinType.PinSubCategoryObject.IsValid())
{
PinDef.SubType = GetCleanClassName(Pin->PinType.PinSubCategoryObject->GetName());
}
else if (!Pin->PinType.PinSubCategory.IsNone())
{
PinDef.SubType = GetCleanClassName(Pin->PinType.PinSubCategory.ToString());
}
// Add to appropriate pin array
if (Pin->Direction == EGPD_Input)
{
OutNodeDef.InputPins.Add(PinDef);
if (Pin->PinType.PinCategory == TEXT("exec"))
{
OutExecInputs.Add(Pin);
FString PinContext = FString::Printf(TEXT("Found exec input pin: %s on node %s"),
*Pin->GetDisplayName().ToString(),
*Node->GetNodeTitle(ENodeTitleType::ListView).ToString());
FN2CLogger::Get().Log(PinContext, EN2CLogSeverity::Debug);
}
}
else if (Pin->Direction == EGPD_Output)
{
OutNodeDef.OutputPins.Add(PinDef);
// Track execution outputs
if (Pin->PinType.PinCategory == TEXT("exec"))
{
OutExecOutputs.Add(Pin);
FString PinContext = FString::Printf(TEXT("Found exec output pin: %s on node %s"),
*Pin->GetDisplayName().ToString(),
*Node->GetNodeTitle(ENodeTitleType::ListView).ToString());
FN2CLogger::Get().Log(PinContext, EN2CLogSeverity::Debug);
}
}
}
}
void FN2CNodeTranslator::ProcessNodeFlows(UK2Node* Node, const TArray<UEdGraphPin*>& ExecInputs, const TArray<UEdGraphPin*>& ExecOutputs)
{
// Record execution flows
FString ExecDebug = FString::Printf(TEXT("Node %s has %d exec outputs"),
*Node->GetNodeTitle(ENodeTitleType::ListView).ToString(),
ExecOutputs.Num());
FN2CLogger::Get().Log(ExecDebug, EN2CLogSeverity::Debug);
for (UEdGraphPin* ExecOutput : ExecOutputs)
{
if (!ExecOutput) continue;
FString PinDebug = FString::Printf(TEXT("Exec output pin %s has %d connections"),
*ExecOutput->GetDisplayName().ToString(),
ExecOutput->LinkedTo.Num());
FN2CLogger::Get().Log(PinDebug, EN2CLogSeverity::Debug);
for (UEdGraphPin* LinkedPin : ExecOutput->LinkedTo)
{
if (!LinkedPin)
{
FN2CLogger::Get().Log(TEXT("Found null linked pin"), EN2CLogSeverity::Warning);
continue;
}
// Trace through any knot nodes to find the actual target
UEdGraphPin* ActualTargetPin = TraceConnectionThroughKnots(LinkedPin);
if (!ActualTargetPin)
{
FN2CLogger::Get().Log(TEXT("Could not find valid target through knot chain"), EN2CLogSeverity::Warning);
continue;
}
UEdGraphNode* TargetNode = ActualTargetPin->GetOwningNode();
if (!TargetNode)
{
FN2CLogger::Get().Log(TEXT("Found null target node"), EN2CLogSeverity::Warning);
continue;
}
// Get or generate IDs for the nodes
FString SourceNodeID = NodeIDMap.FindRef(Node->NodeGuid);
FString TargetNodeID = NodeIDMap.FindRef(TargetNode->NodeGuid);
if (SourceNodeID.IsEmpty())
{
SourceNodeID = GenerateNodeID();
NodeIDMap.Add(Node->NodeGuid, SourceNodeID);
FN2CLogger::Get().Log(TEXT("Generated new source node ID"), EN2CLogSeverity::Debug);
}
if (TargetNodeID.IsEmpty())
{
TargetNodeID = GenerateNodeID();
NodeIDMap.Add(TargetNode->NodeGuid, TargetNodeID);
FN2CLogger::Get().Log(TEXT("Generated new target node ID"), EN2CLogSeverity::Debug);
}
// Add execution flow
FString FlowStr = FString::Printf(TEXT("%s->%s"), *SourceNodeID, *TargetNodeID);
CurrentGraph->Flows.Execution.AddUnique(FlowStr);
// Log execution flow
FString FlowContext = FString::Printf(TEXT("Added execution flow: %s (%s) -> %s (%s)"),
*SourceNodeID, *Node->GetNodeTitle(ENodeTitleType::ListView).ToString(),
*TargetNodeID, *TargetNode->GetNodeTitle(ENodeTitleType::ListView).ToString());
FN2CLogger::Get().Log(FlowContext, EN2CLogSeverity::Debug);
}
}
// Record data flows
for (UEdGraphPin* Pin : Node->Pins)
{
if (Pin && Pin->PinType.PinCategory != TEXT("exec"))
{
for (UEdGraphPin* LinkedPin : Pin->LinkedTo)
{
// Trace through any knot nodes to find the actual source and target
UEdGraphPin* ActualSourcePin = Pin;
UEdGraphPin* ActualTargetPin = TraceConnectionThroughKnots(LinkedPin);
if (ActualSourcePin && ActualTargetPin &&
ActualSourcePin->GetOwningNode() && ActualTargetPin->GetOwningNode())
{
// Get node and pin IDs
FString SourceNodeID = NodeIDMap.FindRef(ActualSourcePin->GetOwningNode()->NodeGuid);
FString SourcePinID = PinIDMap.FindRef(ActualSourcePin->PinId);
FString TargetNodeID = NodeIDMap.FindRef(ActualTargetPin->GetOwningNode()->NodeGuid);
FString TargetPinID = PinIDMap.FindRef(ActualTargetPin->PinId);
if (!SourceNodeID.IsEmpty() && !SourcePinID.IsEmpty() &&
!TargetNodeID.IsEmpty() && !TargetPinID.IsEmpty())
{
// Add data flow (always store as output->input direction)
FString SourceRef = FString::Printf(TEXT("%s.%s"), *SourceNodeID, *SourcePinID);
FString TargetRef = FString::Printf(TEXT("%s.%s"), *TargetNodeID, *TargetPinID);
// Always store flow from output pin to input pin
if (ActualSourcePin->Direction == EGPD_Output)
{
CurrentGraph->Flows.Data.FindOrAdd(SourceRef).TargetPins.Add(TargetRef);
// Log data flow
FString FlowContext = FString::Printf(TEXT("Added data flow: %s.%s (%s.%s) -> %s.%s (%s.%s)"),
*SourceNodeID, *SourcePinID,
*ActualSourcePin->GetOwningNode()->GetNodeTitle(ENodeTitleType::ListView).ToString(),
*ActualSourcePin->GetDisplayName().ToString(),
*TargetNodeID, *TargetPinID,
*ActualTargetPin->GetOwningNode()->GetNodeTitle(ENodeTitleType::ListView).ToString(),
*ActualTargetPin->GetDisplayName().ToString());
FN2CLogger::Get().Log(FlowContext, EN2CLogSeverity::Debug);
}
else
{
CurrentGraph->Flows.Data.FindOrAdd(TargetRef).TargetPins.Add(SourceRef);
// Log data flow
FString FlowContext = FString::Printf(TEXT("Added data flow: %s.%s (%s.%s) -> %s.%s (%s.%s)"),
*TargetNodeID, *TargetPinID,
*ActualTargetPin->GetOwningNode()->GetNodeTitle(ENodeTitleType::ListView).ToString(),
*ActualTargetPin->GetDisplayName().ToString(),
*SourceNodeID, *SourcePinID,
*ActualSourcePin->GetOwningNode()->GetNodeTitle(ENodeTitleType::ListView).ToString(),
*ActualSourcePin->GetDisplayName().ToString());
FN2CLogger::Get().Log(FlowContext, EN2CLogSeverity::Debug);
}
}
}
}
}
}
}
FN2CEnum FN2CNodeTranslator::ProcessBlueprintEnum(UEnum* Enum)
{
FN2CEnum Result;
if (!Enum)
{
FN2CLogger::Get().LogError(TEXT("Null enum provided to ProcessBlueprintEnum"));
return Result;
}
// Get enum path
FString EnumPath = Enum->GetPathName();
FString EnumName = Enum->GetName();
FN2CLogger::Get().Log(
FString::Printf(TEXT("ProcessBlueprintEnum: Processing enum '%s' (Path: %s)"),
*EnumName, *EnumPath),
EN2CLogSeverity::Info);
// Check if we've already processed this enum
if (ProcessedEnumPaths.Contains(EnumPath))
{
FN2CLogger::Get().Log(
FString::Printf(TEXT("Enum %s already processed - skipping"), *EnumPath),
EN2CLogSeverity::Debug);
return Result;
}
// Mark as processed
ProcessedEnumPaths.Add(EnumPath);
FN2CLogger::Get().Log(TEXT("Added enum to processed paths"), EN2CLogSeverity::Debug);
// Set basic enum info
Result.Name = EnumName;
FN2CLogger::Get().Log(
FString::Printf(TEXT("Enum details: Name=%s"),
*Result.Name),
EN2CLogSeverity::Debug);
// Get enum comment if available
FString EnumComment = Enum->GetMetaData(TEXT("ToolTip"));
if (!EnumComment.IsEmpty())
{
Result.Comment = EnumComment;
FN2CLogger::Get().Log(
FString::Printf(TEXT("Enum comment: %s"), *Result.Comment),
EN2CLogSeverity::Debug);
}
// Process enum values
int32 NumEnums = Enum->NumEnums();
FN2CLogger::Get().Log(
FString::Printf(TEXT("Enum has %d values according to NumEnums()"), NumEnums),
EN2CLogSeverity::Debug);
// Log all enum names and values for debugging
for (int32 i = 0; i < NumEnums; ++i)
{
FString ValueName = Enum->GetDisplayNameTextByIndex(i).ToString();
FN2CLogger::Get().Log(
FString::Printf(TEXT("Enum value #%d: Name='%s'"),
i, *ValueName),
EN2CLogSeverity::Debug);
// Check if this is a hidden enum value (like _MAX or similar)
bool bIsHidden = ValueName.Contains(TEXT("_MAX")) ||
ValueName.Contains(TEXT("MAX_")) ||
ValueName.Contains(TEXT("E MAX")) ||
ValueName.Contains(TEXT("MAX")) ||
ValueName.StartsWith(TEXT("_")) ||
ValueName.EndsWith(TEXT("_None"));
if (bIsHidden)
{
FN2CLogger::Get().Log(
FString::Printf(TEXT(" -> Skipping hidden value '%s'"), *ValueName),
EN2CLogSeverity::Debug);
continue; // Skip adding this value
}
FN2CEnumValue Value;
Value.Name = ValueName;
// Get value comment if available
FString ValueComment;
if (Enum->HasMetaData(TEXT("ToolTip"), i))
{
ValueComment = Enum->GetMetaData(TEXT("ToolTip"), i);
Value.Comment = ValueComment;