Routines to find exactly one
This commit is contained in:
@@ -51,11 +51,8 @@ public:
|
|||||||
if (!BP) return;
|
if (!BP) return;
|
||||||
|
|
||||||
// Check graph name uniqueness
|
// Check graph name uniqueness
|
||||||
if (!WingUtils::AllGraphsNamed(BP, Graph).IsEmpty())
|
if (!WingUtils::FindExactlyNoneNamed(Graph, WingUtils::AllGraphs(BP)))
|
||||||
{
|
|
||||||
UWingServer::Printf(TEXT("ERROR: A graph named '%s' already exists in %s\n"), *Graph, *WingUtils::FormatName(BP));
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// For custom events, also check for existing custom events with the same name
|
// For custom events, also check for existing custom events with the same name
|
||||||
if (GraphType == TEXT("customEvent"))
|
if (GraphType == TEXT("customEvent"))
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for name collision
|
// Check for name collision
|
||||||
for (UEdGraph* Existing : WingUtils::AllGraphsNamed(BP, NewName))
|
for (UEdGraph* Existing : WingUtils::FindAllNamed(NewName, WingUtils::AllGraphs(BP)))
|
||||||
{
|
{
|
||||||
if (Existing != TargetGraph)
|
if (Existing != TargetGraph)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -71,11 +71,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check against existing graphs (functions, macros, etc.)
|
// Check against existing graphs (functions, macros, etc.)
|
||||||
if (!WingUtils::AllGraphsNamed(BP, DispatcherName).IsEmpty())
|
if (!WingUtils::FindExactlyNoneNamed(DispatcherName, WingUtils::AllGraphs(BP)))
|
||||||
{
|
|
||||||
UWingServer::Printf(TEXT("Error: A graph named '%s' already exists.\n"), *DispatcherName);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Add a member variable with PC_MCDelegate pin type
|
// Add a member variable with PC_MCDelegate pin type
|
||||||
FEdGraphPinType DelegateType;
|
FEdGraphPinType DelegateType;
|
||||||
|
|||||||
@@ -186,19 +186,10 @@ WingFetcher& WingFetcher::Graph(const FString& Value)
|
|||||||
if (!BP)
|
if (!BP)
|
||||||
return TypeMismatch(TEXT("graph"), TEXT("Blueprint or Material"));
|
return TypeMismatch(TEXT("graph"), TEXT("Blueprint or Material"));
|
||||||
|
|
||||||
TArray<UEdGraph*> Matches = WingUtils::AllGraphsNamed(BP, Value);
|
UEdGraph* Graph = WingUtils::FindExactlyOneNamed(Value, WingUtils::AllGraphs(BP));
|
||||||
if (Matches.Num() == 0)
|
if (!Graph) return SetError();
|
||||||
{
|
|
||||||
UWingServer::Printf(TEXT("ERROR: Graph '%s' not found in %s\n"), *Value, *BP->GetName());
|
|
||||||
return SetError();
|
|
||||||
}
|
|
||||||
if (Matches.Num() > 1)
|
|
||||||
{
|
|
||||||
UWingServer::Printf(TEXT("ERROR: Ambiguous graph '%s' in %s — %d matches\n"), *Value, *BP->GetName(), Matches.Num());
|
|
||||||
return SetError();
|
|
||||||
}
|
|
||||||
|
|
||||||
SetObj(Matches[0]);
|
SetObj(Graph);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -193,25 +193,10 @@ FString WingUtils::FormatName(const FProperty *Prop)
|
|||||||
return SanitizeName(Prop->GetName());
|
return SanitizeName(Prop->GetName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================
|
|
||||||
// Identifies
|
|
||||||
// ============================================================
|
|
||||||
|
|
||||||
// Most types are handled by the template in WingUtils.h.
|
|
||||||
// UEdGraphNode also matches by GUID:
|
|
||||||
|
|
||||||
bool WingUtils::Identifies(const FString &Name, const UEdGraphNode* Node)
|
|
||||||
{
|
|
||||||
if (Node->NodeGuid.ToString().Equals(Name, ESearchCase::IgnoreCase))
|
|
||||||
return true;
|
|
||||||
return FormatName(Node).Equals(Name, ESearchCase::IgnoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Formatting other things
|
// Formatting other things
|
||||||
// ============================================================
|
// ============================================================
|
||||||
|
|
||||||
|
|
||||||
FString WingUtils::FormatNodeTitle(const UEdGraphNode *Node)
|
FString WingUtils::FormatNodeTitle(const UEdGraphNode *Node)
|
||||||
{
|
{
|
||||||
FString Title = Node->GetNodeTitle(ENodeTitleType::FullTitle).ToString();
|
FString Title = Node->GetNodeTitle(ENodeTitleType::FullTitle).ToString();
|
||||||
@@ -284,6 +269,46 @@ bool WingUtils::StringToEnum(UEnum* Enum, const FString& Str, int64& OutValue, c
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ============================================================
|
||||||
|
// Common Error Reporting
|
||||||
|
// ============================================================
|
||||||
|
|
||||||
|
bool WingUtils::CheckExactlyOneNamed(int Count, const FString &Kind, const FString &Name)
|
||||||
|
{
|
||||||
|
if (Count == 0)
|
||||||
|
{
|
||||||
|
UWingServer::Printf(TEXT("Could not find a %s named %s.\n"), *Kind, *Name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (Count > 1)
|
||||||
|
{
|
||||||
|
UWingServer::Printf(TEXT("More than one %s named %s\n"), *Kind, *Name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WingUtils::CheckExactlyOneNamed(int Count, UClass *Class, const FString &Name)
|
||||||
|
{
|
||||||
|
return CheckExactlyOneNamed(Count, Class->GetName(), Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WingUtils::CheckExactlyNoneNamed(int Count, const FString &Kind, const FString &Name)
|
||||||
|
{
|
||||||
|
if (Count > 0)
|
||||||
|
{
|
||||||
|
UWingServer::Printf(TEXT("A %s named %s already exists."), *Kind, *Name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WingUtils::CheckExactlyNoneNamed(int Count, UClass *Class, const FString &Name)
|
||||||
|
{
|
||||||
|
return CheckExactlyNoneNamed(Count, Class->GetName(), Name);
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================
|
// ============================================================
|
||||||
// Blueprint helpers
|
// Blueprint helpers
|
||||||
// ============================================================
|
// ============================================================
|
||||||
@@ -295,14 +320,6 @@ TArray<UEdGraph*> WingUtils::AllGraphs(UBlueprint* BP)
|
|||||||
return Graphs;
|
return Graphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
TArray<UEdGraph*> WingUtils::AllGraphsNamed(UBlueprint* BP, const FString& Name)
|
|
||||||
{
|
|
||||||
TArray<UEdGraph*> Result;
|
|
||||||
for (UEdGraph* Graph : AllGraphs(BP))
|
|
||||||
if (Identifies(Name, Graph))
|
|
||||||
Result.Add(Graph);
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
TArray<UEdGraphNode*> WingUtils::AllNodes(UBlueprint* BP)
|
TArray<UEdGraphNode*> WingUtils::AllNodes(UBlueprint* BP)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -89,8 +89,33 @@ public:
|
|||||||
return FormatName(std::forward<T>(Obj)).Equals(Name, ESearchCase::IgnoreCase);
|
return FormatName(std::forward<T>(Obj)).Equals(Name, ESearchCase::IgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UEdGraphNode also matches by GUID.
|
template<typename T>
|
||||||
static bool Identifies(const FString &Name, const UEdGraphNode* Node);
|
static TArray<T*> FindAllNamed(const FString &Name, const TArray<T*> &Array)
|
||||||
|
{
|
||||||
|
TArray<T*> Result;
|
||||||
|
for (T* Elt : Array) if (Identifies(Name, Elt)) Result.Add(Elt);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* FindExactlyOneNamed(const FString &Name, const TArray<T*> &Array)
|
||||||
|
{
|
||||||
|
int Count = 0;
|
||||||
|
T* Result = nullptr;
|
||||||
|
for (T* Elt : Array) if (Identifies(Name, Elt)) { Count++; Result = Elt; }
|
||||||
|
if (!CheckExactlyOneNamed(Count, T::StaticClass(), Name)) return nullptr;
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool FindExactlyNoneNamed(const FString &Name, const TArray<T*> &Array)
|
||||||
|
{
|
||||||
|
for (T* Elt: Array) if (Identifies(Name, Elt))
|
||||||
|
{
|
||||||
|
return CheckExactlyNoneNamed(1, T::StaticClass(), Name);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@@ -117,7 +142,6 @@ public:
|
|||||||
|
|
||||||
// ----- Blueprint helpers -----
|
// ----- Blueprint helpers -----
|
||||||
static TArray<UEdGraph*> AllGraphs(UBlueprint* BP);
|
static TArray<UEdGraph*> AllGraphs(UBlueprint* BP);
|
||||||
static TArray<UEdGraph*> AllGraphsNamed(UBlueprint* BP, const FString& Name);
|
|
||||||
static TArray<UEdGraphNode*> AllNodes(UBlueprint* BP);
|
static TArray<UEdGraphNode*> AllNodes(UBlueprint* BP);
|
||||||
template<class T> static TArray<T*> AllNodes(UBlueprint* BP)
|
template<class T> static TArray<T*> AllNodes(UBlueprint* BP)
|
||||||
{
|
{
|
||||||
@@ -136,6 +160,7 @@ public:
|
|||||||
Result.Add(Typed);
|
Result.Add(Typed);
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SaveBlueprintPackage(UBlueprint* BP);
|
static bool SaveBlueprintPackage(UBlueprint* BP);
|
||||||
static UClass* FindClassByName(const FString& ClassName);
|
static UClass* FindClassByName(const FString& ClassName);
|
||||||
|
|
||||||
@@ -173,6 +198,12 @@ public:
|
|||||||
static FString GetHandlerGroup(UClass* HandlerClass);
|
static FString GetHandlerGroup(UClass* HandlerClass);
|
||||||
static void FormatCommandHelp(UClass* HandlerClass);
|
static void FormatCommandHelp(UClass* HandlerClass);
|
||||||
|
|
||||||
|
// ----- Common Error Reporting -----
|
||||||
|
bool CheckExactlyOneNamed(int Count, const FString &Kind, const FString &Name);
|
||||||
|
bool CheckExactlyOneNamed(int Count, UClass *Class, const FString &Name);
|
||||||
|
bool CheckExactlyNoneNamed(int Count, const FString &Kind, const FString &Name);
|
||||||
|
bool CheckExactlyNoneNamed(int Count, UClass *Class, const FString &Name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void AppendNumericSuffix(FString &Name, int32 N);
|
static void AppendNumericSuffix(FString &Name, int32 N);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user