From fdccc9e51037e2d188ed27bcf18d86ab1991eaf1 Mon Sep 17 00:00:00 2001 From: Lynix Date: Fri, 1 Apr 2016 18:57:51 +0200 Subject: [PATCH] Sdk/LuaAPI: Bind VelocityComponent Former-commit-id: 7e51aa57854b58cdf8b243f1e02e7bb90a943709 --- .../NDK/Components/VelocityComponent.hpp | 5 ++- SDK/src/NDK/LuaBinding.cpp | 1 + SDK/src/NDK/LuaBinding.hpp | 2 ++ SDK/src/NDK/LuaBinding_SDK.cpp | 35 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/SDK/include/NDK/Components/VelocityComponent.hpp b/SDK/include/NDK/Components/VelocityComponent.hpp index 28d317a2c..33d97b030 100644 --- a/SDK/include/NDK/Components/VelocityComponent.hpp +++ b/SDK/include/NDK/Components/VelocityComponent.hpp @@ -13,8 +13,11 @@ namespace Ndk { class Entity; + class VelocityComponent; - class NDK_API VelocityComponent : public Component + using VelocityComponentHandle = Nz::ObjectHandle; + + class NDK_API VelocityComponent : public Component, public Nz::HandledObject { public: VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero()); diff --git a/SDK/src/NDK/LuaBinding.cpp b/SDK/src/NDK/LuaBinding.cpp index 9af6aab40..0936ac9aa 100644 --- a/SDK/src/NDK/LuaBinding.cpp +++ b/SDK/src/NDK/LuaBinding.cpp @@ -28,6 +28,7 @@ namespace Ndk // SDK nodeComponent("NodeComponent"), entityClass("Entity"), + velocityComponent("VelocityComponent"), worldClass("World") #ifndef NDK_SERVER diff --git a/SDK/src/NDK/LuaBinding.hpp b/SDK/src/NDK/LuaBinding.hpp index 2bb01421f..184996991 100644 --- a/SDK/src/NDK/LuaBinding.hpp +++ b/SDK/src/NDK/LuaBinding.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #endif namespace Ndk @@ -81,6 +82,7 @@ namespace Ndk // SDK Nz::LuaClass entityClass; Nz::LuaClass nodeComponent; + Nz::LuaClass velocityComponent; Nz::LuaClass worldClass; using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&); diff --git a/SDK/src/NDK/LuaBinding_SDK.cpp b/SDK/src/NDK/LuaBinding_SDK.cpp index 15e81b63b..ebbc236ce 100644 --- a/SDK/src/NDK/LuaBinding_SDK.cpp +++ b/SDK/src/NDK/LuaBinding_SDK.cpp @@ -137,6 +137,36 @@ namespace Ndk return handle->GetObject(); }); + /*********************************** Ndk::VelocityComponent **********************************/ + velocityComponent.SetGetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance) + { + std::size_t length; + const char* member = lua.CheckString(1, &length); + + if (std::strcmp(member, "Linear") == 0) + { + lua.Push(instance->linearVelocity); + return true; + } + + return false; + }); + + velocityComponent.SetSetter([] (Nz::LuaInstance& lua, VelocityComponentHandle& instance) + { + std::size_t length; + const char* member = lua.CheckString(1, &length); + + int argIndex = 2; + if (std::strcmp(member, "Linear") == 0) + { + instance->linearVelocity = lua.Check(&argIndex); + return true; + } + + return false; + }); + /*********************************** Ndk::World **********************************/ worldClass.SetMethod("CreateEntity", &World::CreateEntity); worldClass.SetMethod("CreateEntities", &World::CreateEntities); @@ -153,6 +183,7 @@ namespace Ndk m_componentBinding.resize(BaseComponent::GetMaxComponentIndex() + 1); EnableComponentBinding(); + EnableComponentBinding(); #ifndef NDK_SERVER EnableComponentBinding(); @@ -177,6 +208,7 @@ namespace Ndk // Classes entityClass.Register(instance); nodeComponent.Register(instance); + velocityComponent.Register(instance); worldClass.Register(instance); #ifndef NDK_SERVER @@ -196,6 +228,9 @@ namespace Ndk instance.PushInteger(NodeComponent::componentIndex); instance.SetField("Node"); + + instance.PushInteger(VelocityComponent::componentIndex); + instance.SetField("Velocity"); } instance.SetGlobal("ComponentType"); }