framework: Add setting smart_inventory_workbench_mode

to allow usage of smart_inventory as workbench in parallel to other inventory mods
This commit is contained in:
Alexander Weber 2017-07-01 00:30:02 +02:00
parent b4e9bd3147
commit d4353eca3f
9 changed files with 72 additions and 6 deletions

14
API.md
View File

@ -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.

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

29
workbench.lua Normal file
View File

@ -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"}
}
})