Sdk/LuaAPI: Bind VelocityComponent
Former-commit-id: 7e51aa57854b58cdf8b243f1e02e7bb90a943709
This commit is contained in:
parent
2736081578
commit
fdccc9e510
|
|
@ -13,8 +13,11 @@
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
{
|
{
|
||||||
class Entity;
|
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:
|
public:
|
||||||
VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero());
|
VelocityComponent(const Nz::Vector3f& velocity = Nz::Vector3f::Zero());
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ namespace Ndk
|
||||||
// SDK
|
// SDK
|
||||||
nodeComponent("NodeComponent"),
|
nodeComponent("NodeComponent"),
|
||||||
entityClass("Entity"),
|
entityClass("Entity"),
|
||||||
|
velocityComponent("VelocityComponent"),
|
||||||
worldClass("World")
|
worldClass("World")
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
#ifndef NDK_SERVER
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#include <Nazara/Audio.hpp>
|
#include <Nazara/Audio.hpp>
|
||||||
#include <Nazara/Graphics.hpp>
|
#include <Nazara/Graphics.hpp>
|
||||||
#include <Nazara/Renderer.hpp>
|
#include <Nazara/Renderer.hpp>
|
||||||
|
#include <NDK/Console.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Ndk
|
namespace Ndk
|
||||||
|
|
@ -81,6 +82,7 @@ namespace Ndk
|
||||||
// SDK
|
// SDK
|
||||||
Nz::LuaClass<EntityHandle> entityClass;
|
Nz::LuaClass<EntityHandle> entityClass;
|
||||||
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
Nz::LuaClass<NodeComponentHandle> nodeComponent;
|
||||||
|
Nz::LuaClass<VelocityComponentHandle> velocityComponent;
|
||||||
Nz::LuaClass<WorldHandle> worldClass;
|
Nz::LuaClass<WorldHandle> worldClass;
|
||||||
|
|
||||||
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
using AddComponentFunc = int(*)(Nz::LuaInstance&, EntityHandle&);
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,36 @@ namespace Ndk
|
||||||
return handle->GetObject();
|
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 **********************************/
|
/*********************************** Ndk::World **********************************/
|
||||||
worldClass.SetMethod("CreateEntity", &World::CreateEntity);
|
worldClass.SetMethod("CreateEntity", &World::CreateEntity);
|
||||||
worldClass.SetMethod("CreateEntities", &World::CreateEntities);
|
worldClass.SetMethod("CreateEntities", &World::CreateEntities);
|
||||||
|
|
@ -153,6 +183,7 @@ namespace Ndk
|
||||||
m_componentBinding.resize(BaseComponent::GetMaxComponentIndex() + 1);
|
m_componentBinding.resize(BaseComponent::GetMaxComponentIndex() + 1);
|
||||||
|
|
||||||
EnableComponentBinding<NodeComponent>();
|
EnableComponentBinding<NodeComponent>();
|
||||||
|
EnableComponentBinding<VelocityComponent>();
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
#ifndef NDK_SERVER
|
||||||
EnableComponentBinding<GraphicsComponent>();
|
EnableComponentBinding<GraphicsComponent>();
|
||||||
|
|
@ -177,6 +208,7 @@ namespace Ndk
|
||||||
// Classes
|
// Classes
|
||||||
entityClass.Register(instance);
|
entityClass.Register(instance);
|
||||||
nodeComponent.Register(instance);
|
nodeComponent.Register(instance);
|
||||||
|
velocityComponent.Register(instance);
|
||||||
worldClass.Register(instance);
|
worldClass.Register(instance);
|
||||||
|
|
||||||
#ifndef NDK_SERVER
|
#ifndef NDK_SERVER
|
||||||
|
|
@ -196,6 +228,9 @@ namespace Ndk
|
||||||
|
|
||||||
instance.PushInteger(NodeComponent::componentIndex);
|
instance.PushInteger(NodeComponent::componentIndex);
|
||||||
instance.SetField("Node");
|
instance.SetField("Node");
|
||||||
|
|
||||||
|
instance.PushInteger(VelocityComponent::componentIndex);
|
||||||
|
instance.SetField("Velocity");
|
||||||
}
|
}
|
||||||
instance.SetGlobal("ComponentType");
|
instance.SetGlobal("ComponentType");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue