Minor changes to API
This commit is contained in:
parent
74e88acadf
commit
187b0339bd
12
API.md
12
API.md
|
@ -192,14 +192,16 @@ Add a new minitab (limited to 6).
|
|||
Example:
|
||||
|
||||
```Lua
|
||||
i3.new_minitab("Test", {
|
||||
i3.new_minitab("test", {
|
||||
description = "Test",
|
||||
|
||||
-- Whether this tab is visible or not. Optional.
|
||||
access = function(player, data)
|
||||
-- Whether this tab is visible or not. Optional.
|
||||
return player:get_player_name() == "singleplayer"
|
||||
end,
|
||||
|
||||
-- Whether a specific item is shown in the list or not.
|
||||
sorter = function(item, data)
|
||||
-- Whether a specific item is shown in the list or not.
|
||||
return item:find"wood"
|
||||
end
|
||||
})
|
||||
|
@ -212,7 +214,9 @@ i3.new_minitab("Test", {
|
|||
|
||||
#### `i3.remove_minitab(name)`
|
||||
|
||||
Remove a minitab.
|
||||
Remove a minitab by name.
|
||||
|
||||
- `name` is the name of the tab to remove.
|
||||
|
||||
#### `i3.minimap`
|
||||
|
||||
|
|
17
src/api.lua
17
src/api.lua
|
@ -440,13 +440,14 @@ function i3.new_minitab(name, def)
|
|||
return err "i3.new_minitab: definition missing"
|
||||
end
|
||||
|
||||
insert(i3.minitabs, {name = name, def = def})
|
||||
def.name = name
|
||||
insert(i3.minitabs, def)
|
||||
end
|
||||
|
||||
function i3.remove_minitab(name)
|
||||
if not true_str(name) then
|
||||
return err "i3.remove_minitab: name missing"
|
||||
elseif name == "All" then
|
||||
elseif name == "all" then
|
||||
return err "i3.remove_minitab: removing the 'All' tab is not allowed"
|
||||
end
|
||||
|
||||
|
@ -458,19 +459,25 @@ function i3.remove_minitab(name)
|
|||
end
|
||||
end
|
||||
|
||||
i3.new_minitab("All", {
|
||||
i3.new_minitab("all", {
|
||||
description = "All",
|
||||
|
||||
sorter = function()
|
||||
return true
|
||||
end
|
||||
})
|
||||
|
||||
i3.new_minitab("Nodes", {
|
||||
i3.new_minitab("nodes", {
|
||||
description = "Nodes",
|
||||
|
||||
sorter = function(item)
|
||||
return core.registered_nodes[item]
|
||||
end
|
||||
})
|
||||
|
||||
i3.new_minitab("Items", {
|
||||
i3.new_minitab("items", {
|
||||
description = "Items",
|
||||
|
||||
sorter = function(item)
|
||||
return core.registered_craftitems[item] or core.registered_tools[item]
|
||||
end
|
||||
|
|
|
@ -361,7 +361,7 @@ local function sort_by_category(data)
|
|||
for i = 1, #items do
|
||||
local item = items[i]
|
||||
local tab = i3.minitabs[data.itab]
|
||||
local to_add = tab.def.sorter(item, data)
|
||||
local to_add = tab.sorter(item, data)
|
||||
|
||||
if to_add then
|
||||
insert(new, item)
|
||||
|
|
|
@ -1469,10 +1469,10 @@ local function get_minitabs(fs, data, player, full_height)
|
|||
local minitabs = {}
|
||||
|
||||
for i, v in ipairs(i3.minitabs) do
|
||||
local access = v.def.access
|
||||
local access = v.access
|
||||
|
||||
if access == nil or access(player, data) then
|
||||
minitabs[i] = v.name
|
||||
minitabs[i] = v.description
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1480,10 +1480,10 @@ local function get_minitabs(fs, data, player, full_height)
|
|||
|
||||
for id, title in pairs(minitabs) do
|
||||
i++
|
||||
local X = i > 3 and i - 3 or i
|
||||
local top = i > 3
|
||||
local X = top and i - 3 or i
|
||||
local selected = id == data.itab
|
||||
local hover_texture = selected and PNG.tab_small_hover or PNG.tab_small
|
||||
local top = i > 3
|
||||
local flip = top and "^[transformFY" or ""
|
||||
|
||||
fs([[ style_type[image_button;bgimg=%s%s;bgimg_hovered=%s%s;
|
||||
|
|
|
@ -2,14 +2,15 @@ local set_fs = i3.set_fs
|
|||
local hud_notif = i3.hud_notif
|
||||
local POLL_FREQ = 0.25
|
||||
|
||||
IMPORT("reg_items", "reg_nodes")
|
||||
IMPORT("fmt", "table_merge", "array_diff")
|
||||
IMPORT("reg_items", "reg_nodes", "fmt", "table_merge", "array_diff")
|
||||
IMPORT("is_group", "extract_groups", "item_has_groups", "apply_recipe_filters", "sort_by_category")
|
||||
|
||||
i3.remove_minitab"Nodes"
|
||||
i3.remove_minitab"Items"
|
||||
i3.remove_minitab"nodes"
|
||||
i3.remove_minitab"items"
|
||||
|
||||
i3.new_minitab("unlocked", {
|
||||
description = "Unlocked",
|
||||
|
||||
i3.new_minitab("Unlocked", {
|
||||
sorter = function(item, data)
|
||||
return data.items_progress[item]
|
||||
end
|
||||
|
|
Ŝarĝante…
Reference in New Issue