add: lua func
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "../../../window/Events.hpp"
|
||||
#include "../../../window/Window.hpp"
|
||||
#include "../../../world/WorldGenerators.hpp"
|
||||
#include "../../../constants.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@@ -158,6 +159,35 @@ static int l_get_generators(lua::State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_get_constants(lua::State* L) {
|
||||
|
||||
lua::createtable(L, 0, 20);
|
||||
|
||||
const std::pair<const char*, int> numberConstants[] = {
|
||||
{"ENGINE_VERSION_MAJOR", ENGINE_VERSION_MAJOR},
|
||||
{"ENGINE_VERSION_MINOR", ENGINE_VERSION_MINOR},
|
||||
{"BLOCK_AIR", BLOCK_AIR},
|
||||
{"ITEM_EMPTY", ITEM_EMPTY},
|
||||
{"CHUNK_W", CHUNK_W},
|
||||
{"CHUNK_H", CHUNK_H},
|
||||
{"CHUNK_D", CHUNK_D},
|
||||
{"VOXEL_USER_BITS", VOXEL_USER_BITS},
|
||||
{"VOXEL_USER_BITS_OFFSET", VOXEL_USER_BITS_OFFSET},
|
||||
{"ITEM_ICON_SIZE", ITEM_ICON_SIZE},
|
||||
{"CHUNK_VOL", CHUNK_VOL},
|
||||
{"BLOCK_VOID", BLOCK_VOID},
|
||||
{"ITEM_VOID", ITEM_VOID},
|
||||
{"MAX_BLOCKS", MAX_BLOCKS}
|
||||
};
|
||||
|
||||
for (const auto& constant : numberConstants) {
|
||||
lua::pushnumber(L, constant.second);
|
||||
lua::setfield(L, constant.first);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg corelib [] = {
|
||||
{"new_world", lua::wrap<l_new_world>},
|
||||
{"open_world", lua::wrap<l_open_world>},
|
||||
@@ -172,5 +202,6 @@ const luaL_Reg corelib [] = {
|
||||
{"quit", lua::wrap<l_quit>},
|
||||
{"get_default_generator", lua::wrap<l_get_default_generator>},
|
||||
{"get_generators", lua::wrap<l_get_generators>},
|
||||
{"get_constants", lua::wrap<l_get_constants>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -126,6 +126,46 @@ static int l_player_get_selected_block(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_get_spawnpoint(lua::State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
return lua::pushvec3(L, player->getSpawnPoint());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int l_player_set_spawnpoint(lua::State* L) {
|
||||
auto player = get_player(L, 1);
|
||||
|
||||
if (player) {
|
||||
auto x = lua::tonumber(L, 2);
|
||||
auto y = lua::tonumber(L, 3);
|
||||
auto z = lua::tonumber(L, 4);
|
||||
player->setSpawnPoint(glm::vec3(x, y, z));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_set_jump_force(lua::State* L) {
|
||||
|
||||
if (auto player = get_player(L, 1)) {
|
||||
player->setJumpForce(std::abs(lua::tonumber(L, 2)));
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_get_jump_force(lua::State* L) {
|
||||
|
||||
if (auto player = get_player(L, 1)) {
|
||||
return lua::pushnumber(L, player->getJumpForce());
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const luaL_Reg playerlib [] = {
|
||||
{"get_pos", lua::wrap<l_player_get_pos>},
|
||||
{"set_pos", lua::wrap<l_player_set_pos>},
|
||||
@@ -139,5 +179,9 @@ const luaL_Reg playerlib [] = {
|
||||
{"is_noclip", lua::wrap<l_player_is_noclip>},
|
||||
{"set_noclip", lua::wrap<l_player_set_noclip>},
|
||||
{"get_selected_block", lua::wrap<l_player_get_selected_block>},
|
||||
{"set_spawnpoint", lua::wrap<l_player_set_spawnpoint>},
|
||||
{"get_spawnpoint", lua::wrap<l_player_get_spawnpoint>},
|
||||
{"get_jump_force", lua::wrap<l_player_get_jump_force>},
|
||||
{"set_jump_force", lua::wrap<l_player_set_jump_force>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -54,6 +54,12 @@ static int l_world_set_day_time(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_wolrd_set_speed_time(lua::State* L) {
|
||||
auto value = lua::tonumber(L, 1);
|
||||
level->getWorld()->factorSpeedTime = std::abs(value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_world_get_seed(lua::State* L) {
|
||||
return lua::pushinteger(L, level->getWorld()->getSeed());
|
||||
}
|
||||
@@ -64,12 +70,25 @@ static int l_world_exists(lua::State* L) {
|
||||
return lua::pushboolean(L, fs::is_directory(worldsDir));
|
||||
}
|
||||
|
||||
static int l_world_is_day(lua::State* L) {
|
||||
auto daytime = level->getWorld()->daytime;
|
||||
return lua::pushboolean(L, daytime >= 0.2 && daytime <= 0.8);
|
||||
}
|
||||
|
||||
static int l_world_is_night(lua::State* L) {
|
||||
auto daytime = level->getWorld()->daytime;
|
||||
return lua::pushboolean(L, daytime < 0.2 || daytime > 0.8);
|
||||
}
|
||||
|
||||
const luaL_Reg worldlib [] = {
|
||||
{"get_list", lua::wrap<l_world_get_list>},
|
||||
{"get_total_time", lua::wrap<l_world_get_total_time>},
|
||||
{"get_day_time", lua::wrap<l_world_get_day_time>},
|
||||
{"set_day_time", lua::wrap<l_world_set_day_time>},
|
||||
{"set_speed_time", lua::wrap<l_wolrd_set_speed_time>},
|
||||
{"get_seed", lua::wrap<l_world_get_seed>},
|
||||
{"is_day", lua::wrap<l_world_is_day>},
|
||||
{"is_night", lua::wrap<l_world_is_night>},
|
||||
{"exists", lua::wrap<l_world_exists>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user