#include "util/stringutil.hpp" #include "libentity.hpp" static int l_get_vel(lua::State* L) { if (auto entity = get_entity(L, 1)) { return lua::pushvec3(L, entity->getRigidbody().hitbox.velocity); } return 0; } static int l_set_vel(lua::State* L) { if (auto entity = get_entity(L, 1)) { entity->getRigidbody().hitbox.velocity = lua::tovec3(L, 2); } return 0; } static int l_is_enabled(lua::State* L) { if (auto entity = get_entity(L, 1)) { lua::pushboolean(L, entity->getRigidbody().enabled); } return 0; } static int l_set_enabled(lua::State* L) { if (auto entity = get_entity(L, 1)) { entity->getRigidbody().enabled = lua::toboolean(L, 2); } return 0; } static int l_get_size(lua::State* L) { if (auto entity = get_entity(L, 1)) { return lua::pushvec3(L, entity->getRigidbody().hitbox.halfsize * 2.0f); } return 0; } static int l_set_size(lua::State* L) { if (auto entity = get_entity(L, 1)) { entity->getRigidbody().hitbox.halfsize = lua::tovec3(L, 2) * 0.5f; } return 0; } static int l_get_gravity_scale(lua::State* L) { if (auto entity = get_entity(L, 1)) { return lua::pushnumber(L, entity->getRigidbody().hitbox.gravityScale); } return 0; } static int l_set_gravity_scale(lua::State* L) { if (auto entity = get_entity(L, 1)) { entity->getRigidbody().hitbox.gravityScale = lua::tonumber(L, 2); } return 0; } static int l_is_vdamping(lua::State* L) { if (auto entity = get_entity(L, 1)) { return lua::pushboolean( L, entity->getRigidbody().hitbox.verticalDamping ); } return 0; } static int l_set_vdamping(lua::State* L) { if (auto entity = get_entity(L, 1)) { entity->getRigidbody().hitbox.verticalDamping = lua::toboolean(L, 2); } return 0; } static int l_is_grounded(lua::State* L) { if (auto entity = get_entity(L, 1)) { return lua::pushboolean(L, entity->getRigidbody().hitbox.grounded); } return 0; } static int l_is_crouching(lua::State* L) { if (auto entity = get_entity(L, 1)) { return lua::pushboolean(L, entity->getRigidbody().hitbox.crouching); } return 0; } static int l_set_crouching(lua::State* L) { if (auto entity = get_entity(L, 1)) { entity->getRigidbody().hitbox.crouching = lua::toboolean(L, 2); } return 0; } static int l_get_body_type(lua::State* L) { if (auto entity = get_entity(L, 1)) { return lua::pushstring( L, to_string(entity->getRigidbody().hitbox.type) ); } return 0; } static int l_set_body_type(lua::State* L) { if (auto entity = get_entity(L, 1)) { if (auto type = BodyType_from(lua::tostring(L, 2))) { entity->getRigidbody().hitbox.type = *type; } else { throw std::runtime_error( "unknown body type " + util::quote(lua::tostring(L, 2)) ); } } return 0; } static int l_get_linear_damping(lua::State* L) { if (auto entity = get_entity(L, 1)) { return lua::pushnumber(L, entity->getRigidbody().hitbox.linearDamping); } return 0; } static int l_set_linear_damping(lua::State* L) { if (auto entity = get_entity(L, 1)) { entity->getRigidbody().hitbox.linearDamping = lua::tonumber(L, 2); } return 0; } const luaL_Reg rigidbodylib[] = { {"is_enabled", lua::wrap}, {"set_enabled", lua::wrap}, {"get_vel", lua::wrap}, {"set_vel", lua::wrap}, {"get_size", lua::wrap}, {"set_size", lua::wrap}, {"get_gravity_scale", lua::wrap}, {"set_gravity_scale", lua::wrap}, {"get_linear_damping", lua::wrap}, {"set_linear_damping", lua::wrap}, {"is_vdamping", lua::wrap}, {"set_vdamping", lua::wrap}, {"is_grounded", lua::wrap}, {"is_crouching", lua::wrap}, {"set_crouching", lua::wrap}, {"get_body_type", lua::wrap}, {"set_body_type", lua::wrap}, {NULL, NULL}};