Finally finished asset lookup refactor (yeesh).
This commit is contained in:
@@ -10,18 +10,6 @@
|
|||||||
#include "Animation/AnimSequence.h"
|
#include "Animation/AnimSequence.h"
|
||||||
#include "Engine/StaticMesh.h"
|
#include "Engine/StaticMesh.h"
|
||||||
|
|
||||||
void UlxAssetLookup::LogMaybeError(bool Error, const TCHAR *Message, const TCHAR *Path)
|
|
||||||
{
|
|
||||||
if (Error)
|
|
||||||
{
|
|
||||||
UE_LOG(LogLuprexIntegration, Error, TEXT("%s: %s"), Message, Path);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UE_LOG(LogLuprexIntegration, Display, TEXT("%s: %s"), Message, Path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const ElxValidOrNotValid NotValid = ElxValidOrNotValid::NotValid;
|
const ElxValidOrNotValid NotValid = ElxValidOrNotValid::NotValid;
|
||||||
const ElxValidOrNotValid Valid = ElxValidOrNotValid::Valid;
|
const ElxValidOrNotValid Valid = ElxValidOrNotValid::Valid;
|
||||||
@@ -36,7 +24,7 @@ void UlxAssetLookup::RebuildIndex()
|
|||||||
AddAssets(TEXT("/Game/Widgets"), UWidgetBlueprint::StaticClass(), TEXT("WB_"));
|
AddAssets(TEXT("/Game/Widgets"), UWidgetBlueprint::StaticClass(), TEXT("WB_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UlxAssetLookup::AddAssets(const TCHAR *Path, const UClass *Class, const TCHAR *NamePrefix)
|
void UlxAssetLookup::AddAssets(const TCHAR *Path, UClass *Class, const TCHAR *NamePrefix)
|
||||||
{
|
{
|
||||||
TArray<FAssetData> FoundData;
|
TArray<FAssetData> FoundData;
|
||||||
TMap<FName, FString> Result;
|
TMap<FName, FString> Result;
|
||||||
@@ -62,74 +50,71 @@ void UlxAssetLookup::AddAssets(const TCHAR *Path, const UClass *Class, const TCH
|
|||||||
FoundData.Num(), *Class->GetName(), Path);
|
FoundData.Num(), *Class->GetName(), Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
FString UlxAssetLookup::GetAssetPath(const UObject *Context, const UClass *Class, const FString &Name)
|
UObject *UlxAssetLookup::LoadAsset(const UObject *Context, UClass *Class, UClass *ChildOf, const FString &Name, bool ErrorIfNotFound)
|
||||||
{
|
{
|
||||||
const UlxAssetLookup *Lookup = ALuprexGameModeBase::FromContext(Context)->GetAssetLookup();
|
const UlxAssetLookup *Lookup = ALuprexGameModeBase::FromContext(Context)->GetAssetLookup();
|
||||||
const FString *Path = Lookup->AssetPaths.Find(MakeTuple(Class->GetName(), FName(Name)));
|
const FString *Path = Lookup->AssetPaths.Find(MakeTuple(Class->GetName(), FName(Name)));
|
||||||
if (Path == nullptr)
|
if (Path == nullptr)
|
||||||
{
|
{
|
||||||
return FString();
|
if (ErrorIfNotFound)
|
||||||
|
{
|
||||||
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Loading %s %s: asset not found"), *Class->GetName(), *Name);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
return *Path;
|
|
||||||
|
UObject *Result;
|
||||||
|
if (ChildOf == nullptr)
|
||||||
|
{
|
||||||
|
Result = StaticLoadObject(Class, nullptr, **Path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Result = StaticLoadObject(UClass::StaticClass(), nullptr, *((*Path) + FString(TEXT("_C"))));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Result == nullptr)
|
||||||
|
{
|
||||||
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Loading %s %s: unknown load failure"), *Class->GetName(), *Name);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ChildOf != nullptr)
|
||||||
|
{
|
||||||
|
UClass *ResClass = (UClass *)Result;
|
||||||
|
if (!ResClass->IsChildOf(ChildOf))
|
||||||
|
{
|
||||||
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Loading %s %s: blueprint not a child of %s"), *Class->GetName(), *Name, *ChildOf->GetName());
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ElxValidOrNotValid UlxAssetLookup::LoadStaticMeshAsset(
|
ElxValidOrNotValid UlxAssetLookup::LoadStaticMeshAsset(
|
||||||
UStaticMesh *&Result, const UObject *Context, const FString &Name, bool ErrorIfNotFound)
|
UStaticMesh *&Result, const UObject *Context, const FString &Name, bool ErrorIfNotFound)
|
||||||
{
|
{
|
||||||
Result = nullptr;
|
Result = (UStaticMesh *)LoadAsset(Context, UStaticMesh::StaticClass(), nullptr, Name, ErrorIfNotFound);
|
||||||
FString Path = GetAssetPath(Context, UStaticMesh::StaticClass(), Name);
|
return Result ? Valid : NotValid;
|
||||||
if (Path.IsEmpty())
|
|
||||||
{
|
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Static Mesh not found"), *Name);
|
|
||||||
Result = nullptr; return NotValid;
|
|
||||||
}
|
|
||||||
Result = LoadObject<UStaticMesh>(nullptr, *Path);
|
|
||||||
if (Result == nullptr)
|
|
||||||
{
|
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Cannot load Static Mesh"), *Path);
|
|
||||||
Result = nullptr; return NotValid;
|
|
||||||
}
|
|
||||||
return Valid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ElxValidOrNotValid UlxAssetLookup::LoadAnimSequenceAsset(
|
ElxValidOrNotValid UlxAssetLookup::LoadAnimSequenceAsset(
|
||||||
UAnimSequence *&Result, const UObject *Context, const FString &Name, bool ErrorIfNotFound)
|
UAnimSequence *&Result, const UObject *Context, const FString &Name, bool ErrorIfNotFound)
|
||||||
{
|
{
|
||||||
Result = nullptr;
|
Result = (UAnimSequence *)LoadAsset(Context, UAnimSequence::StaticClass(), nullptr, Name, ErrorIfNotFound);
|
||||||
FString Path = GetAssetPath(Context, UAnimSequence::StaticClass(), Name);
|
return Result ? Valid : NotValid;
|
||||||
if (Path.IsEmpty())
|
|
||||||
{
|
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Anim Sequence not found"), *Name);
|
|
||||||
Result = nullptr; return NotValid;
|
|
||||||
}
|
|
||||||
Result = LoadObject<UAnimSequence>(nullptr, *Path);
|
|
||||||
if (Result == nullptr)
|
|
||||||
{
|
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Cannot load Anim Sequence"), *Path);
|
|
||||||
Result = nullptr; return NotValid;
|
|
||||||
}
|
|
||||||
return Valid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ElxValidOrNotValid UlxAssetLookup::LoadTangibleBlueprintAsset(
|
ElxValidOrNotValid UlxAssetLookup::LoadTangibleBlueprintAsset(
|
||||||
TSubclassOf<AActor> &Result, const UObject *Context, const FString &Name, bool ErrorIfNotFound)
|
TSubclassOf<AActor> &Result, const UObject *Context, const FString &Name, bool ErrorIfNotFound)
|
||||||
{
|
{
|
||||||
FString Path = GetAssetPath(Context, UBlueprint::StaticClass(), Name);
|
Result = (UClass*)LoadAsset(Context, UBlueprint::StaticClass(), AActor::StaticClass(), Name, ErrorIfNotFound);
|
||||||
if (Path.IsEmpty())
|
if (Result == nullptr) return NotValid;
|
||||||
{
|
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Tangible not found"), *Name);
|
|
||||||
Result = nullptr; return NotValid;
|
|
||||||
}
|
|
||||||
Result = LoadClass<AActor>(nullptr, *UnderscoreC(Path));
|
|
||||||
if (Result == nullptr)
|
|
||||||
{
|
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Tangible load failed, not an actor blueprint"), *Path);
|
|
||||||
Result = nullptr; return NotValid;
|
|
||||||
}
|
|
||||||
UFunction *aqchanged = Result->FindFunctionByName(FName(TEXT("Animation Queue Changed")));
|
UFunction *aqchanged = Result->FindFunctionByName(FName(TEXT("Animation Queue Changed")));
|
||||||
if ((aqchanged == nullptr)||(aqchanged->ParmsSize != 0))
|
if ((aqchanged == nullptr)||(aqchanged->ParmsSize != 0))
|
||||||
{
|
{
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Tangible does not have 'Animation Queue Changed' function"), *Path);
|
UE_LOG(LogLuprexIntegration, Error, TEXT("Loading Blueprint %s: Tangible does not have 'Animation Queue Changed' function"), *Name);
|
||||||
Result = nullptr; return NotValid;
|
Result = nullptr; return NotValid;
|
||||||
}
|
}
|
||||||
return Valid;
|
return Valid;
|
||||||
@@ -138,38 +123,13 @@ ElxValidOrNotValid UlxAssetLookup::LoadTangibleBlueprintAsset(
|
|||||||
ElxValidOrNotValid UlxAssetLookup::LoadUserWidgetAsset(
|
ElxValidOrNotValid UlxAssetLookup::LoadUserWidgetAsset(
|
||||||
TSubclassOf<UUserWidget> &Result, const UObject *Context, const FString &Name, bool ErrorIfNotFound)
|
TSubclassOf<UUserWidget> &Result, const UObject *Context, const FString &Name, bool ErrorIfNotFound)
|
||||||
{
|
{
|
||||||
Result = nullptr;
|
Result = (UClass *)LoadAsset(Context, UWidgetBlueprint::StaticClass(), UUserWidget::StaticClass(), Name, ErrorIfNotFound);
|
||||||
FString Path = GetAssetPath(Context, UWidgetBlueprint::StaticClass(), Name);
|
return Result ? Valid : NotValid;
|
||||||
if (Path.IsEmpty())
|
|
||||||
{
|
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Widget not Found"), *Name);
|
|
||||||
Result = nullptr; return NotValid;
|
|
||||||
}
|
|
||||||
Result = LoadClass<UUserWidget>(nullptr, *UnderscoreC(Path));
|
|
||||||
if (Result == nullptr)
|
|
||||||
{
|
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Cannot load widget, not a UUserWidget"), *Path);
|
|
||||||
Result = nullptr; return NotValid;
|
|
||||||
}
|
|
||||||
return Valid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ElxValidOrNotValid UlxAssetLookup::LoadLuaWidgetAsset(
|
ElxValidOrNotValid UlxAssetLookup::LoadLuaWidgetAsset(
|
||||||
TSubclassOf<UlxLuaWidget> &Result, const UObject *Context, const FString &Name, bool ErrorIfNotFound)
|
TSubclassOf<UlxLuaWidget> &Result, const UObject *Context, const FString &Name, bool ErrorIfNotFound)
|
||||||
{
|
{
|
||||||
Result = nullptr;
|
Result = (UClass *)LoadAsset(Context, UWidgetBlueprint::StaticClass(), UlxLuaWidget::StaticClass(), Name, ErrorIfNotFound);
|
||||||
FString Path = GetAssetPath(Context, UWidgetBlueprint::StaticClass(), Name);
|
return Result ? Valid : NotValid;
|
||||||
if (Path.IsEmpty())
|
|
||||||
{
|
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Widget not on search path"), *Name);
|
|
||||||
Result = nullptr; return NotValid;
|
|
||||||
}
|
|
||||||
Result = LoadClass<UlxLuaWidget>(nullptr, *UnderscoreC(Path));
|
|
||||||
if (Result == nullptr)
|
|
||||||
{
|
|
||||||
LogMaybeError(ErrorIfNotFound, TEXT("Cannot load widget, not a UlxLuaWidget"), *Path);
|
|
||||||
Result = nullptr; return NotValid;
|
|
||||||
}
|
|
||||||
return Valid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,13 +31,9 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void AddAssets(const TCHAR *Path, const UClass *Class, const TCHAR *NamePrefix);
|
void AddAssets(const TCHAR *Path, UClass *Class, const TCHAR *NamePrefix);
|
||||||
|
|
||||||
static FString GetAssetPath(const UObject *Context, const UClass *Class, const FString &Name);
|
static UObject *LoadAsset(const UObject *Context, UClass *Class, UClass *ChildOf, const FString &Name, bool ErrorIfNotFound);
|
||||||
|
|
||||||
static void LogMaybeError(bool Error, const TCHAR *Message, const TCHAR *Path);
|
|
||||||
|
|
||||||
static FString UnderscoreC(const FString &Name) { return Name + FString(TEXT("_C")); }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void RebuildIndex();
|
void RebuildIndex();
|
||||||
|
|||||||
Reference in New Issue
Block a user