mirror of
https://github.com/minetest-mods/i3.git
synced 2024-11-13 06:10:21 +01:00
API doc clarification
This commit is contained in:
parent
00a258afea
commit
b711f8f195
16
API.md
16
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,
|
||||
})
|
||||
```
|
||||
|
|
2
init.lua
2
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 = {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user