Skip to content

Commit

Permalink
Merge pull request #4049 from myk002/myk_sort_tasks
Browse files Browse the repository at this point in the history
[sort] search associated building in tasks tab
  • Loading branch information
myk002 authored Nov 21, 2023
2 parents 6a14876 + ecd7849 commit 121106d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Template for new versions:
- `buildingplan`: save magma safe mechanisms for when magma safety is requested when linking levers and pressure plates to targets
- `buildingplan`: when choosing mechanisms for linking levers/pressure plates, filter out unreachable mechanisms
- `tailor`: corrected a corner case that resulted in existing stock being ignored in some circumstances
- `sort`: when searching on the Tasks tab, also search the names of the things the task is associated with, such as the name of the stockpile that an item will be stored in

## Documentation

Expand Down
30 changes: 29 additions & 1 deletion plugins/lua/sort/info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,34 @@ local function get_cri_unit_search_key(cri_unit)
cri_unit.job_sort_name)
end

local function get_task_search_key(cri_unit)
local result = {get_cri_unit_search_key(cri_unit)}

if cri_unit.jb then
local bld = dfhack.job.getHolder(cri_unit.jb)
if bld then
table.insert(result, bld.name)
local btype = bld:getType()
if btype == df.building_type.Workshop then
table.insert(result, df.workshop_type.attrs[bld.type].name or '')
table.insert(result, df.workshop_type[bld.type])
elseif btype == df.building_type.Furnace then
table.insert(result, df.furnace_type[bld.type])
elseif btype == df.building_type.Construction then
table.insert(result, df.construction_type[bld.type])
elseif btype == df.building_type.Trap then
table.insert(result, df.trap_type[bld.trap_type])
elseif btype == df.building_type.SiegeEngine then
table.insert(result, df.siegeengine_type[bld.type])
else
table.insert(result, df.building_type.attrs[btype].name)
end
end
end

return table.concat(result, ' ')
end

local function get_race_name(raw_id)
local raw = df.creature_raw.find(raw_id)
if not raw then return end
Expand Down Expand Up @@ -317,7 +345,7 @@ function InfoOverlay:init()
end

self:register_handler('JOBS', tasks.cri_job,
curry(sortoverlay.single_vector_search, {get_search_key_fn=get_cri_unit_search_key}),
curry(sortoverlay.single_vector_search, {get_search_key_fn=get_task_search_key}),
free_allocated_data)
self:register_handler('PET_OT', creatures.atk_index,
curry(sortoverlay.single_vector_search, {get_search_key_fn=get_race_name}))
Expand Down

0 comments on commit 121106d

Please sign in to comment.