mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-11-29 22:03:42 +01:00
Do not search again for same string
This commit is contained in:
parent
70682b230b
commit
134fbf382d
18
init.lua
18
init.lua
@ -517,7 +517,7 @@ local function get_filter_items(data, player)
|
|||||||
|
|
||||||
local items_list = progressive_mode and data.init_filter_items or init_items
|
local items_list = progressive_mode and data.init_filter_items or init_items
|
||||||
local inv = player:get_inventory()
|
local inv = player:get_inventory()
|
||||||
local filtered_list, counter = {}, 0
|
local filtered_list, c = {}, 0
|
||||||
|
|
||||||
for i = 1, #items_list do
|
for i = 1, #items_list do
|
||||||
local item = items_list[i]
|
local item = items_list[i]
|
||||||
@ -525,14 +525,14 @@ local function get_filter_items(data, player)
|
|||||||
|
|
||||||
if filter ~= "" then
|
if filter ~= "" then
|
||||||
if item:find(filter, 1, true) or item_desc:find(filter, 1, true) then
|
if item:find(filter, 1, true) or item_desc:find(filter, 1, true) then
|
||||||
counter = counter + 1
|
c = c + 1
|
||||||
filtered_list[counter] = item
|
filtered_list[c] = item
|
||||||
end
|
end
|
||||||
elseif progressive_mode then
|
elseif progressive_mode then
|
||||||
local _, has_item = recipe_in_inv(inv, item)
|
local _, has_item = recipe_in_inv(inv, item)
|
||||||
if has_item then
|
if has_item then
|
||||||
counter = counter + 1
|
c = c + 1
|
||||||
filtered_list[counter] = item
|
filtered_list[c] = item
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -572,6 +572,7 @@ local function get_init_items()
|
|||||||
init_items[c] = name
|
init_items[c] = name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sort(init_items)
|
sort(init_items)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -648,7 +649,12 @@ local function get_fields(player, ...)
|
|||||||
|
|
||||||
elseif (fields.key_enter_field == "filter" or fields.search) and
|
elseif (fields.key_enter_field == "filter" or fields.search) and
|
||||||
fields.filter ~= "" then
|
fields.filter ~= "" then
|
||||||
data.filter = fields.filter:lower()
|
local fltr = fields.filter:lower()
|
||||||
|
if data.filter == fltr then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
data.filter = fltr
|
||||||
data.pagenum = 1
|
data.pagenum = 1
|
||||||
get_filter_items(data, player)
|
get_filter_items(data, player)
|
||||||
show_fs(player, player_name)
|
show_fs(player, player_name)
|
||||||
|
Loading…
Reference in New Issue
Block a user