Show usages for fuel-able items with no recipes

This commit is contained in:
Jean-Patrick Guerrero 2018-12-30 20:25:28 +01:00
parent e1eedb69bb
commit 897fc3a21d

108
init.lua

@ -83,7 +83,7 @@ local function reset_datas(data)
data.item = nil data.item = nil
data.pagenum = 1 data.pagenum = 1
data.rnum = 1 data.rnum = 1
data.fuel = nil data.items = progressive_mode and data.init_filter_items or datas.init_items
end end
local function in_table(T) local function in_table(T)
@ -166,13 +166,15 @@ local function get_tooltip(item, recipe_type, cooktime, groups)
return has_extras and tooltip .. "]" or "" return has_extras and tooltip .. "]" or ""
end end
local function _get_recipe(iX, iY, xoffset, recipe_num, recipes, show_usage) local function get_recipe_fs(iX, iY, xoffset, recipe_num, recipes, show_usage)
local fs, recipes_total = {}, #recipes local fs, recipes_total = {}, #recipes
if recipes_total > 1 then
fs[#fs + 1] = "button[" .. (iX - (sfinv_only and 2.2 or 2.6)) .. "," .. fs[#fs + 1] = "button[" .. (iX - (sfinv_only and 2.2 or 2.6)) .. "," ..
(iY + (sfinv_only and 3.9 or 3.3)) .. ";2.2,1;alternate;" .. (iY + (sfinv_only and 3.9 or 3.3)) .. ";2.2,1;alternate;" ..
(show_usage and S("Usage") or S("Recipe")) .. " " .. (show_usage and S("Usage") or S("Recipe")) .. " " ..
S("@1 of @2", recipe_num, recipes_total) .. "]" S("@1 of @2", recipe_num, recipes_total) .. "]"
if not recipes[1] then
return ""
end end
local recipe_type = recipes[recipe_num].type local recipe_type = recipes[recipe_num].type
@ -226,8 +228,9 @@ local function _get_recipe(iX, iY, xoffset, recipe_num, recipes, show_usage)
end end
local custom_recipe = craftguide.craft_types[recipe_type] local custom_recipe = craftguide.craft_types[recipe_type]
if recipe_type == "cooking" or (recipe_type == "normal" and width == 0) or if recipe_type == "cooking" or custom_recipe or
custom_recipe then (recipe_type == "normal" and width == 0) then
local icon = recipe_type == "cooking" and "furnace" or "shapeless" local icon = recipe_type == "cooking" and "furnace" or "shapeless"
local coords = (rightest + 1.2) .. "," .. local coords = (rightest + 1.2) .. "," ..
(iY + (sfinv_only and 2.2 or 1.7)) .. (iY + (sfinv_only and 2.2 or 1.7)) ..
@ -244,7 +247,6 @@ local function _get_recipe(iX, iY, xoffset, recipe_num, recipes, show_usage)
local output = recipes[recipe_num].output local output = recipes[recipe_num].output
local output_s = output:match("%S+") local output_s = output:match("%S+")
local output_is_fuel = get_fueltime(output) > 0
local arrow_X = rightest + (s_btn_size or BUTTON_SIZE) local arrow_X = rightest + (s_btn_size or BUTTON_SIZE)
local output_X = arrow_X + 0.9 local output_X = arrow_X + 0.9
@ -253,13 +255,20 @@ local function _get_recipe(iX, iY, xoffset, recipe_num, recipes, show_usage)
(iY + (sfinv_only and 2.85 or 2.35)) .. (iY + (sfinv_only and 2.85 or 2.35)) ..
";0.9,0.7;craftguide_arrow.png]" ";0.9,0.7;craftguide_arrow.png]"
if output == "BURN" then
fs[#fs + 1] = "image[" .. output_X .. "," ..
(iY + (sfinv_only and 2.68 or 2.18)) ..
";1.1,1.1;craftguide_fire.png]"
else
fs[#fs + 1] = "item_image_button[" .. output_X .. "," .. fs[#fs + 1] = "item_image_button[" .. output_X .. "," ..
(iY + (sfinv_only and 2.7 or 2.2)) .. ";" .. (iY + (sfinv_only and 2.7 or 2.2)) .. ";" ..
BUTTON_SIZE .. "," .. BUTTON_SIZE .. ";" .. BUTTON_SIZE .. "," .. BUTTON_SIZE .. ";" ..
output .. ";" .. output_s .. ";]" output .. ";" .. output_s .. ";]"
end
fs[#fs + 1] = get_tooltip(output_s) fs[#fs + 1] = get_tooltip(output_s)
local output_is_fuel = get_fueltime(output) > 0
if output_is_fuel then if output_is_fuel then
fs[#fs + 1] = "image[" .. (output_X + 1) .. "," .. fs[#fs + 1] = "image[" .. (output_X + 1) .. "," ..
(iY + (sfinv_only and 2.83 or 2.33)) .. (iY + (sfinv_only and 2.83 or 2.33)) ..
@ -336,33 +345,14 @@ local function get_formspec(player_name)
end end
if data.item and reg_items[data.item] then if data.item and reg_items[data.item] then
if not data.recipes_item or (data.fuel and not get_recipe(data.item).items) then
local X = floor(xoffset) - (sfinv_only and 0 or 0.2)
fs[#fs + 1] = "item_image_button[" .. X .. "," ..
(iY + (sfinv_only and 2.7 or 2.2)) ..
";" .. BUTTON_SIZE .. "," .. BUTTON_SIZE ..
";" .. data.item .. ";" .. data.item .. ";]"
fs[#fs + 1] = "image[" .. (X + 1.1) .. "," ..
(iY + (sfinv_only and 2.85 or 2.35)) ..
";0.9,0.7;craftguide_arrow.png]"
fs[#fs + 1] = get_tooltip(data.item)
fs[#fs + 1] = "image[" .. (X + 2.1) .. "," ..
(iY + (sfinv_only and 2.68 or 2.18)) ..
";1.1,1.1;craftguide_fire.png]"
else
local usage = data.show_usage local usage = data.show_usage
fs[#fs + 1] = _get_recipe(data.iX, fs[#fs + 1] = get_recipe_fs(data.iX,
iY, iY,
xoffset, xoffset,
data.rnum, data.rnum,
(usage and data.usages or data.recipes_item), (usage and data.usages or data.recipes_item),
usage) usage)
end end
end
fs = concat(fs) fs = concat(fs)
data.formspec = fs data.formspec = fs
@ -568,7 +558,6 @@ local function get_fields(player, ...)
if fields.clear then if fields.clear then
reset_datas(data) reset_datas(data)
data.items = progressive_mode and data.init_filter_items or datas.init_items
show_fs(player, player_name) show_fs(player, player_name)
elseif fields.alternate then elseif fields.alternate then
@ -591,7 +580,6 @@ local function get_fields(player, ...)
elseif fields.prev or fields.next then elseif fields.prev or fields.next then
data.pagenum = data.pagenum - (fields.prev and 1 or -1) data.pagenum = data.pagenum - (fields.prev and 1 or -1)
if data.pagenum > data.pagemax then if data.pagenum > data.pagemax then
data.pagenum = 1 data.pagenum = 1
elseif data.pagenum == 0 then elseif data.pagenum == 0 then
@ -617,18 +605,32 @@ local function get_fields(player, ...)
local is_fuel = get_fueltime(item) > 0 local is_fuel = get_fueltime(item) > 0
local recipes = get_recipes(item) or {} local recipes = get_recipes(item) or {}
recipes = add_custom_recipes(item, recipes) recipes = add_custom_recipes(item, recipes)
if not next(recipes) and not is_fuel then return end
if not data.show_usage and item == data.item and not progressive_mode then local no_recipes = not next(recipes)
data.usages = get_item_usages(item) if no_recipes and not is_fuel then return end
if next(data.usages) then
data.show_usage = true if item ~= data.item then
data.rnum = 1 data.show_usage = nil
end end
show_fs(player, player_name) if not progressive_mode and (is_fuel and no_recipes) or
else (not data.show_usage and item == data.item) then
if progressive_mode then data.usages = get_item_usages(item)
if is_fuel then
data.usages[#data.usages + 1] = {
width = 1,
type = "normal",
items = {item},
output = "BURN",
}
end
if next(data.usages) then
data.show_usage = true
end
elseif progressive_mode then
local inv = player:get_inventory() local inv = player:get_inventory()
local has_item local has_item
recipes, has_item = recipe_in_inv(inv, item, recipes) recipes, has_item = recipe_in_inv(inv, item, recipes)
@ -638,14 +640,12 @@ local function get_fields(player, ...)
data.item = item data.item = item
data.recipes_item = recipes data.recipes_item = recipes
data.rnum = 1 data.rnum = 1
data.show_usage = nil data.show_usage = data.show_usage
data.fuel = is_fuel
show_fs(player, player_name) show_fs(player, player_name)
end end
end end
end end
end
end end
if sfinv_only then if sfinv_only then
@ -785,24 +785,38 @@ if not progressive_mode then
end end
local data = datas[name] local data = datas[name]
reset_datas(data)
local is_fuel = get_fueltime(node_name) > 0 local is_fuel = get_fueltime(node_name) > 0
local recipes = get_recipes(node_name) or {} local recipes = get_recipes(node_name) or {}
recipes = add_custom_recipes(node_name, recipes) recipes = add_custom_recipes(node_name, recipes)
local no_recipes = not next(recipes)
if not next(recipes) and not is_fuel then if no_recipes and not is_fuel then
return false, colorize("[craftguide] ") .. return false, colorize("[craftguide] ") ..
S("No recipe for this node:") .. " " .. S("No recipe for this node:") .. " " ..
colorize(node_name) colorize(node_name)
end end
data.show_usage = nil if is_fuel and no_recipes then
data.filter = "" data.usages = get_item_usages(node_name)
if is_fuel then
data.usages[#data.usages + 1] = {
width = 1,
type = "normal",
items = {node_name},
output = "BURN",
}
end
if next(data.usages) then
data.show_usage = true
end
end
data.show_usage = data.show_usage
data.item = node_name data.item = node_name
data.pagenum = 1
data.rnum = 1
data.recipes_item = recipes data.recipes_item = recipes
data.items = datas.init_items
data.fuel = is_fuel
return true, show_fs(player, name) return true, show_fs(player, name)
end, end,