Move a lot of EngineWrapper interfaces out of LuprexGameModeBase
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
|
||||
#include "LuaCall.h"
|
||||
#include "LuprexGameModeBase.h"
|
||||
#include "Tangible.h"
|
||||
#include "StringDecoder.h"
|
||||
|
||||
#include "EdGraphSchema_K2.h"
|
||||
@@ -196,51 +197,30 @@ FString UlxLuaCallLibrary::AllFunctionsWithPrefix(const TCHAR *Prefix)
|
||||
return Result;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// General Lua-Callable functions of the Lua Call Library.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////
|
||||
|
||||
void UlxLuaCallLibrary::ValidateLuaExpr(
|
||||
ElxLuaSyntaxCheck &Status, FString &ErrorMessage, UObject *context, const FString &Code)
|
||||
{
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
ErrorMessage = mode->ValidateLuaExpr(Code);
|
||||
if (ErrorMessage.IsEmpty())
|
||||
{
|
||||
Status = ElxLuaSyntaxCheck::ValidLua;
|
||||
}
|
||||
else if (ErrorMessage == TEXT("slash command"))
|
||||
{
|
||||
Status = ElxLuaSyntaxCheck::SlashCommand;
|
||||
}
|
||||
else if (ErrorMessage == TEXT("white space"))
|
||||
{
|
||||
Status = ElxLuaSyntaxCheck::Whitespace;
|
||||
}
|
||||
else if (ErrorMessage == TEXT("truncated lua"))
|
||||
{
|
||||
Status = ElxLuaSyntaxCheck::TruncatedLua;
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = ElxLuaSyntaxCheck::InvalidLua;
|
||||
}
|
||||
}
|
||||
|
||||
void UlxLuaCallLibrary::InvokeLuaExpr(UObject *context, const FString &Code)
|
||||
{
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
mode->InvokeLuaExpr(Code);
|
||||
FlxLockedWrapper w(mode->GetLockableWrapper());
|
||||
w.InvokeLuaExpr(Code);
|
||||
}
|
||||
|
||||
// Resolve an AActor to a tangible place_id.
|
||||
// Returns 0 if place is null (meaning "use current
|
||||
// actor"), or the tangible ID if found. Returns -1
|
||||
// if place is non-null but has no tangible.
|
||||
//
|
||||
static int64 ResolvePlaceId(AActor *place)
|
||||
{
|
||||
if (place == nullptr) return 0;
|
||||
UlxTangible *tan = UlxTangible::GetActorTangibleOrLog(place);
|
||||
return tan ? tan->TangibleId : -1;
|
||||
}
|
||||
|
||||
void UlxLuaCallLibrary::LuaCallBegin(UObject *context, const FString &cname, const FString &fname)
|
||||
{
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
mode->LuaCallBegin();
|
||||
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
|
||||
sb.clear();
|
||||
sb.write_string(cname);
|
||||
sb.write_string(fname);
|
||||
}
|
||||
@@ -248,19 +228,33 @@ void UlxLuaCallLibrary::LuaCallBegin(UObject *context, const FString &cname, con
|
||||
void UlxLuaCallLibrary::LuaCallInvoke(UObject *context, AActor *place)
|
||||
{
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
|
||||
if (NotInitialized(sb)) return;
|
||||
mode->LuaCallEnd(AccessKind::INVOKE_LUA_CALL, place);
|
||||
int64 place_id = ResolvePlaceId(place);
|
||||
if (place_id < 0) { sb.clear(); return; }
|
||||
FlxLockedWrapper w(mode->GetLockableWrapper());
|
||||
w.InvokeLuaFunction(sb.view(), place_id);
|
||||
sb.clear();
|
||||
}
|
||||
|
||||
|
||||
bool UlxLuaCallLibrary::LuaCallProbe(UObject *context, AActor *place, UlxLuaValues *&ReturnArray)
|
||||
{
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
|
||||
if (NotInitialized(sb)) return false;
|
||||
ReturnArray = mode->LuaCallEnd(AccessKind::PROBE_LUA_CALL, place);
|
||||
if ((ReturnArray == nullptr) || (ReturnArray->Length() < 1))
|
||||
int64 place_id = ResolvePlaceId(place);
|
||||
if (place_id < 0) {
|
||||
sb.clear();
|
||||
ReturnArray = NewObject<UlxLuaValues>(mode);
|
||||
return false;
|
||||
}
|
||||
ReturnArray = NewObject<UlxLuaValues>(mode);
|
||||
FlxLockedWrapper w(mode->GetLockableWrapper());
|
||||
w.ProbeLuaFunction(sb.view(), place_id, [&](std::string_view retpk) {
|
||||
ReturnArray->Initialize(retpk);
|
||||
});
|
||||
sb.clear();
|
||||
if (ReturnArray->Length() < 1)
|
||||
{
|
||||
UE_LOG(LogLuprexIntegration, Error, TEXT("corruption in lua_probe"));
|
||||
ReturnArray = nullptr;
|
||||
@@ -292,7 +286,7 @@ bool UlxLuaCallLibrary::LuaCallProbe(UObject *context, AActor *place, UlxLuaValu
|
||||
|
||||
void UlxLuaCallLibrary::LuaCallArgument_string(UObject *context, const FString &pstring) {
|
||||
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
|
||||
FlxStreamBuffer &sb = mode->LuaCallGetBuffer();
|
||||
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(LuaValueType::STRING);
|
||||
sb.write_string(pstring);
|
||||
@@ -307,7 +301,7 @@ void UlxLuaCallLibrary::LuaCallArgument_name(UObject *context, const FName &pnam
|
||||
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();
|
||||
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(LuaValueType::TOKEN);
|
||||
sb.write_string(namestr);
|
||||
@@ -315,7 +309,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();
|
||||
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(LuaValueType::NUMBER);
|
||||
sb.write_double(pfloat);
|
||||
@@ -323,7 +317,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();
|
||||
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(LuaValueType::NUMBER);
|
||||
sb.write_double(value);
|
||||
@@ -331,7 +325,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();
|
||||
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(LuaValueType::VECTOR);
|
||||
sb.write_fvector(pvector);
|
||||
@@ -339,7 +333,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();
|
||||
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(LuaValueType::VECTOR);
|
||||
sb.write_double(pvector.X);
|
||||
@@ -349,7 +343,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();
|
||||
FlxStreamBuffer &sb = mode->GetLuaCallBuffer();
|
||||
if (NotInitialized(sb)) return;
|
||||
sb.write_simple_dynamic_tag(LuaValueType::BOOLEAN);
|
||||
sb.write_bool(pbool);
|
||||
|
||||
Reference in New Issue
Block a user