aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-05-13 18:06:47 +0200
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-05-13 18:06:47 +0200
commitf3e741dad1311e0b4057b530386e246f921be52c (patch)
tree64581e3f0ddfa9d4740eed7b545fe3db87b8c126 /src/script/lua_api
parent96a37aed31cfb9c131e46eda80bdbe3d2289a546 (diff)
parent69c70dd319532f7860f211f4a527a902b0386e49 (diff)
downloaddragonfireclient-f3e741dad1311e0b4057b530386e246f921be52c.tar.xz
Merge branch 'master' of https://github.com/minetest/minetest
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_mainmenu.cpp117
-rw-r--r--src/script/lua_api/l_mainmenu.h2
-rw-r--r--src/script/lua_api/l_util.cpp24
-rw-r--r--src/script/lua_api/l_util.h3
4 files changed, 51 insertions, 95 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index 4d437b967..d88bf31c1 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -34,9 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serverlist.h"
#include "mapgen/mapgen.h"
#include "settings.h"
-
-#include <IFileArchive.h>
-#include <IFileSystem.h>
+#include "client/client.h"
#include "client/renderingengine.h"
#include "network/networkprotocol.h"
@@ -399,7 +397,8 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L)
GUIEngine* engine = getGuiEngine(L);
sanity_check(engine != NULL);
- GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(RenderingEngine::get_gui_env(),
+ GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(
+ engine->m_rendering_engine->get_gui_env(),
engine->m_parent,
-1,
engine->m_menumanager,
@@ -629,75 +628,9 @@ int ModApiMainMenu::l_extract_zip(lua_State *L)
std::string absolute_destination = fs::RemoveRelativePathComponents(destination);
if (ModApiMainMenu::mayModifyPath(absolute_destination)) {
+ auto rendering_engine = getGuiEngine(L)->m_rendering_engine;
fs::CreateAllDirs(absolute_destination);
-
- io::IFileSystem *fs = RenderingEngine::get_filesystem();
-
- if (!fs->addFileArchive(zipfile, false, false, io::EFAT_ZIP)) {
- lua_pushboolean(L,false);
- return 1;
- }
-
- sanity_check(fs->getFileArchiveCount() > 0);
-
- /**********************************************************************/
- /* WARNING this is not threadsafe!! */
- /**********************************************************************/
- io::IFileArchive* opened_zip =
- fs->getFileArchive(fs->getFileArchiveCount()-1);
-
- const io::IFileList* files_in_zip = opened_zip->getFileList();
-
- unsigned int number_of_files = files_in_zip->getFileCount();
-
- for (unsigned int i=0; i < number_of_files; i++) {
- std::string fullpath = destination;
- fullpath += DIR_DELIM;
- fullpath += files_in_zip->getFullFileName(i).c_str();
- std::string fullpath_dir = fs::RemoveLastPathComponent(fullpath);
-
- if (!files_in_zip->isDirectory(i)) {
- if (!fs::PathExists(fullpath_dir) && !fs::CreateAllDirs(fullpath_dir)) {
- fs->removeFileArchive(fs->getFileArchiveCount()-1);
- lua_pushboolean(L,false);
- return 1;
- }
-
- io::IReadFile* toread = opened_zip->createAndOpenFile(i);
-
- FILE *targetfile = fopen(fullpath.c_str(),"wb");
-
- if (targetfile == NULL) {
- fs->removeFileArchive(fs->getFileArchiveCount()-1);
- lua_pushboolean(L,false);
- return 1;
- }
-
- char read_buffer[1024];
- long total_read = 0;
-
- while (total_read < toread->getSize()) {
-
- unsigned int bytes_read =
- toread->read(read_buffer,sizeof(read_buffer));
- if ((bytes_read == 0 ) ||
- (fwrite(read_buffer, 1, bytes_read, targetfile) != bytes_read))
- {
- fclose(targetfile);
- fs->removeFileArchive(fs->getFileArchiveCount()-1);
- lua_pushboolean(L,false);
- return 1;
- }
- total_read += bytes_read;
- }
-
- fclose(targetfile);
- }
-
- }
-
- fs->removeFileArchive(fs->getFileArchiveCount()-1);
- lua_pushboolean(L,true);
+ lua_pushboolean(L, fs::extractZipFile(rendering_engine->get_filesystem(), zipfile, destination));
return 1;
}
@@ -716,24 +649,28 @@ int ModApiMainMenu::l_get_mainmenu_path(lua_State *L)
}
/******************************************************************************/
-bool ModApiMainMenu::mayModifyPath(const std::string &path)
+bool ModApiMainMenu::mayModifyPath(std::string path)
{
+ path = fs::RemoveRelativePathComponents(path);
+
if (fs::PathStartsWith(path, fs::TempPath()))
return true;
- if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "games")))
- return true;
+ std::string path_user = fs::RemoveRelativePathComponents(porting::path_user);
- if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "mods")))
+ if (fs::PathStartsWith(path, path_user + DIR_DELIM "client"))
return true;
-
- if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "clientmods")))
+ if (fs::PathStartsWith(path, path_user + DIR_DELIM "clientmods"))
return true;
-
- if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "textures")))
+ if (fs::PathStartsWith(path, path_user + DIR_DELIM "textures"))
return true;
-
- if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "worlds")))
+ if (fs::PathStartsWith(path, path_user + DIR_DELIM "games"))
+ return true;
+ if (fs::PathStartsWith(path, path_user + DIR_DELIM "mods"))
+ return true;
+ if (fs::PathStartsWith(path, path_user + DIR_DELIM "textures"))
+ return true;
+ if (fs::PathStartsWith(path, path_user + DIR_DELIM "worlds"))
return true;
if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_cache)))
@@ -763,7 +700,7 @@ int ModApiMainMenu::l_show_path_select_dialog(lua_State *L)
bool is_file_select = readParam<bool>(L, 3);
GUIFileSelectMenu* fileOpenMenu =
- new GUIFileSelectMenu(RenderingEngine::get_gui_env(),
+ new GUIFileSelectMenu(engine->m_rendering_engine->get_gui_env(),
engine->m_parent,
-1,
engine->m_menumanager,
@@ -859,15 +796,7 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L)
lua_pushnumber(L,RenderingEngine::getDisplayDensity());
lua_settable(L, top);
- lua_pushstring(L,"display_width");
- lua_pushnumber(L,RenderingEngine::getDisplaySize().X);
- lua_settable(L, top);
-
- lua_pushstring(L,"display_height");
- lua_pushnumber(L,RenderingEngine::getDisplaySize().Y);
- lua_settable(L, top);
-
- const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
+ const v2u32 &window_size = RenderingEngine::getWindowSize();
lua_pushstring(L,"window_width");
lua_pushnumber(L, window_size.X);
lua_settable(L, top);
@@ -875,6 +804,10 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L)
lua_pushstring(L,"window_height");
lua_pushnumber(L, window_size.Y);
lua_settable(L, top);
+
+ lua_pushstring(L, "render_info");
+ lua_pushstring(L, wide_to_utf8(RenderingEngine::get_video_driver()->getName()).c_str());
+ lua_settable(L, top);
return 1;
}
diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h
index 49ce7c251..33ac9e721 100644
--- a/src/script/lua_api/l_mainmenu.h
+++ b/src/script/lua_api/l_mainmenu.h
@@ -58,7 +58,7 @@ private:
* @param path path to check
* @return true if the path may be modified
*/
- static bool mayModifyPath(const std::string &path);
+ static bool mayModifyPath(std::string path);
//api calls
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index 60ae7871c..624828956 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "irrlichttypes_extrabloated.h"
#include "lua_api/l_util.h"
#include "lua_api/l_internal.h"
#include "lua_api/l_settings.h"
@@ -40,7 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "util/hex.h"
#include "util/sha1.h"
#include <algorithm>
-
+#include <cstdio>
// log([level,] text)
// Writes a line to the logger.
@@ -479,6 +480,23 @@ int ModApiUtil::l_sha1(lua_State *L)
return 1;
}
+// colorspec_to_colorstring(colorspec)
+int ModApiUtil::l_colorspec_to_colorstring(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+
+ video::SColor color(0);
+ if (read_color(L, 1, &color)) {
+ char colorstring[10];
+ snprintf(colorstring, 10, "#%02X%02X%02X%02X",
+ color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
+ lua_pushstring(L, colorstring);
+ return 1;
+ }
+
+ return 0;
+}
+
void ModApiUtil::Initialize(lua_State *L, int top)
{
API_FCT(log);
@@ -513,6 +531,7 @@ void ModApiUtil::Initialize(lua_State *L, int top)
API_FCT(get_version);
API_FCT(sha1);
+ API_FCT(colorspec_to_colorstring);
LuaSettings::create(L, g_settings, g_settings_path);
lua_setfield(L, top, "settings");
@@ -539,6 +558,7 @@ void ModApiUtil::InitializeClient(lua_State *L, int top)
API_FCT(get_version);
API_FCT(sha1);
+ API_FCT(colorspec_to_colorstring);
LuaSettings::create(L, g_settings, g_settings_path);
lua_setfield(L, top, "settings");
@@ -569,8 +589,8 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top)
API_FCT(get_version);
API_FCT(sha1);
+ API_FCT(colorspec_to_colorstring);
LuaSettings::create(L, g_settings, g_settings_path);
lua_setfield(L, top, "settings");
}
-
diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h
index dbdd62b99..6943a6afb 100644
--- a/src/script/lua_api/l_util.h
+++ b/src/script/lua_api/l_util.h
@@ -101,6 +101,9 @@ private:
// sha1(string, raw)
static int l_sha1(lua_State *L);
+ // colorspec_to_colorstring(colorspec)
+ static int l_colorspec_to_colorstring(lua_State *L);
+
public:
static void Initialize(lua_State *L, int top);
static void InitializeAsync(lua_State *L, int top);