Lots of work on look-at widgets
This commit is contained in:
@@ -5,15 +5,14 @@
|
||||
|
||||
#include "EdGraphSchema_K2.h"
|
||||
|
||||
static void FatalBlueprintError(const TCHAR *message) {
|
||||
FBlueprintExceptionInfo ExceptionInfo(EBlueprintExceptionType::FatalError, FText::FromString(FString(message)));
|
||||
FBlueprintCoreDelegates::ThrowScriptException(FFrame::GetThreadLocalTopStackFrame()->Object, *FFrame::GetThreadLocalTopStackFrame(), ExceptionInfo);
|
||||
}
|
||||
|
||||
static void CheckNotEmpty(const FlxStreamBuffer &sb) {
|
||||
if (sb.empty()) {
|
||||
FatalBlueprintError(TEXT("Must use LuaCallBegin before other LuaCall steps"));
|
||||
static bool NotInitialized(const FlxStreamBuffer &sb) {
|
||||
if (sb.empty())
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("Must use LuaCallBegin before other LuaCall steps"));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static constexpr uint64_t ParseNameAsToken(std::string_view str) {
|
||||
@@ -219,8 +218,8 @@ void UlxLuaCallLibrary::LuaCallInvoke(UObject *context, AActor *place)
|
||||
{
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
mode->LuaCallEnd(InvocationKind::LUA_INVOKE, place);
|
||||
if (NotInitialized(sb)) return;
|
||||
mode->LuaCallEnd(InvocationKind::LUA_INVOKE, place);
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +227,7 @@ void UlxLuaCallLibrary::LuaCallProbe(UObject *context, AActor *place)
|
||||
{
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
if (NotInitialized(sb)) return;
|
||||
mode->LuaCallEnd(InvocationKind::LUA_PROBE, place);
|
||||
}
|
||||
|
||||
@@ -254,7 +253,7 @@ UlxLuaValues *UlxLuaCallLibrary::LuaCallGetRest(UObject *context)
|
||||
void UlxLuaCallLibrary::LuaCallArgument_string(UObject *context, const FString &pstring) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::STRING);
|
||||
sb.write_string(pstring);
|
||||
}
|
||||
@@ -263,12 +262,13 @@ void UlxLuaCallLibrary::LuaCallArgument_name(UObject *context, const FName &pnam
|
||||
FTCHARToUTF8 utf8str(pname.ToString());
|
||||
std::string_view namestr(utf8str.Get(), utf8str.Length());
|
||||
uint64_t tokvalue = ParseNameAsToken(namestr);
|
||||
if ((tokvalue == 0) && !namestr.empty()) {
|
||||
FatalBlueprintError(TEXT("Names passed to lua must be short, and must contain only lowercase and digits"));
|
||||
if ((tokvalue == 0) && !namestr.empty())
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("Names passed to lua must be short, and must contain only lowercase and digits"));
|
||||
}
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::TOKEN);
|
||||
sb.write_string(namestr);
|
||||
}
|
||||
@@ -276,7 +276,7 @@ void UlxLuaCallLibrary::LuaCallArgument_name(UObject *context, const FName &pnam
|
||||
void UlxLuaCallLibrary::LuaCallArgument_float(UObject *context, double pfloat) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
|
||||
sb.write_double(pfloat);
|
||||
}
|
||||
@@ -284,7 +284,7 @@ void UlxLuaCallLibrary::LuaCallArgument_float(UObject *context, double pfloat) {
|
||||
void UlxLuaCallLibrary::LuaCallArgument_int(UObject *context, int value) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::NUMBER);
|
||||
sb.write_double(value);
|
||||
}
|
||||
@@ -292,7 +292,7 @@ void UlxLuaCallLibrary::LuaCallArgument_int(UObject *context, int value) {
|
||||
void UlxLuaCallLibrary::LuaCallArgument_vector(UObject *context, const FVector &pvector) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::VECTOR);
|
||||
sb.write_fvector(pvector);
|
||||
}
|
||||
@@ -300,7 +300,7 @@ void UlxLuaCallLibrary::LuaCallArgument_vector(UObject *context, const FVector &
|
||||
void UlxLuaCallLibrary::LuaCallArgument_vector2d(UObject *context, const FVector2D &pvector) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::VECTOR);
|
||||
sb.write_double(pvector.X);
|
||||
sb.write_double(pvector.Y);
|
||||
@@ -310,7 +310,7 @@ void UlxLuaCallLibrary::LuaCallArgument_vector2d(UObject *context, const FVector
|
||||
void UlxLuaCallLibrary::LuaCallArgument_boolean(UObject *context, bool pbool) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
CheckNotEmpty(sb);
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(SimpleDynamicTag::BOOLEAN);
|
||||
sb.write_bool(pbool);
|
||||
}
|
||||
@@ -327,7 +327,11 @@ FString UlxLuaCallLibrary::LuaCallReturnValue_string(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::STRING) FatalBlueprintError(TEXT("expected lua to return a string"));
|
||||
if (tag != SimpleDynamicTag::STRING)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a string"));
|
||||
return TEXT("");
|
||||
}
|
||||
return sb.read_fstring();
|
||||
}
|
||||
|
||||
@@ -335,7 +339,11 @@ FName UlxLuaCallLibrary::LuaCallReturnValue_name(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::TOKEN) FatalBlueprintError(TEXT("expected lua to return a name"));
|
||||
if (tag != SimpleDynamicTag::TOKEN)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a name"));
|
||||
return FName();
|
||||
}
|
||||
return sb.read_fname();
|
||||
}
|
||||
|
||||
@@ -343,7 +351,11 @@ double UlxLuaCallLibrary::LuaCallReturnValue_float(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::NUMBER) FatalBlueprintError(TEXT("expected lua to return a float"));
|
||||
if (tag != SimpleDynamicTag::NUMBER)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a float"));
|
||||
return 0.0;
|
||||
}
|
||||
return sb.read_double();
|
||||
}
|
||||
|
||||
@@ -351,7 +363,11 @@ int UlxLuaCallLibrary::LuaCallReturnValue_int(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::NUMBER) FatalBlueprintError(TEXT("expected lua to return a number"));
|
||||
if (tag != SimpleDynamicTag::NUMBER)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a number"));
|
||||
return 0;
|
||||
}
|
||||
return int(sb.read_double());
|
||||
}
|
||||
|
||||
@@ -359,7 +375,11 @@ FVector UlxLuaCallLibrary::LuaCallReturnValue_vector(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::VECTOR) FatalBlueprintError(TEXT("expected lua to return a vector"));
|
||||
if (tag != SimpleDynamicTag::VECTOR)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a vector"));
|
||||
return FVector();
|
||||
}
|
||||
return sb.read_fvector();
|
||||
}
|
||||
|
||||
@@ -367,8 +387,12 @@ FVector2D UlxLuaCallLibrary::LuaCallReturnValue_vector2d(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::VECTOR) FatalBlueprintError(TEXT("expected lua to return a vector"));
|
||||
FVector v = sb.read_fvector();
|
||||
if (tag != SimpleDynamicTag::VECTOR)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a vector"));
|
||||
return FVector2D();
|
||||
}
|
||||
FVector v = sb.read_fvector();
|
||||
return FVector2D(v.X, v.Y);
|
||||
}
|
||||
|
||||
@@ -376,7 +400,169 @@ bool UlxLuaCallLibrary::LuaCallReturnValue_boolean(UObject *context) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetResult();
|
||||
SimpleDynamicTag tag = sb.read_simple_dynamic_tag();
|
||||
if (tag != SimpleDynamicTag::BOOLEAN) FatalBlueprintError(TEXT("expected lua to return a boolean"));
|
||||
return sb.read_bool();
|
||||
if (tag != SimpleDynamicTag::BOOLEAN)
|
||||
{
|
||||
UE_LOG(LogBlueprint, Error, TEXT("expected lua to return a boolean"));
|
||||
return false;
|
||||
}
|
||||
return sb.read_bool();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Returning the rest of the lua return values as an array.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void UlxLuaValues::Empty()
|
||||
{
|
||||
Serialized.clear();
|
||||
Types.Empty();
|
||||
Data.Empty();
|
||||
Cursor = 0;
|
||||
}
|
||||
|
||||
bool UlxLuaValues::Initialize(std::string_view data)
|
||||
{
|
||||
Empty();
|
||||
Serialized = data;
|
||||
const char *SerializedChar = &Serialized[0];
|
||||
|
||||
FlxStreamBuffer Decoder(Serialized);
|
||||
|
||||
while (!Decoder.empty())
|
||||
{
|
||||
SimpleDynamicTag Tag = Decoder.read_simple_dynamic_tag();
|
||||
|
||||
int64 Pos = Decoder.total_reads();
|
||||
ElxLuaValueType Type;
|
||||
switch (Tag)
|
||||
{
|
||||
case SimpleDynamicTag::BOOLEAN: Type=ElxLuaValueType::Boolean; Decoder.read_bool(); break;
|
||||
case SimpleDynamicTag::NUMBER: Type=ElxLuaValueType::Float; Decoder.read_double(); break;
|
||||
case SimpleDynamicTag::STRING: Type=ElxLuaValueType::String; Decoder.read_string_view(); break;
|
||||
case SimpleDynamicTag::TOKEN: Type=ElxLuaValueType::Name; Decoder.read_string_view(); break;
|
||||
case SimpleDynamicTag::VECTOR: Type=ElxLuaValueType::Vector; Decoder.read_fvector(); break;
|
||||
default: {
|
||||
Empty();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
int64 Pos2 = Decoder.total_reads();
|
||||
Types.Add(Type);
|
||||
Data.Add(std::string_view(SerializedChar + Pos, Pos2 - Pos));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
FString UlxLuaValues::DebugString() const
|
||||
{
|
||||
TStringBuilder<2048> Output;
|
||||
Output << TEXT("{ ");
|
||||
for (int i = 0; i < Types.Num(); i++)
|
||||
{
|
||||
if (i > 0) Output << TEXT(", ");
|
||||
|
||||
ElxLuaValueType Type = Types[i];
|
||||
FlxStreamBuffer Decoder(Data[i]);
|
||||
switch (Type)
|
||||
{
|
||||
case ElxLuaValueType::Boolean:
|
||||
Output << Decoder.read_bool();
|
||||
break;
|
||||
case ElxLuaValueType::Float:
|
||||
Output << FString::Printf(TEXT("%lf"), Decoder.read_double());
|
||||
break;
|
||||
case ElxLuaValueType::String:
|
||||
Output << TEXT("\"") << Decoder.read_fstring() << TEXT("\"");
|
||||
break;
|
||||
case ElxLuaValueType::Name:
|
||||
Output << Decoder.read_fname();
|
||||
break;
|
||||
case ElxLuaValueType::Vector: {
|
||||
FVector Vec = Decoder.read_fvector();
|
||||
Output << FString::Printf(TEXT("(%lf, %lf, %lf)"), Vec.X, Vec.Y, Vec.Z);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Output << TEXT(" }");
|
||||
return Output.ToString();
|
||||
}
|
||||
|
||||
bool UlxLuaValues::CheckType(ElxLuaValueType Type, ElxLuaValueType Desired)
|
||||
{
|
||||
if (Type != Desired)
|
||||
{
|
||||
FString TypeName = StaticEnum<ElxLuaValueType>()->GetDisplayNameTextByValue(int64(Type)).ToString();
|
||||
FString DesiredName = StaticEnum<ElxLuaValueType>()->GetDisplayNameTextByValue(int64(Desired)).ToString();
|
||||
UE_LOG(LogBlueprint, Error, TEXT("Expected a value of type %s, but found %s instead."), *DesiredName, *TypeName);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ElxLuaValueType UlxLuaValues::GetType(int n) const
|
||||
{
|
||||
if (n < 0) return ElxLuaValueType::None;
|
||||
if (n >= Types.Num()) return ElxLuaValueType::None;
|
||||
return Types[Cursor];
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Nth value in the array. Array bounds-checking
|
||||
// is handled by 'GetType', which returns 'None' for out-of-bounds
|
||||
// accesses.
|
||||
//
|
||||
|
||||
FString UlxLuaValues::GetString(int n) const
|
||||
{
|
||||
if (!CheckType(GetType(n), ElxLuaValueType::String)) return FString();
|
||||
FlxStreamBuffer Decoder(Data[n]);
|
||||
return Decoder.read_fstring();
|
||||
}
|
||||
|
||||
FName UlxLuaValues::GetName(int n) const
|
||||
{
|
||||
if (!CheckType(GetType(n), ElxLuaValueType::Name)) return FName();
|
||||
FlxStreamBuffer Decoder(Data[n]);
|
||||
return Decoder.read_fname();
|
||||
}
|
||||
|
||||
double UlxLuaValues::GetFloat(int n) const
|
||||
{
|
||||
if (!CheckType(GetType(n), ElxLuaValueType::Float)) return 0.0;
|
||||
FlxStreamBuffer Decoder(Data[n]);
|
||||
return Decoder.read_double();
|
||||
}
|
||||
|
||||
int UlxLuaValues::GetInt(int n) const
|
||||
{
|
||||
if (!CheckType(GetType(n), ElxLuaValueType::Float)) return 0;
|
||||
FlxStreamBuffer Decoder(Data[n]);
|
||||
return int(Decoder.read_double());
|
||||
}
|
||||
|
||||
FVector UlxLuaValues::GetVector(int n) const
|
||||
{
|
||||
if (!CheckType(GetType(n), ElxLuaValueType::Vector)) return FVector();
|
||||
FlxStreamBuffer Decoder(Data[n]);
|
||||
return Decoder.read_fvector();
|
||||
}
|
||||
|
||||
FVector2D UlxLuaValues::GetVector2D(int n) const
|
||||
{
|
||||
if (!CheckType(GetType(n), ElxLuaValueType::Vector)) return FVector2D();
|
||||
FlxStreamBuffer Decoder(Data[n]);
|
||||
FVector v = Decoder.read_fvector();
|
||||
return FVector2D(v.X, v.Y);
|
||||
}
|
||||
|
||||
bool UlxLuaValues::GetBoolean(int n) const
|
||||
{
|
||||
if (!CheckType(GetType(n), ElxLuaValueType::Boolean)) return false;
|
||||
FlxStreamBuffer Decoder(Data[n]);
|
||||
return Decoder.read_bool();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user