-
Notifications
You must be signed in to change notification settings - Fork 348
Expand file tree
/
Copy pathFlowNodeAddOn_PredicateCompareValues.cpp
More file actions
791 lines (647 loc) · 25.8 KB
/
FlowNodeAddOn_PredicateCompareValues.cpp
File metadata and controls
791 lines (647 loc) · 25.8 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
// Copyright https://github.com/MothCocoon/FlowGraph/graphs/contributors
#include "AddOns/FlowNodeAddOn_PredicateCompareValues.h"
#include "FlowSettings.h"
#include "Types/FlowPinTypeNamesStandard.h"
#include "Types/FlowPinTypesStandard.h"
#include "Types/FlowDataPinValuesStandard.h"
#include "FlowAsset.h"
#include "Policies/FlowPinConnectionPolicy.h"
#define LOCTEXT_NAMESPACE "FlowNodeAddOn_PredicateCompareValues"
#include UE_INLINE_GENERATED_CPP_BY_NAME(FlowNodeAddOn_PredicateCompareValues)
namespace
{
#if WITH_EDITOR
static void ForceNamedPropertyPinDirection(FFlowNamedDataPinProperty& NamedProperty, const bool bIsInput)
{
const UScriptStruct* ScriptStruct = NamedProperty.DataPinValue.GetScriptStruct();
if (IsValid(ScriptStruct) && ScriptStruct->IsChildOf<FFlowDataPinValue>())
{
FFlowDataPinValue& WrapperValue = NamedProperty.DataPinValue.GetMutable<FFlowDataPinValue>();
WrapperValue.bIsInputPin = bIsInput;
}
}
#endif // WITH_EDITOR
}
UFlowNodeAddOn_PredicateCompareValues::UFlowNodeAddOn_PredicateCompareValues()
: Super()
{
#if WITH_EDITOR
NodeDisplayStyle = FlowNodeStyle::AddOn_Predicate;
Category = TEXT("DataPins");
#endif
if (GetAuthoredValueName(LeftValue).IsNone())
{
LeftValue.Name = TEXT("Compare Left Value");
}
if (GetAuthoredValueName(RightValue).IsNone())
{
RightValue.Name = TEXT("Compare Right Value");
}
#if WITH_EDITORONLY_DATA
// Encourage input pins by default; PostEditChangeChainProperty enforces it.
if (FFlowDataPinValue* LeftWrapper = LeftValue.DataPinValue.GetMutablePtr<FFlowDataPinValue>())
{
LeftWrapper->bIsInputPin = true;
}
if (FFlowDataPinValue* RightWrapper = RightValue.DataPinValue.GetMutablePtr<FFlowDataPinValue>())
{
RightWrapper->bIsInputPin = true;
}
#endif
}
bool UFlowNodeAddOn_PredicateCompareValues::TryFindPropertyByPinName(const FName& PinName, const FProperty*& OutFoundProperty, TInstancedStruct<FFlowDataPinValue>& OutFoundInstancedStruct) const
{
// TODO (gtaylor) It would be nicer if the base IFlowDataPinValueOwnerInterface::TryFindPropertyByPinName implementation
// could find member FFlowNamedDataPinProperty's by their Name field, but that would require a property search,
// so we don't need to special-case these. Maybe we can think of a more clever version at some point.
if (GetAuthoredValueName(LeftValue) == PinName)
{
OutFoundInstancedStruct = LeftValue.DataPinValue;
return true;
}
if (GetAuthoredValueName(RightValue) == PinName)
{
OutFoundInstancedStruct = RightValue.DataPinValue;
return true;
}
if (Super::TryFindPropertyByPinName(PinName, OutFoundProperty, OutFoundInstancedStruct))
{
return true;
}
return false;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsEqualityOp() const
{
return EFlowPredicateCompareOperatorType_Classifiers::IsEqualityOperation(OperatorType);
}
bool UFlowNodeAddOn_PredicateCompareValues::IsArithmeticOp() const
{
return EFlowPredicateCompareOperatorType_Classifiers::IsArithmeticOperation(OperatorType);
}
bool UFlowNodeAddOn_PredicateCompareValues::IsNumericTypeName(
const FFlowPinConnectionPolicy& PinConnectionPolicy,
const FName& TypeName)
{
return
PinConnectionPolicy.GetAllSupportedIntegerTypes().Contains(TypeName) ||
PinConnectionPolicy.GetAllSupportedFloatTypes().Contains(TypeName);
}
bool UFlowNodeAddOn_PredicateCompareValues::IsFloatingPointType(
const FFlowPinConnectionPolicy& PinConnectionPolicy,
const FName& TypeName)
{
return PinConnectionPolicy.GetAllSupportedFloatTypes().Contains(TypeName);
}
bool UFlowNodeAddOn_PredicateCompareValues::IsIntegerType(
const FFlowPinConnectionPolicy& PinConnectionPolicy,
const FName& TypeName)
{
return PinConnectionPolicy.GetAllSupportedIntegerTypes().Contains(TypeName);
}
bool UFlowNodeAddOn_PredicateCompareValues::IsTextType(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameText;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsStringType(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameString;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsNameLikeType(const FName& TypeName)
{
// Treat Enum as "Name-like" for comparisons (case-insensitive)
return
TypeName == FFlowPinTypeNamesStandard::PinTypeNameName ||
TypeName == FFlowPinTypeNamesStandard::PinTypeNameEnum;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsAnyStringLikeTypeName(
const FFlowPinConnectionPolicy& PinConnectionPolicy,
const FName& TypeName)
{
// Special-casing NameLike, since the CompareValues predicate counts Enums as Names
return
IsNameLikeType(TypeName) ||
PinConnectionPolicy.GetAllSupportedStringLikeTypes().Contains(TypeName);
}
bool UFlowNodeAddOn_PredicateCompareValues::IsGameplayTagLikeTypeName(
const FFlowPinConnectionPolicy& PinConnectionPolicy,
const FName& TypeName)
{
return PinConnectionPolicy.GetAllSupportedGameplayTagTypes().Contains(TypeName);
}
bool UFlowNodeAddOn_PredicateCompareValues::IsBoolTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameBool;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsVectorTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameVector;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsRotatorTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameRotator;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsTransformTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameTransform;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsObjectTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameObject;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsClassTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameClass;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsInstancedStructTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameInstancedStruct;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsBoolTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameBool;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsVectorTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameVector;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsRotatorTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameRotator;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsTransformTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameTransform;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsObjectTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameObject;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsClassTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameClass;
}
bool UFlowNodeAddOn_PredicateCompareValues::IsInstancedStructTypeName(const FName& TypeName)
{
return TypeName == FFlowPinTypeNamesStandard::PinTypeNameInstancedStruct;
}
#if WITH_EDITOR
void UFlowNodeAddOn_PredicateCompareValues::PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent)
{
// Force both FFlowNamedDataPinProperty values to always be input pins.
const auto& ChangedProperty = PropertyChangedEvent.PropertyChain.GetActiveMemberNode()->GetValue();
constexpr bool bIsInput = true;
OnPostEditEnsureAllNamedPropertiesPinDirection(*ChangedProperty, bIsInput);
Super::PostEditChangeChainProperty(PropertyChangedEvent);
OnReconstructionRequested.ExecuteIfBound();
}
void UFlowNodeAddOn_PredicateCompareValues::OnPostEditEnsureAllNamedPropertiesPinDirection(const FProperty& Property, bool bIsInput)
{
if (Property.GetFName() == GetLeftValuePropertyName())
{
ForceNamedPropertyPinDirection(LeftValue, bIsInput);
}
else if (Property.GetFName() == GetRightValuePropertyName())
{
ForceNamedPropertyPinDirection(RightValue, bIsInput);
}
}
EDataValidationResult UFlowNodeAddOn_PredicateCompareValues::ValidateNode()
{
EDataValidationResult Result = Super::ValidateNode();
// Validate that both values are configured
if (!LeftValue.IsValid())
{
LogValidationError(TEXT("LeftValue is not configured (missing name or pin type)."));
Result = EDataValidationResult::Invalid;
}
if (!RightValue.IsValid())
{
LogValidationError(TEXT("RightValue is not configured (missing name or pin type)."));
Result = EDataValidationResult::Invalid;
}
// Remaining checks require both values to be valid
if (!LeftValue.IsValid() || !RightValue.IsValid())
{
return Result;
}
const FFlowPinTypeName LeftPinTypeName = LeftValue.DataPinValue.Get().GetPinTypeName();
const FFlowPinTypeName RightPinTypeName = RightValue.DataPinValue.Get().GetPinTypeName();
// Validate pin type names are set
if (LeftPinTypeName.IsNone())
{
LogValidationError(TEXT("LeftValue has an unknown or unset pin type."));
Result = EDataValidationResult::Invalid;
}
if (RightPinTypeName.IsNone())
{
LogValidationError(TEXT("RightValue has an unknown or unset pin type."));
Result = EDataValidationResult::Invalid;
}
if (LeftPinTypeName.IsNone() || RightPinTypeName.IsNone())
{
return Result;
}
// Check type compatibility
const UFlowAsset* FlowAsset = GetFlowAsset();
check(IsValid(FlowAsset));
const FFlowPinConnectionPolicy& PinConnectionPolicy = FlowAsset->GetPinConnectionPolicy();
const FName LeftTypeName = LeftPinTypeName.Name;
const FName RightTypeName = RightPinTypeName.Name;
const bool bSameType = (LeftTypeName == RightTypeName);
if (!bSameType && !AreComparablePinTypes(PinConnectionPolicy, LeftTypeName, RightTypeName))
{
LogValidationError(FString::Printf(
TEXT("Pin types are not comparable: '%s' vs '%s'."),
*LeftTypeName.ToString(),
*RightTypeName.ToString()));
Result = EDataValidationResult::Invalid;
}
// Validate arithmetic operators are only used with numeric types
if (IsArithmeticOp() &&
!(IsNumericTypeName(PinConnectionPolicy, LeftTypeName) && IsNumericTypeName(PinConnectionPolicy, RightTypeName)))
{
LogValidationError(FString::Printf(
TEXT("Arithmetic operator '%s' is only supported for numeric pin types (Int/Int64/Float/Double). Current types: '%s' vs '%s'."),
*EFlowPredicateCompareOperatorType_Classifiers::GetOperatorSymbolString(OperatorType),
*LeftTypeName.ToString(),
*RightTypeName.ToString()));
Result = EDataValidationResult::Invalid;
}
// Warn if both sides have the same authored name (potential user confusion)
if (GetAuthoredValueName(LeftValue) == GetAuthoredValueName(RightValue))
{
LogValidationWarning(FString::Printf(
TEXT("LeftValue and RightValue have the same name '%s'. This may cause confusion with pin disambiguation."),
*GetAuthoredValueName(LeftValue).ToString()));
}
if (Result == EDataValidationResult::NotValidated)
{
Result = EDataValidationResult::Valid;
}
return Result;
}
FText UFlowNodeAddOn_PredicateCompareValues::K2_GetNodeTitle_Implementation() const
{
using namespace EFlowPredicateCompareOperatorType_Classifiers;
const bool bIsClassDefault = HasAnyFlags(RF_ArchetypeObject | RF_ClassDefaultObject);
if (!bIsClassDefault &&
GetDefault<UFlowSettings>()->bUseAdaptiveNodeTitles)
{
const FText LeftDisplayName = FText::FromName(GetAuthoredValueName(LeftValue));
const FText RightDisplayName = FText::FromName(GetAuthoredValueName(RightValue));
const FString OperatorString = GetOperatorSymbolString(OperatorType);
const FText OperatorText = FText::FromString(OperatorString);
return FText::Format(LOCTEXT("CompareValuesTitle", "{0} {1} {2}"), { LeftDisplayName, OperatorText, RightDisplayName });
}
return Super::K2_GetNodeTitle_Implementation();
}
#endif // WITH_EDITOR
bool UFlowNodeAddOn_PredicateCompareValues::AreComparablePinTypes(const FFlowPinConnectionPolicy& PinConnectionPolicy, const FName& LeftPinTypeName, const FName& RightPinTypeName)
{
return PinConnectionPolicy.CanConnectPinTypeNames(LeftPinTypeName, RightPinTypeName);
}
bool UFlowNodeAddOn_PredicateCompareValues::CacheTypeNames(FCachedTypeNames& OutCache) const
{
OutCache.Reset();
if (!LeftValue.IsValid() || !RightValue.IsValid())
{
LogError(TEXT("Compare Values requires both LeftValue and RightValue to be configured."));
return false;
}
OutCache.LeftTypeName = LeftValue.DataPinValue.Get().GetPinTypeName().Name;
OutCache.RightTypeName = RightValue.DataPinValue.Get().GetPinTypeName().Name;
OutCache.bIsValid = true;
// String-like: allow Name/String/Text/Enum interchange
// (we include Enums as they have FName values for the purposes of comparison)
if (IsAnyStringLikeTypeName(LeftPinTypeName) && IsAnyStringLikeTypeName(RightPinTypeName))
{
return true;
}
// GameplayTag / Container: allow interchange (type templates can upscale tag -> container)
if (IsGameplayTagLikeTypeName(LeftPinTypeName) && IsGameplayTagLikeTypeName(RightPinTypeName))
{
return true;
}
// Note: Bool, Vector, Rotator, Transform, Object, Class, InstancedStruct are all
// only comparable with themselves (handled by the LeftPinTypeName == RightPinTypeName check above).
// Unknown/user types also fall into same-type comparison via the fallback path in EvaluatePredicate.
return false;
}
bool UFlowNodeAddOn_PredicateCompareValues::CacheTypeNames(FCachedTypeNames& OutCache) const
{
OutCache.Reset();
if (!LeftValue.IsValid() || !RightValue.IsValid())
{
LogError(TEXT("Compare Values requires both LeftValue and RightValue to be configured."));
return false;
}
OutCache.LeftTypeName = LeftValue.DataPinValue.Get().GetPinTypeName().Name;
OutCache.RightTypeName = RightValue.DataPinValue.Get().GetPinTypeName().Name;
OutCache.bIsValid = true;
return true;
}
bool UFlowNodeAddOn_PredicateCompareValues::TryCheckGameplayTagsEqual(bool& bOutIsEqual) const
{
// Compare both sides as containers; pin type templates should allow tag->container conversion.
FGameplayTagContainer LeftContainer;
{
const EFlowDataPinResolveResult ResolveResult =
TryResolveDataPinValue<FFlowPinType_GameplayTagContainer>(GetDisambiguatedValueName(LeftValue), LeftContainer, SingleFromArray);
if (!FlowPinType::IsSuccess(ResolveResult))
{
LogError(TEXT("Failed to resolve LeftValue as GameplayTagContainer."));
return false;
}
}
FGameplayTagContainer RightContainer;
{
const EFlowDataPinResolveResult ResolveResult =
TryResolveDataPinValue<FFlowPinType_GameplayTagContainer>(GetDisambiguatedValueName(RightValue), RightContainer, SingleFromArray);
if (!FlowPinType::IsSuccess(ResolveResult))
{
LogError(TEXT("Failed to resolve RightValue as GameplayTagContainer."));
return false;
}
}
bOutIsEqual = (LeftContainer == RightContainer);
return true;
}
bool UFlowNodeAddOn_PredicateCompareValues::TryCheckFallbackStringEqual(bool& bOutIsEqual) const
{
// Fallback path: try to convert both sides to string via their FFlowDataPinValue::TryConvertValuesToString.
// This enables user-added pin types (from other plugins) to participate in equality comparisons
// as long as they implement TryConvertValuesToString on their FFlowDataPinValue subclass.
const FFlowDataPinValue* LeftDataPinValue = LeftValue.DataPinValue.GetPtr<FFlowDataPinValue>();
const FFlowDataPinValue* RightDataPinValue = RightValue.DataPinValue.GetPtr<FFlowDataPinValue>();
if (!LeftDataPinValue || !RightDataPinValue)
{
return false;
}
FString LeftString;
if (!LeftDataPinValue->TryConvertValuesToString(LeftString))
{
LogError(TEXT("Failed to convert LeftValue to String for fallback comparison."));
return false;
}
FString RightString;
if (!RightDataPinValue->TryConvertValuesToString(RightString))
{
LogError(TEXT("Failed to convert RightValue to String for fallback comparison."));
return false;
}
bOutIsEqual = (LeftString == RightString);
return true;
}
bool UFlowNodeAddOn_PredicateCompareValues::CompareDoubleUsingOperator(double LeftValueAsDouble, double RightValueAsDouble) const
{
FLOW_ASSERT_ENUM_MAX(EFlowPredicateCompareOperatorType, 6);
switch (OperatorType)
{
case EFlowPredicateCompareOperatorType::Equal:
return FMath::IsNearlyEqual(LeftValueAsDouble, RightValueAsDouble, static_cast<double>(SMALL_NUMBER));
case EFlowPredicateCompareOperatorType::NotEqual:
return !FMath::IsNearlyEqual(LeftValueAsDouble, RightValueAsDouble, static_cast<double>(SMALL_NUMBER));
case EFlowPredicateCompareOperatorType::Less:
return (LeftValueAsDouble < RightValueAsDouble);
case EFlowPredicateCompareOperatorType::LessOrEqual:
return (LeftValueAsDouble <= RightValueAsDouble + static_cast<double>(SMALL_NUMBER));
case EFlowPredicateCompareOperatorType::Greater:
return (LeftValueAsDouble > RightValueAsDouble);
case EFlowPredicateCompareOperatorType::GreaterOrEqual:
return (LeftValueAsDouble >= RightValueAsDouble - static_cast<double>(SMALL_NUMBER));
default:
break;
}
return false;
}
bool UFlowNodeAddOn_PredicateCompareValues::CompareInt64UsingOperator(int64 LeftValueAsInt64, int64 RightValueAsInt64) const
{
FLOW_ASSERT_ENUM_MAX(EFlowPredicateCompareOperatorType, 6);
switch (OperatorType)
{
case EFlowPredicateCompareOperatorType::Equal:
return (LeftValueAsInt64 == RightValueAsInt64);
case EFlowPredicateCompareOperatorType::NotEqual:
return (LeftValueAsInt64 != RightValueAsInt64);
case EFlowPredicateCompareOperatorType::Less:
return (LeftValueAsInt64 < RightValueAsInt64);
case EFlowPredicateCompareOperatorType::LessOrEqual:
return (LeftValueAsInt64 <= RightValueAsInt64);
case EFlowPredicateCompareOperatorType::Greater:
return (LeftValueAsInt64 > RightValueAsInt64);
case EFlowPredicateCompareOperatorType::GreaterOrEqual:
return (LeftValueAsInt64 >= RightValueAsInt64);
default:
break;
}
return false;
}
const FName& UFlowNodeAddOn_PredicateCompareValues::GetLeftValuePropertyName() const
{
static const FName LeftValueName = GET_MEMBER_NAME_CHECKED(ThisClass, LeftValue);
return LeftValueName;
}
const FName& UFlowNodeAddOn_PredicateCompareValues::GetRightValuePropertyName() const
{
static const FName RightValueName = GET_MEMBER_NAME_CHECKED(ThisClass, RightValue);
return RightValueName;
}
bool UFlowNodeAddOn_PredicateCompareValues::TryCompareAsDouble() const
{
double LeftDouble = 0.0;
{
const EFlowDataPinResolveResult ResolveResult =
TryResolveDataPinValue<FFlowPinType_Double>(GetDisambiguatedValueName(LeftValue), LeftDouble, SingleFromArray);
if (!FlowPinType::IsSuccess(ResolveResult))
{
LogError(TEXT("Failed to resolve LeftValue as Double."));
return false;
}
}
double RightDouble = 0.0;
{
const EFlowDataPinResolveResult ResolveResult =
TryResolveDataPinValue<FFlowPinType_Double>(GetDisambiguatedValueName(RightValue), RightDouble, SingleFromArray);
if (!FlowPinType::IsSuccess(ResolveResult))
{
LogError(TEXT("Failed to resolve RightValue as Double."));
return false;
}
}
return CompareDoubleUsingOperator(LeftDouble, RightDouble);
}
bool UFlowNodeAddOn_PredicateCompareValues::TryCompareAsInt64() const
{
int64 LeftInt64 = 0;
{
const EFlowDataPinResolveResult ResolveResult =
TryResolveDataPinValue<FFlowPinType_Int64>(GetDisambiguatedValueName(LeftValue), LeftInt64, SingleFromArray);
if (!FlowPinType::IsSuccess(ResolveResult))
{
LogError(TEXT("Failed to resolve LeftValue as Int64."));
return false;
}
}
int64 RightInt64 = 0;
{
const EFlowDataPinResolveResult ResolveResult =
TryResolveDataPinValue<FFlowPinType_Int64>(GetDisambiguatedValueName(RightValue), RightInt64, SingleFromArray);
if (!FlowPinType::IsSuccess(ResolveResult))
{
LogError(TEXT("Failed to resolve RightValue as Int64."));
return false;
}
}
return CompareInt64UsingOperator(LeftInt64, RightInt64);
}
bool UFlowNodeAddOn_PredicateCompareValues::EvaluateEqualityBlock(const TCHAR* TypeLabel, const TFunctionRef<bool(bool& /*bOutIsEqual*/)> CompareFunc) const
{
if (!IsEqualityOp())
{
LogError(FString::Printf(TEXT("Arithmetic operators are not supported for %s comparisons."), TypeLabel));
return false;
}
bool bIsEqual = false;
if (!CompareFunc(bIsEqual))
{
return false;
}
return (OperatorType == EFlowPredicateCompareOperatorType::Equal) == bIsEqual;
}
bool UFlowNodeAddOn_PredicateCompareValues::EvaluatePredicate_Implementation() const
{
// Cache type names once to avoid repeated TInstancedStruct::Get() virtual dispatch.
FCachedTypeNames Cache;
if (!CacheTypeNames(Cache))
{
return false;
}
const UFlowAsset* FlowAsset = GetFlowAsset();
check(IsValid(FlowAsset));
const FFlowPinConnectionPolicy& PinConnectionPolicy = FlowAsset->GetPinConnectionPolicy();
const FName& LeftTypeName = Cache.LeftTypeName;
const FName& RightTypeName = Cache.RightTypeName;
const bool bSameType = (LeftTypeName == RightTypeName);
// Type compatibility gate.
// Same-type unknowns are allowed through for the fallback path at the bottom.
if (!bSameType && !AreComparablePinTypes(PinConnectionPolicy, LeftTypeName, RightTypeName))
{
LogError(FString::Printf(
TEXT("Compare Values pin types are not comparable: '%s' vs '%s'."),
*LeftTypeName.ToString(),
*RightTypeName.ToString()));
return false;
}
// Arithmetic operators: numeric only (fast reject before the cascade)
if (IsArithmeticOp() && !(IsNumericTypeName(PinConnectionPolicy, LeftTypeName) && IsNumericTypeName(PinConnectionPolicy, RightTypeName)))
{
LogError(TEXT("Arithmetic operators are only supported for numeric pin types (Int/Int64/Float/Double)."));
return false;
}
// Numeric (full operator set)
if (IsNumericTypeName(PinConnectionPolicy, LeftTypeName) && IsNumericTypeName(PinConnectionPolicy, RightTypeName))
{
if (IsFloatingPointType(PinConnectionPolicy, LeftTypeName) || IsFloatingPointType(PinConnectionPolicy, RightTypeName))
{
return TryCompareAsDouble();
}
return TryCompareAsInt64();
}
// Gameplay tags: compare as container (superset). Equality ops only.
if (IsGameplayTagLikeTypeName(PinConnectionPolicy, LeftTypeName) || IsGameplayTagLikeTypeName(PinConnectionPolicy, RightTypeName))
{
return EvaluateEqualityBlock(TEXT("Gameplay Tag"),
[this](bool& bIsEqual) { return TryCheckGameplayTagsEqual(bIsEqual); });
}
// String-like (including enums-as-names). Equality ops only.
if (IsAnyStringLikeTypeName(PinConnectionPolicy, LeftTypeName) || IsAnyStringLikeTypeName(PinConnectionPolicy, RightTypeName))
{
// Dispatch order is significant:
// 1) Name-like (Name OR Enum) => case-insensitive compare via FString
// 2) Text => FText::EqualTo (culture-aware)
// 3) String => exact FString equality
if (IsNameLikeType(LeftTypeName) || IsNameLikeType(RightTypeName))
{
return EvaluateEqualityBlock(TEXT("Name/Enum"),
[this](bool& bIsEqual)
{
return TryCheckResolvedValuesEqual<FFlowPinType_String>(bIsEqual, TEXT("String (Name-like)"),
[](const FString& L, const FString& R) { return L.Equals(R, ESearchCase::IgnoreCase); });
});
}
if (IsTextType(LeftTypeName) || IsTextType(RightTypeName))
{
return EvaluateEqualityBlock(TEXT("Text"),
[this](bool& bIsEqual)
{
return TryCheckResolvedValuesEqual<FFlowPinType_Text>(bIsEqual, TEXT("Text"),
[](const FText& L, const FText& R) { return L.EqualTo(R); });
});
}
return EvaluateEqualityBlock(TEXT("String"),
[this](bool& bIsEqual)
{
return TryCheckResolvedValuesEqual<FFlowPinType_String>(bIsEqual, TEXT("String"));
});
}
// Bool. Equality ops only.
if (IsBoolTypeName(LeftTypeName) && IsBoolTypeName(RightTypeName))
{
return EvaluateEqualityBlock(TEXT("Bool"),
[this](bool& bIsEqual) { return TryCheckResolvedValuesEqual<FFlowPinType_Bool>(bIsEqual, TEXT("Bool")); });
}
// Vector. Equality ops only, strict comparison (no tolerance).
if (IsVectorTypeName(LeftTypeName) && IsVectorTypeName(RightTypeName))
{
return EvaluateEqualityBlock(TEXT("Vector"),
[this](bool& bIsEqual) { return TryCheckResolvedValuesEqual<FFlowPinType_Vector>(bIsEqual, TEXT("Vector")); });
}
// Rotator. Equality ops only, strict comparison (no tolerance).
if (IsRotatorTypeName(LeftTypeName) && IsRotatorTypeName(RightTypeName))
{
return EvaluateEqualityBlock(TEXT("Rotator"),
[this](bool& bIsEqual) { return TryCheckResolvedValuesEqual<FFlowPinType_Rotator>(bIsEqual, TEXT("Rotator")); });
}
// Transform. Equality ops only, strict comparison (zero tolerance).
if (IsTransformTypeName(LeftTypeName) && IsTransformTypeName(RightTypeName))
{
return EvaluateEqualityBlock(TEXT("Transform"),
[this](bool& bIsEqual)
{
return TryCheckResolvedValuesEqual<FFlowPinType_Transform>(bIsEqual, TEXT("Transform"),
[](const FTransform& L, const FTransform& R) { return L.Equals(R, 0.0); });
});
}
// Object. Equality ops only, pointer identity.
if (IsObjectTypeName(LeftTypeName) && IsObjectTypeName(RightTypeName))
{
return EvaluateEqualityBlock(TEXT("Object"),
[this](bool& bIsEqual) { return TryCheckResolvedValuesEqual<FFlowPinType_Object>(bIsEqual, TEXT("Object")); });
}
// Class. Equality ops only, strict class identity (not "is derived from").
if (IsClassTypeName(LeftTypeName) && IsClassTypeName(RightTypeName))
{
return EvaluateEqualityBlock(TEXT("Class"),
[this](bool& bIsEqual) { return TryCheckResolvedValuesEqual<FFlowPinType_Class>(bIsEqual, TEXT("Class")); });
}
// InstancedStruct. Equality ops only, struct type + data equality.
if (IsInstancedStructTypeName(LeftTypeName) && IsInstancedStructTypeName(RightTypeName))
{
return EvaluateEqualityBlock(TEXT("InstancedStruct"),
[this](bool& bIsEqual) { return TryCheckResolvedValuesEqual<FFlowPinType_InstancedStruct>(bIsEqual, TEXT("InstancedStruct")); });
}
// Fallback: same-type comparison via string conversion.
// This supports user-added types from other plugins as long as they
// implement TryConvertValuesToString on their FFlowDataPinValue subclass.
if (bSameType)
{
return EvaluateEqualityBlock(*LeftTypeName.ToString(),
[this](bool& bIsEqual) { return TryCheckFallbackStringEqual(bIsEqual); });
}
LogError(FString::Printf(
TEXT("Compare Values does not support comparing pin types '%s' and '%s'."),
*LeftTypeName.ToString(),
*RightTypeName.ToString()));
return false;
}
#undef LOCTEXT_NAMESPACE