More work on look-at, split LuaCall into LuaInvoke/LuaProbe

This commit is contained in:
2025-04-08 16:31:16 -04:00
parent c060b87556
commit 8a9d5550d9
10 changed files with 126 additions and 111 deletions

View File

@@ -93,87 +93,104 @@ FString UlxAssetLookup::WidgetLoadPath(const FName &AssetName) const
return *Result;
}
UStaticMesh *UlxAssetLookup::GetStaticMeshByName(const UObject *Context, const FString &Name, bool ErrorIfNotFound, bool ErrorIfInvalid)
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);
}
}
UStaticMesh *UlxAssetLookup::GetStaticMeshByName(const UObject *Context, const FString &Name, bool ErrorIfNotFound)
{
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(Context);
FString Path = mode->GetAssetLookup()->StaticMeshLoadPath(FName(FString("SM_") + Name));
if (Path.IsEmpty())
{
if (ErrorIfNotFound) UE_LOG(LogLuprexIntegration, Error, TEXT("Static mesh not on search path: %s"), *Name);
LogMaybeError(ErrorIfNotFound, TEXT("Static mesh not on search path"), *Name);
return nullptr;
}
UStaticMesh *Result = LoadObject<UStaticMesh>(nullptr, *Path);
if (Result == nullptr) {
if (ErrorIfInvalid) UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load static mesh: %s"), *Path);
if (Result == nullptr)
{
LogMaybeError(ErrorIfNotFound, TEXT("Cannot load static mesh"), *Path);
return nullptr;
}
return Result;
}
TSubclassOf<AActor> UlxAssetLookup::GetTangibleClassByName(const UObject *Context, const FString &Name, bool ErrorIfNotFound, bool ErrorIfInvalid) {
TSubclassOf<AActor> UlxAssetLookup::GetTangibleClassByName(const UObject *Context, const FString &Name, bool ErrorIfNotFound) {
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(Context);
FString Path = mode->GetAssetLookup()->TangibleLoadPath(FName(FString("TAN_") + Name));
if (Path.IsEmpty())
{
if (ErrorIfNotFound) UE_LOG(LogLuprexIntegration, Error, TEXT("Tangible not on search path: %s"), *Name);
LogMaybeError(ErrorIfNotFound, TEXT("Tangible not on search path"), *Name);
return nullptr;
}
UClass *Result = LoadObject<UClass>(nullptr, *Path);
if (Result == nullptr) {
if (ErrorIfInvalid) UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load tangible class: %s"), *Path);
if (Result == nullptr)
{
LogMaybeError(ErrorIfNotFound, TEXT("Cannot load tangible class"), *Path);
return nullptr;
}
if (!Result->IsChildOf(AActor::StaticClass())) {
if (ErrorIfInvalid) UE_LOG(LogLuprexIntegration, Error, TEXT("Tangible class is not an actor: %s"), *Path);
if (!Result->IsChildOf(AActor::StaticClass()))
{
LogMaybeError(ErrorIfNotFound, TEXT("Tangible class is not an actor"), *Path);
return nullptr;
}
UFunction *aqchanged = Result->FindFunctionByName(FName(TEXT("Animation Queue Changed")));
if ((aqchanged == nullptr)||(aqchanged->ParmsSize != 0))
{
if (ErrorIfInvalid) UE_LOG(LogLuprexIntegration, Error, TEXT("Tangible does not have 'Animation Queue Changed' function: %s"), *Path);
LogMaybeError(ErrorIfNotFound, TEXT("Tangible does not have 'Animation Queue Changed' function"), *Path);
return nullptr;
}
return Result;
}
TSubclassOf<UUserWidget> UlxAssetLookup::GetWidgetByName(const UObject *Context, const FString &Name, bool ErrorIfNotFound, bool ErrorIfInvalid) {
TSubclassOf<UUserWidget> UlxAssetLookup::GetWidgetByName(const UObject *Context, const FString &Name, bool ErrorIfNotFound) {
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(Context);
FString Path = mode->GetAssetLookup()->WidgetLoadPath(FName(FString("WB_") + Name));
if (Path.IsEmpty())
{
if (ErrorIfNotFound) UE_LOG(LogLuprexIntegration, Error, TEXT("Widget not on search path: %s"), *Name);
LogMaybeError(ErrorIfNotFound, TEXT("Widget not on search path"), *Name);
return nullptr;
}
UClass *Result = LoadObject<UClass>(nullptr, *Path);
if (Result == nullptr) {
if (ErrorIfInvalid) UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load widget blueprint: %s"), *Path);
if (Result == nullptr)
{
LogMaybeError(ErrorIfNotFound, TEXT("Cannot load widget blueprint"), *Path);
return nullptr;
}
if (!Result->IsChildOf(UUserWidget::StaticClass()))
{
if (ErrorIfInvalid) UE_LOG(LogLuprexIntegration, Error, TEXT("Blueprint is not a Widget Blueprint: %s"), *Path);
LogMaybeError(ErrorIfNotFound, TEXT("Blueprint is not a Widget Blueprint"), *Path);
return nullptr;
}
return Result;
}
TSubclassOf<UlxLookAtWidget> UlxAssetLookup::GetLookAtWidgetByName(const UObject *Context, const FString &Name, bool ErrorIfNotFound, bool ErrorIfInvalid) {
TSubclassOf<UlxLookAtWidget> UlxAssetLookup::GetLookAtWidgetByName(const UObject *Context, const FString &Name, bool ErrorIfNotFound) {
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(Context);
FString Path = mode->GetAssetLookup()->WidgetLoadPath(FName(FString("WB_") + Name));
if (Path.IsEmpty())
{
if (ErrorIfNotFound) UE_LOG(LogLuprexIntegration, Error, TEXT("Widget not on search path: %s"), *Name);
LogMaybeError(ErrorIfNotFound, TEXT("Widget not on search path"), *Name);
return nullptr;
}
UClass *Result = LoadObject<UClass>(nullptr, *Path);
if (Result == nullptr) {
if (ErrorIfInvalid) UE_LOG(LogLuprexIntegration, Error, TEXT("Cannot load widget blueprint: %s"), *Path);
if (Result == nullptr)
{
LogMaybeError(ErrorIfNotFound, TEXT("Cannot load widget blueprint"), *Path);
return nullptr;
}
if (!Result->IsChildOf(UlxLookAtWidget::StaticClass()))
{
if (ErrorIfInvalid) UE_LOG(LogLuprexIntegration, Error, TEXT("Blueprint is not a Luprex Look-At Widget: %s"), *Path);
LogMaybeError(ErrorIfNotFound, TEXT("Blueprint is not a Luprex Look-At Widget"), *Path);
return nullptr;
}
return Result;