diff --git a/API.md b/API.md index 47405f5..ddd8d61 100644 --- a/API.md +++ b/API.md @@ -1,6 +1,8 @@ # API definition to working together with smart_inventory -## Register new page +## Pages framework + +### Register page To get own page in smart_inventory the next register method should be used ``` smart_inventory.register_page({ @@ -21,6 +23,16 @@ smart_inventory.register_page({ - sequence - The buttons are sorted by this number (crafting=10, creative=15, player=20) - on_button_click(state) - function called each page button click +### Get the definition for registered smart_inventory page +```smart_inventory.get_registered_page(pagename)``` + +### Get smartfs state for players inventory +```smart_inventory.get_player_state(playername)``` +Get the root smartfs state for players inventory. Note: In workbench mode the function return nil if the player does not have the form open + +### Get smartfs state for a registered page in players inventory +```smart_inventory.get_page_state(pagename, playername)``` + ## 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. diff --git a/README.md b/README.md index 8a27a6d..a3f9f6e 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,4 @@ smart_inventory_shaped_groups (List of groups to be handled as separate) string ``` License: [LGPL-3](https://github.com/bell07/minetest-smart_inventory/blob/master/LICENSE) +Textures: Workbench: WTFPL (credits: to xdecor project) diff --git a/inventory_framework.lua b/inventory_framework.lua index e1078f8..32d2b8f 100644 --- a/inventory_framework.lua +++ b/inventory_framework.lua @@ -1,5 +1,6 @@ -smartfs = smart_inventory.smartfs +local smartfs = smart_inventory.smartfs local maininv = smart_inventory.maininv +local modpath = smart_inventory.modpath -- smartfs callback local inventory_form = smartfs.create("smart_inventory:main", function(state) @@ -78,7 +79,24 @@ local inventory_form = smartfs.create("smart_inventory:main", function(state) end tab_controller:set_active(smart_inventory.registered_pages[1].name) end) -smartfs.set_player_inventory(inventory_form) + +if minetest.settings:get_bool("smart_inventory_workbench_mode") then + dofile(modpath.."/workbench.lua") + smart_inventory.get_player_state = function(playername) + -- check the inventory is shown + local state = smartfs.opened[playername] + if state and (not state.obsolete) and + state.location.type == "player" and + state.def.name == "smart_inventory:main" then + return state + end + end +else + smartfs.set_player_inventory(inventory_form) + smart_inventory.get_player_state = function(playername) + return smartfs.inv[playername] + end +end -- pages list smart_inventory.registered_pages = {} @@ -88,9 +106,11 @@ function smart_inventory.register_page(def) table.insert(smart_inventory.registered_pages, def) end +-- smart_inventory.get_player_state(playername) defined above + -- get state of active page function smart_inventory.get_page_state(pagename, playername) - local rootstate = smart_inventory.smartfs.inv[playername] + local rootstate = smart_inventory.get_player_state(playername) if not rootstate then return end diff --git a/pages/crafting.lua b/pages/crafting.lua index 55260ee..7c7fb50 100644 --- a/pages/crafting.lua +++ b/pages/crafting.lua @@ -280,7 +280,7 @@ local function create_lookup_inv(state, name) do_lookup_item(state, name, stack:get_name()) -- we are outsite of usual smartfs processing. So trigger the formspec update byself - smartfs.inv[name]:show() + state.location.rootState:show() -- put back minetest.after(1, function(stack) @@ -529,6 +529,6 @@ minetest.register_craft_predict(function(stack, player, old_craft_grid, craft_in local recipes = crecipes.get_recipes_started_craft(name, old_craft_grid, reference_items) update_from_recipelist(state, recipes, stack:get_name(), true) -- replace_not_in_list=true end - smartfs.inv[name]:show() + state.location.rootState:show() end end) diff --git a/settingtypes.txt b/settingtypes.txt index 75581d3..da274d2 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -4,3 +4,7 @@ smart_inventory_friendly_group_names (Show “friendly” filter grouping names) #List of groups defined for special handling of "Shaped nodes" (Comma separated). #Items in this groups ignores the "not_in_inventory" group and are moved to separate "Shaped" category smart_inventory_shaped_groups (List of groups to be handled as separate) string carpet,door,fence,stair,slab,wall,micro,panel,slope,dye + +#If enabled, the the mod does not replace other inventory mods. +#The functionality is provided in a workbench. +smart_inventory_workbench_mode (Use workbench instead of players inventory) bool false diff --git a/textures/smart_inventory_workbench_front.png b/textures/smart_inventory_workbench_front.png new file mode 100644 index 0000000..cc2142d Binary files /dev/null and b/textures/smart_inventory_workbench_front.png differ diff --git a/textures/smart_inventory_workbench_sides.png b/textures/smart_inventory_workbench_sides.png new file mode 100644 index 0000000..29c4b3b Binary files /dev/null and b/textures/smart_inventory_workbench_sides.png differ diff --git a/textures/smart_inventory_workbench_top.png b/textures/smart_inventory_workbench_top.png new file mode 100644 index 0000000..f9a36cf Binary files /dev/null and b/textures/smart_inventory_workbench_top.png differ diff --git a/workbench.lua b/workbench.lua new file mode 100644 index 0000000..a96d4a7 --- /dev/null +++ b/workbench.lua @@ -0,0 +1,29 @@ +local smartfs = smart_inventory.smartfs + +local function on_rightclick(pos, node, player, itemstack, pointed_thing) + smartfs.get("smart_inventory:main"):show(player:get_player_name(name)) +end + +-- Return smart inventory workbench definition if enabled +minetest.register_node("smart_inventory:workbench", { + description = "Smart inventory workbench", + groups = {cracky=2, choppy=2, oddly_breakable_by_hand=1}, + sounds = default.node_sound_wood_defaults(), + tiles = { + "smart_inventory_workbench_top.png", + "smart_inventory_workbench_top.png", + "smart_inventory_workbench_sides.png", + "smart_inventory_workbench_sides.png", + "smart_inventory_workbench_front.png", + "smart_inventory_workbench_front.png" + }, + on_rightclick = on_rightclick +}) + +minetest.register_craft({ +output = "smart_inventory:workbench", + recipe = { + {"default:coral_skeleton", "default:coral_skeleton"}, + {"default:coral_skeleton", "default:coral_skeleton"} + } +})