From c7aa0c0a139f58ea9acaf1209c3b56b21579cf66 Mon Sep 17 00:00:00 2001 From: Panakotta00 Date: Wed, 24 Jul 2024 22:03:13 +0200 Subject: [PATCH] feat: `id` & `nick` now reflection properties that may throw an exception Removes the special treatment from Reflection Lua Implementation, instead they are normal properties that may throw an exception if called on a non-network-component. --- .../Reflection/FINStaticReflectionSource.cpp | 25 +++++++++++++++++++ .../Private/FINLua/Reflection/LuaObject.cpp | 21 ---------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Source/FicsItNetworks/Private/Reflection/FINStaticReflectionSource.cpp b/Source/FicsItNetworks/Private/Reflection/FINStaticReflectionSource.cpp index 81296a952..1a32a17a3 100644 --- a/Source/FicsItNetworks/Private/Reflection/FINStaticReflectionSource.cpp +++ b/Source/FicsItNetworks/Private/Reflection/FINStaticReflectionSource.cpp @@ -16,6 +16,7 @@ #include "FINGlobalRegisterHelper.h" #include "Computer/FINComputerGPUT1.h" +#include "Network/FINNetworkUtils.h" #include "Network/FINFuture.h" #include "Network/FINNetworkConnectionComponent.h" #include "Utils/FINTargetPoint.h" @@ -64,6 +65,7 @@ #include "Computer/FINComputerGPUT2.h" #include "Computer/FINComputerSubsystem.h" #include "FicsItKernel/Logging.h" +#include "Network/FINNetworkComponent.h" #include "WheeledVehicles/FGTargetPointLinkedList.h" #include "WheeledVehicles/FGWheeledVehicle.h" @@ -598,6 +600,29 @@ class FStaticReflectionSourceHelper { }; BeginClass(UObject, "Object", "Object", "The base class of every object.") +BeginProp(RString, nick, "Nick", "**Only available for Network Components!** Allows access to the Network Components Nick.") { + UObject* NetworkHandler = UFINNetworkUtils::FindNetworkComponentFromObject(self); + if (NetworkHandler) { + Return IFINNetworkComponent::Execute_GetNick(NetworkHandler); + } else { + throw FFINException("Not a network component!"); + } +} PropSet() { + UObject* NetworkHandler = UFINNetworkUtils::FindNetworkComponentFromObject(self); + if (NetworkHandler) { + IFINNetworkComponent::Execute_SetNick(NetworkHandler, Val); + } else { + throw FFINException("Not a network component!"); + } +} EndProp() +BeginProp(RString, id, "ID", "**Only available for Network Components!** Allows access to the Network Components UUID.") { + UObject* NetworkHandler = UFINNetworkUtils::FindNetworkComponentFromObject(self); + if (NetworkHandler) { + Return IFINNetworkComponent::Execute_GetID(NetworkHandler).ToString(); + } else { + throw FFINException("Not a network component!"); + } +} EndProp() BeginProp(RInt, hash, "Hash", "A Hash of this object. This is a value that nearly uniquely identifies this object.") { Return (int64)GetTypeHash(self); } EndProp() diff --git a/Source/FicsItNetworksLua/Private/FINLua/Reflection/LuaObject.cpp b/Source/FicsItNetworksLua/Private/FINLua/Reflection/LuaObject.cpp index ce5540aaa..8fc2714ec 100644 --- a/Source/FicsItNetworksLua/Private/FINLua/Reflection/LuaObject.cpp +++ b/Source/FicsItNetworksLua/Private/FINLua/Reflection/LuaObject.cpp @@ -95,18 +95,6 @@ namespace FINLua { FLuaObject* LuaObject = luaFIN_checkLuaObject(L, thisIndex, nullptr); FString MemberName = luaFIN_toFString(L, nameIndex); - UObject* NetworkHandler = UFINNetworkUtils::FindNetworkComponentFromObject(*LuaObject->Object); - if (NetworkHandler) { - if (MemberName == "id") { - lua_pushstring(L, TCHAR_TO_UTF8(*IFINNetworkComponent::Execute_GetID(NetworkHandler).ToString())); - return 1; - } - if (MemberName == "nick") { - lua_pushstring(L, TCHAR_TO_UTF8(*IFINNetworkComponent::Execute_GetNick(NetworkHandler))); - return 1; - } - } - FFINExecutionContext Context(LuaObject->Object); return luaFIN_pushFunctionOrGetProperty(L, thisIndex, LuaObject->Type, MemberName, FIN_Func_MemberFunc, FIN_Prop_Attrib, Context, true); } @@ -124,15 +112,6 @@ namespace FINLua { FLuaObject* LuaObject = luaFIN_checkLuaObject(L, thisIndex, nullptr); FString MemberName = luaFIN_toFString(L, nameIndex); - UObject* NetworkHandler = UFINNetworkUtils::FindNetworkComponentFromObject(*LuaObject->Object); - if (NetworkHandler) { - if (MemberName == "nick") { - FString nick = luaFIN_toFString(L, valueIndex); - IFINNetworkComponent::Execute_SetNick(NetworkHandler, nick); - return 0; - } - } - FFINExecutionContext Context(LuaObject->Object); luaFIN_tryExecuteSetProperty(L, thisIndex, LuaObject->Type, MemberName, FIN_Prop_Attrib, Context, valueIndex, true); return 0;