[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
develop
pre-commit-ci[bot] 2023-11-07 07:54:34 +00:00
parent 9953f81248
commit b71e283b3e
1 changed files with 121 additions and 121 deletions

@ -1,121 +1,121 @@
local _ENV = mkmodule('plugins.sort.places') local _ENV = mkmodule('plugins.sort.places')
local sortoverlay = require('plugins.sort.sortoverlay') local sortoverlay = require('plugins.sort.sortoverlay')
local widgets = require('gui.widgets') local widgets = require('gui.widgets')
local info = df.global.game.main_interface.info local info = df.global.game.main_interface.info
local buildings = info.buildings local buildings = info.buildings
local function get_default_zone_name(zone_type) local function get_default_zone_name(zone_type)
if zone_type == df.civzone_type.Dump then return 'Garbage dump' end if zone_type == df.civzone_type.Dump then return 'Garbage dump' end
if zone_type == df.civzone_type.WaterSource then return 'Water source' end if zone_type == df.civzone_type.WaterSource then return 'Water source' end
if zone_type == df.civzone_type.SandCollection then return 'Sand' end if zone_type == df.civzone_type.SandCollection then return 'Sand' end
if zone_type == df.civzone_type.FishingArea then return 'Fishing' end if zone_type == df.civzone_type.FishingArea then return 'Fishing' end
if zone_type == df.civzone_type.Pond then return 'Pit/pond' end if zone_type == df.civzone_type.Pond then return 'Pit/pond' end
if zone_type == df.civzone_type.Pen then return 'Pen/pasture' end if zone_type == df.civzone_type.Pen then return 'Pen/pasture' end
if zone_type == df.civzone_type.ClayCollection then return 'Clay' end if zone_type == df.civzone_type.ClayCollection then return 'Clay' end
if zone_type == df.civzone_type.AnimalTraining then return 'Animal training' end if zone_type == df.civzone_type.AnimalTraining then return 'Animal training' end
if zone_type == df.civzone_type.PlantGathering then return 'Gather fruit' end if zone_type == df.civzone_type.PlantGathering then return 'Gather fruit' end
if zone_type == df.civzone_type.Dungeon then return 'Dungeon' end if zone_type == df.civzone_type.Dungeon then return 'Dungeon' end
if zone_type == df.civzone_type.MeetingHall then return 'Meeting area' end if zone_type == df.civzone_type.MeetingHall then return 'Meeting area' end
if zone_type == df.civzone_type.Barracks then return 'Barracks' end if zone_type == df.civzone_type.Barracks then return 'Barracks' end
if zone_type == df.civzone_type.ArcheryRange then return 'Archery range' end if zone_type == df.civzone_type.ArcheryRange then return 'Archery range' end
if zone_type == df.civzone_type.Office then return 'Office' end if zone_type == df.civzone_type.Office then return 'Office' end
if zone_type == df.civzone_type.DiningHall then return 'Dining hall' end if zone_type == df.civzone_type.DiningHall then return 'Dining hall' end
if zone_type == df.civzone_type.Dormitory then return 'Dormitory' end if zone_type == df.civzone_type.Dormitory then return 'Dormitory' end
if zone_type == df.civzone_type.Bedroom then return 'Bedroom' end if zone_type == df.civzone_type.Bedroom then return 'Bedroom' end
if zone_type == df.civzone_type.Tomb then return 'Tomb' end if zone_type == df.civzone_type.Tomb then return 'Tomb' end
return '' -- If zone_type is anything else it will not have a default name populated in the Zones page when left nameless return '' -- If zone_type is anything else it will not have a default name populated in the Zones page when left nameless
end end
local function get_zone_search_key(zone) local function get_zone_search_key(zone)
local site = df.global.world.world_data.active_site[0] local site = df.global.world.world_data.active_site[0]
local result = {} local result = {}
-- allow zones to be searchable by their name -- allow zones to be searchable by their name
if zone.name == nil or zone.name == '' then if zone.name == nil or zone.name == '' then
table.insert(result, get_default_zone_name(zone.type)) table.insert(result, get_default_zone_name(zone.type))
else else
table.insert(result, zone.name) table.insert(result, zone.name)
end end
-- allow zones w/ assignments to be searchable by their assigned unit -- allow zones w/ assignments to be searchable by their assigned unit
if zone.assigned_unit ~= nil then if zone.assigned_unit ~= nil then
table.insert(result, dfhack.TranslateName(zone.assigned_unit.name)) table.insert(result, dfhack.TranslateName(zone.assigned_unit.name))
table.insert(result, dfhack.units.getReadableName(zone.assigned_unit)) table.insert(result, dfhack.units.getReadableName(zone.assigned_unit))
end end
-- allow zones to be searchable by type -- allow zones to be searchable by type
if zone.location_id == -1 then -- zone is NOT a special location and we don't need to do anything special for type searching if zone.location_id == -1 then -- zone is NOT a special location and we don't need to do anything special for type searching
table.insert(result, df.civzone_type[zone.type]); table.insert(result, df.civzone_type[zone.type]);
else -- zone is a special location and we need to get its type from world data else -- zone is a special location and we need to get its type from world data
table.insert(result, dfhack.TranslateName(site.buildings[zone.location_id].name, true)) table.insert(result, dfhack.TranslateName(site.buildings[zone.location_id].name, true))
table.insert(result, df.civzone_type[site.buildings[zone.location_id].name.type]) table.insert(result, df.civzone_type[site.buildings[zone.location_id].name.type])
end end
-- allow barracks to be searchable by assigned squad -- allow barracks to be searchable by assigned squad
for _, squad in ipairs(zone.squad_room_info) do for _, squad in ipairs(zone.squad_room_info) do
table.insert(result, dfhack.military.getSquadName(squad.squad_id)) table.insert(result, dfhack.military.getSquadName(squad.squad_id))
end end
return table.concat(result, ' ') return table.concat(result, ' ')
end end
-- ---------------------- -- ----------------------
-- PlacesOverlay -- PlacesOverlay
-- --
PlacesOverlay = defclass(PlacesOverlay, sortoverlay.SortOverlay) PlacesOverlay = defclass(PlacesOverlay, sortoverlay.SortOverlay)
PlacesOverlay.ATTRS{ PlacesOverlay.ATTRS{
default_pos={x=71, y=8}, default_pos={x=71, y=8},
viewscreens='dwarfmode/Info', viewscreens='dwarfmode/Info',
frame={w=40, h=6} frame={w=40, h=6}
} }
function PlacesOverlay:init() function PlacesOverlay:init()
self:addviews{ self:addviews{
widgets.BannerPanel{ widgets.BannerPanel{
frame={l=0, t=0, r=0, h=1}, frame={l=0, t=0, r=0, h=1},
visible=self:callback('get_key'), visible=self:callback('get_key'),
subviews={ subviews={
widgets.EditField{ widgets.EditField{
view_id='search', view_id='search',
frame={l=1, t=0, r=1}, frame={l=1, t=0, r=1},
label_text="Search: ", label_text="Search: ",
key='CUSTOM_ALT_S', key='CUSTOM_ALT_S',
on_change=function(text) self:do_search(text) end, on_change=function(text) self:do_search(text) end,
}, },
}, },
}, },
} }
self:register_handler('ZONES', buildings.list[df.buildings_mode_type.ZONES], curry(sortoverlay.single_vector_search, {get_search_key_fn=get_zone_search_key})) self:register_handler('ZONES', buildings.list[df.buildings_mode_type.ZONES], curry(sortoverlay.single_vector_search, {get_search_key_fn=get_zone_search_key}))
end end
function PlacesOverlay:get_key() function PlacesOverlay:get_key()
if info.current_mode == df.info_interface_mode_type.BUILDINGS then if info.current_mode == df.info_interface_mode_type.BUILDINGS then
-- TODO: Replace nested if with 'return df.buildings_mode_type[buildings.mode]' once other handlers are written -- TODO: Replace nested if with 'return df.buildings_mode_type[buildings.mode]' once other handlers are written
-- Not there right now so it doesn't render a search bar on unsupported Places subpages -- Not there right now so it doesn't render a search bar on unsupported Places subpages
if buildings.mode == df.buildings_mode_type.ZONES then if buildings.mode == df.buildings_mode_type.ZONES then
return 'ZONES' return 'ZONES'
end end
end end
end end
function PlacesOverlay:onRenderBody(dc) function PlacesOverlay:onRenderBody(dc)
PlacesOverlay.super.onRenderBody(self, dc) PlacesOverlay.super.onRenderBody(self, dc)
if self.refresh_search then if self.refresh_search then
self.refresh_search = nil self.refresh_search = nil
self:do_search(self.subviews.search.text) self:do_search(self.subviews.search.text)
end end
end end
function PlacesOverlay:onInput(keys) function PlacesOverlay:onInput(keys)
if keys._MOUSE_L then if keys._MOUSE_L then
self.refresh_search = true self.refresh_search = true
end end
return PlacesOverlay.super.onInput(self, keys) return PlacesOverlay.super.onInput(self, keys)
end end
return _ENV return _ENV