From 9953f81248d3542702bcfd6cc543b6833b148ec2 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 6 Nov 2023 23:28:08 -0800 Subject: [PATCH 1/9] Add search to Zones page --- plugins/lua/sort.lua | 1 + plugins/lua/sort/places.lua | 121 ++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 plugins/lua/sort/places.lua diff --git a/plugins/lua/sort.lua b/plugins/lua/sort.lua index 6b9c963bd..68e422ac6 100644 --- a/plugins/lua/sort.lua +++ b/plugins/lua/sort.lua @@ -1297,6 +1297,7 @@ OVERLAY_WIDGETS = { worker_assignment=require('plugins.sort.unitselector').WorkerAssignmentOverlay, slab=require('plugins.sort.slab').SlabOverlay, world=require('plugins.sort.world').WorldOverlay, + places=require('plugins.sort.places').PlacesOverlay, } dfhack.onStateChange[GLOBAL_KEY] = function(sc) diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua new file mode 100644 index 000000000..c57e728ee --- /dev/null +++ b/plugins/lua/sort/places.lua @@ -0,0 +1,121 @@ +local _ENV = mkmodule('plugins.sort.places') + +local sortoverlay = require('plugins.sort.sortoverlay') +local widgets = require('gui.widgets') + +local info = df.global.game.main_interface.info +local buildings = info.buildings + +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.WaterSource then return 'Water source' 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.Pond then return 'Pit/pond' 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.AnimalTraining then return 'Animal training' 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.MeetingHall then return 'Meeting area' 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.Office then return 'Office' 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.Bedroom then return 'Bedroom' 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 +end + +local function get_zone_search_key(zone) + local site = df.global.world.world_data.active_site[0] + local result = {} + + -- allow zones to be searchable by their name + if zone.name == nil or zone.name == '' then + table.insert(result, get_default_zone_name(zone.type)) + else + table.insert(result, zone.name) + end + + -- allow zones w/ assignments to be searchable by their assigned unit + if zone.assigned_unit ~= nil then + table.insert(result, dfhack.TranslateName(zone.assigned_unit.name)) + table.insert(result, dfhack.units.getReadableName(zone.assigned_unit)) + end + + -- 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 + table.insert(result, df.civzone_type[zone.type]); + 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, df.civzone_type[site.buildings[zone.location_id].name.type]) + end + + -- allow barracks to be searchable by assigned squad + for _, squad in ipairs(zone.squad_room_info) do + table.insert(result, dfhack.military.getSquadName(squad.squad_id)) + end + + return table.concat(result, ' ') +end + +-- ---------------------- +-- PlacesOverlay +-- + +PlacesOverlay = defclass(PlacesOverlay, sortoverlay.SortOverlay) +PlacesOverlay.ATTRS{ + default_pos={x=71, y=8}, + viewscreens='dwarfmode/Info', + frame={w=40, h=6} +} + +function PlacesOverlay:init() + self:addviews{ + widgets.BannerPanel{ + frame={l=0, t=0, r=0, h=1}, + visible=self:callback('get_key'), + subviews={ + widgets.EditField{ + view_id='search', + frame={l=1, t=0, r=1}, + label_text="Search: ", + key='CUSTOM_ALT_S', + 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})) +end + +function PlacesOverlay:get_key() + 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 + -- 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 + return 'ZONES' + end + end +end + +function PlacesOverlay:onRenderBody(dc) + PlacesOverlay.super.onRenderBody(self, dc) + if self.refresh_search then + self.refresh_search = nil + self:do_search(self.subviews.search.text) + end +end + +function PlacesOverlay:onInput(keys) + if keys._MOUSE_L then + self.refresh_search = true + end + return PlacesOverlay.super.onInput(self, keys) +end + +return _ENV \ No newline at end of file From b71e283b3e9c77967421279c565230373b8af4ec Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Nov 2023 07:54:34 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugins/lua/sort/places.lua | 242 ++++++++++++++++++------------------ 1 file changed, 121 insertions(+), 121 deletions(-) diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua index c57e728ee..f00599d87 100644 --- a/plugins/lua/sort/places.lua +++ b/plugins/lua/sort/places.lua @@ -1,121 +1,121 @@ -local _ENV = mkmodule('plugins.sort.places') - -local sortoverlay = require('plugins.sort.sortoverlay') -local widgets = require('gui.widgets') - -local info = df.global.game.main_interface.info -local buildings = info.buildings - -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.WaterSource then return 'Water source' 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.Pond then return 'Pit/pond' 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.AnimalTraining then return 'Animal training' 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.MeetingHall then return 'Meeting area' 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.Office then return 'Office' 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.Bedroom then return 'Bedroom' 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 -end - -local function get_zone_search_key(zone) - local site = df.global.world.world_data.active_site[0] - local result = {} - - -- allow zones to be searchable by their name - if zone.name == nil or zone.name == '' then - table.insert(result, get_default_zone_name(zone.type)) - else - table.insert(result, zone.name) - end - - -- allow zones w/ assignments to be searchable by their assigned unit - if zone.assigned_unit ~= nil then - table.insert(result, dfhack.TranslateName(zone.assigned_unit.name)) - table.insert(result, dfhack.units.getReadableName(zone.assigned_unit)) - end - - -- 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 - table.insert(result, df.civzone_type[zone.type]); - 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, df.civzone_type[site.buildings[zone.location_id].name.type]) - end - - -- allow barracks to be searchable by assigned squad - for _, squad in ipairs(zone.squad_room_info) do - table.insert(result, dfhack.military.getSquadName(squad.squad_id)) - end - - return table.concat(result, ' ') -end - --- ---------------------- --- PlacesOverlay --- - -PlacesOverlay = defclass(PlacesOverlay, sortoverlay.SortOverlay) -PlacesOverlay.ATTRS{ - default_pos={x=71, y=8}, - viewscreens='dwarfmode/Info', - frame={w=40, h=6} -} - -function PlacesOverlay:init() - self:addviews{ - widgets.BannerPanel{ - frame={l=0, t=0, r=0, h=1}, - visible=self:callback('get_key'), - subviews={ - widgets.EditField{ - view_id='search', - frame={l=1, t=0, r=1}, - label_text="Search: ", - key='CUSTOM_ALT_S', - 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})) -end - -function PlacesOverlay:get_key() - 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 - -- 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 - return 'ZONES' - end - end -end - -function PlacesOverlay:onRenderBody(dc) - PlacesOverlay.super.onRenderBody(self, dc) - if self.refresh_search then - self.refresh_search = nil - self:do_search(self.subviews.search.text) - end -end - -function PlacesOverlay:onInput(keys) - if keys._MOUSE_L then - self.refresh_search = true - end - return PlacesOverlay.super.onInput(self, keys) -end - -return _ENV \ No newline at end of file +local _ENV = mkmodule('plugins.sort.places') + +local sortoverlay = require('plugins.sort.sortoverlay') +local widgets = require('gui.widgets') + +local info = df.global.game.main_interface.info +local buildings = info.buildings + +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.WaterSource then return 'Water source' 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.Pond then return 'Pit/pond' 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.AnimalTraining then return 'Animal training' 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.MeetingHall then return 'Meeting area' 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.Office then return 'Office' 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.Bedroom then return 'Bedroom' 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 +end + +local function get_zone_search_key(zone) + local site = df.global.world.world_data.active_site[0] + local result = {} + + -- allow zones to be searchable by their name + if zone.name == nil or zone.name == '' then + table.insert(result, get_default_zone_name(zone.type)) + else + table.insert(result, zone.name) + end + + -- allow zones w/ assignments to be searchable by their assigned unit + if zone.assigned_unit ~= nil then + table.insert(result, dfhack.TranslateName(zone.assigned_unit.name)) + table.insert(result, dfhack.units.getReadableName(zone.assigned_unit)) + end + + -- 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 + table.insert(result, df.civzone_type[zone.type]); + 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, df.civzone_type[site.buildings[zone.location_id].name.type]) + end + + -- allow barracks to be searchable by assigned squad + for _, squad in ipairs(zone.squad_room_info) do + table.insert(result, dfhack.military.getSquadName(squad.squad_id)) + end + + return table.concat(result, ' ') +end + +-- ---------------------- +-- PlacesOverlay +-- + +PlacesOverlay = defclass(PlacesOverlay, sortoverlay.SortOverlay) +PlacesOverlay.ATTRS{ + default_pos={x=71, y=8}, + viewscreens='dwarfmode/Info', + frame={w=40, h=6} +} + +function PlacesOverlay:init() + self:addviews{ + widgets.BannerPanel{ + frame={l=0, t=0, r=0, h=1}, + visible=self:callback('get_key'), + subviews={ + widgets.EditField{ + view_id='search', + frame={l=1, t=0, r=1}, + label_text="Search: ", + key='CUSTOM_ALT_S', + 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})) +end + +function PlacesOverlay:get_key() + 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 + -- 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 + return 'ZONES' + end + end +end + +function PlacesOverlay:onRenderBody(dc) + PlacesOverlay.super.onRenderBody(self, dc) + if self.refresh_search then + self.refresh_search = nil + self:do_search(self.subviews.search.text) + end +end + +function PlacesOverlay:onInput(keys) + if keys._MOUSE_L then + self.refresh_search = true + end + return PlacesOverlay.super.onInput(self, keys) +end + +return _ENV From 2162341e7ff5f21590b940c097289d98ae15f54a Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 7 Nov 2023 02:24:30 -0800 Subject: [PATCH 3/9] Implement myk002's proposed changes --- plugins/lua/sort/places.lua | 76 +++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua index f00599d87..9183fe95d 100644 --- a/plugins/lua/sort/places.lua +++ b/plugins/lua/sort/places.lua @@ -2,31 +2,34 @@ local _ENV = mkmodule('plugins.sort.places') local sortoverlay = require('plugins.sort.sortoverlay') local widgets = require('gui.widgets') +local utils = require('utils') local info = df.global.game.main_interface.info local buildings = info.buildings +local zone_names = { + [df.civzone_type.MeetingHall] = 'Meeting Area', + [df.civzone_type.Bedroom] = 'Bedroom', + [df.civzone_type.DiningHall] = 'Dining Hall', + [df.civzone_type.Pen] = 'Pen/Pasture', + [df.civzone_type.Pond] = 'Pit/Pond', + [df.civzone_type.WaterSource] = 'Water Source', + [df.civzone_type.Dungeon] = 'Dungeon', + [df.civzone_type.FishingArea] = 'Fishing', + [df.civzone_type.SandCollection] = 'Sand', + [df.civzone_type.Office] = 'Office', + [df.civzone_type.Dormitory] = 'Dormitory', + [df.civzone_type.Barracks] = 'Barrachs', + [df.civzone_type.ArcheryRange] = 'Archery Range', + [df.civzone_type.Dump] = 'Garbage Dump', + [df.civzone_type.AnimalTraining] = 'Animal Training', + [df.civzone_type.Tomb] = 'Tomb', + [df.civzone_type.PlantGathering] = 'Gather Fruit', + [df.civzone_type.ClayCollection] = 'Clay' +} + 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.WaterSource then return 'Water source' 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.Pond then return 'Pit/pond' 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.AnimalTraining then return 'Animal training' 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.MeetingHall then return 'Meeting area' 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.Office then return 'Office' 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.Bedroom then return 'Bedroom' 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 zone_names[zone_type] or '' end local function get_zone_search_key(zone) @@ -34,7 +37,7 @@ local function get_zone_search_key(zone) local result = {} -- allow zones to be searchable by their name - if zone.name == nil or zone.name == '' then + if #zone.name == 0 then table.insert(result, get_default_zone_name(zone.type)) else table.insert(result, zone.name) @@ -42,16 +45,20 @@ local function get_zone_search_key(zone) -- allow zones w/ assignments to be searchable by their assigned unit if zone.assigned_unit ~= nil then - table.insert(result, dfhack.TranslateName(zone.assigned_unit.name)) - table.insert(result, dfhack.units.getReadableName(zone.assigned_unit)) + table.insert(result, sortoverlay.get_unit_search_key(zone.assigned_unit)) end -- 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 table.insert(result, df.civzone_type[zone.type]); 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, df.civzone_type[site.buildings[zone.location_id].name.type]) + local building, success, _ = utils.binsearch(site.buildings, zone.location_id, 'id') + if success then + table.insert(result, df.language_name_type[building.name.type]) + if building.name and building.name.has_name then + table.insert(result, dfhack.TranslateName(building.name, true)) + end + end end -- allow barracks to be searchable by assigned squad @@ -68,7 +75,7 @@ end PlacesOverlay = defclass(PlacesOverlay, sortoverlay.SortOverlay) PlacesOverlay.ATTRS{ - default_pos={x=71, y=8}, + default_pos={x=71, y=9}, viewscreens='dwarfmode/Info', frame={w=40, h=6} } @@ -103,19 +110,4 @@ function PlacesOverlay:get_key() end end -function PlacesOverlay:onRenderBody(dc) - PlacesOverlay.super.onRenderBody(self, dc) - if self.refresh_search then - self.refresh_search = nil - self:do_search(self.subviews.search.text) - end -end - -function PlacesOverlay:onInput(keys) - if keys._MOUSE_L then - self.refresh_search = true - end - return PlacesOverlay.super.onInput(self, keys) -end - -return _ENV +return _ENV \ No newline at end of file From 8b625e30dbcacf586ac17c94dd4dc8a3bc094671 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:26:03 +0000 Subject: [PATCH 4/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- plugins/lua/sort/places.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua index 9183fe95d..ab6720c2d 100644 --- a/plugins/lua/sort/places.lua +++ b/plugins/lua/sort/places.lua @@ -110,4 +110,4 @@ function PlacesOverlay:get_key() end end -return _ENV \ No newline at end of file +return _ENV From 4798dc656020c14ba2c22dcff49a8beff0e8c856 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 7 Nov 2023 02:30:06 -0800 Subject: [PATCH 5/9] Fix nested if order of operations --- plugins/lua/sort/places.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua index ab6720c2d..dc8816970 100644 --- a/plugins/lua/sort/places.lua +++ b/plugins/lua/sort/places.lua @@ -53,9 +53,9 @@ local function get_zone_search_key(zone) table.insert(result, df.civzone_type[zone.type]); else -- zone is a special location and we need to get its type from world data local building, success, _ = utils.binsearch(site.buildings, zone.location_id, 'id') - if success then + if success and building.name then table.insert(result, df.language_name_type[building.name.type]) - if building.name and building.name.has_name then + if building.name.has_name then table.insert(result, dfhack.TranslateName(building.name, true)) end end From fc2819ec1ac5e0b63a02a0d8c39e685c424af858 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 7 Nov 2023 12:52:04 -0800 Subject: [PATCH 6/9] Add get_typestring_from_language_name --- plugins/lua/sort/places.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua index dc8816970..0baefb980 100644 --- a/plugins/lua/sort/places.lua +++ b/plugins/lua/sort/places.lua @@ -28,10 +28,22 @@ local zone_names = { [df.civzone_type.ClayCollection] = 'Clay' } +-- I used strings rather than df.civzone_type because nobody is going to search "MeadHall" they're going to search "Tavern" +local language_name_type_strings = { + [df.language_name_type.SymbolFood] = 'Inn/Tavern', + [df.language_name_type.SymbolDomestic] = 'MarketStall' +} + local function get_default_zone_name(zone_type) return zone_names[zone_type] or '' end +local function get_typestring_from_language_name(language_name_type) + -- Looking at df.language.xml I think SymbolFood and SymbolDomestic are the only two we need to override? + -- Every other df.language_name_type for a location matches the displayed type name (e.g. Temples are language_name_type.Temple, etc) + return language_name_type_strings[language_name_type] or df.language_name_type[language_name_type] +end + local function get_zone_search_key(zone) local site = df.global.world.world_data.active_site[0] local result = {} @@ -54,7 +66,7 @@ local function get_zone_search_key(zone) else -- zone is a special location and we need to get its type from world data local building, success, _ = utils.binsearch(site.buildings, zone.location_id, 'id') if success and building.name then - table.insert(result, df.language_name_type[building.name.type]) + table.insert(result, get_typestring_from_language_name(building.name.type)) if building.name.has_name then table.insert(result, dfhack.TranslateName(building.name, true)) end From 14d441344f0a7eaa44f9d9aa3dfba4e9c300123d Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 7 Nov 2023 12:55:55 -0800 Subject: [PATCH 7/9] Rename 'get_typestring_from_language_name' to 'get_location_type_from_language_name' --- plugins/lua/sort/places.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua index 0baefb980..de4017e8f 100644 --- a/plugins/lua/sort/places.lua +++ b/plugins/lua/sort/places.lua @@ -38,7 +38,7 @@ local function get_default_zone_name(zone_type) return zone_names[zone_type] or '' end -local function get_typestring_from_language_name(language_name_type) +local function get_location_type_from_language_name(language_name_type) -- Looking at df.language.xml I think SymbolFood and SymbolDomestic are the only two we need to override? -- Every other df.language_name_type for a location matches the displayed type name (e.g. Temples are language_name_type.Temple, etc) return language_name_type_strings[language_name_type] or df.language_name_type[language_name_type] @@ -66,7 +66,7 @@ local function get_zone_search_key(zone) else -- zone is a special location and we need to get its type from world data local building, success, _ = utils.binsearch(site.buildings, zone.location_id, 'id') if success and building.name then - table.insert(result, get_typestring_from_language_name(building.name.type)) + table.insert(result, get_location_type_from_language_name(building.name.type)) if building.name.has_name then table.insert(result, dfhack.TranslateName(building.name, true)) end From e58553fd0cd66245d680b8864bed981bd39cf7a7 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 7 Nov 2023 21:29:27 -0800 Subject: [PATCH 8/9] Replace get_location_type_from_language_name with static language_name_type mapping --- plugins/lua/sort/places.lua | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua index de4017e8f..e592081ad 100644 --- a/plugins/lua/sort/places.lua +++ b/plugins/lua/sort/places.lua @@ -29,21 +29,17 @@ local zone_names = { } -- I used strings rather than df.civzone_type because nobody is going to search "MeadHall" they're going to search "Tavern" -local language_name_type_strings = { +local language_name_types = { [df.language_name_type.SymbolFood] = 'Inn/Tavern', - [df.language_name_type.SymbolDomestic] = 'MarketStall' + [df.language_name_type.Temple] = 'Temple', + [df.language_name_type.Hospital] = 'Hospital', + [df.language_name_type.Guildhall] = 'Guildhall' } local function get_default_zone_name(zone_type) return zone_names[zone_type] or '' end -local function get_location_type_from_language_name(language_name_type) - -- Looking at df.language.xml I think SymbolFood and SymbolDomestic are the only two we need to override? - -- Every other df.language_name_type for a location matches the displayed type name (e.g. Temples are language_name_type.Temple, etc) - return language_name_type_strings[language_name_type] or df.language_name_type[language_name_type] -end - local function get_zone_search_key(zone) local site = df.global.world.world_data.active_site[0] local result = {} @@ -66,7 +62,7 @@ local function get_zone_search_key(zone) else -- zone is a special location and we need to get its type from world data local building, success, _ = utils.binsearch(site.buildings, zone.location_id, 'id') if success and building.name then - table.insert(result, get_location_type_from_language_name(building.name.type)) + table.insert(result, language_name_types[building.name.type] or '') if building.name.has_name then table.insert(result, dfhack.TranslateName(building.name, true)) end From 924c7802102380b092e7063f5ec95311241eaec3 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 8 Nov 2023 00:30:58 -0800 Subject: [PATCH 9/9] Replace slashes with spaces for multi-named zones --- plugins/lua/sort/places.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/lua/sort/places.lua b/plugins/lua/sort/places.lua index e592081ad..5292d227b 100644 --- a/plugins/lua/sort/places.lua +++ b/plugins/lua/sort/places.lua @@ -11,8 +11,8 @@ local zone_names = { [df.civzone_type.MeetingHall] = 'Meeting Area', [df.civzone_type.Bedroom] = 'Bedroom', [df.civzone_type.DiningHall] = 'Dining Hall', - [df.civzone_type.Pen] = 'Pen/Pasture', - [df.civzone_type.Pond] = 'Pit/Pond', + [df.civzone_type.Pen] = 'Pen Pasture', + [df.civzone_type.Pond] = 'Pit Pond', [df.civzone_type.WaterSource] = 'Water Source', [df.civzone_type.Dungeon] = 'Dungeon', [df.civzone_type.FishingArea] = 'Fishing', @@ -30,7 +30,7 @@ local zone_names = { -- I used strings rather than df.civzone_type because nobody is going to search "MeadHall" they're going to search "Tavern" local language_name_types = { - [df.language_name_type.SymbolFood] = 'Inn/Tavern', + [df.language_name_type.SymbolFood] = 'Inn Tavern', [df.language_name_type.Temple] = 'Temple', [df.language_name_type.Hospital] = 'Hospital', [df.language_name_type.Guildhall] = 'Guildhall'