Add debug_mode setting + cleanup
This commit is contained in:
parent
d8e17687e1
commit
b48c7862dc
25
init.lua
25
init.lua
|
@ -20,6 +20,7 @@ end
|
||||||
|
|
||||||
i3 = {
|
i3 = {
|
||||||
settings = {
|
settings = {
|
||||||
|
debug_mode = false,
|
||||||
max_favs = 6,
|
max_favs = 6,
|
||||||
min_fs_version = 4,
|
min_fs_version = 4,
|
||||||
item_btn_size = 1.1,
|
item_btn_size = 1.1,
|
||||||
|
@ -66,13 +67,6 @@ i3 = {
|
||||||
model_alias = lf"/src/model_aliases.lua",
|
model_alias = lf"/src/model_aliases.lua",
|
||||||
progressive = lf"/src/progressive.lua",
|
progressive = lf"/src/progressive.lua",
|
||||||
styles = lf"/src/styles.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
|
-- Caches
|
||||||
|
@ -121,10 +115,9 @@ local function get_formspec_version(info)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function outdated(name)
|
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(
|
core.show_formspec(name, "i3_outdated",
|
||||||
"Your Minetest client is outdated.\nGet the latest version on minetest.net to play the game.")
|
("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."))
|
||||||
core.show_formspec(name, "i3_outdated", fs)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if rawget(_G, "armor") then
|
if rawget(_G, "armor") then
|
||||||
|
@ -254,7 +247,9 @@ if i3.settings.progressive_mode then
|
||||||
i3.files.progressive()
|
i3.files.progressive()
|
||||||
end
|
end
|
||||||
|
|
||||||
--i3.files.tests.tabs()
|
if i3.settings.debug_mode then
|
||||||
--i3.files.tests.operators()
|
lf("/tests/test_tabs.lua")()
|
||||||
--i3.files.tests.compression()
|
lf("/tests/test_operators.lua")()
|
||||||
--i3.files.tests.custom_recipes()
|
lf("/tests/test_compression.lua")()
|
||||||
|
lf("/tests/test_custom_recipes.lua")()
|
||||||
|
end
|
||||||
|
|
|
@ -229,6 +229,9 @@ i3.new_tab("inventory", {
|
||||||
})
|
})
|
||||||
|
|
||||||
data.scrbar_inv += 1000
|
data.scrbar_inv += 1000
|
||||||
|
|
||||||
|
elseif fields.hide_debug_grid then
|
||||||
|
data.hide_debug_grid = not data.hide_debug_grid
|
||||||
end
|
end
|
||||||
|
|
||||||
return set_fs(player)
|
return set_fs(player)
|
||||||
|
@ -376,13 +379,12 @@ local function rcp_fields(player, data, fields)
|
||||||
data.scrbar_usg = 1
|
data.scrbar_usg = 1
|
||||||
|
|
||||||
elseif fields.fav then
|
elseif fields.fav then
|
||||||
local fav, i = is_fav(data.favs, data.query_item)
|
local fav = is_fav(data)
|
||||||
local total = #data.favs
|
|
||||||
|
|
||||||
if total < i3.settings.max_favs and not fav then
|
if #data.favs < i3.settings.max_favs and not fav then
|
||||||
data.favs[total + 1] = data.query_item
|
insert(data.favs, data.query_item)
|
||||||
elseif fav then
|
elseif fav then
|
||||||
remove(data.favs, i)
|
remove(data.favs, fav)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif fields.export_rcp or fields.export_usg then
|
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()
|
local name = player:get_player_name()
|
||||||
|
|
||||||
if formname == "i3_outdated" then
|
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
|
elseif formname ~= "" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
|
@ -289,17 +289,12 @@ local function compressible(item, data)
|
||||||
return compression_active(data) and i3.compress_groups[item]
|
return compression_active(data) and i3.compress_groups[item]
|
||||||
end
|
end
|
||||||
|
|
||||||
local function is_fav(favs, query_item)
|
local function is_fav(data)
|
||||||
local fav, i
|
for i = 1, #data.favs do
|
||||||
for j = 1, #favs do
|
if data.favs[i] == data.query_item then
|
||||||
if favs[j] == query_item then
|
return i
|
||||||
fav = true
|
|
||||||
i = j
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return fav, i
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function sort_by_category(data)
|
local function sort_by_category(data)
|
||||||
|
|
22
src/gui.lua
22
src/gui.lua
|
@ -7,9 +7,9 @@ local PNG, styles, fs_elements, colors = i3.files.styles()
|
||||||
local sprintf = string.format
|
local sprintf = string.format
|
||||||
local VoxelArea, VoxelManip = VoxelArea, VoxelManip
|
local VoxelArea, VoxelManip = VoxelArea, VoxelManip
|
||||||
|
|
||||||
IMPORT("clr", "ESC", "check_privs")
|
|
||||||
IMPORT("find", "match", "sub", "upper")
|
IMPORT("find", "match", "sub", "upper")
|
||||||
IMPORT("vec_new", "vec_sub", "vec_round")
|
IMPORT("vec_new", "vec_sub", "vec_round")
|
||||||
|
IMPORT("clr", "ESC", "msg", "check_privs")
|
||||||
IMPORT("min", "max", "floor", "ceil", "round")
|
IMPORT("min", "max", "floor", "ceil", "round")
|
||||||
IMPORT("reg_items", "reg_tools", "reg_entities")
|
IMPORT("reg_items", "reg_tools", "reg_entities")
|
||||||
IMPORT("get_bag_description", "get_detached_inv")
|
IMPORT("get_bag_description", "get_detached_inv")
|
||||||
|
@ -1114,7 +1114,7 @@ local function get_model_fs(fs, data, def, model_alias)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_header(fs, data)
|
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 nfavs = #data.favs
|
||||||
local max_favs = i3.settings.max_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
|
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
|
end
|
||||||
|
|
||||||
local function get_debug_grid(data, fs, full_height)
|
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]")
|
fs("style_type[label;font_size=8;noclip=true]")
|
||||||
local spacing, i = 0.2, 1
|
local spacing, i = 0.2, 1
|
||||||
|
|
||||||
|
@ -1456,7 +1460,7 @@ local function get_debug_grid(data, fs, full_height)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function make_fs(player, data)
|
local function make_fs(player, data)
|
||||||
--local start = os.clock()
|
local start = i3.settings.debug_mode and os.clock() or nil
|
||||||
|
|
||||||
local fs = setmetatable({}, {
|
local fs = setmetatable({}, {
|
||||||
__call = function(t, ...)
|
__call = function(t, ...)
|
||||||
|
@ -1474,13 +1478,13 @@ local function make_fs(player, data)
|
||||||
data.inv_width = 10.23
|
data.inv_width = 10.23
|
||||||
local full_height = 12
|
local full_height = 12
|
||||||
|
|
||||||
local tab = i3.tabs[data.tab]
|
|
||||||
|
|
||||||
fs(fmt("formspec_version[%u]size[%f,%f]no_prepend[]bgcolor[#0000]",
|
fs(fmt("formspec_version[%u]size[%f,%f]no_prepend[]bgcolor[#0000]",
|
||||||
i3.settings.min_fs_version, data.inv_width + 8, full_height), styles)
|
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)
|
fs("bg9", 0, 0, data.inv_width, full_height, PNG.bg_full, 10)
|
||||||
|
|
||||||
|
local tab = i3.tabs[data.tab]
|
||||||
|
|
||||||
if tab then
|
if tab then
|
||||||
tab.formspec(player, data, fs)
|
tab.formspec(player, data, fs)
|
||||||
end
|
end
|
||||||
|
@ -1495,9 +1499,11 @@ local function make_fs(player, data)
|
||||||
get_tabs_fs(fs, player, data, full_height)
|
get_tabs_fs(fs, player, data, full_height)
|
||||||
end
|
end
|
||||||
|
|
||||||
--get_debug_grid(data, fs, full_height)
|
if i3.settings.debug_mode then
|
||||||
--print("make_fs()", fmt("%.2f ms", (os.clock() - start) * 1000))
|
get_debug_grid(data, fs, full_height)
|
||||||
--print("#fs elements", #fs)
|
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)
|
return concat(fs)
|
||||||
end
|
end
|
||||||
|
|
Ŝarĝante…
Reference in New Issue