moved doc integration to doc_addon.lua. Added doc button on survival page
This commit is contained in:
parent
9808ac4c58
commit
93ee3be696
@ -1,4 +1,5 @@
|
||||
local filter = smart_inventory.filter
|
||||
local doc_addon = smart_inventory.doc_addon
|
||||
|
||||
local cache = {}
|
||||
cache.cgroups = {}
|
||||
@ -249,7 +250,7 @@ function cache.get_recipes_craftable_atnext(player, item)
|
||||
for recipe_item, itemtab in pairs(cache.crecipes[recipe].recipe_items) do
|
||||
recipe_ok = false
|
||||
for _, itemname in ipairs(itemtab) do
|
||||
if filter.is_revealed_item(itemname, player) == true then
|
||||
if doc_addon.is_revealed_item(itemname, player) == true then
|
||||
recipe_ok = true
|
||||
break
|
||||
end
|
||||
|
20
crafting.lua
20
crafting.lua
@ -1,5 +1,5 @@
|
||||
local cache = smart_inventory.cache
|
||||
local filter = smart_inventory.filter
|
||||
local doc_addon = smart_inventory.doc_addon
|
||||
local ui_tools = smart_inventory.ui_tools
|
||||
|
||||
-----------------------------------------------------
|
||||
@ -39,7 +39,7 @@ local function update_preview(state)
|
||||
if state.param.crafting_items_in_inventory[item_in_list.name] then
|
||||
item = item_in_list.name
|
||||
break
|
||||
elseif filter.is_revealed_item(item_in_list.name, player) then
|
||||
elseif doc_addon.is_revealed_item(item_in_list.name, player) then
|
||||
item = item_in_list.name
|
||||
elseif item == nil then
|
||||
item = item_in_list.name
|
||||
@ -304,6 +304,22 @@ local function crafting_callback(state)
|
||||
smart_inventory.smartfs_elements.craft_preview(state, 6, 0, "craft_preview")
|
||||
inf_state:label(6.7,3,"cr_type", "")
|
||||
inf_state:item_image(10.2,0.3, 1, 1, "craft_result",nil):setVisible(false)
|
||||
|
||||
if smart_inventory.doc_items_mod then
|
||||
local doc_btn = inf_state:item_image_button(10.2,2.3, 1, 1, "doc_btn","", "doc_identifier:identifier_solid")
|
||||
doc_btn:setVisible(true)
|
||||
doc_btn:onClick(function(self, state, player)
|
||||
local outitem = state:get("craft_result"):getImage()
|
||||
if outitem then
|
||||
outitem:gsub("[^%s]+", function(z)
|
||||
if minetest.registered_items[z] then
|
||||
doc_addon.show(z, player)
|
||||
end
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
inf_area:setVisible(false)
|
||||
|
||||
local pr_prev_btn = state:button(6, 3, 1, 0.5, "preview_prev", "<<")
|
||||
|
60
doc_addon.lua
Normal file
60
doc_addon.lua
Normal file
@ -0,0 +1,60 @@
|
||||
local filter = smart_inventory.filter
|
||||
local doc_addon = {}
|
||||
|
||||
function doc_addon.is_revealed_item(itemname, playername)
|
||||
local cache = smart_inventory.cache
|
||||
if minetest.registered_items[itemname] == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
if smart_inventory.doc_items_mod then
|
||||
local category_id
|
||||
if not cache.citems[itemname] then
|
||||
-- not in creative or something like
|
||||
return false
|
||||
else
|
||||
for _, group in pairs(cache.citems[itemname].cgroups) do
|
||||
if group.name == "type:node" then
|
||||
category_id = "nodes"
|
||||
elseif group.name == "type:tool" then
|
||||
category_id = "tools"
|
||||
elseif group.name == "type:craft" then
|
||||
category_id = "craftitems"
|
||||
end
|
||||
end
|
||||
if category_id then
|
||||
return doc.entry_revealed(playername, category_id, itemname)
|
||||
else
|
||||
-- unknown item
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function doc_addon.show(itemname, playername)
|
||||
local cache = smart_inventory.cache
|
||||
if smart_inventory.doc_items_mod then
|
||||
local category_id
|
||||
if cache.citems[itemname] then
|
||||
for _, group in pairs(cache.citems[itemname].cgroups) do
|
||||
if group.name == "type:node" then
|
||||
category_id = "nodes"
|
||||
elseif group.name == "type:tool" then
|
||||
category_id = "tools"
|
||||
elseif group.name == "type:craft" then
|
||||
category_id = "craftitems"
|
||||
end
|
||||
end
|
||||
if category_id then
|
||||
doc.show_entry(playername, category_id, itemname, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
-------------------------
|
||||
return doc_addon
|
32
filter.lua
32
filter.lua
@ -23,38 +23,6 @@ function filter.register_filter(def)
|
||||
filter.registered_filter[self.name] = self
|
||||
end
|
||||
|
||||
function filter.is_revealed_item(itemname, playername)
|
||||
local cache = smart_inventory.cache
|
||||
if minetest.registered_items[itemname] == nil then
|
||||
return false
|
||||
end
|
||||
|
||||
if smart_inventory.doc_items_mod then
|
||||
local category_id
|
||||
if not cache.citems[itemname] then
|
||||
-- not in creative or something like
|
||||
return false
|
||||
else
|
||||
for _, group in pairs(cache.citems[itemname].cgroups) do
|
||||
if group.name == "type:node" then
|
||||
category_id = "nodes"
|
||||
elseif group.name == "type:tool" then
|
||||
category_id = "tools"
|
||||
elseif group.name == "type:craft" then
|
||||
category_id = "craftitems"
|
||||
end
|
||||
end
|
||||
if category_id then
|
||||
return doc.entry_revealed(playername, category_id, itemname)
|
||||
else
|
||||
-- unknown item
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
filter.register_filter({
|
||||
name = "transluc",
|
||||
shortdesc = "Translucent blocks",
|
||||
|
Loading…
x
Reference in New Issue
Block a user