57 lines
1.4 KiB
C++
Executable File
57 lines
1.4 KiB
C++
Executable File
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
|
|
/**
|
|
* Utility functions.
|
|
*/
|
|
class PRESIDENTSBRIGADE_API Util
|
|
{
|
|
public:
|
|
template<typename TEnum>
|
|
static FORCEINLINE FString enum_as_string(const FString& str, TEnum value)
|
|
{
|
|
FName result;
|
|
|
|
const UEnum* enum_ptr = FindObject<UEnum>(ANY_PACKAGE, *str, true);
|
|
if (!enum_ptr)
|
|
{
|
|
result = FName("Invalid Enum");
|
|
}
|
|
else
|
|
{
|
|
result = enum_ptr->GetNameByValue((int64)value);
|
|
}
|
|
return result.ToString();
|
|
}
|
|
|
|
#define EnumAsString(EnumClassName, Value) RhythmUtilities::enum_as_string<EnumClassName>(FString(TEXT(#EnumClassName)), (Value))
|
|
|
|
static FORCEINLINE void log_error(const FString& prefix, const FString& msg)
|
|
{
|
|
const FString log = FString::Printf(TEXT("%s: INFO: %s"), *prefix, *msg);
|
|
// Log to console
|
|
UE_LOG(LogTemp, Warning, TEXT("%s"), *log);
|
|
|
|
// Log to screen
|
|
GEngine->AddOnScreenDebugMessage(
|
|
-1,
|
|
20.f,
|
|
FColor::Red,
|
|
FString::Printf(TEXT("%s: ERROR: %s"), *prefix, *msg)
|
|
);
|
|
}
|
|
|
|
static FORCEINLINE void log_info(const FString& prefix, const FString& msg)
|
|
{
|
|
const FString log = FString::Printf(TEXT("%s: INFO: %s"), *prefix, *msg);
|
|
// Log to console
|
|
UE_LOG(LogTemp, Log, TEXT("%s"), *log);
|
|
|
|
// Log to screen
|
|
GEngine->AddOnScreenDebugMessage(-1, 3.f, FColor::Green, log);
|
|
}
|
|
};
|