WingUtils::FormatName uses WingTypes::TypeToTextOrDie for types

This commit is contained in:
2026-03-19 01:52:14 -04:00
parent e9ad41bbb3
commit cc3d03541c
4 changed files with 41 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
#include "WingTypes.h" #include "WingTypes.h"
#include "WingUtils.h"
#include "WingServer.h" #include "WingServer.h"
#include "Editor.h" #include "Editor.h"
#include "EdGraphSchema_K2.h" #include "EdGraphSchema_K2.h"
@@ -12,7 +13,7 @@
// Choose Short Name // Choose Short Name
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
FString UWingTypes::GetNameWithoutUnderscoreC(const UObject *Obj) FString UWingTypes::GetProposedName(const UObject *Obj)
{ {
FString Name = Obj->GetName(); FString Name = Obj->GetName();
if (Name.EndsWith(TEXT("_C"))) if (Name.EndsWith(TEXT("_C")))
@@ -23,6 +24,7 @@ FString UWingTypes::GetNameWithoutUnderscoreC(const UObject *Obj)
Name.LeftChopInline(2); Name.LeftChopInline(2);
} }
} }
WingUtils::SanitizeNameInPlace(Name);
return Name; return Name;
} }
@@ -67,10 +69,18 @@ FString UWingTypes::ChooseShortName(const FString &Proposal, const FString &Full
FString UWingTypes::ChooseShortName(const UObject* Obj) FString UWingTypes::ChooseShortName(const UObject* Obj)
{ {
// If it's a blueprint, register its generated class instead.
if (const UBlueprint* BP = Cast<UBlueprint>(Obj))
{
if (BP->GeneratedClass)
return ChooseShortName(BP->GeneratedClass);
return FString();
}
if (!Cast<UScriptStruct>(Obj) && !Cast<UClass>(Obj) && !Cast<UEnum>(Obj)) if (!Cast<UScriptStruct>(Obj) && !Cast<UClass>(Obj) && !Cast<UEnum>(Obj))
return FString(); return FString();
FString ProposedName = GetNameWithoutUnderscoreC(Obj); FString ProposedName = GetProposedName(Obj);
return ChooseShortName(ProposedName, Obj->GetPathName()); return ChooseShortName(ProposedName, Obj->GetPathName());
} }
@@ -208,6 +218,15 @@ FString UWingTypes::TypeToText(const UObject* Obj)
return Types->ChooseShortName(Obj); return Types->ChooseShortName(Obj);
} }
FString UWingTypes::TypeToTextOrDie(const UObject* Obj)
{
UWingTypes* Types = GEditor->GetEditorSubsystem<UWingTypes>();
if (!Types) return FString();
FString Result = Types->ChooseShortName(Obj);
check(!Result.IsEmpty());
return Result;
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Subsystem lifecycle // Subsystem lifecycle
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@@ -106,7 +106,7 @@ FString WingUtils::FormatName(const UWorld *World)
FString WingUtils::FormatName(const UBlueprint *BP) FString WingUtils::FormatName(const UBlueprint *BP)
{ {
return BP->GetPathName(); return UWingTypes::TypeToTextOrDie(BP);
} }
FString WingUtils::FormatName(const UActorComponent *C) FString WingUtils::FormatName(const UActorComponent *C)
@@ -121,7 +121,6 @@ FString WingUtils::FormatName(const USCS_Node *Node)
FString WingUtils::FormatName(const UEdGraph *Graph) FString WingUtils::FormatName(const UEdGraph *Graph)
{ {
return SanitizeName(Graph->GetName()); return SanitizeName(Graph->GetName());
} }
@@ -147,9 +146,16 @@ FString WingUtils::FormatName(const FBPVariableDescription &Var)
FString WingUtils::FormatName(const UStruct *Struct) FString WingUtils::FormatName(const UStruct *Struct)
{ {
if (Cast<UScriptStruct>(Struct) || Cast<UClass>(Struct))
return UWingTypes::TypeToTextOrDie(Struct);
return SanitizeName(Struct->GetName()); return SanitizeName(Struct->GetName());
} }
FString WingUtils::FormatName(const UClass *Class)
{
return UWingTypes::TypeToTextOrDie(Class);
}
FString WingUtils::FormatName(const UMaterial *Material) FString WingUtils::FormatName(const UMaterial *Material)
{ {
return Material->GetPathName(); return Material->GetPathName();
@@ -197,12 +203,12 @@ FString WingUtils::FormatName(const UTexture *Texture)
FString WingUtils::FormatName(const UScriptStruct *Struct) FString WingUtils::FormatName(const UScriptStruct *Struct)
{ {
return SanitizeName(Struct->GetName());; return UWingTypes::TypeToTextOrDie(Struct);
} }
FString WingUtils::FormatName(const UEnum *Enum) FString WingUtils::FormatName(const UEnum *Enum)
{ {
return SanitizeName(Enum->GetName()); return UWingTypes::TypeToTextOrDie(Enum);
} }
FString WingUtils::FormatName(const FProperty *Prop) FString WingUtils::FormatName(const FProperty *Prop)

View File

@@ -18,20 +18,25 @@ public:
virtual void Initialize(FSubsystemCollectionBase& Collection) override; virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override; virtual void Deinitialize() override;
// Convert a pin type to a type string. Returns empty string on failure. // Convert a pin type to a type string. Returns empty string
// on failure.
static FString TypeToText(const FEdGraphPinType& PinType); static FString TypeToText(const FEdGraphPinType& PinType);
static FString TypeToText(const FProperty *Property); static FString TypeToText(const FProperty *Property);
// Get the short name for a UClass, UScriptStruct, or UEnum. // Get the type name for a UClass, UScriptStruct, or UEnum.
// Returns empty string if the object is not one of those types. // Returns empty string if the object is not one of those types.
static FString TypeToText(const UObject* Obj); static FString TypeToText(const UObject* Obj);
// Get the type name for a UClass, UScriptStruct, or UEnum.
// Check fail if the result is empty.
static FString TypeToTextOrDie(const UObject* Obj);
// Try to parse a type. If there's a problem, returns an error // Try to parse a type. If there's a problem, returns an error
// message. If all goes well, returns empty string. // message. If all goes well, returns empty string.
static FString TryTextToType(const FString& Text, FEdGraphPinType& OutPinType); static FString TryTextToType(const FString& Text, FEdGraphPinType& OutPinType);
// Try to parse a type. If there's a problem, prints an error // Try to parse a type. If there's a problem, prints an error
// via UWingServer and returns false. // message and returns false.
static bool TextToType(const FString& Text, FEdGraphPinType& OutPinType); static bool TextToType(const FString& Text, FEdGraphPinType& OutPinType);
// Parse a type string and verify it's a single object class (PC_Object, // Parse a type string and verify it's a single object class (PC_Object,
@@ -50,7 +55,7 @@ private:
// Get the object's name, not including the _C generated // Get the object's name, not including the _C generated
// by the blueprint compiler for generated classes. // by the blueprint compiler for generated classes.
static FString GetNameWithoutUnderscoreC(const UObject *Obj); static FString GetProposedName(const UObject *Obj);
// Reserve the short name for a primitive type. // Reserve the short name for a primitive type.
// The value stored in the map is just "PRIMITIVE". // The value stored in the map is just "PRIMITIVE".

View File

@@ -58,6 +58,7 @@ public:
static FString FormatName(const FMemberReference &Ref); static FString FormatName(const FMemberReference &Ref);
static FString FormatName(const FBPVariableDescription &Var); static FString FormatName(const FBPVariableDescription &Var);
static FString FormatName(const UStruct *Struct); static FString FormatName(const UStruct *Struct);
static FString FormatName(const UClass *Class);
static FString FormatName(const UMaterial *Material); static FString FormatName(const UMaterial *Material);
static FString FormatName(const UMaterialInstance *MaterialInstance); static FString FormatName(const UMaterialInstance *MaterialInstance);
static FString FormatName(const UMaterialFunction *MaterialFunction); static FString FormatName(const UMaterialFunction *MaterialFunction);