Files
integration/Plugins/UEWingman/Deprecated/Class_Search.h

113 lines
3.1 KiB
C
Raw Normal View History

2026-03-08 22:17:14 -04:00
#pragma once
#include "CoreMinimal.h"
2026-03-18 10:17:58 -04:00
#include "WingServer.h"
#include "WingHandler.h"
#include "WingUtils.h"
2026-03-08 22:17:14 -04:00
#include "UObject/UObjectIterator.h"
2026-03-12 00:44:17 -04:00
#include "Class_Search.generated.h"
2026-03-08 22:17:14 -04:00
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// ============================================================
// HandleListClasses — discover available UClasses
// ============================================================
2026-03-15 19:32:09 -04:00
UCLASS()
2026-03-18 10:17:58 -04:00
class UWing_Class_Search : public UObject, public IWingHandler
2026-03-08 22:17:14 -04:00
{
GENERATED_BODY()
public:
UPROPERTY(meta=(Optional, Description="Substring filter for class names"))
2026-03-10 20:15:59 -04:00
FString Query;
2026-03-08 22:17:14 -04:00
UPROPERTY(meta=(Optional, Description="Parent class name to restrict results to subclasses"))
FString ParentClass;
UPROPERTY(meta=(Optional, Description="Maximum number of results to return (1-500, default 100)"))
int32 Limit = 100;
virtual FString GetDescription() const override
{
return TEXT("Search for available UClasses by name substring and/or parent class. "
2026-03-10 07:17:42 -04:00
"Returns class names, parent class, package, and flags.");
2026-03-08 22:17:14 -04:00
}
virtual void Handle() override
2026-03-08 22:17:14 -04:00
{
2026-03-10 07:17:42 -04:00
Limit = FMath::Clamp(Limit, 1, 500);
2026-03-08 22:17:14 -04:00
UClass* ParentClassObj = nullptr;
if (!ParentClass.IsEmpty())
{
for (TObjectIterator<UClass> It; It; ++It)
{
2026-03-18 10:17:58 -04:00
if (WingUtils::Identifies(ParentClass, *It))
2026-03-08 22:17:14 -04:00
{
ParentClassObj = *It;
break;
}
}
if (!ParentClassObj)
{
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Error: Parent class '%s' not found\n"), *ParentClass);
2026-03-10 07:17:42 -04:00
return;
2026-03-08 22:17:14 -04:00
}
}
2026-03-10 07:17:42 -04:00
TArray<UClass*> Matches;
2026-03-08 22:17:14 -04:00
int32 TotalMatched = 0;
for (TObjectIterator<UClass> It; It; ++It)
{
UClass* Class = *It;
if (!Class) continue;
if (Class->HasAnyClassFlags(CLASS_Deprecated | CLASS_NewerVersionExists)) continue;
if (ParentClassObj && !Class->IsChildOf(ParentClassObj)) continue;
2026-03-18 10:17:58 -04:00
FString ClassName = WingUtils::FormatName(Class);
2026-03-10 20:15:59 -04:00
if (!Query.IsEmpty() && !ClassName.Contains(Query, ESearchCase::IgnoreCase)) continue;
2026-03-08 22:17:14 -04:00
2026-03-10 07:17:42 -04:00
TotalMatched++;
if (Matches.Num() < Limit)
2026-03-08 22:17:14 -04:00
{
2026-03-10 07:17:42 -04:00
Matches.Add(Class);
2026-03-08 22:17:14 -04:00
}
2026-03-10 07:17:42 -04:00
}
2026-03-08 22:17:14 -04:00
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT("Found %d classes"), TotalMatched);
2026-03-10 07:17:42 -04:00
if (TotalMatched > Limit)
{
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT(" (showing %d)"), Limit);
2026-03-10 07:17:42 -04:00
}
2026-03-18 10:17:58 -04:00
UWingServer::Print(TEXT("\n"));
2026-03-08 22:17:14 -04:00
2026-03-10 07:17:42 -04:00
for (UClass* Class : Matches)
{
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT(" %s"), *WingUtils::FormatName(Class));
2026-03-08 22:17:14 -04:00
2026-03-10 07:17:42 -04:00
// Flags
TStringBuilder<64> Flags;
if (Class->HasAnyClassFlags(CLASS_Abstract)) Flags.Append(TEXT(" Abstract"));
if (Class->HasAnyClassFlags(CLASS_Interface)) Flags.Append(TEXT(" Interface"));
if (Class->HasAnyClassFlags(CLASS_MinimalAPI)) Flags.Append(TEXT(" MinimalAPI"));
if (Class->ClassGeneratedBy) Flags.Append(TEXT(" Blueprint"));
if (Flags.Len() > 0)
2026-03-08 22:17:14 -04:00
{
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT(" [%s]"), Flags.ToString() + 1); // skip leading space
2026-03-08 22:17:14 -04:00
}
2026-03-10 07:17:42 -04:00
if (Class->GetSuperClass())
2026-03-08 22:17:14 -04:00
{
2026-03-18 10:17:58 -04:00
UWingServer::Printf(TEXT(" : %s"), *WingUtils::FormatName(Class->GetSuperClass()));
2026-03-08 22:17:14 -04:00
}
2026-03-18 10:17:58 -04:00
UWingServer::Print(TEXT("\n"));
2026-03-08 22:17:14 -04:00
}
}
};