API doc clarification

This commit is contained in:
Jean-Patrick Guerrero 2022-11-12 19:40:06 +01:00
parent 00a258afea
commit b711f8f195
4 changed files with 16 additions and 7 deletions

16
API.md
View File

@ -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,
})
```

View File

@ -20,7 +20,7 @@ local function lf(path)
end
i3 = {
version = 1121,
version = 1122,
data = core.deserialize(storage:get_string"data") or {},
settings = {

View File

@ -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

View File

@ -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,
})