Add Compression API

fork-master
Jean-Patrick Guerrero 2021-10-25 00:14:21 +02:00
parent bd5ea4e6a8
commit 9e50f58f5b
4 changed files with 66 additions and 0 deletions

27
API.md
View File

@ -231,6 +231,33 @@ A map of search filters, indexed by name.
---
### Item compression
`i3` is capable of reducing the item list size by compressing a group of items.
#### `i3.compress(item, def)`
Adds a new group of items to compress.
- `item` is the item that serve as stereotype for the group of compressed items.
- `def` is a table specifying the substring replace patterns to be used.
Example:
```Lua
i3.compress("default:diamondblock", {
replace = "diamond",
by = {"bronze", "copper", "gold", "steel", "tin"}
})
```
#### `i3.get_compress_groups()`
Returns a map of all compressed item groups, indexed by stereotypes.
---
### Miscellaneous
#### `i3.get_recipes(item)`

View File

@ -285,4 +285,38 @@ i3.add_search_filter("groups", function(item, groups)
return has_groups
end)
function i3.compress(item, def)
if not true_str(item) then
return err "i3.compress: item name missing"
end
if not is_table(def) then
return err "i3.compress: replace definition missing"
end
if not true_str(def.replace) then
return err "i3.compress: replace string missing"
end
if not is_table(def.by) then
return err "i3.compress: replace substrings missing"
end
local t = {}
i3.compress_groups[item] = i3.compress_groups[item] or {}
for _, str in ipairs(def.by) do
local it = item:gsub(def.replace, str)
insert(t, it)
insert(i3.compress_groups[item], it)
i3.compressed[it] = true
end
end
function i3.get_compress_groups()
return i3.compress_groups
end
return set_fs, i3.set_tab

View File

@ -291,4 +291,5 @@ if i3.progressive_mode then
end
--dofile(modpath .. "/tests/test_tabs.lua")
--dofile(modpath .. "/tests/test_compression.lua")
--dofile(modpath .. "/tests/test_custom_recipes.lua")

View File

@ -0,0 +1,4 @@
i3.compress("default:diamondblock", {
replace = "diamond",
by = {"bronze", "copper", "gold", "steel", "tin"}
})