3.1 KiB
3.1 KiB
API definition to working together with smart_inventory
Register new page
To get own page in smart_inventory the next register method should be used
smart_inventory.register_page({
name = string,
icon = string,
label = string,
tooltip = string,
smartfs_callback = function,
sequence = number,
on_button_click = function,
})
- name - unique short name, used for identification
- icon - Image displayed on page button. Optional
- label - Label displayed on page button. Optional
- tooltip - Text displayed at mouseover on the page button. Optional
- smartfs_callback(state) - smartfs callback function See smartfs documentation and existing pages implementations for reference.
- sequence - The buttons are sorted by this number (crafting=10, creative=15, player=20)
- on_button_click(state) - function called each page button click
Filter framework
Smart_inventory uses a filter-framework for dynamic grouping in creative and crafting page. The filter framework allow to register additional classify filters for beter dynamic grouping results. Maybe the framework will be moved to own mod in the feature if needed. Please note the smart_inventory caches all results at init time so static groups only allowed. The groups will not be re-checked at runtime.
Register new filter
smart_inventory.filter.register_filter({
name = string,
filter_func = function,
shortdesc_func = function,
})
- name - unique filter name
- filter_func(itemdef) - function to check the item classify by item definition. Item definition is the reference to minetest.registered_items[item] entry
next return values allowed:
- true -> direct (belongs to) assignment to the classify group named by filtername
- string -> dimension, steps splitted by ":" (
a:b:c:d results in filtername, filtername:a, filtername:a:b, filtername:a:b:c, filtername:a:b:c:d
) - key/value table -> multiple groups assignment. Values could be dimensions as above (
{a,b} results in filtername, filtername:a, filtername:b
) - nil -> no group assingment by this filter
- shortdesc_func(fltobj, filterstring, textstring) - optional - get human readable description for the dimension string (
filtername:a:b:c
). "false" means the group should be ignored. Usefull so skip some dimension characteristics - if no function is given the descriptions can be added to smart_inventory.txt[filterstring].label See classify_description.lua. If nothing defined the filterstring will be displayed
Filter Object methods
smart_inventory.filter.get(name) get filter object by registered name. Returns filter object fltobj
- fltobj:check_item_by_name(itemname) classify by itemname
- fltobj:check_item_by_def(def) classify by item definition
- fltobj:get_description(group) get group description