aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/common/chatcommands.lua76
-rw-r--r--doc/client_lua_api.txt10
-rw-r--r--src/gui/cheatMenu.cpp28
-rw-r--r--src/gui/cheatMenu.h14
-rw-r--r--src/script/cpp_api/s_cheats.cpp10
-rw-r--r--src/script/cpp_api/s_cheats.h5
-rw-r--r--src/script/lua_api/l_localplayer.h8
7 files changed, 80 insertions, 71 deletions
diff --git a/builtin/common/chatcommands.lua b/builtin/common/chatcommands.lua
index 3d04391fb..709c3d00a 100644
--- a/builtin/common/chatcommands.lua
+++ b/builtin/common/chatcommands.lua
@@ -29,47 +29,49 @@ function core.override_chatcommand(name, redefinition)
core.registered_chatcommands[name] = chatcommand
end
-function core.register_list_command(command, desc, setting)
- local def = {}
- def.description = desc
- def.params = "del <item> | add <item> | list"
- function def.func(param)
- local list = (minetest.settings:get(setting) or ""):split(",")
- if param == "list" then
- return true, table.concat(list, ", ")
- else
- local sparam = param:split(" ")
- local cmd = sparam[1]
- local item = sparam[2]
- if cmd == "del" then
- if not item then
- return false, "Missing item."
- end
- local i = table.indexof(list, item)
- if i == -1 then
- return false, item .. " is not on the list."
- else
- table.remove(list, i)
- core.settings:set(setting, table.concat(list, ","))
- return true, "Removed " .. item .. " from the list."
- end
- elseif cmd == "add" then
- if not item then
- return false, "Missing item."
- end
- local i = table.indexof(list, item)
- if i ~= -1 then
- return false, item .. " is already on the list."
- else
- table.insert(list, item)
- core.settings:set(setting, table.concat(list, ","))
- return true, "Added " .. item .. " to the list."
+if INIT == "client" then
+ function core.register_list_command(command, desc, setting)
+ local def = {}
+ def.description = desc
+ def.params = "del <item> | add <item> | list"
+ function def.func(param)
+ local list = (minetest.settings:get(setting) or ""):split(",")
+ if param == "list" then
+ return true, table.concat(list, ", ")
+ else
+ local sparam = param:split(" ")
+ local cmd = sparam[1]
+ local item = sparam[2]
+ if cmd == "del" then
+ if not item then
+ return false, "Missing item."
+ end
+ local i = table.indexof(list, item)
+ if i == -1 then
+ return false, item .. " is not on the list."
+ else
+ table.remove(list, i)
+ core.settings:set(setting, table.concat(list, ","))
+ return true, "Removed " .. item .. " from the list."
+ end
+ elseif cmd == "add" then
+ if not item then
+ return false, "Missing item."
+ end
+ local i = table.indexof(list, item)
+ if i ~= -1 then
+ return false, item .. " is already on the list."
+ else
+ table.insert(list, item)
+ core.settings:set(setting, table.concat(list, ","))
+ return true, "Added " .. item .. " to the list."
+ end
end
end
+ return false, "Invalid usage. (See /help " .. command .. ")"
end
- return false, "Invalid usage. (See /help " .. command .. ")"
+ core.register_chatcommand(command, def)
end
- core.register_chatcommand(command, def)
end
local cmd_marker = "/"
diff --git a/doc/client_lua_api.txt b/doc/client_lua_api.txt
index 15c0b8a6a..599ce0b83 100644
--- a/doc/client_lua_api.txt
+++ b/doc/client_lua_api.txt
@@ -674,9 +674,8 @@ Minetest namespace reference
### Global callback registration functions
Call these functions only at load time!
-* `minetest.open_special_inventory()`
+* `minetest.open_enderchest()`
* This function is called if the client uses the Keybind for it (by default "O")
- * It is used for a client provided inventory
* You can override it
* `minetest.register_globalstep(function(dtime))`
* Called every client environment step, usually interval of 0.1s
@@ -697,6 +696,13 @@ Call these functions only at load time!
* Adds definition to minetest.registered_chatcommands
* `minetest.unregister_chatcommand(name)`
* Unregisters a chatcommands registered with register_chatcommand.
+* `minetest.register_list_command(command, desc, setting)`
+ * Registers a chatcommand `command` to manage a list that takes the args `del | add | list <param>`
+ * The list is stored comma-seperated in `setting`
+ * `desc` is the description
+ * `add` adds something to the list
+ * `del` del removes something from the list
+ * `list` lists all items on the list
* `minetest.register_on_death(function())`
* Called when the local player dies
* `minetest.register_on_hp_modification(function(hp))`
diff --git a/src/gui/cheatMenu.cpp b/src/gui/cheatMenu.cpp
index b22b8da30..b103e6301 100644
--- a/src/gui/cheatMenu.cpp
+++ b/src/gui/cheatMenu.cpp
@@ -37,8 +37,8 @@ CheatMenu::CheatMenu(Client *client) : m_client(client)
m_fontsize.Y = MYMAX(m_fontsize.Y, 1);
}
-void CheatMenu::drawEntry(video::IVideoDriver* driver, std::string name, int number,
- bool selected, bool active, CheatMenuEntryType entry_type)
+void CheatMenu::drawEntry(video::IVideoDriver *driver, std::string name, int number,
+ bool selected, bool active, CheatMenuEntryType entry_type)
{
int x = m_gap, y = m_gap, width = m_entry_width, height = m_entry_height;
video::SColor *bgcolor = &m_bg_color, *fontcolor = &m_font_color;
@@ -49,7 +49,7 @@ void CheatMenu::drawEntry(video::IVideoDriver* driver, std::string name, int num
bool is_category = entry_type == CHEAT_MENU_ENTRY_TYPE_CATEGORY;
y += m_gap + m_head_height +
(number + (is_category ? 0 : m_selected_category)) *
- (m_entry_height + m_gap);
+ (m_entry_height + m_gap);
x += (is_category ? 0 : m_gap + m_entry_width);
if (active)
bgcolor = &m_active_bg_color;
@@ -70,7 +70,7 @@ void CheatMenu::drawEntry(video::IVideoDriver* driver, std::string name, int num
void CheatMenu::draw(video::IVideoDriver* driver, bool show_debug)
{
CHEAT_MENU_GET_SCRIPTPTR
-
+
if (!show_debug)
drawEntry(driver, "Dragonfireclient", 0, false, false,
CHEAT_MENU_ENTRY_TYPE_HEAD);
@@ -97,11 +97,11 @@ void CheatMenu::draw(video::IVideoDriver* driver, bool show_debug)
void CheatMenu::selectUp()
{
CHEAT_MENU_GET_SCRIPTPTR
-
+
int max = (m_cheat_layer ? script->m_cheat_categories[m_selected_category]
- ->m_cheats.size()
- : script->m_cheat_categories.size()) -
- 1;
+ ->m_cheats.size()
+ : script->m_cheat_categories.size()) -
+ 1;
int *selected = m_cheat_layer ? &m_selected_cheat : &m_selected_category;
--*selected;
if (*selected < 0)
@@ -111,11 +111,11 @@ void CheatMenu::selectUp()
void CheatMenu::selectDown()
{
CHEAT_MENU_GET_SCRIPTPTR
-
+
int max = (m_cheat_layer ? script->m_cheat_categories[m_selected_category]
- ->m_cheats.size()
- : script->m_cheat_categories.size()) -
- 1;
+ ->m_cheats.size()
+ : script->m_cheat_categories.size()) -
+ 1;
int *selected = m_cheat_layer ? &m_selected_cheat : &m_selected_category;
++*selected;
if (*selected > max)
@@ -140,8 +140,8 @@ void CheatMenu::selectLeft()
void CheatMenu::selectConfirm()
{
CHEAT_MENU_GET_SCRIPTPTR
-
+
if (m_cheat_layer)
script->toggle_cheat(script->m_cheat_categories[m_selected_category]
- ->m_cheats[m_selected_cheat]);
+ ->m_cheats[m_selected_cheat]);
}
diff --git a/src/gui/cheatMenu.h b/src/gui/cheatMenu.h
index de369485c..3c4bec471 100644
--- a/src/gui/cheatMenu.h
+++ b/src/gui/cheatMenu.h
@@ -22,9 +22,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irrlichttypes_extrabloated.h"
#include <string>
-#define CHEAT_MENU_GET_SCRIPTPTR \
- ClientScripting *script = m_client->getScript(); \
- if (! script || ! script->m_cheats_loaded) \
+#define CHEAT_MENU_GET_SCRIPTPTR \
+ ClientScripting *script = m_client->getScript(); \
+ if (! script || ! script->m_cheats_loaded) \
return;
class Client;
@@ -39,11 +39,11 @@ typedef enum
class CheatMenu
{
public:
- CheatMenu(Client* client);
+ CheatMenu(Client *client);
- void draw(video::IVideoDriver* driver, bool show_debug);
+ void draw(video::IVideoDriver *driver, bool show_debug);
- void drawEntry(video::IVideoDriver* driver, std::string name, int number,
+ void drawEntry(video::IVideoDriver *driver, std::string name, int number,
bool selected, bool active,
CheatMenuEntryType entry_type = CHEAT_MENU_ENTRY_TYPE_ENTRY);
@@ -66,7 +66,7 @@ private:
video::SColor m_bg_color = video::SColor(192, 255, 145, 88);
video::SColor m_active_bg_color = video::SColor(192, 255, 87, 53);
video::SColor m_font_color = video::SColor(255, 0, 0, 0);
- video::SColor m_selected_font_color = video::SColor(255, 255, 252, 88);
+ video::SColor m_selected_font_color = video::SColor(255, 255, 252, 88);
Client *m_client;
diff --git a/src/script/cpp_api/s_cheats.cpp b/src/script/cpp_api/s_cheats.cpp
index 4ad62f2fe..45b75ff6d 100644
--- a/src/script/cpp_api/s_cheats.cpp
+++ b/src/script/cpp_api/s_cheats.cpp
@@ -23,14 +23,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
ScriptApiCheatsCheat::ScriptApiCheatsCheat(
- const std::string &name, const std::string &setting) :
+ const std::string &name, const std::string &setting) :
m_name(name),
m_setting(setting), m_function_ref(0)
{
}
-ScriptApiCheatsCheat::ScriptApiCheatsCheat(const std::string &name, const int &function) :
+ScriptApiCheatsCheat::ScriptApiCheatsCheat(const std::string &name, const int &function) :
m_name(name), m_setting(""), m_function_ref(function)
{
}
@@ -53,8 +53,7 @@ void ScriptApiCheatsCheat::toggle(lua_State *L, int error_handler)
g_settings->setBool(m_setting, !is_enabled());
}
-ScriptApiCheatsCategory::ScriptApiCheatsCategory(const std::string &name) :
- m_name(name)
+ScriptApiCheatsCategory::ScriptApiCheatsCategory(const std::string &name) : m_name(name)
{
}
@@ -102,7 +101,8 @@ void ScriptApiCheats::init_cheats()
lua_pushnil(L);
while (lua_next(L, -2)) {
if (lua_istable(L, -1)) {
- ScriptApiCheatsCategory *category = new ScriptApiCheatsCategory(lua_tostring(L, -2));
+ ScriptApiCheatsCategory *category =
+ new ScriptApiCheatsCategory(lua_tostring(L, -2));
category->read_cheats(L);
m_cheat_categories.push_back(category);
}
diff --git a/src/script/cpp_api/s_cheats.h b/src/script/cpp_api/s_cheats.h
index a93768659..9b5ace3e7 100644
--- a/src/script/cpp_api/s_cheats.h
+++ b/src/script/cpp_api/s_cheats.h
@@ -31,6 +31,7 @@ public:
std::string m_name;
bool is_enabled();
void toggle(lua_State *L, int error_handler);
+
private:
std::string m_setting;
int m_function_ref;
@@ -43,7 +44,7 @@ public:
~ScriptApiCheatsCategory();
std::string m_name;
void read_cheats(lua_State *L);
- std::vector<ScriptApiCheatsCheat*> m_cheats;
+ std::vector<ScriptApiCheatsCheat *> m_cheats;
};
class ScriptApiCheats : virtual public ScriptApiBase
@@ -53,5 +54,5 @@ public:
void init_cheats();
void toggle_cheat(ScriptApiCheatsCheat *cheat);
bool m_cheats_loaded = false;
- std::vector<ScriptApiCheatsCategory*> m_cheat_categories;
+ std::vector<ScriptApiCheatsCategory *> m_cheat_categories;
};
diff --git a/src/script/lua_api/l_localplayer.h b/src/script/lua_api/l_localplayer.h
index c59cef764..f43eb2a4d 100644
--- a/src/script/lua_api/l_localplayer.h
+++ b/src/script/lua_api/l_localplayer.h
@@ -34,13 +34,13 @@ 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);
@@ -52,7 +52,7 @@ private:
// get_wield_index(self)
static int l_get_wield_index(lua_State *L);
-
+
// set_wield_index(self)
static int l_set_wield_index(lua_State *L);
@@ -84,7 +84,7 @@ private:
// get_pos(self)
static int l_get_pos(lua_State *L);
-
+
// set_pos(self, pos)
static int l_set_pos(lua_State *L);