Fix search filters
This commit is contained in:
parent
c7c043fcb1
commit
9bc190443c
20
API.md
20
API.md
|
@ -185,7 +185,7 @@ Returns a map of recipe filters, indexed by name.
|
||||||
### Search filters
|
### Search filters
|
||||||
|
|
||||||
Search filters are used to perform specific searches inside the search field.
|
Search filters are used to perform specific searches inside the search field.
|
||||||
You can cumulate several filters to perform a specific search.
|
These filters are cumulative to perform a specific search.
|
||||||
They can be used like so: `<optional_name> +<filter name>=<value1>,<value2>,<...>`
|
They can be used like so: `<optional_name> +<filter name>=<value1>,<value2>,<...>`
|
||||||
|
|
||||||
Example usages:
|
Example usages:
|
||||||
|
@ -200,20 +200,22 @@ Notes:
|
||||||
|
|
||||||
#### `i3.add_search_filter(name, function(item, values))`
|
#### `i3.add_search_filter(name, function(item, values))`
|
||||||
|
|
||||||
Adds a search filter with the given `name`.
|
Adds a search filter with the given `name`. `values` is a table of all possible values.
|
||||||
The search function must return a boolean value (whether the given item should be listed or not).
|
The search function must return a boolean value (whether the given item should be listed or not).
|
||||||
|
|
||||||
Example function sorting items by drawtype:
|
Example function sorting items by drawtype:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
i3.add_search_filter("type", function(item, drawtype)
|
i3.add_search_filter("types", function(item, drawtypes)
|
||||||
if drawtype == "node" then
|
local t = {}
|
||||||
return reg_nodes[item]
|
|
||||||
elseif drawtype == "item" then
|
for i, dt in ipairs(drawtypes) do
|
||||||
return reg_craftitems[item]
|
t[i] = (dt == "node" and reg_nodes[item] and 1) or
|
||||||
elseif drawtype == "tool" then
|
(dt == "item" and reg_craftitems[item] and 1) or
|
||||||
return reg_tools[item]
|
(dt == "tool" and reg_tools[item] and 1) or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return #t > 0
|
||||||
end)
|
end)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
16
init.lua
16
init.lua
|
@ -2512,14 +2512,16 @@ i3.add_search_filter("groups", function(item, groups)
|
||||||
return has_groups
|
return has_groups
|
||||||
end)
|
end)
|
||||||
|
|
||||||
i3.add_search_filter("type", function(item, drawtype)
|
i3.add_search_filter("types", function(item, drawtypes)
|
||||||
if drawtype == "node" then
|
local t = {}
|
||||||
return reg_nodes[item]
|
|
||||||
elseif drawtype == "item" then
|
for i, dt in ipairs(drawtypes) do
|
||||||
return reg_craftitems[item]
|
t[i] = (dt == "node" and reg_nodes[item] and 1) or
|
||||||
elseif drawtype == "tool" then
|
(dt == "item" and reg_craftitems[item] and 1) or
|
||||||
return reg_tools[item]
|
(dt == "tool" and reg_tools[item] and 1) or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return #t > 0
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--[[ As `core.get_craft_recipe` and `core.get_all_craft_recipes` do not
|
--[[ As `core.get_craft_recipe` and `core.get_all_craft_recipes` do not
|
||||||
|
|
Ŝarĝante…
Reference in New Issue