crafting: fix crash on lookup unknown item

This commit is contained in:
Alexander Weber 2017-02-28 21:34:12 +01:00
parent 93ee3be696
commit 2c45a5bc11

View File

@ -10,6 +10,12 @@ local function update_preview(state)
local player = state.location.rootState.location.player local player = state.location.rootState.location.player
local listentry = state.param.crafting_recipes_preivew_listentry local listentry = state.param.crafting_recipes_preivew_listentry
local selected = state.param.crafting_recipes_preivew_selected local selected = state.param.crafting_recipes_preivew_selected
local itemdef = listentry.itemdef
local inf_state = state:get("inf_area"):getContainerState()
-- recipe to display and prepare them. Check for paging buttons needed
local recipe
if listentry.recipes then
if not listentry.recipes[selected] then if not listentry.recipes[selected] then
selected = 1 selected = 1
end end
@ -25,9 +31,7 @@ local function update_preview(state)
state:get("preview_next"):setVisible(false) state:get("preview_next"):setVisible(false)
end end
-- create the recipe preview, set right items for groups -- set right items for groups in recipe
local itemdef = listentry.itemdef
local recipe
if listentry.recipes[selected] then if listentry.recipes[selected] then
recipe = table.copy(listentry.recipes[selected]) recipe = table.copy(listentry.recipes[selected])
recipe.items = table.copy(recipe.items) recipe.items = table.copy(recipe.items)
@ -51,24 +55,12 @@ local function update_preview(state)
end end
end end
end end
-- update info area
local inf_state = state:get("inf_area"):getContainerState()
if itemdef then
inf_state:get("info1"):setText(itemdef.description)
inf_state:get("info2"):setText("("..itemdef.name..")")
if itemdef._doc_items_longdesc then
inf_state:get("info3"):setText(itemdef._doc_items_longdesc)
else else
inf_state:get("info3"):setText("") state:get("preview_prev"):setVisible(false)
end state:get("preview_next"):setVisible(false)
else
inf_state:get("info1"):setText("")
inf_state:get("info2"):setText("")
inf_state:get("info3"):setText("")
inf_state:get("cr_type"):setText("")
end end
-- display the recipe result or selected item
if recipe then if recipe then
if recipe.type ~="normal" then if recipe.type ~="normal" then
inf_state:get("cr_type"):setText(recipe.type) inf_state:get("cr_type"):setText(recipe.type)
@ -88,6 +80,23 @@ local function update_preview(state)
end end
state:get("craft_preview"):setCraft(nil) state:get("craft_preview"):setCraft(nil)
end end
-- update info area
if itemdef then
inf_state:get("info1"):setText(itemdef.description)
inf_state:get("info2"):setText("("..itemdef.name..")")
if itemdef._doc_items_longdesc then
inf_state:get("info3"):setText(itemdef._doc_items_longdesc)
else
inf_state:get("info3"):setText("")
end
else
inf_state:get("info1"):setText("")
inf_state:get("info2"):setText("")
inf_state:get("info3"):setText("")
inf_state:get("cr_type"):setText("")
end
end end
----------------------------------------------------- -----------------------------------------------------
@ -202,9 +211,11 @@ local function create_lookup_inv(state, name)
state.param.crafting_recipes_preivew_selected = 1 state.param.crafting_recipes_preivew_selected = 1
state.param.crafting_recipes_preivew_listentry = { state.param.crafting_recipes_preivew_listentry = {
itemdef = minetest.registered_items[lookup_item], itemdef = minetest.registered_items[lookup_item],
recipes = cache.citems[lookup_item].in_output_recipe,
item = lookup_item item = lookup_item
} }
if cache.citems[lookup_item] then
state.param.crafting_recipes_preivew_listentry.recipes = cache.citems[lookup_item].in_output_recipe
end
update_preview(state) update_preview(state)
if state:get("inf_area"):getVisible() == false then if state:get("inf_area"):getVisible() == false then
state:get("groups_btn"):submit() state:get("groups_btn"):submit()