Progressive mode: fix search

This commit is contained in:
JPG 2016-12-24 21:17:32 +01:00
parent 7234e42123
commit 3776ac9412

@ -21,10 +21,10 @@ local group_stereotypes = {
function craftguide:group_to_item(item) function craftguide:group_to_item(item)
if item:sub(1,6) == "group:" then if item:sub(1,6) == "group:" then
local short_itemstr = item:sub(7) local itemsub = item:sub(7)
if group_stereotypes[short_itemstr] then if group_stereotypes[itemsub] then
item = group_stereotypes[short_itemstr] item = group_stereotypes[itemsub]
elseif reg_items["default:"..item:sub(7)] then elseif reg_items["default:"..itemsub] then
item = item:gsub("group:", "default:") item = item:gsub("group:", "default:")
else else
for name, def in pairs(reg_items) do for name, def in pairs(reg_items) do
@ -147,6 +147,10 @@ function craftguide:get_formspec(player_name, is_fuel)
local data = datas[player_name] local data = datas[player_name]
local iY = data.iX - 5 local iY = data.iX - 5
local ipp = data.iX * iY local ipp = data.iX * iY
if not data.items then
data.items = data.init_items
end
data.pagemax = max(1, ceil(#data.items / ipp)) data.pagemax = max(1, ceil(#data.items / ipp))
local formspec = "size["..data.iX..","..(iY+3)..".6;]"..[[ local formspec = "size["..data.iX..","..(iY+3)..".6;]"..[[
@ -279,12 +283,12 @@ function craftguide:get_init_items(player_name)
sort(items_list) sort(items_list)
data.init_items = items_list data.init_items = items_list
data.items = items_list
end end
function craftguide:get_filter_items(data, player) function craftguide:get_filter_items(data, player)
local filter = data.filter local filter = data.filter
local items_list = progressive_mode and data.items or data.init_items local items_list = progressive_mode and data.init_filter_items or
data.init_items
local inv = player:get_inventory() local inv = player:get_inventory()
local filtered_list, counter = {}, 0 local filtered_list, counter = {}, 0
@ -306,6 +310,10 @@ function craftguide:get_filter_items(data, player)
end end
end end
end end
if progressive_mode and not data.items then
data.init_filter_items = filtered_list
end
data.items = filtered_list data.items = filtered_list
end end
@ -317,10 +325,8 @@ mt.register_on_player_receive_fields(function(player, formname, fields)
if fields.clear then if fields.clear then
data.filter, data.item, data.pagenum, data.recipe_num = data.filter, data.item, data.pagenum, data.recipe_num =
"", nil, 1, 1 "", nil, 1, 1
data.items = data.init_items data.items = progressive_mode and data.init_filter_items or
if progressive_mode then data.init_items
craftguide:get_filter_items(data, player)
end
craftguide:get_formspec(player_name) craftguide:get_formspec(player_name)
elseif fields.alternate then elseif fields.alternate then
local recipe = data.recipes_item[data.recipe_num + 1] local recipe = data.recipes_item[data.recipe_num + 1]