From b711f8f1957978db2d353a5e4bcacfe79abbdc4b Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Sat, 12 Nov 2022 19:40:06 +0100 Subject: [PATCH] API doc clarification --- API.md | 16 ++++++++++++---- init.lua | 2 +- src/gui.lua | 2 +- tests/test_tabs.lua | 3 ++- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/API.md b/API.md index 017756e..6d22301 100644 --- a/API.md +++ b/API.md @@ -12,23 +12,31 @@ Custom tabs can be added to the `i3` inventory as follow (example): ```Lua i3.new_tab("stuff", { description = "Stuff", - image = "image.png", -- Optional, adds an image next to the tab description + image = "image.png", -- Optional, add an image next to the tab description - -- Determine if the tab is visible by a player, `false` or `nil` hide the tab + -- + -- The functions below are all optional + -- + + -- Determine if the tab is visible by a player, return false to hide the tab access = function(player, data) local name = player:get_player_name() return name == "singleplayer" end, formspec = function(player, data, fs) - fs"label[3,1;This is just a test]" + fs("label", 3, 1, "Just a test") + fs"label[3,2;Lorem Ipsum]" + -- No need to return anything end, -- Events handling happens here fields = function(player, data, fields) if fields.mybutton then - do_things() + -- Do things end + + i3.set_fs(player) -- Update the formspec, mandatory end, }) ``` diff --git a/init.lua b/init.lua index d11c718..4d5ad0d 100644 --- a/init.lua +++ b/init.lua @@ -20,7 +20,7 @@ local function lf(path) end i3 = { - version = 1121, + version = 1122, data = core.deserialize(storage:get_string"data") or {}, settings = { diff --git a/src/gui.lua b/src/gui.lua index a1d175c..7181ad3 100644 --- a/src/gui.lua +++ b/src/gui.lua @@ -1695,7 +1695,7 @@ local function make_fs(player, data) local tab = i3.tabs[data.tab] - if tab then + if tab and tab.formspec then tab.formspec(player, data, fs) end diff --git a/tests/test_tabs.lua b/tests/test_tabs.lua index 70e9847..376bfd9 100644 --- a/tests/test_tabs.lua +++ b/tests/test_tabs.lua @@ -3,7 +3,8 @@ i3.new_tab("test1", { image = "i3_heart.png", formspec = function(player, data, fs) - fs("label[3,1;Test 1]") + fs("label", 3, 1, "Just a test") + fs"label[3,2;Lorem Ipsum]" end, })