Code cleaning

This commit is contained in:
Jean-Patrick Guerrero 2021-01-31 00:01:44 +01:00
parent 3dc8e038f3
commit 88c20f8a3b
3 changed files with 11 additions and 16 deletions

2
API.md
View File

@ -25,7 +25,7 @@ i3.new_tab {
end,
fields = function(player, data, fields)
i3.set_fs(player)
end,
-- Determine if the recipe panels must be hidden or not (must return a boolean)

View File

@ -2023,7 +2023,7 @@ local function make_fs(player, data)
local tab = tabs[data.current_tab]
local hide_panels = tab and tab.hide_panels and tab.hide_panels(player, data)
local show_panels = data.query_item and not hide_panels
local show_panels = data.query_item and tab and not hide_panels
fs(fmt("formspec_version[%u]size[%f,%f]no_prepend[]bgcolor[#0000]",
MIN_FORMSPEC_VERSION, data.xoffset + (show_panels and 8 or 0), full_height), styles)
@ -2843,7 +2843,10 @@ on_shutdown(function()
end)
on_receive_fields(function(player, formname, fields)
if formname ~= "" then return false end
if formname ~= "" then
return true
end
local name = player:get_player_name()
local data = pdata[name]
if not data then return end
@ -2858,7 +2861,11 @@ on_receive_fields(function(player, formname, fields)
local tab = tabs[data.current_tab]
return true, tab and tab.fields and tab.fields(player, data, fields)
if tab and tab.fields then
return true, tab.fields(player, data, fields)
end
return true, set_fs(player)
end)
core.register_on_player_hpchange(function(player, hpchange)

View File

@ -6,10 +6,6 @@ i3.new_tab {
formspec = function(player, data, fs)
fs("label[3,1;Test 1]")
end,
fields = function(player, data, fields)
i3.set_fs(player)
end,
}
i3.new_tab {
@ -20,10 +16,6 @@ i3.new_tab {
formspec = function(player, data, fs)
fs("label[3,1;Test 2]")
end,
fields = function(player, data, fields)
i3.set_fs(player)
end,
}
i3.new_tab {
@ -54,8 +46,4 @@ i3.override_tab("test2", {
formspec = function(player, data, fs)
fs("label[3,1;Override!]")
end,
fields = function(player, data, fields)
i3.set_fs(player)
end,
})