diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2020-10-04 10:50:07 +0200 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2020-10-04 10:50:07 +0200 |
commit | b9f8f0a232d9d00a323084e0e4807b3e3469720d (patch) | |
tree | 564679fd09da5cb4ef7da82dde5b7d8d5c2d7aee /src/script/lua_api | |
parent | af085acbd32707576ff9e67c3b267ad6cf267288 (diff) | |
download | dragonfireclient-b9f8f0a232d9d00a323084e0e4807b3e3469720d.tar.xz |
The Robot Update
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_client.cpp | 22 | ||||
-rw-r--r-- | src/script/lua_api/l_client.h | 3 | ||||
-rw-r--r-- | src/script/lua_api/l_env.cpp | 7 | ||||
-rw-r--r-- | src/script/lua_api/l_localplayer.cpp | 35 | ||||
-rw-r--r-- | src/script/lua_api/l_localplayer.h | 11 |
5 files changed, 74 insertions, 4 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 5d0ccf2e0..b9a8f77a8 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -35,6 +35,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "map.h" #include "util/string.h" #include "nodedef.h" +#include "client/keycode.h" #define checkCSMRestrictionFlag(flag) \ ( getClient(L)->checkCSMRestrictionFlag(CSMRestrictionFlags::flag) ) @@ -470,13 +471,31 @@ int ModApiClient::l_get_inventory(lua_State *L) inventory_location.deSerialize(location); inventory = client->getInventory(inventory_location); push_inventory(L, inventory); - } catch (SerializationError) { + } catch (SerializationError &) { lua_pushnil(L); } return 1; } +// set_keypress(key_setting, pressed) -> returns true on success +int ModApiClient::l_set_keypress(lua_State *L) +{ + std::string setting_name = "keymap_" + readParam<std::string>(L, 1); + bool pressed = lua_isboolean(L, 2) && readParam<bool>(L, 2); + try { + KeyPress keyCode = getKeySetting(setting_name.c_str()); + if (pressed) + g_game->input->setKeypress(keyCode); + else + g_game->input->unsetKeypress(keyCode); + lua_pushboolean(L, true); + } catch (SettingNotFoundException &) { + lua_pushboolean(L, false); + } + return 1; +} + void ModApiClient::Initialize(lua_State *L, int top) { API_FCT(get_current_modname); @@ -508,4 +527,5 @@ void ModApiClient::Initialize(lua_State *L, int top) API_FCT(place_node); API_FCT(dig_node); API_FCT(get_inventory); + API_FCT(set_keypress); } diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h index 21a540f8f..1ea57f9ee 100644 --- a/src/script/lua_api/l_client.h +++ b/src/script/lua_api/l_client.h @@ -116,6 +116,9 @@ private: // get_inventory(location) static int l_get_inventory(lua_State *L); + + // l_set_keypress(key_setting, pressed) + static int l_set_keypress(lua_State *L); public: static void Initialize(lua_State *L, int top); }; diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 2ea3b08b9..ee384ad10 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -1365,7 +1365,7 @@ int ModApiEnvMod::l_delete_area(lua_State *L) // max_jump, max_drop, algorithm) -> table containing path int ModApiEnvMod::l_find_path(lua_State *L) { - GET_ENV_PTR; + Environment *env = getEnv(L); v3s16 pos1 = read_v3s16(L, 1); v3s16 pos2 = read_v3s16(L, 2); @@ -1382,8 +1382,8 @@ int ModApiEnvMod::l_find_path(lua_State *L) if (algorithm == "Dijkstra") algo = PA_DIJKSTRA; } - - std::vector<v3s16> path = get_path(&env->getServerMap(), env->getGameDef()->ndef(), pos1, pos2, + + std::vector<v3s16> path = get_path(&env->getMap(), env->getGameDef()->ndef(), pos1, pos2, searchdistance, max_jump, max_drop, algo); if (!path.empty()) { @@ -1568,6 +1568,7 @@ void ModApiEnvMod::InitializeClient(lua_State *L, int top) API_FCT(find_nodes_near_under_air_except); API_FCT(find_nodes_in_area); API_FCT(find_nodes_in_area_under_air); + API_FCT(find_path); API_FCT(line_of_sight); API_FCT(raycast); } diff --git a/src/script/lua_api/l_localplayer.cpp b/src/script/lua_api/l_localplayer.cpp index 9d7db41ce..8e743c3ab 100644 --- a/src/script/lua_api/l_localplayer.cpp +++ b/src/script/lua_api/l_localplayer.cpp @@ -62,6 +62,38 @@ int LuaLocalPlayer::l_get_velocity(lua_State *L) return 1; } +int LuaLocalPlayer::l_set_velocity(lua_State *L) +{ + LocalPlayer *player = getobject(L, 1); + + v3f pos = checkFloatPos(L, 2); + player->setSpeed(pos); + + return 0; +} + +int LuaLocalPlayer::l_get_yaw(lua_State *L) +{ + LocalPlayer *player = getobject(L, 1); + + lua_pushinteger(L, player->getYaw()); + return 1; +} + +int LuaLocalPlayer::l_set_yaw(lua_State *L) +{ + LocalPlayer *player = getobject(L, 1); + + if (lua_isnumber(L, 2)) { + int yaw = lua_tonumber(L, 2); + player->setYaw(yaw); + g_game->cam_view.camera_yaw = yaw; + g_game->cam_view_target.camera_yaw = yaw; + } + + return 0; +} + int LuaLocalPlayer::l_get_hp(lua_State *L) { LocalPlayer *player = getobject(L, 1); @@ -480,6 +512,9 @@ void LuaLocalPlayer::Register(lua_State *L) const char LuaLocalPlayer::className[] = "LocalPlayer"; const luaL_Reg LuaLocalPlayer::methods[] = { luamethod(LuaLocalPlayer, get_velocity), + luamethod(LuaLocalPlayer, set_velocity), + luamethod(LuaLocalPlayer, get_yaw), + luamethod(LuaLocalPlayer, set_yaw), luamethod(LuaLocalPlayer, get_hp), luamethod(LuaLocalPlayer, get_name), luamethod(LuaLocalPlayer, get_wield_index), diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h index a5d1081c7..c59cef764 100644 --- a/src/script/lua_api/l_localplayer.h +++ b/src/script/lua_api/l_localplayer.h @@ -34,6 +34,15 @@ private: // get_velocity(self) static int l_get_velocity(lua_State *L); + + // set_velocity(self, vel) + static int l_set_velocity(lua_State *L); + + // get_yaw(self) + static int l_get_yaw(lua_State *L); + + // set_yaw(self, yaw) + static int l_set_yaw(lua_State *L); // get_hp(self) static int l_get_hp(lua_State *L); @@ -75,6 +84,8 @@ private: // get_pos(self) static int l_get_pos(lua_State *L); + + // set_pos(self, pos) static int l_set_pos(lua_State *L); // get_movement_acceleration(self) |