Small cleanup

This commit is contained in:
Jean-Patrick Guerrero 2019-09-05 14:57:58 +02:00
parent ae4b15a748
commit cb0200a222

View File

@ -210,9 +210,7 @@ end
local function item_has_groups(item_groups, groups) local function item_has_groups(item_groups, groups)
for i = 1, #groups do for i = 1, #groups do
local group = groups[i] local group = groups[i]
if (item_groups[group] or 0) == 0 then if (item_groups[group] or 0) == 0 then return end
return
end
end end
return true return true
@ -339,9 +337,7 @@ local function get_recipes(item, data, player)
if data.show_usages then if data.show_usages then
recipes = apply_recipe_filters(usages_cache[item], player) recipes = apply_recipe_filters(usages_cache[item], player)
if recipes and #recipes == 0 then if recipes and #recipes == 0 then return end
return
end
end end
return recipes return recipes
@ -645,9 +641,7 @@ local function make_formspec(name)
local first_item = (data.pagenum - 1) * ipp local first_item = (data.pagenum - 1) * ipp
for i = first_item, first_item + ipp - 1 do for i = first_item, first_item + ipp - 1 do
local item = data.items[i + 1] local item = data.items[i + 1]
if not item then if not item then break end
break
end
local X = i % data.iX local X = i % data.iX
local Y = (i % ipp - X) / data.iX + 1 local Y = (i % ipp - X) / data.iX + 1
@ -806,41 +800,35 @@ end
local function _fields(player, fields) local function _fields(player, fields)
local name = player:get_player_name() local name = player:get_player_name()
local data = pdata[name] local data = pdata[name]
local _f = fields
if fields.clear then if _f.clear then
reset_data(data) reset_data(data)
show_fs(player, name) show_fs(player, name)
return true return true
elseif fields.alternate then elseif _f.alternate then
if #data.recipes == 1 then if #data.recipes == 1 then return end
return
end
local num_next = data.rnum + 1 local num_next = data.rnum + 1
data.rnum = data.recipes[num_next] and num_next or 1 data.rnum = data.recipes[num_next] and num_next or 1
show_fs(player, name) show_fs(player, name)
return true return true
elseif (fields.key_enter_field == "filter" or fields.search) and elseif (_f.key_enter_field == "filter" or _f.search) and _f.filter ~= "" then
fields.filter ~= "" then local fltr = lower(_f.filter)
local fltr = lower(fields.filter) if data.filter == fltr then return end
if data.filter == fltr then
return
end
data.filter = fltr data.filter = fltr
data.pagenum = 1 data.pagenum = 1
search(data) search(data)
show_fs(player, name) show_fs(player, name)
return true return true
elseif fields.prev or fields.next then elseif _f.prev or _f.next then
if data.pagemax == 1 then if data.pagemax == 1 then return end
return data.pagenum = data.pagenum - (_f.prev and 1 or -1)
end
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
@ -851,15 +839,15 @@ local function _fields(player, fields)
show_fs(player, name) show_fs(player, name)
return true return true
elseif (fields.size_inc and data.iX < MAX_LIMIT) or elseif (_f.size_inc and data.iX < MAX_LIMIT) or
(fields.size_dec and data.iX > MIN_LIMIT) then (_f.size_dec and data.iX > MIN_LIMIT) then
data.pagenum = 1 data.pagenum = 1
data.iX = data.iX + (fields.size_inc and 1 or -1) data.iX = data.iX + (_f.size_inc and 1 or -1)
show_fs(player, name) show_fs(player, name)
return true return true
else else
local item local item
for field in pairs(fields) do for field in pairs(_f) do
if find(field, ":") then if find(field, ":") then
item = field item = field
break break
@ -869,7 +857,7 @@ local function _fields(player, fields)
if not item then if not item then
return return
elseif sub(item, -4) == "_inv" then elseif sub(item, -4) == "_inv" then
item = sub(item, 1, -5) item = sub(item, 1,-5)
end end
if item ~= data.query_item then if item ~= data.query_item then
@ -879,9 +867,7 @@ local function _fields(player, fields)
end end
local recipes = get_recipes(item, data, player) local recipes = get_recipes(item, data, player)
if not recipes then if not recipes then return end
return
end
data.query_item = item data.query_item = item
data.recipes = recipes data.recipes = recipes
@ -1048,9 +1034,7 @@ if progressive_mode then
local function recipe_in_inv(recipe, inv_items) local function recipe_in_inv(recipe, inv_items)
for _, item in pairs(recipe.items) do for _, item in pairs(recipe.items) do
if not item_in_inv(item, inv_items) then if not item_in_inv(item, inv_items) then return end
return
end
end end
return true return true