Improvements to ranking in TypeName_Search
This commit is contained in:
@@ -4,6 +4,12 @@
|
||||
#include "WingServer.h"
|
||||
#include "WingHandler.h"
|
||||
#include "WingTypes.h"
|
||||
#include "EdGraphSchema_K2.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "GameFramework/Pawn.h"
|
||||
#include "Engine/DataAsset.h"
|
||||
#include "TypeName_Search.generated.h"
|
||||
|
||||
|
||||
@@ -32,37 +38,67 @@ public:
|
||||
"Returns short names that can be used with commands like Blueprint_ChangeVariableType.");
|
||||
}
|
||||
|
||||
static bool IsProjectDefined(const UWingTypes::Info& Info)
|
||||
{
|
||||
return Info.IsUserDefined && Info.PinSubCategoryObject.StartsWith(TEXT("/Game/"));
|
||||
}
|
||||
|
||||
static FString BroadCategory(const UWingTypes::Info& Info)
|
||||
{
|
||||
if (Info.PinSubCategoryObject.IsEmpty()) return TEXT("Primitive");
|
||||
if (Info.PinCategory == UEdGraphSchema_K2::PC_Enum) return TEXT("Enum");
|
||||
if (Info.PinCategory == UEdGraphSchema_K2::PC_Struct) return TEXT("Struct");
|
||||
if (Info.PinCategory == UEdGraphSchema_K2::PC_Interface) return TEXT("Interface");
|
||||
if (Info.NativeParent)
|
||||
{
|
||||
if (Info.NativeParent->IsChildOf(UUserWidget::StaticClass())) return TEXT("Widget");
|
||||
if (Info.NativeParent->IsChildOf(UActorComponent::StaticClass())) return TEXT("ActorComponent");
|
||||
if (Info.NativeParent->IsChildOf(APawn::StaticClass())) return TEXT("Pawn");
|
||||
if (Info.NativeParent->IsChildOf(AActor::StaticClass())) return TEXT("Actor");
|
||||
if (Info.NativeParent->IsChildOf(UDataAsset::StaticClass())) return TEXT("DataAsset");
|
||||
}
|
||||
return TEXT("Object");
|
||||
}
|
||||
|
||||
static int Importance(const UWingTypes::Info& Info)
|
||||
{
|
||||
if (IsProjectDefined(Info)) return 1;
|
||||
if (Info.PinSubCategoryObject.IsEmpty()) return 2;
|
||||
if (Info.PinSubCategoryObject.StartsWith(TEXT("/Script/CoreUObject."))) return 3;
|
||||
if (Info.PinSubCategoryObject.StartsWith(TEXT("/Script/Engine."))) return 4;
|
||||
return 5;
|
||||
}
|
||||
|
||||
virtual void Handle() override
|
||||
{
|
||||
const TMap<FString, UWingTypes::Info>& AllTypes = UWingTypes::GetAllTypes();
|
||||
|
||||
TArray<FString> Results;
|
||||
TArray<const UWingTypes::Info*> Matches;
|
||||
for (const auto& Pair : AllTypes)
|
||||
{
|
||||
if (Results.Num() >= Limit) break;
|
||||
|
||||
const UWingTypes::Info& Info = Pair.Value;
|
||||
if (!Info.Short.Contains(Query, ESearchCase::IgnoreCase)) continue;
|
||||
if (!Exhaustive && !UWingTypes::IsBlueprintType(Info) && !UWingTypes::IsBlueprintable(Info)) continue;
|
||||
|
||||
FString Line = FString::Printf(TEXT("%s %s %s"),
|
||||
*Info.PinCategory.ToString(), *Info.Short, *Info.PinSubCategoryObject);
|
||||
if (Info.NativeParent)
|
||||
Line += FString::Printf(TEXT(" Nat=%s"), *Info.NativeParent->GetName());
|
||||
if (!Info.PinSubCategory.IsNone())
|
||||
Line += FString::Printf(TEXT(" PSC=%s"), *Info.PinSubCategory.ToString());
|
||||
if (Info.IsUserDefined)
|
||||
Line += TEXT(" (UserDefined)");
|
||||
Line += TEXT("\n");
|
||||
Results.Add(MoveTemp(Line));
|
||||
Matches.Add(&Info);
|
||||
}
|
||||
|
||||
Results.Sort();
|
||||
for (const auto& Result : Results)
|
||||
Matches.Sort([](const UWingTypes::Info& A, const UWingTypes::Info& B)
|
||||
{
|
||||
UWingServer::Print(Result);
|
||||
int IA = Importance(A), IB = Importance(B);
|
||||
if (IA != IB) return IA < IB;
|
||||
return A.Short < B.Short;
|
||||
});
|
||||
|
||||
int32 Count = FMath::Min(Matches.Num(), Limit);
|
||||
for (int32 i = 0; i < Count; ++i)
|
||||
{
|
||||
const UWingTypes::Info& Info = *Matches[i];
|
||||
if (IsProjectDefined(Info))
|
||||
UWingServer::Printf(TEXT("%s (%s, User-Defined)\n"), *Info.Short, *BroadCategory(Info));
|
||||
else
|
||||
UWingServer::Printf(TEXT("%s (%s)\n"), *Info.Short, *BroadCategory(Info));
|
||||
}
|
||||
if (Results.Num() >= Limit)
|
||||
if (Count >= Limit)
|
||||
{
|
||||
UWingServer::Printf(TEXT("Search limit reached, raise it with Limit=\n"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user