diff --git a/init.lua b/init.lua index a7582aa..8dd0ea9 100644 --- a/init.lua +++ b/init.lua @@ -20,6 +20,7 @@ end i3 = { settings = { + debug_mode = false, max_favs = 6, min_fs_version = 4, item_btn_size = 1.1, @@ -66,13 +67,6 @@ i3 = { model_alias = lf"/src/model_aliases.lua", progressive = lf"/src/progressive.lua", styles = lf"/src/styles.lua", - - tests = { - tabs = lf"/tests/test_tabs.lua", - operators = lf"/tests/test_operators.lua", - compression = lf"/tests/test_compression.lua", - custom_recipes = lf"/tests/test_custom_recipes.lua", - } }, -- Caches @@ -121,10 +115,9 @@ local function get_formspec_version(info) end local function outdated(name) - local fs = ("size[6.3,1.3]image[0,0;1,1;i3_book.png]label[1,0;%s]button_exit[2.6,0.8;1,1;;OK]"):format( - "Your Minetest client is outdated.\nGet the latest version on minetest.net to play the game.") - - core.show_formspec(name, "i3_outdated", fs) + core.show_formspec(name, "i3_outdated", + ("size[6.5,1.3]image[0,0;1,1;i3_book.png]label[1,0;%s]button_exit[2.6,0.8;1,1;;OK]"):format( + "Your Minetest client is outdated.\nGet the latest version on minetest.net to play the game.")) end if rawget(_G, "armor") then @@ -254,7 +247,9 @@ if i3.settings.progressive_mode then i3.files.progressive() end ---i3.files.tests.tabs() ---i3.files.tests.operators() ---i3.files.tests.compression() ---i3.files.tests.custom_recipes() +if i3.settings.debug_mode then + lf("/tests/test_tabs.lua")() + lf("/tests/test_operators.lua")() + lf("/tests/test_compression.lua")() + lf("/tests/test_custom_recipes.lua")() +end diff --git a/src/callbacks.lua b/src/callbacks.lua index 0cb3152..de4e632 100644 --- a/src/callbacks.lua +++ b/src/callbacks.lua @@ -229,6 +229,9 @@ i3.new_tab("inventory", { }) data.scrbar_inv += 1000 + + elseif fields.hide_debug_grid then + data.hide_debug_grid = not data.hide_debug_grid end return set_fs(player) @@ -376,13 +379,12 @@ local function rcp_fields(player, data, fields) data.scrbar_usg = 1 elseif fields.fav then - local fav, i = is_fav(data.favs, data.query_item) - local total = #data.favs + local fav = is_fav(data) - if total < i3.settings.max_favs and not fav then - data.favs[total + 1] = data.query_item + if #data.favs < i3.settings.max_favs and not fav then + insert(data.favs, data.query_item) elseif fav then - remove(data.favs, i) + remove(data.favs, fav) end elseif fields.export_rcp or fields.export_usg then @@ -423,7 +425,8 @@ core.register_on_player_receive_fields(function(player, formname, fields) local name = player:get_player_name() if formname == "i3_outdated" then - return false, core.kick_player(name, S"Come back when your client is up-to-date.") + return false, core.kick_player(name, + S"Come back when your Minetest client is up-to-date (www.minetest.net).") elseif formname ~= "" then return false end diff --git a/src/common.lua b/src/common.lua index dd40517..a180b0a 100644 --- a/src/common.lua +++ b/src/common.lua @@ -289,17 +289,12 @@ local function compressible(item, data) return compression_active(data) and i3.compress_groups[item] end -local function is_fav(favs, query_item) - local fav, i - for j = 1, #favs do - if favs[j] == query_item then - fav = true - i = j - break +local function is_fav(data) + for i = 1, #data.favs do + if data.favs[i] == data.query_item then + return i end end - - return fav, i end local function sort_by_category(data) diff --git a/src/gui.lua b/src/gui.lua index cda50ac..9c46842 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -7,9 +7,9 @@ local PNG, styles, fs_elements, colors = i3.files.styles() local sprintf = string.format local VoxelArea, VoxelManip = VoxelArea, VoxelManip -IMPORT("clr", "ESC", "check_privs") IMPORT("find", "match", "sub", "upper") IMPORT("vec_new", "vec_sub", "vec_round") +IMPORT("clr", "ESC", "msg", "check_privs") IMPORT("min", "max", "floor", "ceil", "round") IMPORT("reg_items", "reg_tools", "reg_entities") IMPORT("get_bag_description", "get_detached_inv") @@ -1114,7 +1114,7 @@ local function get_model_fs(fs, data, def, model_alias) end local function get_header(fs, data) - local fav = is_fav(data.favs, data.query_item) + local fav = is_fav(data) local nfavs = #data.favs local max_favs = i3.settings.max_favs local star_x, star_y, size = data.inv_width + 0.3, data.yoffset + 0.2, 0.4 @@ -1433,6 +1433,10 @@ local function get_tabs_fs(fs, player, data, full_height) end local function get_debug_grid(data, fs, full_height) + fs"style[hide_debug_grid;noclip=true]" + fs("button", -2, full_height - 1, 2, 1, "hide_debug_grid", "Toggle grid") + if data.hide_debug_grid then return end + fs("style_type[label;font_size=8;noclip=true]") local spacing, i = 0.2, 1 @@ -1456,7 +1460,7 @@ local function get_debug_grid(data, fs, full_height) end local function make_fs(player, data) - --local start = os.clock() + local start = i3.settings.debug_mode and os.clock() or nil local fs = setmetatable({}, { __call = function(t, ...) @@ -1474,13 +1478,13 @@ local function make_fs(player, data) data.inv_width = 10.23 local full_height = 12 - local tab = i3.tabs[data.tab] - fs(fmt("formspec_version[%u]size[%f,%f]no_prepend[]bgcolor[#0000]", i3.settings.min_fs_version, data.inv_width + 8, full_height), styles) fs("bg9", 0, 0, data.inv_width, full_height, PNG.bg_full, 10) + local tab = i3.tabs[data.tab] + if tab then tab.formspec(player, data, fs) end @@ -1495,9 +1499,11 @@ local function make_fs(player, data) get_tabs_fs(fs, player, data, full_height) end - --get_debug_grid(data, fs, full_height) - --print("make_fs()", fmt("%.2f ms", (os.clock() - start) * 1000)) - --print("#fs elements", #fs) + if i3.settings.debug_mode then + get_debug_grid(data, fs, full_height) + msg(data.player_name, fmt("make_fs(): %.2f ms", (os.clock() - start) * 1000)) + msg(data.player_name, fmt("#fs elements: %u", #fs)) + end return concat(fs) end