Rollback changes in srarch()

This commit is contained in:
Jean-Patrick Guerrero 2020-02-16 14:48:43 +01:00
parent ca723202d6
commit 189a3ff971

@ -1160,16 +1160,6 @@ craftguide.register_craft_type("digging_chance", {
icon = "default_tool_mesepick.png", icon = "default_tool_mesepick.png",
}) })
local function sfind(str, filter)
if filter == "" then
return 0
end
if find(str, filter, 1, true) then
return #str - #filter
end
end
local function search(data) local function search(data)
local filter = data.filter local filter = data.filter
@ -1191,28 +1181,30 @@ local function search(data)
end end
end end
local filtered_list, order, c = {}, {}, 0 local filtered_list, c = {}, 0
for i = 1, #data.items_raw do for i = 1, #data.items_raw do
local item = data.items_raw[i] local item = data.items_raw[i]
local def = reg_items[item] local def = reg_items[item]
local desc = (def and def.description) and lower(def.description) or "" local desc = (def and def.description) and lower(def.description) or ""
local search_in = fmt("%s %s", item, desc)
local to_add local to_add
if search_filter then if search_filter then
for filter_name, values in pairs(filters) do for filter_name, values in pairs(filters) do
local func = search_filters[filter_name] if values then
to_add = func(item, values) and (search_filter == "" or local func = search_filters[filter_name]
(sfind(item, search_filter) or sfind(desc, search_filter))) to_add = func(item, values) and (search_filter == "" or
find(search_in, search_filter, 1, true))
end
end end
else else
to_add = sfind(item, filter) or sfind(desc, filter) to_add = find(search_in, filter, 1, true)
end end
if to_add then if to_add then
c = c + 1 c = c + 1
filtered_list[c] = item filtered_list[c] = item
order[item] = to_add
end end
end end
@ -1225,10 +1217,6 @@ local function search(data)
end end
end end
sort(filtered_list, function(a, b)
return order[a] < order[b]
end)
data.items = filtered_list data.items = filtered_list
end end