mirror of
https://github.com/minetest-mods/i3.git
synced 2024-12-26 02:40:38 +01:00
Add Compression API
This commit is contained in:
parent
bd5ea4e6a8
commit
9e50f58f5b
27
API.md
27
API.md
@ -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)`
|
||||
|
34
etc/api.lua
34
etc/api.lua
@ -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
|
||||
|
1
init.lua
1
init.lua
@ -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")
|
||||
|
4
tests/test_compression.lua
Normal file
4
tests/test_compression.lua
Normal file
@ -0,0 +1,4 @@
|
||||
i3.compress("default:diamondblock", {
|
||||
replace = "diamond",
|
||||
by = {"bronze", "copper", "gold", "steel", "tin"}
|
||||
})
|
Loading…
Reference in New Issue
Block a user