enable filtering by race

develop
Myk Taylor 2023-09-05 17:49:58 -07:00
parent db67ff735a
commit 229e7aef87
No known key found for this signature in database
1 changed files with 15 additions and 8 deletions

@ -410,12 +410,19 @@ function AssignAnimal:refresh_list(sort_widget, sort_fn)
list:setFilter(saved_filter) list:setFilter(saved_filter)
end end
local function make_search_key(desc) function add_words(words, str)
local out = '' for word in dfhack.toSearchNormalized(str):gmatch("[%w-]+") do
for c in dfhack.toSearchNormalized(desc):gmatch("[%w%s]") do table.insert(words, word:lower())
out = out .. c:lower()
end end
return out end
function make_search_key(desc, race_raw)
local words = {}
add_words(words, desc)
if race_raw then
add_words(words, race_raw.name[0])
end
return table.concat(words, ' ')
end end
function AssignAnimal:make_choice_text(data) function AssignAnimal:make_choice_text(data)
@ -551,7 +558,7 @@ function AssignAnimal:cache_choices()
graze=dfhack.units.isGrazer(unit), graze=dfhack.units.isGrazer(unit),
} }
local choice = { local choice = {
search_key=make_search_key(data.desc), search_key=make_search_key(data.desc, raw),
data=data, data=data,
text=self:make_choice_text(data), text=self:make_choice_text(data),
} }
@ -570,7 +577,7 @@ function AssignAnimal:cache_choices()
disposition=get_item_disposition(vermin), disposition=get_item_disposition(vermin),
} }
local choice = { local choice = {
search_key=make_search_key(data.desc), search_key=make_search_key(data.desc, raw),
data=data, data=data,
text=self:make_choice_text(data), text=self:make_choice_text(data),
} }
@ -589,7 +596,7 @@ function AssignAnimal:cache_choices()
disposition=get_item_disposition(small_pet), disposition=get_item_disposition(small_pet),
} }
local choice = { local choice = {
search_key=make_search_key(data.desc), search_key=make_search_key(data.desc, raw),
data=data, data=data,
text=self:make_choice_text(data), text=self:make_choice_text(data),
} }