Sdk/LuaAPI: Bind VelocityComponent

Former-commit-id: 7e51aa57854b58cdf8b243f1e02e7bb90a943709
This commit is contained in:
Lynix 2016-04-01 18:57:51 +02:00
parent 2736081578
commit fdccc9e510
4 changed files with 42 additions and 1 deletions

View File

@ -13,8 +13,11 @@
namespace Ndk
{
class Entity;
class VelocityComponent;
class NDK_API VelocityComponent : public Component<VelocityComponent>
using VelocityComponentHandle = Nz::ObjectHandle<VelocityComponent>;
class NDK_API VelocityComponent : public Component<VelocityComponent>, public Nz::HandledObject<VelocityComponent>
{
public:
VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero());

View File

@ -28,6 +28,7 @@ namespace Ndk
// SDK
nodeComponent("NodeComponent"),
entityClass("Entity"),
velocityComponent("VelocityComponent"),
worldClass("World")
#ifndef NDK_SERVER

View File

@ -21,6 +21,7 @@
#include <Nazara/Audio.hpp>
#include <Nazara/Graphics.hpp>
#include <Nazara/Renderer.hpp>
#include <NDK/Console.hpp>
#endif
namespace Ndk
@ -81,6 +82,7 @@ namespace Ndk
// SDK
Nz::LuaClass<EntityHandle> entityClass;
Nz::LuaClass<NodeComponentHandle> nodeComponent;
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
Nz::LuaClass<WorldHandle> worldClass;
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);

View File

@ -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<Nz::Vector3f>(&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<NodeComponent>();
EnableComponentBinding<VelocityComponent>();
#ifndef NDK_SERVER
EnableComponentBinding<GraphicsComponent>();
@ -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");
}