From 189a3ff97132bf4bf3198ab87b50f187e34f6cf6 Mon Sep 17 00:00:00 2001 From: Jean-Patrick Guerrero Date: Sun, 16 Feb 2020 14:48:43 +0100 Subject: [PATCH] Rollback changes in srarch() --- init.lua | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/init.lua b/init.lua index ee3c2af..eae34b2 100644 --- a/init.lua +++ b/init.lua @@ -1160,16 +1160,6 @@ craftguide.register_craft_type("digging_chance", { 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 filter = data.filter @@ -1191,28 +1181,30 @@ local function search(data) end end - local filtered_list, order, c = {}, {}, 0 + local filtered_list, c = {}, 0 for i = 1, #data.items_raw do local item = data.items_raw[i] local def = reg_items[item] local desc = (def and def.description) and lower(def.description) or "" + local search_in = fmt("%s %s", item, desc) local to_add if search_filter then for filter_name, values in pairs(filters) do - local func = search_filters[filter_name] - to_add = func(item, values) and (search_filter == "" or - (sfind(item, search_filter) or sfind(desc, search_filter))) + if values then + local func = search_filters[filter_name] + to_add = func(item, values) and (search_filter == "" or + find(search_in, search_filter, 1, true)) + end end else - to_add = sfind(item, filter) or sfind(desc, filter) + to_add = find(search_in, filter, 1, true) end if to_add then c = c + 1 filtered_list[c] = item - order[item] = to_add end end @@ -1225,10 +1217,6 @@ local function search(data) end end - sort(filtered_list, function(a, b) - return order[a] < order[b] - end) - data.items = filtered_list end