From cbdcc3de38cfebb777e5bd504c3512155dafdf27 Mon Sep 17 00:00:00 2001 From: Brandon Date: Fri, 12 Jul 2013 21:39:49 -0500 Subject: [PATCH] Revert "Merge branch 'master' of https://github.com/minetest/minetest" This reverts commit 6388be305763c330ce9fd33e19ec8b8c9faf19bf, reversing changes made to 036095e237474770d38ccf04fd1a074ffb87bba2. --- README.txt | 2 +- builtin/builtin.lua | 32 +- builtin/chatcommands.lua | 6 - builtin/gamemgr.lua | 309 --- builtin/item.lua | 13 +- builtin/mainmenu.lua | 1327 ------------ builtin/mainmenu_helper.lua | 107 - builtin/mainmenu_worldlist.lua | 211 -- builtin/misc_helpers.lua | 10 - builtin/modmgr.lua | 883 -------- builtin/modstore.lua | 276 --- builtin/vector.lua | 141 -- builtin/voxelarea.lua | 41 - client/shaders/bumpmaps_liquids/base.txt | 1 - .../bumpmaps_liquids/opengl_fragment.glsl | 47 - .../bumpmaps_liquids/opengl_vertex.glsl | 98 - client/shaders/bumpmaps_solids/base.txt | 1 - .../bumpmaps_solids/opengl_fragment.glsl | 46 - .../bumpmaps_solids/opengl_vertex.glsl | 98 - doc/lua_api.txt | 128 +- doc/menu_lua_api.txt | 163 -- minetest.conf.example | 15 +- po/da/minetest.po | 120 +- po/de/minetest.po | 128 +- po/du/minetest.po | 116 +- po/es/minetest.po | 115 +- po/et/minetest.po | 114 +- po/fr/minetest.po | 124 +- po/hu/minetest.po | 96 +- po/it/minetest.po | 121 +- po/ja/minetest.po | 114 +- po/ko/minetest.po | 96 +- po/ky/minetest.po | 97 +- po/minetest.pot | 96 +- po/nb/minetest.po | 114 +- po/nl/minetest.po | 116 +- po/pl/minetest.po | 114 +- po/pt/minetest.po | 115 +- po/pt_BR/minetest.po | 115 +- po/ro/minetest.po | 96 +- po/ru/minetest.po | 116 +- po/uk/minetest.po | 100 +- po/zh_CN/minetest.po | 115 +- src/CMakeLists.txt | 9 +- src/biome.cpp | 67 +- src/biome.h | 16 +- src/cavegen.cpp | 36 +- src/cavegen.h | 3 - src/client.cpp | 47 +- src/collision.cpp | 34 +- src/connection.cpp | 3 +- src/content_abm.cpp | 9 +- src/content_cao.cpp | 27 +- src/content_cso.cpp | 2 +- src/content_mapblock.cpp | 170 +- src/convert_json.cpp | 367 ---- src/defaultsettings.cpp | 24 +- src/environment.cpp | 2 +- src/farmesh.cpp | 2 +- src/filesys.cpp | 267 +-- src/filesys.h | 33 +- src/game.cpp | 88 +- src/guiConfigureWorld.cpp | 693 +++++++ src/guiConfigureWorld.h | 107 + src/guiConfirmMenu.cpp | 204 ++ src/{convert_json.h => guiConfirmMenu.h} | 42 +- src/guiCreateWorld.cpp | 280 +++ src/guiCreateWorld.h | 64 + src/guiEngine.cpp | 573 ------ src/guiEngine.h | 260 --- src/guiFileSelectMenu.cpp | 133 -- src/guiFileSelectMenu.h | 80 - src/guiFormSpecMenu.cpp | 1801 ++--------------- src/guiFormSpecMenu.h | 138 +- src/guiLuaApi.cpp | 1068 ---------- src/guiLuaApi.h | 183 -- src/guiMainMenu.cpp | 1521 ++++++++++++++ src/guiMainMenu.h | 111 +- src/hud.cpp | 6 +- src/itemdef.cpp | 68 +- src/main.cpp | 466 ++++- src/map.cpp | 32 +- src/mapblock_mesh.cpp | 144 +- src/mapgen.cpp | 157 +- src/mapgen.h | 12 +- src/mapgen_math.cpp | 11 +- src/mapgen_math.h | 2 +- src/mapgen_v7.cpp | 429 ++-- src/mapgen_v7.h | 41 +- src/mapnode.cpp | 27 - src/mapnode.h | 13 - src/mesh.cpp | 91 +- src/mesh.h | 16 + src/mods.cpp | 28 - src/mods.h | 68 - src/nodedef.cpp | 19 +- src/nodedef.h | 1 + src/particles.cpp | 60 +- src/particles.h | 15 +- src/script/common/c_converter.cpp | 6 +- src/script/lua_api/l_env.cpp | 2 +- src/script/lua_api/l_vmanip.cpp | 46 +- src/script/lua_api/l_vmanip.h | 4 +- src/script/lua_api/luaapi.cpp | 60 +- src/script/lua_api/luaapi.h | 3 +- src/server.cpp | 11 +- src/serverlist.cpp | 84 +- src/serverlist.h | 3 +- src/shader.cpp | 37 +- src/test.cpp | 212 -- src/tile.cpp | 698 +++++-- src/tile.h | 127 +- src/util/numeric.cpp | 1 - src/util/string.h | 2 +- textures/base/pack/no_screenshot.png | Bin 2446 -> 0 bytes util/generate-texture-normals.sh | 255 --- util/master/list.js | 19 +- util/master/master.cgi | 62 +- util/master/style.css | 20 +- 119 files changed, 6209 insertions(+), 11906 deletions(-) delete mode 100644 builtin/gamemgr.lua delete mode 100644 builtin/mainmenu.lua delete mode 100644 builtin/mainmenu_helper.lua delete mode 100644 builtin/mainmenu_worldlist.lua delete mode 100644 builtin/modmgr.lua delete mode 100644 builtin/modstore.lua delete mode 100644 builtin/vector.lua delete mode 100644 client/shaders/bumpmaps_liquids/base.txt delete mode 100644 client/shaders/bumpmaps_liquids/opengl_fragment.glsl delete mode 100644 client/shaders/bumpmaps_liquids/opengl_vertex.glsl delete mode 100644 client/shaders/bumpmaps_solids/base.txt delete mode 100644 client/shaders/bumpmaps_solids/opengl_fragment.glsl delete mode 100644 client/shaders/bumpmaps_solids/opengl_vertex.glsl delete mode 100644 doc/menu_lua_api.txt delete mode 100644 src/convert_json.cpp create mode 100644 src/guiConfigureWorld.cpp create mode 100644 src/guiConfigureWorld.h create mode 100644 src/guiConfirmMenu.cpp rename src/{convert_json.h => guiConfirmMenu.h} (52%) create mode 100644 src/guiCreateWorld.cpp create mode 100644 src/guiCreateWorld.h delete mode 100644 src/guiEngine.cpp delete mode 100644 src/guiEngine.h delete mode 100644 src/guiFileSelectMenu.cpp delete mode 100644 src/guiFileSelectMenu.h delete mode 100644 src/guiLuaApi.cpp delete mode 100644 src/guiLuaApi.h create mode 100644 src/guiMainMenu.cpp delete mode 100644 textures/base/pack/no_screenshot.png delete mode 100755 util/generate-texture-normals.sh diff --git a/README.txt b/README.txt index 9e8e11b30..43b31d70f 100644 --- a/README.txt +++ b/README.txt @@ -16,7 +16,7 @@ See the README.txt in it. Further documentation ---------------------- - Website: http://minetest.net/ -- Wiki: http://wiki.minetest.net/ +- Wiki: http://wiki.minetest.com/ - Developer wiki: http://dev.minetest.net/ - Forum: http://forum.minetest.net/ - Github: https://github.com/minetest/minetest/ diff --git a/builtin/builtin.lua b/builtin/builtin.lua index 34477e6aa..d573cba90 100644 --- a/builtin/builtin.lua +++ b/builtin/builtin.lua @@ -11,20 +11,18 @@ math.randomseed(os.time()) os.setlocale("C", "numeric") -- Load other files -local modpath = minetest.get_modpath("__builtin") -dofile(modpath.."/serialize.lua") -dofile(modpath.."/misc_helpers.lua") -dofile(modpath.."/item.lua") -dofile(modpath.."/misc_register.lua") -dofile(modpath.."/item_entity.lua") -dofile(modpath.."/deprecated.lua") -dofile(modpath.."/misc.lua") -dofile(modpath.."/privileges.lua") -dofile(modpath.."/auth.lua") -dofile(modpath.."/chatcommands.lua") -dofile(modpath.."/static_spawn.lua") -dofile(modpath.."/detached_inventory.lua") -dofile(modpath.."/falling.lua") -dofile(modpath.."/features.lua") -dofile(modpath.."/voxelarea.lua") -dofile(modpath.."/vector.lua") +dofile(minetest.get_modpath("__builtin").."/serialize.lua") +dofile(minetest.get_modpath("__builtin").."/misc_helpers.lua") +dofile(minetest.get_modpath("__builtin").."/item.lua") +dofile(minetest.get_modpath("__builtin").."/misc_register.lua") +dofile(minetest.get_modpath("__builtin").."/item_entity.lua") +dofile(minetest.get_modpath("__builtin").."/deprecated.lua") +dofile(minetest.get_modpath("__builtin").."/misc.lua") +dofile(minetest.get_modpath("__builtin").."/privileges.lua") +dofile(minetest.get_modpath("__builtin").."/auth.lua") +dofile(minetest.get_modpath("__builtin").."/chatcommands.lua") +dofile(minetest.get_modpath("__builtin").."/static_spawn.lua") +dofile(minetest.get_modpath("__builtin").."/detached_inventory.lua") +dofile(minetest.get_modpath("__builtin").."/falling.lua") +dofile(minetest.get_modpath("__builtin").."/features.lua") +dofile(minetest.get_modpath("__builtin").."/voxelarea.lua") diff --git a/builtin/chatcommands.lua b/builtin/chatcommands.lua index 7d1c2b62a..6a3b29e7c 100644 --- a/builtin/chatcommands.lua +++ b/builtin/chatcommands.lua @@ -272,9 +272,6 @@ minetest.register_chatcommand("teleport", { local teleportee = nil local p = {} p.x, p.y, p.z = string.match(param, "^([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$") - p.x = tonumber(p.x) - p.y = tonumber(p.y) - p.z = tonumber(p.z) teleportee = minetest.get_player_by_name(name) if teleportee and p.x and p.y and p.z then minetest.chat_send_player(name, "Teleporting to ("..p.x..", "..p.y..", "..p.z..")") @@ -305,9 +302,6 @@ minetest.register_chatcommand("teleport", { local p = {} local teleportee_name = nil teleportee_name, p.x, p.y, p.z = string.match(param, "^([^ ]+) +([%d.-]+)[, ] *([%d.-]+)[, ] *([%d.-]+)$") - p.x = tonumber(p.x) - p.y = tonumber(p.y) - p.z = tonumber(p.z) if teleportee_name then teleportee = minetest.get_player_by_name(teleportee_name) end diff --git a/builtin/gamemgr.lua b/builtin/gamemgr.lua deleted file mode 100644 index bbff51305..000000000 --- a/builtin/gamemgr.lua +++ /dev/null @@ -1,309 +0,0 @@ ---Minetest ---Copyright (C) 2013 sapier --- ---This program is free software; you can redistribute it and/or modify ---it under the terms of the GNU Lesser General Public License as published by ---the Free Software Foundation; either version 2.1 of the License, or ---(at your option) any later version. --- ---This program is distributed in the hope that it will be useful, ---but WITHOUT ANY WARRANTY; without even the implied warranty of ---MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ---GNU Lesser General Public License for more details. --- ---You should have received a copy of the GNU Lesser General Public License along ---with this program; if not, write to the Free Software Foundation, Inc., ---51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -gamemgr = {} - --------------------------------------------------------------------------------- -function gamemgr.dialog_new_game() - local retval = - "label[2,2;Game Name]".. - "field[4.5,2.4;6,0.5;te_game_name;;]" .. - "button[5,4.2;2.6,0.5;new_game_confirm;Create]" .. - "button[7.5,4.2;2.8,0.5;new_game_cancel;Cancel]" - - return retval -end - --------------------------------------------------------------------------------- -function gamemgr.handle_games_buttons(fields) - if fields["gamelist"] ~= nil then - local event = explode_textlist_event(fields["gamelist"]) - gamemgr.selected_game = event.index - end - - if fields["btn_game_mgr_edit_game"] ~= nil then - return { - is_dialog = true, - show_buttons = false, - current_tab = "dialog_edit_game" - } - end - - if fields["btn_game_mgr_new_game"] ~= nil then - return { - is_dialog = true, - show_buttons = false, - current_tab = "dialog_new_game" - } - end - - return nil -end - --------------------------------------------------------------------------------- -function gamemgr.handle_new_game_buttons(fields) - - if fields["new_game_confirm"] and - fields["te_game_name"] ~= nil and - fields["te_game_name"] ~= "" then - local gamepath = engine.get_gamepath() - - if gamepath ~= nil and - gamepath ~= "" then - local gamefolder = cleanup_path(fields["te_game_name"]) - - --TODO check for already existing first - engine.create_dir(gamepath .. DIR_DELIM .. gamefolder) - engine.create_dir(gamepath .. DIR_DELIM .. gamefolder .. DIR_DELIM .. "mods") - engine.create_dir(gamepath .. DIR_DELIM .. gamefolder .. DIR_DELIM .. "menu") - - local gameconf = - io.open(gamepath .. DIR_DELIM .. gamefolder .. DIR_DELIM .. "game.conf","w") - - if gameconf then - gameconf:write("name = " .. fields["te_game_name"]) - gameconf:close() - end - end - end - - return { - is_dialog = false, - show_buttons = true, - current_tab = engine.setting_get("main_menu_tab") - } -end - --------------------------------------------------------------------------------- -function gamemgr.handle_edit_game_buttons(fields) - local current_game = gamemgr.get_game(gamemgr.selected_game) - - if fields["btn_close_edit_game"] ~= nil or - current_game == nil then - return { - is_dialog = false, - show_buttons = true, - current_tab = engine.setting_get("main_menu_tab") - } - end - - if fields["btn_remove_mod_from_game"] ~= nil then - gamemgr.delete_mod(current_game,engine.get_textlist_index("mods_current")) - end - - if fields["btn_add_mod_to_game"] ~= nil then - local modindex = engine.get_textlist_index("mods_available") - - if modindex > 0 and - modindex <= #modmgr.global_mods then - - local sourcepath = - engine.get_modpath() .. DIR_DELIM .. modmgr.global_mods[modindex] - - gamemgr.add_mod(current_game,sourcepath) - end - end - - return nil -end - --------------------------------------------------------------------------------- -function gamemgr.add_mod(gamespec,sourcepath) - if gamespec.gamemods_path ~= nil and - gamespec.gamemods_path ~= "" then - - local modname = get_last_folder(sourcepath) - - engine.copy_dir(sourcepath,gamespec.gamemods_path .. DIR_DELIM .. modname); - end -end - --------------------------------------------------------------------------------- -function gamemgr.delete_mod(gamespec,modindex) - if gamespec.gamemods_path ~= nil and - gamespec.gamemods_path ~= "" then - local game_mods = {} - get_mods(gamespec.gamemods_path,game_mods) - - if modindex > 0 and - #game_mods >= modindex then - - local modname = game_mods[modindex] - - if modname:find("") ~= nil then - modname = modname:sub(0,modname:find("<") -2) - end - - local modpath = gamespec.gamemods_path .. DIR_DELIM .. modname - if modpath:sub(0,gamespec.gamemods_path:len()) == gamespec.gamemods_path then - engine.delete_dir(modpath) - end - end - end -end - --------------------------------------------------------------------------------- -function gamemgr.get_game_mods(gamespec) - - local retval = "" - - if gamespec.gamemods_path ~= nil and - gamespec.gamemods_path ~= "" then - local game_mods = {} - get_mods(gamespec.gamemods_path,game_mods) - - for i=1,#game_mods,1 do - if retval ~= "" then - retval = retval.."," - end - retval = retval .. game_mods[i] - end - end - return retval -end - --------------------------------------------------------------------------------- -function gamemgr.gettab(name) - local retval = "" - - if name == "dialog_edit_game" then - retval = retval .. gamemgr.dialog_edit_game() - end - - if name == "dialog_new_game" then - retval = retval .. gamemgr.dialog_new_game() - end - - if name == "game_mgr" then - retval = retval .. gamemgr.tab() - end - - return retval -end - --------------------------------------------------------------------------------- -function gamemgr.tab() - if gamemgr.selected_game == nil then - gamemgr.selected_game = 1 - end - - local retval = - "vertlabel[0,-0.25;GAMES]" .. - "label[1,-0.25;Games:]" .. - "textlist[1,0.25;4.5,4.4;gamelist;" .. - gamemgr.gamelist() .. - ";" .. gamemgr.selected_game .. "]" - - local current_game = gamemgr.get_game(gamemgr.selected_game) - - if current_game ~= nil then - if current_game.menuicon_path ~= nil and - current_game.menuicon_path ~= "" then - retval = retval .. - "image[5.8,-0.25;2,2;" .. current_game.menuicon_path .. "]" - end - - retval = retval .. - "field[8,-0.25;6,2;;" .. current_game.name .. ";]".. - "label[6,1.4;Mods:]" .. - "button[9.7,1.5;2,0.2;btn_game_mgr_edit_game;edit game]" .. - "textlist[6,2;5.5,3.3;game_mgr_modlist;" - .. gamemgr.get_game_mods(current_game) ..";0]" .. - "button[1,4.75;3.2,0.5;btn_game_mgr_new_game;new game]" - end - return retval -end - --------------------------------------------------------------------------------- -function gamemgr.dialog_edit_game() - local current_game = gamemgr.get_game(gamemgr.selected_game) - if current_game ~= nil then - local retval = - "vertlabel[0,-0.25;EDIT GAME]" .. - "label[0,-0.25;" .. current_game.name .. "]" .. - "button[11.55,-0.2;0.75,0.5;btn_close_edit_game;x]" - - if current_game.menuicon_path ~= nil and - current_game.menuicon_path ~= "" then - retval = retval .. - "image[5.25,0;2,2;" .. current_game.menuicon_path .. "]" - end - - retval = retval .. - "textlist[0.5,0.5;4.5,4.3;mods_current;" - .. gamemgr.get_game_mods(current_game) ..";0]" - - - retval = retval .. - "textlist[7,0.5;4.5,4.3;mods_available;" - .. modmgr.get_mods_list() .. ";0]" - - retval = retval .. - "button[0.55,4.95;4.7,0.5;btn_remove_mod_from_game;Remove selected mod]" - - retval = retval .. - "button[7.05,4.95;4.7,0.5;btn_add_mod_to_game;<<-- Add mod]" - - return retval - end -end - --------------------------------------------------------------------------------- -function gamemgr.handle_buttons(tab,fields) - local retval = nil - - if tab == "dialog_edit_game" then - retval = gamemgr.handle_edit_game_buttons(fields) - end - - if tab == "dialog_new_game" then - retval = gamemgr.handle_new_game_buttons(fields) - end - - if tab == "game_mgr" then - retval = gamemgr.handle_games_buttons(fields) - end - - return retval -end - --------------------------------------------------------------------------------- -function gamemgr.get_game(index) - if index > 0 and index <= #gamemgr.games then - return gamemgr.games[index] - end - - return nil -end - --------------------------------------------------------------------------------- -function gamemgr.update_gamelist() - gamemgr.games = engine.get_games() -end - --------------------------------------------------------------------------------- -function gamemgr.gamelist() - local retval = "" - if #gamemgr.games > 0 then - retval = retval .. gamemgr.games[1].id - - for i=2,#gamemgr.games,1 do - retval = retval .. "," .. gamemgr.games[i].name - end - end - return retval -end diff --git a/builtin/item.lua b/builtin/item.lua index b8381515a..85b4cc0e4 100644 --- a/builtin/item.lua +++ b/builtin/item.lua @@ -311,9 +311,12 @@ function minetest.handle_node_drops(pos, drops, digger) end function minetest.node_dig(pos, node, digger) + minetest.debug("node_dig") + local def = ItemStack({name=node.name}):get_definition() -- Check if def ~= 0 because we always want to be able to remove unknown nodes if #def ~= 0 and not def.diggable or (def.can_dig and not def.can_dig(pos,digger)) then + minetest.debug("not diggable") minetest.log("info", digger:get_player_name() .. " tried to dig " .. node.name .. " which is not diggable " .. minetest.pos_to_string(pos)) @@ -327,12 +330,10 @@ function minetest.node_dig(pos, node, digger) local drops = minetest.get_node_drops(node.name, wielded:get_name()) -- Wear out tool - if not minetest.setting_getbool("creative_mode") then - local tp = wielded:get_tool_capabilities() - local dp = minetest.get_dig_params(def.groups, tp) - wielded:add_wear(dp.wear) - digger:set_wielded_item(wielded) - end + local tp = wielded:get_tool_capabilities() + local dp = minetest.get_dig_params(def.groups, tp) + wielded:add_wear(dp.wear) + digger:set_wielded_item(wielded) -- Handle drops minetest.handle_node_drops(pos, drops, digger) diff --git a/builtin/mainmenu.lua b/builtin/mainmenu.lua deleted file mode 100644 index c8b0e4b87..000000000 --- a/builtin/mainmenu.lua +++ /dev/null @@ -1,1327 +0,0 @@ -os.setlocale("C", "numeric") - -local scriptpath = engine.get_scriptdir() - -dofile(scriptpath .. DIR_DELIM .. "mainmenu_worldlist.lua") -dofile(scriptpath .. DIR_DELIM .. "modmgr.lua") -dofile(scriptpath .. DIR_DELIM .. "modstore.lua") -dofile(scriptpath .. DIR_DELIM .. "gamemgr.lua") - -local menu = {} -local tabbuilder = {} -local menubar = {} - --------------------------------------------------------------------------------- -function render_favourite(spec,render_details) - local text = "" - - if spec.name ~= nil then - text = text .. fs_escape_string(spec.name:trim()) - --- if spec.description ~= nil and --- fs_escape_string(spec.description):trim() ~= "" then --- text = text .. " (" .. fs_escape_string(spec.description) .. ")" --- end - else - if spec.address ~= nil then - text = text .. spec.address:trim() - end - end - - if not render_details then - return text - end - - local details = "" - if spec.password == true then - details = details .. "*" - else - details = details .. "_" - end - - if spec.creative then - details = details .. "C" - else - details = details .. "_" - end - - if spec.damage then - details = details .. "D" - else - details = details .. "_" - end - - if spec.pvp then - details = details .. "P" - else - details = details .. "_" - end - details = details .. " " - - return fs_escape_string(details) .. text -end - --------------------------------------------------------------------------------- -os.tempfolder = function() - local filetocheck = os.tmpname() - os.remove(filetocheck) - - local randname = "MTTempModFolder_" .. math.random(0,10000) - if DIR_DELIM == "\\" then - local tempfolder = os.getenv("TEMP") - return tempfolder .. filetocheck - else - local backstring = filetocheck:reverse() - return filetocheck:sub(0,filetocheck:len()-backstring:find(DIR_DELIM)+1) ..randname - end - -end - --------------------------------------------------------------------------------- -function cleanup_path(temppath) - - local parts = temppath:split("-") - temppath = "" - for i=1,#parts,1 do - if temppath ~= "" then - temppath = temppath .. "_" - end - temppath = temppath .. parts[i] - end - - parts = temppath:split(".") - temppath = "" - for i=1,#parts,1 do - if temppath ~= "" then - temppath = temppath .. "_" - end - temppath = temppath .. parts[i] - end - - parts = temppath:split("'") - temppath = "" - for i=1,#parts,1 do - if temppath ~= "" then - temppath = temppath .. "" - end - temppath = temppath .. parts[i] - end - - parts = temppath:split(" ") - temppath = "" - for i=1,#parts,1 do - if temppath ~= "" then - temppath = temppath - end - temppath = temppath .. parts[i] - end - - return temppath -end - --------------------------------------------------------------------------------- - -function menu.set_texture(identifier,gamedetails) - local texture_set = false - if menu.texturepack ~= nil and gamedetails ~= nil then - local path = menu.basetexturedir .. - gamedetails.id .. "_menu_" .. identifier .. ".png" - - if engine.set_background(identifier,path) then - texture_set = true - end - end - - if not texture_set and gamedetails ~= nil then - local path = gamedetails.path .. DIR_DELIM .."menu" .. - DIR_DELIM .. identifier .. ".png" - if engine.set_background(identifier,path) then - texture_set = true - end - end - - if not texture_set then - local path = menu.basetexturedir .. DIR_DELIM .."menu_" .. - identifier .. ".png" - if engine.set_background(identifier,path) then - texture_set = true - end - end - - if not texture_set then - local path = menu.defaulttexturedir .. DIR_DELIM .."menu_" .. - identifier .. ".png" - engine.set_background(identifier,path) - end -end - --------------------------------------------------------------------------------- -function menu.update_gametype() - - - - if (menu.game_last_check == nil or - menu.game_last_check ~= menu.last_game) and - tabbuilder.current_tab == "singleplayer" then - - local gamedetails = menu.lastgame() - engine.set_topleft_text(gamedetails.name) - worldlist.set_gamefilter(gamedetails.id) - - --background - local background_set = false - if menu.texturepack ~= nil then - local path_background_texture = menu.basetexturedir .. - gamedetails.id .. "_menu_background.png" - - if engine.set_background("background",path_background_texture) then - background_set = true - engine.set_clouds(false) - end - end - - if not background_set then - local path_background_texture = gamedetails.path .. DIR_DELIM .."menu" .. - DIR_DELIM .. "background.png" - if engine.set_background("background",path_background_texture) then - background_set = true - engine.set_clouds(false) - end - end - - if not background_set then - engine.set_clouds(true) - end - - menu.set_texture("overlay",gamedetails) - menu.set_texture("header",gamedetails) - menu.set_texture("footer",gamedetails) - - menu.game_last_check = menu.last_game - else - if menu.game_last_check ~= menu.last_game then - menu.game_last_check = menu.last_game - menu.reset_gametype() - end - end -end - --------------------------------------------------------------------------------- -function menu.reset_gametype() - worldlist.set_gamefilter(nil) - menu.game_last_check = nil - - local path_background_texture = menu.basetexturedir .. "menu_background.png" - - if engine.set_background("background",path_background_texture) then - background_set = true - engine.set_clouds(false) - else - engine.set_clouds(true) - end - - menu.set_texture("overlay",nil) - menu.set_texture("header",nil) - menu.set_texture("footer",nil) - engine.set_topleft_text("") -end - --------------------------------------------------------------------------------- -function get_last_folder(text,count) - local parts = text:split(DIR_DELIM) - - if count == nil then - return parts[#parts] - end - - local retval = "" - for i=1,count,1 do - retval = retval .. parts[#parts - (count-i)] .. DIR_DELIM - end - - return retval -end - --------------------------------------------------------------------------------- -function init_globals() - --init gamedata - gamedata.worldindex = 0 -end - --------------------------------------------------------------------------------- -function identify_filetype(name) - - if name:sub(-3):lower() == "zip" then - return { - name = name, - type = "zip" - } - end - - if name:sub(-6):lower() == "tar.gz" or - name:sub(-3):lower() == "tgz"then - return { - name = name, - type = "tgz" - } - end - - if name:sub(-6):lower() == "tar.bz2" then - return { - name = name, - type = "tbz" - } - end - - if name:sub(-2):lower() == "7z" then - return { - name = name, - type = "7z" - } - end - - return { - name = name, - type = "ukn" - } -end - --------------------------------------------------------------------------------- -function update_menu() - - local formspec = "size[12,5.2]" - - -- handle errors - if gamedata.errormessage ~= nil then - formspec = formspec .. - "field[1,2;10,2;;ERROR: " .. - gamedata.errormessage .. - ";]".. - "button[4.5,4.2;3,0.5;btn_error_confirm;Ok]" - else - formspec = formspec .. tabbuilder.gettab() - end - - engine.update_formspec(formspec) -end - --------------------------------------------------------------------------------- -function menu.render_world_list() - local retval = "" - - local current_worldlist = worldlist.get_list() - - for i,v in ipairs(current_worldlist) do - if retval ~= "" then - retval = retval .."," - end - - retval = retval .. v.name .. - " \\[" .. v.gameid .. "\\]" - end - - return retval -end - --------------------------------------------------------------------------------- -function menu.init() - --init menu data - gamemgr.update_gamelist() - - menu.last_game = tonumber(engine.setting_get("main_menu_last_game_idx")) - - if type(menu.last_game) ~= "number" then - menu.last_game = 1 - end - - if engine.setting_getbool("public_serverlist") then - menu.favorites = engine.get_favorites("online") - else - menu.favorites = engine.get_favorites("local") - end - - - menu.defaulttexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." .. - DIR_DELIM .. "textures" .. DIR_DELIM .. "base" .. - DIR_DELIM .. "pack" .. DIR_DELIM - menu.basetexturedir = menu.defaulttexturedir - - menu.texturepack = engine.setting_get("texture_path") - - if menu.texturepack ~= nil then - menu.basetexturedir = menu.texturepack .. DIR_DELIM - end -end - --------------------------------------------------------------------------------- -function menu.lastgame() - if menu.last_game > 0 and menu.last_game <= #gamemgr.games then - return gamemgr.games[menu.last_game] - end - - if #gamemgr.games >= 1 then - menu.last_game = 1 - return gamemgr.games[menu.last_game] - end - - --error case!! - return nil -end - --------------------------------------------------------------------------------- -function menu.update_last_game() - - local current_world = worldlist.get_raw_world( - engine.setting_get("mainmenu_last_selected_world") - ) - - if current_world == nil then - return - end - - for i=1,#gamemgr.games,1 do - if gamemgr.games[i].id == current_world.gameid then - menu.last_game = i - engine.setting_set("main_menu_last_game_idx",menu.last_game) - break - end - end -end - --------------------------------------------------------------------------------- -function menu.handle_key_up_down(fields,textlist,settingname) - - if fields["key_up"] then - local oldidx = engine.get_textlist_index(textlist) - - if oldidx > 1 then - local newidx = oldidx -1 - engine.setting_set(settingname, - worldlist.get_engine_index(newidx)) - end - end - - if fields["key_down"] then - local oldidx = engine.get_textlist_index(textlist) - - if oldidx < worldlist.size() then - local newidx = oldidx + 1 - engine.setting_set(settingname, - worldlist.get_engine_index(newidx)) - end - end -end - - --------------------------------------------------------------------------------- -function menubar.handle_buttons(fields) - for i=1,#menubar.buttons,1 do - if fields[menubar.buttons[i].btn_name] ~= nil then - menu.last_game = menubar.buttons[i].index - engine.setting_set("main_menu_last_game_idx",menu.last_game) - menu.update_gametype() - end - end -end - --------------------------------------------------------------------------------- -function menubar.refresh() - menubar.formspec = "box[-0.3,5.625;12.4,1.3;000000]" .. - "box[-0.3,5.6;12.4,0.05;FFFFFF]" - menubar.buttons = {} - - local button_base = -0.25 - - local maxbuttons = #gamemgr.games - - if maxbuttons > 10 then - maxbuttons = 10 - end - - for i=1,maxbuttons,1 do - - local btn_name = "menubar_btn_" .. gamemgr.games[i].id - local buttonpos = button_base + (i-1) * 1.245 - if gamemgr.games[i].menuicon_path ~= nil and - gamemgr.games[i].menuicon_path ~= "" then - - menubar.formspec = menubar.formspec .. - "image_button[" .. buttonpos .. ",5.7;1.3,1.3;" .. - gamemgr.games[i].menuicon_path .. ";" .. btn_name .. ";;true;false]" - else - - local part1 = gamemgr.games[i].id:sub(1,5) - local part2 = gamemgr.games[i].id:sub(6,10) - local part3 = gamemgr.games[i].id:sub(11) - - local text = part1 .. "\n" .. part2 - if part3 ~= nil and - part3 ~= "" then - text = text .. "\n" .. part3 - end - menubar.formspec = menubar.formspec .. - "image_button[" .. buttonpos .. ",5.7;1.3,1.3;;" ..btn_name .. - ";" .. text .. ";true;true]" - end - - local toadd = { - btn_name = btn_name, - index = i, - } - - table.insert(menubar.buttons,toadd) - end -end - --------------------------------------------------------------------------------- -function tabbuilder.dialog_create_world() - local mapgens = {"v6", "v7", "indev", "singlenode", "math"} - - local current_mg = engine.setting_get("mg_name") - - local mglist = "" - local selindex = 1 - local i = 1 - for k,v in pairs(mapgens) do - if current_mg == v then - selindex = i - end - i = i + 1 - mglist = mglist .. v .. "," - end - mglist = mglist:sub(1, -2) - - local retval = - "label[2,0;World name]".. - "label[2,1;Mapgen]".. - "field[4.5,0.4;6,0.5;te_world_name;;]" .. - "label[2,2;Game]".. - "button[5,4.5;2.6,0.5;world_create_confirm;Create]" .. - "button[7.5,4.5;2.8,0.5;world_create_cancel;Cancel]" .. - "dropdown[4.2,1;6.3;dd_mapgen;" .. mglist .. ";" .. selindex .. "]" .. - "textlist[4.2,1.9;5.8,2.3;games;" .. - gamemgr.gamelist() .. - ";" .. menu.last_game .. ";true]" - - return retval -end - --------------------------------------------------------------------------------- -function tabbuilder.dialog_delete_world() - return "label[2,2;Delete World \"" .. worldlist.get_raw_list()[menu.world_to_del].name .. "\"?]".. - "button[3.5,4.2;2.6,0.5;world_delete_confirm;Yes]" .. - "button[6,4.2;2.8,0.5;world_delete_cancel;No]" -end - --------------------------------------------------------------------------------- -function tabbuilder.gettab() - local retval = "" - - if tabbuilder.show_buttons then - retval = retval .. tabbuilder.tab_header() - end - - if tabbuilder.current_tab == "singleplayer" then - retval = retval .. tabbuilder.tab_singleplayer() - end - - if tabbuilder.current_tab == "multiplayer" then - retval = retval .. tabbuilder.tab_multiplayer() - end - - if tabbuilder.current_tab == "server" then - retval = retval .. tabbuilder.tab_server() - end - - if tabbuilder.current_tab == "settings" then - retval = retval .. tabbuilder.tab_settings() - end - - if tabbuilder.current_tab == "credits" then - retval = retval .. tabbuilder.tab_credits() - end - - if tabbuilder.current_tab == "dialog_create_world" then - retval = retval .. tabbuilder.dialog_create_world() - end - - if tabbuilder.current_tab == "dialog_delete_world" then - retval = retval .. tabbuilder.dialog_delete_world() - end - - retval = retval .. modmgr.gettab(tabbuilder.current_tab) - retval = retval .. gamemgr.gettab(tabbuilder.current_tab) - retval = retval .. modstore.gettab(tabbuilder.current_tab) - - return retval -end - --------------------------------------------------------------------------------- -function tabbuilder.handle_create_world_buttons(fields) - - if fields["world_create_confirm"] or - fields["key_enter"] then - - local worldname = fields["te_world_name"] - local gameindex = engine.get_textlist_index("games") - - if gameindex > 0 and - worldname ~= "" then - - local message = nil - - if not worldlist.exists(worldname) then - engine.setting_set("mg_name",fields["dd_mapgen"]) - message = engine.create_world(worldname,gameindex) - else - message = "A world named \"" .. worldname .. "\" already exists" - end - - if message ~= nil then - gamedata.errormessage = message - else - menu.last_game = gameindex - engine.setting_set("main_menu_last_game_idx",gameindex) - - worldlist.refresh() - engine.setting_set("mainmenu_last_selected_world", - worldlist.engine_index_by_name(worldname)) - end - else - gamedata.errormessage = "No worldname given or no game selected" - end - end - - if fields["games"] then - tabbuilder.skipformupdate = true - return - end - - --close dialog - tabbuilder.is_dialog = false - tabbuilder.show_buttons = true - tabbuilder.current_tab = engine.setting_get("main_menu_tab") -end - --------------------------------------------------------------------------------- -function tabbuilder.handle_delete_world_buttons(fields) - - if fields["world_delete_confirm"] then - if menu.world_to_del > 0 and - menu.world_to_del <= #worldlist.get_raw_list() then - engine.delete_world(menu.world_to_del) - menu.world_to_del = 0 - worldlist.refresh() - end - end - - tabbuilder.is_dialog = false - tabbuilder.show_buttons = true - tabbuilder.current_tab = engine.setting_get("main_menu_tab") -end - --------------------------------------------------------------------------------- -function tabbuilder.handle_multiplayer_buttons(fields) - - if fields["te_name"] ~= nil then - gamedata.playername = fields["te_name"] - engine.setting_set("name", fields["te_name"]) - end - - if fields["favourites"] ~= nil then - local event = explode_textlist_event(fields["favourites"]) - if event.typ == "DCL" then - gamedata.address = menu.favorites[event.index].address - gamedata.port = menu.favorites[event.index].port - gamedata.playername = fields["te_name"] - if fields["te_pwd"] ~= nil then - gamedata.password = fields["te_pwd"] - end - gamedata.selected_world = 0 - - if menu.favorites ~= nil then - gamedata.servername = menu.favorites[event.index].name - gamedata.serverdescription = menu.favorites[event.index].description - end - - if menu.favorites ~= nil then - gamedata.servername = menu.favorites[event.index].name - gamedata.serverdescription = menu.favorites[event.index].description - end - - if gamedata.address ~= nil and - gamedata.port ~= nil then - - engine.start() - end - end - - if event.typ == "CHG" then - local address = menu.favorites[event.index].address - local port = menu.favorites[event.index].port - - if address ~= nil and - port ~= nil then - engine.setting_set("address",address) - engine.setting_set("port",port) - end - - menu.fav_selected = event.index - end - return - end - - if fields["key_up"] ~= nil or - fields["key_down"] ~= nil then - - local fav_idx = engine.get_textlist_index("favourites") - - if fields["key_up"] ~= nil and fav_idx > 1 then - fav_idx = fav_idx -1 - else if fields["key_down"] and fav_idx < #menu.favorites then - fav_idx = fav_idx +1 - end end - - local address = menu.favorites[fav_idx].address - local port = menu.favorites[fav_idx].port - - if address ~= nil and - port ~= nil then - engine.setting_set("address",address) - engine.setting_set("port",port) - end - - menu.fav_selected = fav_idx - return - end - - if fields["cb_public_serverlist"] ~= nil then - engine.setting_setbool("public_serverlist", - tabbuilder.tobool(fields["cb_public_serverlist"])) - - if engine.setting_getbool("public_serverlist") then - menu.favorites = engine.get_favorites("online") - else - menu.favorites = engine.get_favorites("local") - end - menu.fav_selected = nil - return - end - - if fields["btn_delete_favorite"] ~= nil then - local current_favourite = engine.get_textlist_index("favourites") - engine.delete_favorite(current_favourite) - menu.favorites = engine.get_favorites() - menu.fav_selected = nil - - engine.setting_set("address","") - engine.setting_get("port","") - - return - end - - if fields["btn_mp_connect"] ~= nil or - fields["key_enter"] then - - gamedata.playername = fields["te_name"] - gamedata.password = fields["te_pwd"] - gamedata.address = fields["te_address"] - gamedata.port = fields["te_port"] - - local fav_idx = engine.get_textlist_index("favourites") - - if fav_idx > 0 and fav_idx <= #menu.favorites and - menu.favorites[fav_idx].address == fields["te_address"] and - menu.favorites[fav_idx].port == fields["te_port"] then - - gamedata.servername = menu.favorites[fav_idx].name - gamedata.serverdescription = menu.favorites[fav_idx].description - else - gamedata.servername = "" - gamedata.serverdescription = "" - end - - gamedata.selected_world = 0 - - engine.start() - return - end -end - --------------------------------------------------------------------------------- -function tabbuilder.handle_server_buttons(fields) - - local world_doubleclick = false - - if fields["srv_worlds"] ~= nil then - local event = explode_textlist_event(fields["srv_worlds"]) - - if event.typ == "DCL" then - world_doubleclick = true - end - if event.typ == "CHG" then - engine.setting_set("mainmenu_last_selected_world", - worldlist.get_engine_index(engine.get_textlist_index("srv_worlds"))) - end - end - - menu.handle_key_up_down(fields,"srv_worlds","mainmenu_last_selected_world") - - if fields["cb_creative_mode"] then - engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"])) - end - - if fields["cb_enable_damage"] then - engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"])) - end - - if fields["cb_server_announce"] then - engine.setting_setbool("server_announce",tabbuilder.tobool(fields["cb_server_announce"])) - end - - if fields["start_server"] ~= nil or - world_doubleclick or - fields["key_enter"] then - local selected = engine.get_textlist_index("srv_worlds") - if selected > 0 then - gamedata.playername = fields["te_playername"] - gamedata.password = fields["te_passwd"] - gamedata.port = fields["te_serverport"] - gamedata.address = "" - gamedata.selected_world = worldlist.get_engine_index(selected) - - menu.update_last_game(gamedata.selected_world) - engine.start() - end - end - - if fields["world_create"] ~= nil then - tabbuilder.current_tab = "dialog_create_world" - tabbuilder.is_dialog = true - tabbuilder.show_buttons = false - end - - if fields["world_delete"] ~= nil then - local selected = engine.get_textlist_index("srv_worlds") - if selected > 0 and - selected <= worldlist.size() then - local world = worldlist.get_list()[selected] - if world ~= nil and - world.name ~= nil and - world.name ~= "" then - menu.world_to_del = worldlist.get_engine_index(selected) - tabbuilder.current_tab = "dialog_delete_world" - tabbuilder.is_dialog = true - tabbuilder.show_buttons = false - else - menu.world_to_del = 0 - end - end - end - - if fields["world_configure"] ~= nil then - selected = engine.get_textlist_index("srv_worlds") - if selected > 0 then - modmgr.world_config_selected_world = worldlist.get_engine_index(selected) - if modmgr.init_worldconfig() then - tabbuilder.current_tab = "dialog_configure_world" - tabbuilder.is_dialog = true - tabbuilder.show_buttons = false - end - end - end -end - --------------------------------------------------------------------------------- -function tabbuilder.tobool(text) - if text == "true" then - return true - else - return false - end -end - --------------------------------------------------------------------------------- -function tabbuilder.handle_settings_buttons(fields) - if fields["cb_fancy_trees"] then - engine.setting_setbool("new_style_leaves",tabbuilder.tobool(fields["cb_fancy_trees"])) - end - - if fields["cb_smooth_lighting"] then - engine.setting_setbool("smooth_lighting",tabbuilder.tobool(fields["cb_smooth_lighting"])) - end - if fields["cb_3d_clouds"] then - engine.setting_setbool("enable_3d_clouds",tabbuilder.tobool(fields["cb_3d_clouds"])) - end - if fields["cb_opaque_water"] then - engine.setting_setbool("opaque_water",tabbuilder.tobool(fields["cb_opaque_water"])) - end - - if fields["cb_mipmapping"] then - engine.setting_setbool("mip_map",tabbuilder.tobool(fields["cb_mipmapping"])) - end - if fields["cb_anisotrophic"] then - engine.setting_setbool("anisotropic_filter",tabbuilder.tobool(fields["cb_anisotrophic"])) - end - if fields["cb_bilinear"] then - engine.setting_setbool("bilinear_filter",tabbuilder.tobool(fields["cb_bilinear"])) - end - if fields["cb_trilinear"] then - engine.setting_setbool("trilinear_filter",tabbuilder.tobool(fields["cb_trilinear"])) - end - - if fields["cb_shaders"] then - engine.setting_setbool("enable_shaders",tabbuilder.tobool(fields["cb_shaders"])) - end - if fields["cb_pre_ivis"] then - engine.setting_setbool("preload_item_visuals",tabbuilder.tobool(fields["cb_pre_ivis"])) - end - if fields["cb_particles"] then - engine.setting_setbool("enable_particles",tabbuilder.tobool(fields["cb_particles"])) - end - if fields["cb_finite_liquid"] then - engine.setting_setbool("liquid_finite",tabbuilder.tobool(fields["cb_finite_liquid"])) - end - - if fields["btn_change_keys"] ~= nil then - engine.show_keys_menu() - end -end - --------------------------------------------------------------------------------- -function tabbuilder.handle_singleplayer_buttons(fields) - - local world_doubleclick = false - - if fields["sp_worlds"] ~= nil then - local event = explode_textlist_event(fields["sp_worlds"]) - - if event.typ == "DCL" then - world_doubleclick = true - end - - if event.typ == "CHG" then - engine.setting_set("mainmenu_last_selected_world", - worldlist.get_engine_index(engine.get_textlist_index("sp_worlds"))) - end - end - - menu.handle_key_up_down(fields,"sp_worlds","mainmenu_last_selected_world") - - if fields["cb_creative_mode"] then - engine.setting_setbool("creative_mode",tabbuilder.tobool(fields["cb_creative_mode"])) - end - - if fields["cb_enable_damage"] then - engine.setting_setbool("enable_damage",tabbuilder.tobool(fields["cb_enable_damage"])) - end - - if fields["play"] ~= nil or - world_doubleclick or - fields["key_enter"] then - local selected = engine.get_textlist_index("sp_worlds") - if selected > 0 then - gamedata.selected_world = worldlist.get_engine_index(selected) - gamedata.singleplayer = true - - menu.update_last_game(gamedata.selected_world) - - engine.start() - end - end - - if fields["world_create"] ~= nil then - tabbuilder.current_tab = "dialog_create_world" - tabbuilder.is_dialog = true - tabbuilder.show_buttons = false - end - - if fields["world_delete"] ~= nil then - local selected = engine.get_textlist_index("sp_worlds") - if selected > 0 and - selected <= worldlist.size() then - local world = worldlist.get_list()[selected] - if world ~= nil and - world.name ~= nil and - world.name ~= "" then - menu.world_to_del = worldlist.get_engine_index(selected) - tabbuilder.current_tab = "dialog_delete_world" - tabbuilder.is_dialog = true - tabbuilder.show_buttons = false - else - menu.world_to_del = 0 - end - end - end - - if fields["world_configure"] ~= nil then - selected = engine.get_textlist_index("sp_worlds") - if selected > 0 then - modmgr.world_config_selected_world = worldlist.get_engine_index(selected) - if modmgr.init_worldconfig() then - tabbuilder.current_tab = "dialog_configure_world" - tabbuilder.is_dialog = true - tabbuilder.show_buttons = false - end - end - end -end - --------------------------------------------------------------------------------- -function tabbuilder.tab_header() - - if tabbuilder.last_tab_index == nil then - tabbuilder.last_tab_index = 1 - end - - local toadd = "" - - for i=1,#tabbuilder.current_buttons,1 do - - if toadd ~= "" then - toadd = toadd .. "," - end - - toadd = toadd .. tabbuilder.current_buttons[i].caption - end - return "tabheader[-0.3,-0.99;main_tab;" .. toadd ..";" .. tabbuilder.last_tab_index .. ";true;false]" -end - --------------------------------------------------------------------------------- -function tabbuilder.handle_tab_buttons(fields) - - if fields["main_tab"] then - local index = tonumber(fields["main_tab"]) - tabbuilder.last_tab_index = index - tabbuilder.current_tab = tabbuilder.current_buttons[index].name - - engine.setting_set("main_menu_tab",tabbuilder.current_tab) - end - - --handle tab changes - if tabbuilder.current_tab ~= tabbuilder.old_tab then - if tabbuilder.current_tab ~= "singleplayer" then - menu.reset_gametype() - end - end - - if tabbuilder.current_tab == "singleplayer" then - menu.update_gametype() - end - - tabbuilder.old_tab = tabbuilder.current_tab -end - --------------------------------------------------------------------------------- -function tabbuilder.init() - tabbuilder.current_tab = engine.setting_get("main_menu_tab") - - if tabbuilder.current_tab == nil or - tabbuilder.current_tab == "" then - tabbuilder.current_tab = "singleplayer" - engine.setting_set("main_menu_tab",tabbuilder.current_tab) - end - - - --initialize tab buttons - tabbuilder.last_tab = nil - tabbuilder.show_buttons = true - - tabbuilder.current_buttons = {} - table.insert(tabbuilder.current_buttons,{name="singleplayer", caption="Singleplayer"}) - table.insert(tabbuilder.current_buttons,{name="multiplayer", caption="Client"}) - table.insert(tabbuilder.current_buttons,{name="server", caption="Server"}) - table.insert(tabbuilder.current_buttons,{name="settings", caption="Settings"}) - - if engine.setting_getbool("main_menu_game_mgr") then - table.insert(tabbuilder.current_buttons,{name="game_mgr", caption="Games"}) - end - - if engine.setting_getbool("main_menu_mod_mgr") then - table.insert(tabbuilder.current_buttons,{name="mod_mgr", caption="Mods"}) - end - table.insert(tabbuilder.current_buttons,{name="credits", caption="Credits"}) - - - for i=1,#tabbuilder.current_buttons,1 do - if tabbuilder.current_buttons[i].name == tabbuilder.current_tab then - tabbuilder.last_tab_index = i - end - end - - menu.update_gametype() -end - --------------------------------------------------------------------------------- -function tabbuilder.tab_multiplayer() - - local retval = - "vertlabel[0,-0.25;CLIENT]" .. - "label[1,-0.25;Favorites:]".. - "label[1,4.25;Address/Port]".. - "label[9,0;Name/Password]" .. - "field[1.25,5.25;5.5,0.5;te_address;;" ..engine.setting_get("address") .."]" .. - "field[6.75,5.25;2.25,0.5;te_port;;" ..engine.setting_get("port") .."]" .. - "checkbox[1,3.6;cb_public_serverlist;Public Serverlist;" .. - dump(engine.setting_getbool("public_serverlist")) .. "]" - - if not engine.setting_getbool("public_serverlist") then - retval = retval .. - "button[6.45,3.95;2.25,0.5;btn_delete_favorite;Delete]" - end - - retval = retval .. - "button[9,4.95;2.5,0.5;btn_mp_connect;Connect]" .. - "field[9.25,1;2.5,0.5;te_name;;" ..engine.setting_get("name") .."]" .. - "pwdfield[9.25,1.75;2.5,0.5;te_pwd;]" .. - "textarea[9.25,2.25;2.5,2.75;;" - if menu.fav_selected ~= nil and - menu.favorites[menu.fav_selected].description ~= nil then - retval = retval .. - fs_escape_string(menu.favorites[menu.fav_selected].description,true) - end - - retval = retval .. - ";]" .. - "textlist[1,0.35;7.5,3.35;favourites;" - - local render_details = engine.setting_getbool("public_serverlist") - - if #menu.favorites > 0 then - retval = retval .. render_favourite(menu.favorites[1],render_details) - - for i=2,#menu.favorites,1 do - retval = retval .. "," .. render_favourite(menu.favorites[i],render_details) - end - end - - if menu.fav_selected ~= nil then - retval = retval .. ";" .. menu.fav_selected .. "]" - else - retval = retval .. ";0]" - end - - return retval -end - --------------------------------------------------------------------------------- -function tabbuilder.tab_server() - - local index = worldlist.get_current_index( - tonumber(engine.setting_get("mainmenu_last_selected_world")) - ) - - local retval = - "button[4,4.15;2.6,0.5;world_delete;Delete]" .. - "button[6.5,4.15;2.8,0.5;world_create;New]" .. - "button[9.2,4.15;2.55,0.5;world_configure;Configure]" .. - "button[8.5,4.9;3.25,0.5;start_server;Start Game]" .. - "label[4,-0.25;Select World:]".. - "vertlabel[0,-0.25;START SERVER]" .. - "checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" .. - dump(engine.setting_getbool("creative_mode")) .. "]".. - "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" .. - dump(engine.setting_getbool("enable_damage")) .. "]".. - "checkbox[0.5,1.15;cb_server_announce;Public;" .. - dump(engine.setting_getbool("server_announce")) .. "]".. - "field[0.8,3.2;3,0.5;te_playername;Name;" .. - engine.setting_get("name") .. "]" .. - "pwdfield[0.8,4.2;3,0.5;te_passwd;Password]" .. - "field[0.8,5.2;3,0.5;te_serverport;Server Port;30000]" .. - "textlist[4,0.25;7.5,3.7;srv_worlds;" .. - menu.render_world_list() .. - ";" .. index .. "]" - - return retval -end - --------------------------------------------------------------------------------- -function tabbuilder.tab_settings() - return "vertlabel[0,0;SETTINGS]" .. - "checkbox[1,0.75;cb_fancy_trees;Fancy trees;" .. dump(engine.setting_getbool("new_style_leaves")) .. "]".. - "checkbox[1,1.25;cb_smooth_lighting;Smooth Lighting;".. dump(engine.setting_getbool("smooth_lighting")) .. "]".. - "checkbox[1,1.75;cb_3d_clouds;3D Clouds;" .. dump(engine.setting_getbool("enable_3d_clouds")) .. "]".. - "checkbox[1,2.25;cb_opaque_water;Opaque Water;" .. dump(engine.setting_getbool("opaque_water")) .. "]".. - - "checkbox[4,0.75;cb_mipmapping;Mip-Mapping;" .. dump(engine.setting_getbool("mip_map")) .. "]".. - "checkbox[4,1.25;cb_anisotrophic;Anisotropic Filtering;".. dump(engine.setting_getbool("anisotropic_filter")) .. "]".. - "checkbox[4,1.75;cb_bilinear;Bi-Linear Filtering;" .. dump(engine.setting_getbool("bilinear_filter")) .. "]".. - "checkbox[4,2.25;cb_trilinear;Tri-Linear Filtering;" .. dump(engine.setting_getbool("trilinear_filter")) .. "]".. - - "checkbox[7.5,0.75;cb_shaders;Shaders;" .. dump(engine.setting_getbool("enable_shaders")) .. "]".. - "checkbox[7.5,1.25;cb_pre_ivis;Preload item visuals;".. dump(engine.setting_getbool("preload_item_visuals")) .. "]".. - "checkbox[7.5,1.75;cb_particles;Enable Particles;" .. dump(engine.setting_getbool("enable_particles")) .. "]".. - "checkbox[7.5,2.25;cb_finite_liquid;Finite Liquid;" .. dump(engine.setting_getbool("liquid_finite")) .. "]".. - - "button[1,3.75;2.25,0.5;btn_change_keys;Change keys]" -end - --------------------------------------------------------------------------------- -function tabbuilder.tab_singleplayer() - - local index = worldlist.get_current_index( - tonumber(engine.setting_get("mainmenu_last_selected_world")) - ) - - return "button[4,4.15;2.6,0.5;world_delete;Delete]" .. - "button[6.5,4.15;2.8,0.5;world_create;New]" .. - "button[9.2,4.15;2.55,0.5;world_configure;Configure]" .. - "button[8.5,4.95;3.25,0.5;play;Play]" .. - "label[4,-0.25;Select World:]".. - "vertlabel[0,-0.25;SINGLE PLAYER]" .. - "checkbox[0.5,0.25;cb_creative_mode;Creative Mode;" .. - dump(engine.setting_getbool("creative_mode")) .. "]".. - "checkbox[0.5,0.7;cb_enable_damage;Enable Damage;" .. - dump(engine.setting_getbool("enable_damage")) .. "]".. - "textlist[4,0.25;7.5,3.7;sp_worlds;" .. - menu.render_world_list() .. - ";" .. index .. "]" .. - menubar.formspec -end - --------------------------------------------------------------------------------- -function tabbuilder.tab_credits() - return "vertlabel[0,-0.5;CREDITS]" .. - "label[0.5,3;Minetest " .. engine.get_version() .. "]" .. - "label[0.5,3.3;http://minetest.net]" .. - "image[0.5,1;" .. menu.defaulttexturedir .. "logo.png]" .. - "textlist[3.5,-0.25;8.5,5.8;list_credits;" .. - "#FFFF00Core Developers," .. - "Perttu Ahola (celeron55) ,".. - "Ryan Kwolek (kwolekr) ,".. - "PilzAdam ," .. - "IIya Zhuravlev (thexyz) ,".. - "Lisa Milne (darkrose) ,".. - "Maciej Kasatkin (RealBadAngel) ,".. - "proller ,".. - "sfan5 ,".. - "kahrl ,".. - ",".. - "#FFFF00Active Contributors," .. - "sapier,".. - "Vanessa Ezekowitz (VanessaE) ,".. - "Jurgen Doser (doserj) ,".. - "Jeija ,".. - "MirceaKitsune ,".. - "ShadowNinja,".. - "dannydark ,".. - "0gb.us <0gb.us@0gb.us>,".. - "," .. - "#FFFF00Previous Contributors," .. - "Guiseppe Bilotta (Oblomov) ,".. - "Jonathan Neuschafer ,".. - "Nils Dagsson Moskopp (erlehmann) ,".. - "Constantin Wenger (SpeedProg) ,".. - "matttpt ,".. - "JacobF ,".. - ";0;true]" -end - --------------------------------------------------------------------------------- -function tabbuilder.checkretval(retval) - - if retval ~= nil then - if retval.current_tab ~= nil then - tabbuilder.current_tab = retval.current_tab - end - - if retval.is_dialog ~= nil then - tabbuilder.is_dialog = retval.is_dialog - end - - if retval.show_buttons ~= nil then - tabbuilder.show_buttons = retval.show_buttons - end - - if retval.skipformupdate ~= nil then - tabbuilder.skipformupdate = retval.skipformupdate - end - end -end - --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- --- initialize callbacks --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -engine.button_handler = function(fields) - --print("Buttonhandler: tab: " .. tabbuilder.current_tab .. " fields: " .. dump(fields)) - - if fields["btn_error_confirm"] then - gamedata.errormessage = nil - end - - local retval = modmgr.handle_buttons(tabbuilder.current_tab,fields) - tabbuilder.checkretval(retval) - - retval = gamemgr.handle_buttons(tabbuilder.current_tab,fields) - tabbuilder.checkretval(retval) - - retval = modstore.handle_buttons(tabbuilder.current_tab,fields) - tabbuilder.checkretval(retval) - - if tabbuilder.current_tab == "dialog_create_world" then - tabbuilder.handle_create_world_buttons(fields) - end - - if tabbuilder.current_tab == "dialog_delete_world" then - tabbuilder.handle_delete_world_buttons(fields) - end - - if tabbuilder.current_tab == "singleplayer" then - tabbuilder.handle_singleplayer_buttons(fields) - end - - if tabbuilder.current_tab == "multiplayer" then - tabbuilder.handle_multiplayer_buttons(fields) - end - - if tabbuilder.current_tab == "settings" then - tabbuilder.handle_settings_buttons(fields) - end - - if tabbuilder.current_tab == "server" then - tabbuilder.handle_server_buttons(fields) - end - - --tab buttons - tabbuilder.handle_tab_buttons(fields) - - --menubar buttons - menubar.handle_buttons(fields) - - if not tabbuilder.skipformupdate then - --update menu - update_menu() - else - tabbuilder.skipformupdate = false - end -end - --------------------------------------------------------------------------------- -engine.event_handler = function(event) - if event == "MenuQuit" then - if tabbuilder.is_dialog then - tabbuilder.is_dialog = false - tabbuilder.show_buttons = true - tabbuilder.current_tab = engine.setting_get("main_menu_tab") - update_menu() - else - engine.close() - end - end -end - --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- --- menu startup --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -init_globals() -worldlist.init() -menu.init() -tabbuilder.init() -menubar.refresh() -modstore.init() - -update_menu() diff --git a/builtin/mainmenu_helper.lua b/builtin/mainmenu_helper.lua deleted file mode 100644 index 25ad072fd..000000000 --- a/builtin/mainmenu_helper.lua +++ /dev/null @@ -1,107 +0,0 @@ --------------------------------------------------------------------------------- -function dump(o, dumped) - dumped = dumped or {} - if type(o) == "number" then - return tostring(o) - elseif type(o) == "string" then - return string.format("%q", o) - elseif type(o) == "table" then - if dumped[o] then - return "" - end - dumped[o] = true - local t = {} - for k,v in pairs(o) do - t[#t+1] = "" .. k .. " = " .. dump(v, dumped) - end - return "{" .. table.concat(t, ", ") .. "}" - elseif type(o) == "boolean" then - return tostring(o) - elseif type(o) == "function" then - return "" - elseif type(o) == "userdata" then - return "" - elseif type(o) == "nil" then - return "nil" - else - error("cannot dump a " .. type(o)) - return nil - end -end - --------------------------------------------------------------------------------- -function string:split(sep) - local sep, fields = sep or ",", {} - local pattern = string.format("([^%s]+)", sep) - self:gsub(pattern, function(c) fields[#fields+1] = c end) - return fields -end - --------------------------------------------------------------------------------- -function string:trim() - return (self:gsub("^%s*(.-)%s*$", "%1")) -end - --------------------------------------------------------------------------------- -engine.get_game = function(index) - local games = game.get_games() - - if index > 0 and index <= #games then - return games[index] - end - - return nil -end - --------------------------------------------------------------------------------- -function fs_escape_string(text) - if text ~= nil then - while (text:find("\r\n") ~= nil) do - local newtext = text:sub(1,text:find("\r\n")-1) - newtext = newtext .. " " .. text:sub(text:find("\r\n")+3) - - text = newtext - end - - while (text:find("\n") ~= nil) do - local newtext = text:sub(1,text:find("\n")-1) - newtext = newtext .. " " .. text:sub(text:find("\n")+1) - - text = newtext - end - - while (text:find("\r") ~= nil) do - local newtext = text:sub(1,text:find("\r")-1) - newtext = newtext .. " " .. text:sub(text:find("\r")+1) - - text = newtext - end - - text = string.gsub(text,"\\","\\\\") - text = string.gsub(text,"%]","\\]") - text = string.gsub(text,"%[","\\[") - text = string.gsub(text,";","\\;") - text = string.gsub(text,",","\\,") - end - return text -end - --------------------------------------------------------------------------------- -function explode_textlist_event(text) - - local retval = {} - retval.typ = "INV" - - local parts = text:split(":") - - if #parts == 2 then - retval.typ = parts[1]:trim() - retval.index= tonumber(parts[2]:trim()) - - if type(retval.index) ~= "number" then - retval.typ = "INV" - end - end - - return retval -end diff --git a/builtin/mainmenu_worldlist.lua b/builtin/mainmenu_worldlist.lua deleted file mode 100644 index 4f7ba097c..000000000 --- a/builtin/mainmenu_worldlist.lua +++ /dev/null @@ -1,211 +0,0 @@ -worldlist = {} - --------------------------------------------------------------------------------- -function worldlist.refresh() - worldlist.m_raw_worldlist = engine.get_worlds() - worldlist.process() -end - --------------------------------------------------------------------------------- -function worldlist.init() - worldlist.m_gamefilter = nil - worldlist.m_sortmode = "alphabetic" - - worldlist.m_processed_worldlist = nil - worldlist.m_raw_worldlist = engine.get_worlds() - - worldlist.process() -end - --------------------------------------------------------------------------------- -function worldlist.set_gamefilter(gameid) - if gameid == worldlist.m_gamefilter then - return - end - worldlist.m_gamefilter = gameid - worldlist.process() -end - --------------------------------------------------------------------------------- -function worldlist.get_gamefilter() - return worldlist.m_gamefilter -end - --------------------------------------------------------------------------------- ---supported sort mode "alphabetic|none" -function worldlist.set_sortmode(mode) - if (mode == worldlist.m_sortmode) then - return - end - worldlist.m_sortmode = mode - worldlist.process() -end - --------------------------------------------------------------------------------- -function worldlist.get_list() - return worldlist.m_processed_worldlist -end - --------------------------------------------------------------------------------- -function worldlist.get_raw_list() - return worldlist.m_raw_worldlist -end - --------------------------------------------------------------------------------- -function worldlist.get_raw_world(idx) - if type(idx) ~= "number" then - idx = tonumber(idx) - end - - if idx ~= nil and idx > 0 and idx < #worldlist.m_raw_worldlist then - return worldlist.m_raw_worldlist[idx] - end - - return nil -end - --------------------------------------------------------------------------------- -function worldlist.get_engine_index(worldlistindex) - assert(worldlist.m_processed_worldlist ~= nil) - - if worldlistindex ~= nil and worldlistindex > 0 and - worldlistindex <= #worldlist.m_processed_worldlist then - local entry = worldlist.m_processed_worldlist[worldlistindex] - - for i,v in ipairs(worldlist.m_raw_worldlist) do - - if worldlist.compare(v,entry) then - return i - end - end - end - - return 0 -end - --------------------------------------------------------------------------------- -function worldlist.get_current_index(worldlistindex) - assert(worldlist.m_processed_worldlist ~= nil) - - if worldlistindex ~= nil and worldlistindex > 0 and - worldlistindex <= #worldlist.m_raw_worldlist then - local entry = worldlist.m_raw_worldlist[worldlistindex] - - for i,v in ipairs(worldlist.m_processed_worldlist) do - - if worldlist.compare(v,entry) then - return i - end - end - end - - return 0 -end - --------------------------------------------------------------------------------- -function worldlist.process() - assert(worldlist.m_raw_worldlist ~= nil) - - if worldlist.m_sortmode == "none" and - worldlist.m_gamefilter == nil then - worldlist.m_processed_worldlist = worldlist.m_raw_worldlist - return - end - - worldlist.m_processed_worldlist = {} - - for i,v in ipairs(worldlist.m_raw_worldlist) do - - if worldlist.m_gamefilter == nil or - v.gameid == worldlist.m_gamefilter then - table.insert(worldlist.m_processed_worldlist,v) - end - end - - if worldlist.m_sortmode == "none" then - return - end - - if worldlist.m_sortmode == "alphabetic" then - worldlist.sort_alphabetic() - end - -end - --------------------------------------------------------------------------------- -function worldlist.compare(world1,world2) - - if world1.path ~= world2.path then - return false - end - - if world1.name ~= world2.name then - return false - end - - if world1.gameid ~= world2.gameid then - return false - end - - return true -end - --------------------------------------------------------------------------------- -function worldlist.size() - if worldlist.m_processed_worldlist == nil then - return 0 - end - - return #worldlist.m_processed_worldlist -end - --------------------------------------------------------------------------------- -function worldlist.exists(worldname) - for i,v in ipairs(worldlist.m_raw_worldlist) do - if v.name == worldname then - return true - end - end - return false -end - - --------------------------------------------------------------------------------- -function worldlist.engine_index_by_name(worldname) - local worldcount = 0 - local worldidx = 0 - for i,v in ipairs(worldlist.m_raw_worldlist) do - if v.name == worldname then - worldcount = worldcount +1 - worldidx = i - end - end - - - -- If there are more worlds than one with same name we can't decide which - -- one is meant. This shouldn't be possible but just for sure. - if worldcount > 1 then - worldidx=0 - end - - return worldidx -end - --------------------------------------------------------------------------------- -function worldlist.sort_alphabetic() - - table.sort(worldlist.m_processed_worldlist, function(a, b) - local n1 = a.name - local n2 = b.name - local count = math.min(#n1, #n2) - - for i=1,count do - if n1:sub(i, i):lower() < n2:sub(i, i):lower() then - return true - elseif n1:sub(i, i):lower() > n2:sub(i, i):lower() then - return false - end - end - return (#n1 <= #n2) - end) -end diff --git a/builtin/misc_helpers.lua b/builtin/misc_helpers.lua index 0439415b1..743a9cfd3 100644 --- a/builtin/misc_helpers.lua +++ b/builtin/misc_helpers.lua @@ -91,14 +91,4 @@ function minetest.pos_to_string(pos) return "(" .. pos.x .. "," .. pos.y .. "," .. pos.z .. ")" end -function math.hypot(x, y) - local t - x = math.abs(x) - y = math.abs(y) - t = math.min(x, y) - x = math.max(x, y) - if x == 0 then return 0 end - t = t / x - return x * math.sqrt(1 + t * t) -end diff --git a/builtin/modmgr.lua b/builtin/modmgr.lua deleted file mode 100644 index b42492882..000000000 --- a/builtin/modmgr.lua +++ /dev/null @@ -1,883 +0,0 @@ ---Minetest ---Copyright (C) 2013 sapier --- ---This program is free software; you can redistribute it and/or modify ---it under the terms of the GNU Lesser General Public License as published by ---the Free Software Foundation; either version 2.1 of the License, or ---(at your option) any later version. --- ---This program is distributed in the hope that it will be useful, ---but WITHOUT ANY WARRANTY; without even the implied warranty of ---MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ---GNU Lesser General Public License for more details. --- ---You should have received a copy of the GNU Lesser General Public License along ---with this program; if not, write to the Free Software Foundation, Inc., ---51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - --------------------------------------------------------------------------------- -function get_mods(path,retval,basefolder) - - local mods = engine.get_dirlist(path,true) - - for i=1,#mods,1 do - local filename = path .. DIR_DELIM .. mods[i] .. DIR_DELIM .. "modpack.txt" - local modpackfile,error = io.open(filename,"r") - - local name = mods[i] - if basefolder ~= nil and - basefolder ~= "" then - name = basefolder .. DIR_DELIM .. mods[i] - end - - if modpackfile ~= nil then - modpackfile:close() - table.insert(retval,name .. " ") - get_mods(path .. DIR_DELIM .. name,retval,name) - else - - table.insert(retval,name) - end - end -end - ---modmanager implementation -modmgr = {} - --------------------------------------------------------------------------------- -function modmgr.extract(modfile) - if modfile.type == "zip" then - local tempfolder = os.tempfolder() - - if tempfolder ~= nil and - tempfodler ~= "" then - engine.create_dir(tempfolder) - engine.extract_zip(modfile.name,tempfolder) - return tempfolder - end - end -end - -------------------------------------------------------------------------------- -function modmgr.getbasefolder(temppath) - - if temppath == nil then - return { - type = "invalid", - path = "" - } - end - - local testfile = io.open(temppath .. DIR_DELIM .. "init.lua","r") - if testfile ~= nil then - testfile:close() - return { - type="mod", - path=temppath - } - end - - testfile = io.open(temppath .. DIR_DELIM .. "modpack.txt","r") - if testfile ~= nil then - testfile:close() - return { - type="modpack", - path=temppath - } - end - - local subdirs = engine.get_dirlist(temppath,true) - - --only single mod or modpack allowed - if #subdirs ~= 1 then - return { - type = "invalid", - path = "" - } - end - - testfile = - io.open(temppath .. DIR_DELIM .. subdirs[1] ..DIR_DELIM .."init.lua","r") - if testfile ~= nil then - testfile:close() - return { - type="mod", - path= temppath .. DIR_DELIM .. subdirs[1] - } - end - - testfile = - io.open(temppath .. DIR_DELIM .. subdirs[1] ..DIR_DELIM .."modpack.txt","r") - if testfile ~= nil then - testfile:close() - return { - type="modpack", - path=temppath .. DIR_DELIM .. subdirs[1] - } - end - - return { - type = "invalid", - path = "" - } -end - --------------------------------------------------------------------------------- -function modmgr.isValidModname(modpath) - if modpath:find("-") ~= nil then - return false - end - - return true -end - --------------------------------------------------------------------------------- -function modmgr.parse_register_line(line) - local pos1 = line:find("\"") - local pos2 = nil - if pos1 ~= nil then - pos2 = line:find("\"",pos1+1) - end - - if pos1 ~= nil and pos2 ~= nil then - local item = line:sub(pos1+1,pos2-1) - - if item ~= nil and - item ~= "" then - local pos3 = item:find(":") - - if pos3 ~= nil then - return item:sub(1,pos3-1) - end - end - end - return nil -end - --------------------------------------------------------------------------------- -function modmgr.parse_dofile_line(modpath,line) - local pos1 = line:find("\"") - local pos2 = nil - if pos1 ~= nil then - pos2 = line:find("\"",pos1+1) - end - - if pos1 ~= nil and pos2 ~= nil then - local filename = line:sub(pos1+1,pos2-1) - - if filename ~= nil and - filename ~= "" and - filename:find(".lua") then - return modmgr.identify_modname(modpath,filename) - end - end - return nil -end - --------------------------------------------------------------------------------- -function modmgr.update_global_mods() - local modpath = engine.get_modpath() - modmgr.global_mods = {} - if modpath ~= nil and - modpath ~= "" then - get_mods(modpath,modmgr.global_mods) - end -end - --------------------------------------------------------------------------------- -function modmgr.get_mods_list() - local toadd = "" - - modmgr.update_global_mods() - - if modmgr.global_mods ~= nil then - for i=1,#modmgr.global_mods,1 do - if toadd ~= "" then - toadd = toadd.."," - end - toadd = toadd .. modmgr.global_mods[i] - end - end - - return toadd -end - --------------------------------------------------------------------------------- -function modmgr.mod_exists(basename) - modmgr.update_global_mods() - - if modmgr.global_mods ~= nil then - for i=1,#modmgr.global_mods,1 do - if modmgr.global_mods[i] == basename then - return true - end - end - end - - return false -end - --------------------------------------------------------------------------------- -function modmgr.identify_modname(modpath,filename) - local testfile = io.open(modpath .. DIR_DELIM .. filename,"r") - if testfile ~= nil then - local line = testfile:read() - - while line~= nil do - local modname = nil - - if line:find("minetest.register_tool") then - modname = modmgr.parse_register_line(line) - end - - if line:find("minetest.register_craftitem") then - modname = modmgr.parse_register_line(line) - end - - - if line:find("minetest.register_node") then - modname = modmgr.parse_register_line(line) - end - - if line:find("dofile") then - modname = modmgr.parse_dofile_line(modpath,line) - end - - if modname ~= nil then - testfile:close() - return modname - end - - line = testfile:read() - end - testfile:close() - end - - return nil -end - --------------------------------------------------------------------------------- -function modmgr.tab() - if modmgr.selected_mod == nil then - modmgr.selected_mod = 1 - end - - local retval = - "vertlabel[0,-0.25;MODS]" .. - "label[0.8,-0.25;Installed Mods:]" .. - "textlist[0.75,0.25;4.5,4.3;modlist;" .. - modmgr.get_mods_list() .. - ";" .. modmgr.selected_mod .. "]" - - retval = retval .. - "button[1,4.85;2,0.5;btn_mod_mgr_install_local;Install]" .. - "button[3,4.85;2,0.5;btn_mod_mgr_download;Download]" - - if #modmgr.global_mods >= modmgr.selected_mod and - modmgr.global_mods[modmgr.selected_mod]:find("") then - retval = retval .. "button[10,4.85;2,0.5;btn_mod_mgr_rename_modpack;Rename]" - end - - if #modmgr.global_mods >= modmgr.selected_mod then - local modpath = engine.get_modpath() - --show dependencys - if modmgr.global_mods[modmgr.selected_mod]:find("") == nil then - retval = retval .. - "label[6,1.9;Depends:]" .. - "textlist[6,2.4;5.7,2;deplist;" - - toadd = modmgr.get_dependencys(modpath .. DIR_DELIM .. - modmgr.global_mods[modmgr.selected_mod]) - - retval = retval .. toadd .. ";0;true,false]" - - --TODO read modinfo - end - --show delete button - retval = retval .. "button[8,4.85;2,0.5;btn_mod_mgr_delete_mod;Delete]" - end - return retval -end - --------------------------------------------------------------------------------- -function modmgr.dialog_rename_modpack() - - local modname = modmgr.global_mods[modmgr.selected_mod] - modname = modname:sub(0,modname:find("<") -2) - - local retval = - "label[1.75,1;Rename Modpack:]".. - "field[4.5,1.4;6,0.5;te_modpack_name;;" .. - modname .. - "]" .. - "button[5,4.2;2.6,0.5;dlg_rename_modpack_confirm;Accept]" .. - "button[7.5,4.2;2.8,0.5;dlg_rename_modpack_cancel;Cancel]" - - return retval -end - --------------------------------------------------------------------------------- -function modmgr.precheck() - if modmgr.global_mods == nil then - modmgr.update_global_mods() - end - - if modmgr.world_config_selected_world == nil then - modmgr.world_config_selected_world = 1 - end - - if modmgr.world_config_selected_mod == nil then - modmgr.world_config_selected_mod = 1 - end - - if modmgr.hide_gamemods == nil then - modmgr.hide_gamemods = true - end -end - --------------------------------------------------------------------------------- -function modmgr.get_worldmod_idx() - if not modmgr.hide_gamemods then - return modmgr.world_config_selected_mod - #modmgr.worldconfig.game_mods - else - return modmgr.world_config_selected_mod - end -end - --------------------------------------------------------------------------------- -function modmgr.is_gamemod() - if not modmgr.hide_gamemods then - if modmgr.world_config_selected_mod <= #modmgr.worldconfig.game_mods then - return true - else - return false - end - else - return false - end -end - --------------------------------------------------------------------------------- -function modmgr.render_worldmodlist() - local retval = "" - - for i=1,#modmgr.global_mods,1 do - local parts = modmgr.global_mods[i]:split(DIR_DELIM) - local shortname = parts[#parts] - if modmgr.worldconfig.global_mods[shortname] then - retval = retval .. "#22F922" .. modmgr.global_mods[i] .. "," - else - retval = retval .. modmgr.global_mods[i] .. "," - end - end - - return retval -end - --------------------------------------------------------------------------------- -function modmgr.render_gamemodlist() - local retval = "" - for i=1,#modmgr.worldconfig.game_mods,1 do - retval = retval .. - "#0000FF" .. modmgr.worldconfig.game_mods[i] .. "," - end - - return retval -end - --------------------------------------------------------------------------------- -function modmgr.dialog_configure_world() - modmgr.precheck() - - local modpack_selected = false - local gamemod_selected = modmgr.is_gamemod() - local modname = "" - local modfolder = "" - local shortname = "" - - if not gamemod_selected then - local worldmodidx = modmgr.get_worldmod_idx() - modname = modmgr.global_mods[worldmodidx] - - if modname ~= nil then - - if modname:find("") ~= nil then - modname = modname:sub(0,modname:find("<") -2) - modpack_selected = true - end - - local parts = modmgr.global_mods[worldmodidx]:split(DIR_DELIM) - shortname = parts[#parts] - - modfolder = engine.get_modpath() .. DIR_DELIM .. modname - else - modname = "" - end - end - - local worldspec = engine.get_worlds()[modmgr.world_config_selected_world] - - local retval = - "size[11,6.5]" .. - "label[1.5,-0.25;World: " .. worldspec.name .. "]" - - if modmgr.hide_gamemods then - retval = retval .. "checkbox[5.5,6.15;cb_hide_gamemods;Hide Game;true]" - else - retval = retval .. "checkbox[5.5,6.15;cb_hide_gamemods;Hide Game;false]" - end - retval = retval .. - "button[9.25,6.35;2,0.5;btn_config_world_save;Save]" .. - "button[7.4,6.35;2,0.5;btn_config_world_cancel;Cancel]" .. - "textlist[5.5,-0.25;5.5,6.5;world_config_modlist;" - - - if not modmgr.hide_gamemods then - retval = retval .. modmgr.render_gamemodlist() - end - - retval = retval .. modmgr.render_worldmodlist() - - retval = retval .. ";" .. modmgr.world_config_selected_mod .."]" - - if not gamemod_selected then - retval = retval .. - "label[0,0.45;Mod:]" .. - "label[0.75,0.45;" .. modname .. "]" .. - "label[0,1.5;depends on:]" .. - "textlist[0,2;5,2;world_config_depends;" .. - modmgr.get_dependencys(modfolder) .. ";0]" .. - "label[0,4;depends on:]" .. - "textlist[0,4.5;5,2;world_config_is_required;;0]" - - if modpack_selected then - retval = retval .. - "button[-0.05,1.05;2,0.5;btn_cfgw_enable_all;Enable All]" .. - "button[3.25,1.05;2,0.5;btn_cfgw_disable_all;Disable All]" - else - retval = retval .. - "checkbox[0,0.8;cb_mod_enabled;enabled;" - - if modmgr.worldconfig.global_mods[shortname] then - retval = retval .. "true" - else - retval = retval .. "false" - end - - retval = retval .. "]" - end - end - - return retval -end - --------------------------------------------------------------------------------- -function modmgr.handle_buttons(tab,fields) - - local retval = nil - - if tab == "mod_mgr" then - retval = modmgr.handle_modmgr_buttons(fields) - end - - if tab == "dialog_rename_modpack" then - retval = modmgr.handle_rename_modpack_buttons(fields) - end - - if tab == "dialog_delete_mod" then - retval = modmgr.handle_delete_mod_buttons(fields) - end - - if tab == "dialog_configure_world" then - retval = modmgr.handle_configure_world_buttons(fields) - end - - return retval -end - --------------------------------------------------------------------------------- -function modmgr.get_dependencys(modfolder) - local filename = modfolder .. - DIR_DELIM .. "depends.txt" - - local dependencyfile = io.open(filename,"r") - - local toadd = "" - if dependencyfile then - local dependency = dependencyfile:read("*l") - while dependency do - if toadd ~= "" then - toadd = toadd .. "," - end - toadd = toadd .. dependency - dependency = dependencyfile:read() - end - dependencyfile:close() - else - print("Modmgr:" .. filename .. " not found") - end - - return toadd -end - - --------------------------------------------------------------------------------- -function modmgr.get_worldconfig(worldpath) - local filename = worldpath .. - DIR_DELIM .. "world.mt" - - local worldfile = io.open(filename,"r") - - local worldconfig = {} - worldconfig.global_mods = {} - worldconfig.game_mods = {} - - if worldfile then - local dependency = worldfile:read("*l") - while dependency do - local parts = dependency:split("=") - - local key = parts[1]:trim() - - if key == "gameid" then - worldconfig.id = parts[2]:trim() - else - local key = parts[1]:trim():sub(10) - if parts[2]:trim() == "true" then - worldconfig.global_mods[key] = true - else - worldconfig.global_mods[key] = false - end - end - dependency = worldfile:read("*l") - end - worldfile:close() - else - print("Modmgr: " .. filename .. " not found") - end - - --read gamemods - local gamemodpath = engine.get_gamepath() .. DIR_DELIM .. worldconfig.id .. DIR_DELIM .. "mods" - - get_mods(gamemodpath,worldconfig.game_mods) - - return worldconfig -end --------------------------------------------------------------------------------- -function modmgr.handle_modmgr_buttons(fields) - local retval = { - tab = nil, - is_dialog = nil, - show_buttons = nil, - } - - if fields["modlist"] ~= nil then - local event = explode_textlist_event(fields["modlist"]) - modmgr.selected_mod = event.index - end - - if fields["btn_mod_mgr_install_local"] ~= nil then - engine.show_file_open_dialog("mod_mgt_open_dlg","Select Mod File:") - end - - if fields["btn_mod_mgr_download"] ~= nil then - retval.current_tab = "dialog_modstore_unsorted" - retval.is_dialog = true - retval.show_buttons = false - return retval - end - - if fields["btn_mod_mgr_rename_modpack"] ~= nil then - retval.current_tab = "dialog_rename_modpack" - retval.is_dialog = true - retval.show_buttons = false - return retval - end - - if fields["btn_mod_mgr_delete_mod"] ~= nil then - retval.current_tab = "dialog_delete_mod" - retval.is_dialog = true - retval.show_buttons = false - return retval - end - - if fields["mod_mgt_open_dlg_accepted"] ~= nil and - fields["mod_mgt_open_dlg_accepted"] ~= "" then - modmgr.installmod(fields["mod_mgt_open_dlg_accepted"],nil) - end - - return nil; -end - --------------------------------------------------------------------------------- -function modmgr.installmod(modfilename,basename) - local modfile = identify_filetype(modfilename) - - local modpath = modmgr.extract(modfile) - - if modpath == nil then - gamedata.errormessage = "Install Mod: file: " .. modfile.name .. - "\nInstall Mod: unsupported filetype \"" .. modfile.type .. "\"" - return - end - - - local basefolder = modmgr.getbasefolder(modpath) - - if basefolder.type == "modpack" then - local clean_path = nil - - if basename ~= nil then - clean_path = "mp_" .. basename - end - - if clean_path == nil then - clean_path = get_last_folder(cleanup_path(basefolder.path)) - end - - if clean_path ~= nil then - local targetpath = engine.get_modpath() .. DIR_DELIM .. clean_path - if not engine.copy_dir(basefolder.path,targetpath) then - gamedata.errormessage = "Failed to install " .. basename .. " to " .. targetpath - end - else - gamedata.errormessage = "Install Mod: unable to find suitable foldername for modpack " - .. modfilename - end - end - - if basefolder.type == "mod" then - local targetfolder = basename - - if targetfolder == nil then - targetfolder = modmgr.identify_modname(basefolder.path,"init.lua") - end - - --if heuristic failed try to use current foldername - if targetfolder == nil then - targetfolder = get_last_folder(basefolder.path) - end - - if targetfolder ~= nil and modmgr.isValidModname(targetfolder) then - local targetpath = engine.get_modpath() .. DIR_DELIM .. targetfolder - engine.copy_dir(basefolder.path,targetpath) - else - gamedata.errormessage = "Install Mod: unable to find real modname for: " - .. modfilename - end - end - - engine.delete_dir(modpath) -end - --------------------------------------------------------------------------------- -function modmgr.handle_rename_modpack_buttons(fields) - local oldname = modmgr.global_mods[modmgr.selected_mod] - oldname = oldname:sub(0,oldname:find("<") -2) - - if fields["dlg_rename_modpack_confirm"] ~= nil then - local oldpath = engine.get_modpath() .. DIR_DELIM .. oldname - local targetpath = engine.get_modpath() .. DIR_DELIM .. fields["te_modpack_name"] - engine.copy_dir(oldpath,targetpath,false) - end - - return { - is_dialog = false, - show_buttons = true, - current_tab = engine.setting_get("main_menu_tab") - } -end --------------------------------------------------------------------------------- -function modmgr.handle_configure_world_buttons(fields) - if fields["world_config_modlist"] ~= nil then - local event = explode_textlist_event(fields["world_config_modlist"]) - modmgr.world_config_selected_mod = event.index - end - - if fields["cb_mod_enabled"] ~= nil then - local index = modmgr.get_worldmod_idx() - local modname = modmgr.global_mods[index] - - local parts = modmgr.global_mods[index]:split(DIR_DELIM) - local shortname = parts[#parts] - - if fields["cb_mod_enabled"] == "true" then - modmgr.worldconfig.global_mods[shortname] = true - else - modmgr.worldconfig.global_mods[shortname] = false - end - end - - if fields["cb_hide_gamemods"] ~= nil then - if fields["cb_hide_gamemods"] == "true" then - modmgr.hide_gamemods = true - else - modmgr.hide_gamemods = false - end - end - - if fields["btn_config_world_save"] then - local worldspec = engine.get_worlds()[modmgr.world_config_selected_world] - - local filename = worldspec.path .. - DIR_DELIM .. "world.mt" - - local worldfile = io.open(filename,"w") - - if worldfile then - worldfile:write("gameid = " .. modmgr.worldconfig.id .. "\n") - for key,value in pairs(modmgr.worldconfig.global_mods) do - if value then - worldfile:write("load_mod_" .. key .. " = true" .. "\n") - else - worldfile:write("load_mod_" .. key .. " = false" .. "\n") - end - end - - worldfile:close() - end - - modmgr.worldconfig = nil - - return { - is_dialog = false, - show_buttons = true, - current_tab = engine.setting_get("main_menu_tab") - } - end - - if fields["btn_config_world_cancel"] then - - modmgr.worldconfig = nil - - return { - is_dialog = false, - show_buttons = true, - current_tab = engine.setting_get("main_menu_tab") - } - end - - if fields["btn_cfgw_enable_all"] then - local worldmodidx = modmgr.get_worldmod_idx() - modname = modmgr.global_mods[worldmodidx] - - modname = modname:sub(0,modname:find("<") -2) - - for i=1,#modmgr.global_mods,1 do - - if modmgr.global_mods[i]:find("") == nil then - local modpackpart = modmgr.global_mods[i]:sub(0,modname:len()) - - if modpackpart == modname then - local parts = modmgr.global_mods[i]:split(DIR_DELIM) - local shortname = parts[#parts] - modmgr.worldconfig.global_mods[shortname] = true - end - end - end - end - - if fields["btn_cfgw_disable_all"] then - local worldmodidx = modmgr.get_worldmod_idx() - modname = modmgr.global_mods[worldmodidx] - - modname = modname:sub(0,modname:find("<") -2) - - for i=1,#modmgr.global_mods,1 do - local modpackpart = modmgr.global_mods[i]:sub(0,modname:len()) - - if modpackpart == modname then - local parts = modmgr.global_mods[i]:split(DIR_DELIM) - local shortname = parts[#parts] - modmgr.worldconfig.global_mods[shortname] = nil - end - end - end - - return nil -end --------------------------------------------------------------------------------- -function modmgr.handle_delete_mod_buttons(fields) - local modname = modmgr.global_mods[modmgr.selected_mod] - - if modname:find("") ~= nil then - modname = modname:sub(0,modname:find("<") -2) - end - - if fields["dlg_delete_mod_confirm"] ~= nil then - local oldpath = engine.get_modpath() .. DIR_DELIM .. modname - - if oldpath ~= nil and - oldpath ~= "" and - oldpath ~= engine.get_modpath() then - engine.delete_dir(oldpath) - end - end - - return { - is_dialog = false, - show_buttons = true, - current_tab = engine.setting_get("main_menu_tab") - } -end - --------------------------------------------------------------------------------- -function modmgr.dialog_delete_mod() - - local modname = modmgr.global_mods[modmgr.selected_mod] - - if modname:find("") ~= nil then - modname = modname:sub(0,modname:find("<") -2) - end - - local retval = - "field[1.75,1;10,3;;Are you sure you want to delete ".. modname .. "?;]".. - "button[4,4.2;1,0.5;dlg_delete_mod_confirm;Yes]" .. - "button[6.5,4.2;3,0.5;dlg_delete_mod_cancel;No of course not!]" - - return retval -end - --------------------------------------------------------------------------------- -function modmgr.init_worldconfig() - - local worldspec = engine.get_worlds()[modmgr.world_config_selected_world] - - if worldspec ~= nil then - --read worldconfig - modmgr.worldconfig = modmgr.get_worldconfig(worldspec.path) - - if modmgr.worldconfig.id == nil or - modmgr.worldconfig.id == "" then - modmgr.worldconfig = nil - return false - end - - return true - end - - return false -end - --------------------------------------------------------------------------------- -function modmgr.gettab(name) - local retval = "" - - if name == "mod_mgr" then - retval = retval .. modmgr.tab() - end - - if name == "dialog_rename_modpack" then - retval = retval .. modmgr.dialog_rename_modpack() - end - - if name == "dialog_delete_mod" then - retval = retval .. modmgr.dialog_delete_mod() - end - - if name == "dialog_configure_world" then - retval = retval .. modmgr.dialog_configure_world() - end - - return retval -end diff --git a/builtin/modstore.lua b/builtin/modstore.lua deleted file mode 100644 index 2c9e69069..000000000 --- a/builtin/modstore.lua +++ /dev/null @@ -1,276 +0,0 @@ ---Minetest ---Copyright (C) 2013 sapier --- ---This program is free software; you can redistribute it and/or modify ---it under the terms of the GNU Lesser General Public License as published by ---the Free Software Foundation; either version 2.1 of the License, or ---(at your option) any later version. --- ---This program is distributed in the hope that it will be useful, ---but WITHOUT ANY WARRANTY; without even the implied warranty of ---MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ---GNU Lesser General Public License for more details. --- ---You should have received a copy of the GNU Lesser General Public License along ---with this program; if not, write to the Free Software Foundation, Inc., ---51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - --------------------------------------------------------------------------------- - ---modstore implementation -modstore = {} - --------------------------------------------------------------------------------- -function modstore.init() - modstore.tabnames = {} - - table.insert(modstore.tabnames,"dialog_modstore_unsorted") - table.insert(modstore.tabnames,"dialog_modstore_search") - - modstore.modsperpage = 5 - - modstore.basetexturedir = engine.get_gamepath() .. DIR_DELIM .. ".." .. - DIR_DELIM .. "textures" .. DIR_DELIM .. "base" .. - DIR_DELIM .. "pack" .. DIR_DELIM - modstore.update_modlist() - - modstore.current_list = nil - - modstore.details_cache = {} -end --------------------------------------------------------------------------------- -function modstore.nametoindex(name) - - for i=1,#modstore.tabnames,1 do - if modstore.tabnames[i] == name then - return i - end - end - - return 1 -end - --------------------------------------------------------------------------------- -function modstore.gettab(tabname) - local retval = "" - - local is_modstore_tab = false - - if tabname == "dialog_modstore_unsorted" then - retval = modstore.getmodlist(modstore.modlist_unsorted) - is_modstore_tab = true - end - - if tabname == "dialog_modstore_search" then - - - is_modstore_tab = true - end - - if is_modstore_tab then - return modstore.tabheader(tabname) .. retval - end - - if tabname == "modstore_mod_installed" then - return "size[6,2]label[0.25,0.25;Mod: " .. modstore.lastmodtitle .. - " installed successfully]" .. - "button[2.5,1.5;1,0.5;btn_confirm_mod_successfull;ok]" - end - - return "" -end - --------------------------------------------------------------------------------- -function modstore.tabheader(tabname) - local retval = "size[12,9.25]" - retval = retval .. "tabheader[-0.3,-0.99;modstore_tab;" .. - "Unsorted,Search;" .. - modstore.nametoindex(tabname) .. ";true;false]" - - return retval -end - --------------------------------------------------------------------------------- -function modstore.handle_buttons(current_tab,fields) - - modstore.lastmodtitle = "" - - if fields["modstore_tab"] then - local index = tonumber(fields["modstore_tab"]) - - if index > 0 and - index <= #modstore.tabnames then - return { - current_tab = modstore.tabnames[index], - is_dialog = true, - show_buttons = false - } - end - - modstore.modlist_page = 0 - end - - if fields["btn_modstore_page_up"] then - if modstore.current_list ~= nil and modstore.current_list.page > 0 then - modstore.current_list.page = modstore.current_list.page - 1 - end - end - - if fields["btn_modstore_page_down"] then - if modstore.current_list ~= nil and - modstore.current_list.page #list.data) then - endmod = #list.data - end - - for i=(list.page * modstore.modsperpage) +1, endmod, 1 do - --getmoddetails - local details = modstore.get_details(list.data[i].id) - - if details ~= nil then - local screenshot_ypos = (i-1 - (list.page * modstore.modsperpage))*1.9 +0.2 - - retval = retval .. "box[0," .. screenshot_ypos .. ";11.4,1.75;FFFFFF]" - - --screenshot - if details.screenshot_url ~= nil and - details.screenshot_url ~= "" then - if list.data[i].texturename == nil then - print("downloading screenshot: " .. details.screenshot_url) - local filename = os.tempfolder() - - if engine.download_file(details.screenshot_url,filename) then - list.data[i].texturename = filename - end - end - end - - if list.data[i].texturename == nil then - list.data[i].texturename = modstore.basetexturedir .. "no_screenshot.png" - end - - retval = retval .. "image[0,".. screenshot_ypos .. ";3,2;" .. - list.data[i].texturename .. "]" - - --title + author - retval = retval .."label[2.75," .. screenshot_ypos .. ";" .. - fs_escape_string(details.title) .. " (" .. details.author .. ")]" - - --description - local descriptiony = screenshot_ypos + 0.5 - retval = retval .. "textarea[3," .. descriptiony .. ";6.5,1.6;;" .. - fs_escape_string(details.description) .. ";]" - --rating - local ratingy = screenshot_ypos + 0.6 - retval = retval .."label[10.1," .. ratingy .. ";Rating: " .. details.rating .."]" - - --install button - local buttony = screenshot_ypos + 1.2 - local buttonnumber = (i - (list.page * modstore.modsperpage)) - retval = retval .."button[9.6," .. buttony .. ";2,0.5;btn_install_mod_" .. buttonnumber .. ";" - - if modmgr.mod_exists(details.basename) then - retval = retval .. "re-Install]" - else - retval = retval .. "Install]" - end - end - end - - modstore.current_list = list - - return retval -end - --------------------------------------------------------------------------------- -function modstore.get_details(modid) - - if modstore.details_cache[modid] ~= nil then - return modstore.details_cache[modid] - end - - local retval = engine.get_modstore_details(tostring(modid)) - modstore.details_cache[modid] = retval - return retval -end - diff --git a/builtin/vector.lua b/builtin/vector.lua deleted file mode 100644 index 839f139ca..000000000 --- a/builtin/vector.lua +++ /dev/null @@ -1,141 +0,0 @@ - -vector = {} - -function vector.new(a, b, c) - v = {x=0, y=0, z=0} - if type(a) == "table" then - v = {x=a.x, y=a.y, z=a.z} - elseif a and b and c then - v = {x=a, y=b, z=c} - end - setmetatable(v, { - __add = vector.add, - __sub = vector.subtract, - __mul = vector.multiply, - __div = vector.divide, - __umn = function(v) return vector.multiply(v, -1) end, - __len = vector.length, - __eq = vector.equals, - }) - return v -end - -function vector.equals(a, b) - return a.x == b.x and - a.y == b.y and - a.z == b.z -end - -function vector.length(v) - return math.hypot(v.x, math.hypot(v.y, v.z)) -end - -function vector.normalize(v) - local len = vector.length(v) - if len == 0 then - return vector.new() - else - return vector.divide(v, len) - end -end - -function vector.round(v) - return { - x = math.floor(v.x + 0.5), - y = math.floor(v.y + 0.5), - z = math.floor(v.z + 0.5) - } -end - -function vector.distance(a, b) - local x = a.x - b.x - local y = a.y - b.y - local z = a.z - b.z - return math.hypot(x, math.hypot(y, z)) -end - -function vector.direction(pos1, pos2) - local x_raw = pos2.x - pos1.x - local y_raw = pos2.y - pos1.y - local z_raw = pos2.z - pos1.z - local x_abs = math.abs(x_raw) - local y_abs = math.abs(y_raw) - local z_abs = math.abs(z_raw) - if x_abs >= y_abs and - x_abs >= z_abs then - y_raw = y_raw * (1 / x_abs) - z_raw = z_raw * (1 / x_abs) - x_raw = x_raw / x_abs - end - if y_abs >= x_abs and - y_abs >= z_abs then - x_raw = x_raw * (1 / y_abs) - z_raw = z_raw * (1 / y_abs) - y_raw = y_raw / y_abs - end - if z_abs >= y_abs and - z_abs >= x_abs then - x_raw = x_raw * (1 / z_abs) - y_raw = y_raw * (1 / z_abs) - z_raw = z_raw / z_abs - end - return {x=x_raw, y=y_raw, z=z_raw} -end - - -function vector.add(a, b) - if type(b) == "table" then - return vector.new( - a.x + b.x, - a.y + b.y, - a.z + b.z) - else - return vector.new( - a.x + b, - a.y + b, - a.z + b) - end -end - -function vector.subtract(a, b) - if type(b) == "table" then - return vector.new( - a.x - b.x, - a.y - b.y, - a.z - b.z) - else - return vector.new( - a.x - b, - a.y - b, - a.z - b) - end -end - -function vector.multiply(a, b) - if type(b) == "table" then - return vector.new( - a.x * b.x, - a.y * b.y, - a.z * b.z) - else - return vector.new( - a.x * b, - a.y * b, - a.z * b) - end -end - -function vector.divide(a, b) - if type(b) == "table" then - return vector.new( - a.x / b.x, - a.y / b.y, - a.z / b.z) - else - return vector.new( - a.x / b, - a.y / b, - a.z / b) - end -end - diff --git a/builtin/voxelarea.lua b/builtin/voxelarea.lua index 93bbf73a8..dd9af7910 100644 --- a/builtin/voxelarea.lua +++ b/builtin/voxelarea.lua @@ -44,22 +44,6 @@ function VoxelArea:indexp(p) return math.floor(i) end -function VoxelArea:position(i) - local p = {} - - i = i - 1 - - p.z = math.floor(i / self.zstride) + self.MinEdge.z - i = i % self.zstride - - p.y = math.floor(i / self.ystride) + self.MinEdge.y - i = i % self.ystride - - p.x = math.floor(i) + self.MinEdge.x - - return p -end - function VoxelArea:contains(x, y, z) return (x >= self.MinEdge.x) and (x <= self.MaxEdge.x) and (y >= self.MinEdge.y) and (y <= self.MaxEdge.y) and @@ -76,28 +60,3 @@ function VoxelArea:containsi(i) return (i >= 1) and (i <= self:getVolume()) end -function VoxelArea:iter(minx, miny, minz, maxx, maxy, maxz) - local i = self:index(minx, miny, minz) - 1 - local last = self:index(maxx, maxy, maxz) - local ystride = self.ystride - local zstride = self.zstride - local yoff = (last+1) % ystride - local zoff = (last+1) % zstride - local ystridediff = (i - last) % ystride - local zstridediff = (i - last) % zstride - return function() - i = i + 1 - if i % zstride == zoff then - i = i + zstridediff - elseif i % ystride == yoff then - i = i + ystridediff - end - if i <= last then - return i - end - end -end - -function VoxelArea:iterp(minp, maxp) - return self:iter(minp.x, minp.y, minp.z, maxp.x, maxp.y, maxp.z) -end diff --git a/client/shaders/bumpmaps_liquids/base.txt b/client/shaders/bumpmaps_liquids/base.txt deleted file mode 100644 index 1c2647118..000000000 --- a/client/shaders/bumpmaps_liquids/base.txt +++ /dev/null @@ -1 +0,0 @@ -trans_alphach diff --git a/client/shaders/bumpmaps_liquids/opengl_fragment.glsl b/client/shaders/bumpmaps_liquids/opengl_fragment.glsl deleted file mode 100644 index ea618384f..000000000 --- a/client/shaders/bumpmaps_liquids/opengl_fragment.glsl +++ /dev/null @@ -1,47 +0,0 @@ - -uniform sampler2D myTexture; -uniform sampler2D normalTexture; - -uniform vec4 skyBgColor; -uniform float fogDistance; - -varying vec3 vPosition; - -varying vec3 viewVec; - -void main (void) -{ - vec4 col = texture2D(myTexture, vec2(gl_TexCoord[0])); - float alpha = col.a; - vec2 uv = gl_TexCoord[0].st; - vec4 base = texture2D(myTexture, uv); - vec4 final_color = vec4(0.2, 0.2, 0.2, 1.0) * base; - vec3 vVec = normalize(viewVec); - vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0); - vec3 R = reflect(-vVec, bump); - vec3 lVec = normalize(vec3(0.0, -0.4, 0.5)); - float diffuse = max(dot(lVec, bump), 0.0); - - vec3 color = diffuse * texture2D(myTexture, gl_TexCoord[0].st).rgb; - - - float specular = pow(clamp(dot(R, lVec), 0.0, 1.0),1.0); - vec4 vSpecular = 0.2*specular * diffuse; - color += vSpecular; - - - col = vec4(color.r, color.g, color.b, alpha); - col *= gl_Color; - col = col * col; // SRGB -> Linear - col *= 1.8; - col.r = 1.0 - exp(1.0 - col.r) / exp(1.0); - col.g = 1.0 - exp(1.0 - col.g) / exp(1.0); - col.b = 1.0 - exp(1.0 - col.b) / exp(1.0); - col = sqrt(col); // Linear -> SRGB - if(fogDistance != 0.0){ - float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0)); - alpha = mix(alpha, 0.0, d); - } - - gl_FragColor = vec4(col.r, col.g, col.b, alpha); -} diff --git a/client/shaders/bumpmaps_liquids/opengl_vertex.glsl b/client/shaders/bumpmaps_liquids/opengl_vertex.glsl deleted file mode 100644 index 99c208bdd..000000000 --- a/client/shaders/bumpmaps_liquids/opengl_vertex.glsl +++ /dev/null @@ -1,98 +0,0 @@ - -uniform mat4 mWorldViewProj; -uniform mat4 mInvWorld; -uniform mat4 mTransWorld; -uniform float dayNightRatio; - -varying vec3 vPosition; -varying vec3 viewVec; - -void main(void) -{ - gl_Position = mWorldViewProj * gl_Vertex; - - vPosition = (mWorldViewProj * gl_Vertex).xyz; - - vec3 tangent; - vec3 binormal; - - vec3 c1 = cross( gl_Normal, vec3(0.0, 0.0, 1.0) ); - vec3 c2 = cross( gl_Normal, vec3(0.0, 1.0, 0.0) ); - - if( length(c1)>length(c2) ) - { - tangent = c1; - } - else - { - tangent = c2; - } - - tangent = normalize(tangent); - -//binormal = cross(gl_Normal, tangent); -//binormal = normalize(binormal); - - vec4 color; - //color = vec4(1.0, 1.0, 1.0, 1.0); - - float day = gl_Color.r; - float night = gl_Color.g; - float light_source = gl_Color.b; - - /*color.r = mix(night, day, dayNightRatio); - color.g = color.r; - color.b = color.r;*/ - - float rg = mix(night, day, dayNightRatio); - rg += light_source * 1.5; // Make light sources brighter - float b = rg; - - // Moonlight is blue - b += (day - night) / 13.0; - rg -= (day - night) / 13.0; - - // Emphase blue a bit in darker places - // See C++ implementation in mapblock_mesh.cpp finalColorBlend() - b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025); - - // Artificial light is yellow-ish - // See C++ implementation in mapblock_mesh.cpp finalColorBlend() - rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065); - - color.r = rg; - color.g = rg; - color.b = b; - - // Make sides and bottom darker than the top - color = color * color; // SRGB -> Linear - if(gl_Normal.y <= 0.5) - color *= 0.6; - //color *= 0.7; - color = sqrt(color); // Linear -> SRGB - - color.a = gl_Color.a; - - gl_FrontColor = gl_BackColor = color; - - gl_TexCoord[0] = gl_MultiTexCoord0; - - vec3 n1 = normalize(gl_NormalMatrix * gl_Normal); - vec4 tangent1 = vec4(tangent.x, tangent.y, tangent.z, 0); - //vec3 t1 = normalize(gl_NormalMatrix * tangent1); - //vec3 b1 = cross(n1, t1); - - vec3 v; - vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex); - vec3 vVec = -vVertex; - //v.x = dot(vVec, t1); - //v.y = dot(vVec, b1); - //v.z = dot(vVec, n1); - //viewVec = vVec; - viewVec = normalize(vec3(0.0, -0.4, 0.5)); - //Vector representing the 0th texture coordinate passed to fragment shader -//gl_TexCoord[0] = vec2(gl_MultiTexCoord0); - -// Transform the current vertex -//gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; -} diff --git a/client/shaders/bumpmaps_solids/base.txt b/client/shaders/bumpmaps_solids/base.txt deleted file mode 100644 index 080df30dd..000000000 --- a/client/shaders/bumpmaps_solids/base.txt +++ /dev/null @@ -1 +0,0 @@ -trans_alphach_ref diff --git a/client/shaders/bumpmaps_solids/opengl_fragment.glsl b/client/shaders/bumpmaps_solids/opengl_fragment.glsl deleted file mode 100644 index 6203592f7..000000000 --- a/client/shaders/bumpmaps_solids/opengl_fragment.glsl +++ /dev/null @@ -1,46 +0,0 @@ - -uniform sampler2D myTexture; -uniform sampler2D normalTexture; - -uniform vec4 skyBgColor; -uniform float fogDistance; - -varying vec3 vPosition; - -varying vec3 viewVec; - -void main (void) -{ - vec4 col = texture2D(myTexture, vec2(gl_TexCoord[0])); - float alpha = col.a; - vec2 uv = gl_TexCoord[0].st; - vec4 base = texture2D(myTexture, uv); - vec4 final_color = vec4(0.2, 0.2, 0.2, 1.0) * base; - vec3 vVec = normalize(viewVec); - vec3 bump = normalize(texture2D(normalTexture, uv).xyz * 2.0 - 1.0); - vec3 R = reflect(-vVec, bump); - vec3 lVec = normalize(vec3(0.0, -0.4, 0.5)); - float diffuse = max(dot(lVec, bump), 0.0); - - vec3 color = diffuse * texture2D(myTexture, gl_TexCoord[0].st).rgb; - - - float specular = pow(clamp(dot(R, lVec), 0.0, 1.0),1.0); - vec4 vSpecular = 0.2*specular * diffuse; - color += vSpecular; - - - col = vec4(color.r, color.g, color.b, alpha); - col *= gl_Color; - col = col * col; // SRGB -> Linear - col *= 1.8; - col.r = 1.0 - exp(1.0 - col.r) / exp(1.0); - col.g = 1.0 - exp(1.0 - col.g) / exp(1.0); - col.b = 1.0 - exp(1.0 - col.b) / exp(1.0); - col = sqrt(col); // Linear -> SRGB - if(fogDistance != 0.0){ - float d = max(0.0, min(vPosition.z / fogDistance * 1.5 - 0.6, 1.0)); - col = mix(col, skyBgColor, d); - } - gl_FragColor = vec4(col.r, col.g, col.b, alpha); -} diff --git a/client/shaders/bumpmaps_solids/opengl_vertex.glsl b/client/shaders/bumpmaps_solids/opengl_vertex.glsl deleted file mode 100644 index 99c208bdd..000000000 --- a/client/shaders/bumpmaps_solids/opengl_vertex.glsl +++ /dev/null @@ -1,98 +0,0 @@ - -uniform mat4 mWorldViewProj; -uniform mat4 mInvWorld; -uniform mat4 mTransWorld; -uniform float dayNightRatio; - -varying vec3 vPosition; -varying vec3 viewVec; - -void main(void) -{ - gl_Position = mWorldViewProj * gl_Vertex; - - vPosition = (mWorldViewProj * gl_Vertex).xyz; - - vec3 tangent; - vec3 binormal; - - vec3 c1 = cross( gl_Normal, vec3(0.0, 0.0, 1.0) ); - vec3 c2 = cross( gl_Normal, vec3(0.0, 1.0, 0.0) ); - - if( length(c1)>length(c2) ) - { - tangent = c1; - } - else - { - tangent = c2; - } - - tangent = normalize(tangent); - -//binormal = cross(gl_Normal, tangent); -//binormal = normalize(binormal); - - vec4 color; - //color = vec4(1.0, 1.0, 1.0, 1.0); - - float day = gl_Color.r; - float night = gl_Color.g; - float light_source = gl_Color.b; - - /*color.r = mix(night, day, dayNightRatio); - color.g = color.r; - color.b = color.r;*/ - - float rg = mix(night, day, dayNightRatio); - rg += light_source * 1.5; // Make light sources brighter - float b = rg; - - // Moonlight is blue - b += (day - night) / 13.0; - rg -= (day - night) / 13.0; - - // Emphase blue a bit in darker places - // See C++ implementation in mapblock_mesh.cpp finalColorBlend() - b += max(0.0, (1.0 - abs(b - 0.13)/0.17) * 0.025); - - // Artificial light is yellow-ish - // See C++ implementation in mapblock_mesh.cpp finalColorBlend() - rg += max(0.0, (1.0 - abs(rg - 0.85)/0.15) * 0.065); - - color.r = rg; - color.g = rg; - color.b = b; - - // Make sides and bottom darker than the top - color = color * color; // SRGB -> Linear - if(gl_Normal.y <= 0.5) - color *= 0.6; - //color *= 0.7; - color = sqrt(color); // Linear -> SRGB - - color.a = gl_Color.a; - - gl_FrontColor = gl_BackColor = color; - - gl_TexCoord[0] = gl_MultiTexCoord0; - - vec3 n1 = normalize(gl_NormalMatrix * gl_Normal); - vec4 tangent1 = vec4(tangent.x, tangent.y, tangent.z, 0); - //vec3 t1 = normalize(gl_NormalMatrix * tangent1); - //vec3 b1 = cross(n1, t1); - - vec3 v; - vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex); - vec3 vVec = -vVertex; - //v.x = dot(vVec, t1); - //v.y = dot(vVec, b1); - //v.z = dot(vVec, n1); - //viewVec = vVec; - viewVec = normalize(vec3(0.0, -0.4, 0.5)); - //Vector representing the 0th texture coordinate passed to fragment shader -//gl_TexCoord[0] = vec2(gl_MultiTexCoord0); - -// Transform the current vertex -//gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; -} diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 74b3d3ba5..c39098a7a 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -507,7 +507,8 @@ Representations of simple things -------------------------------- Position/vector: {x=num, y=num, z=num} -For helper functions see "Vector helpers". +Currently the API does not provide any helper functions for addition, +subtraction and whatever; you can define those that you need yourself. pointed_thing: {type="nothing"} @@ -882,15 +883,6 @@ background[,;,;] ^ Position and size units are inventory slots ^ Example for formspec 8x4 in 16x resolution: image shall be sized 8*16px x 4*16px -pwdfield[,;,;;