Better code reuse with locationselector.get_religion_string

develop
Ryan Dwyer 2023-11-08 12:41:28 -08:00
parent f3e96d206c
commit 217258b013
2 changed files with 6 additions and 35 deletions

@ -31,7 +31,7 @@ local function stringify_spheres(spheres)
return table.concat(strs, ' ')
end
local function get_religion_string(religion_id, religion_type)
function get_religion_string(religion_id, religion_type)
if religion_id == -1 then return end
local entity
local spheres = {}

@ -1,6 +1,7 @@
local _ENV = mkmodule('plugins.sort.places')
local sortoverlay = require('plugins.sort.sortoverlay')
local locationselector = require('plugins.sort.locationselector')
local widgets = require('gui.widgets')
local utils = require('utils')
@ -37,39 +38,9 @@ local language_name_types = {
[df.language_name_type.Library] = 'Library'
}
local function add_spheres(hf, spheres)
if not hf then return end
for _, sphere in ipairs(hf.info.spheres.spheres) do
spheres[sphere] = true
end
end
local function stringify_spheres(spheres)
local strs = {}
for sphere in pairs(spheres) do
table.insert(strs, df.sphere_type[sphere])
end
return table.concat(strs, ' ')
end
local function get_religion_string(religion_id, religion_type)
if religion_id == -1 then return '' end
if religion_type == -1 then return 'Temple' end
local entity
local spheres = {}
if religion_type == 0 then
entity = df.historical_figure.find(religion_id)
add_spheres(entity, spheres)
elseif religion_type == 1 then
entity = df.historical_entity.find(religion_id)
if entity then
for _, deity in ipairs(entity.relations.deities) do
add_spheres(df.historical_figure.find(deity), spheres)
end
end
end
if not entity then return end
return ('%s %s'):format(dfhack.TranslateName(entity.name, true), stringify_spheres(spheres))
local function get_location_religion(religion_id, religion_type)
if religion_type == -1 then return 'Temple'
else return locationselector.get_religion_string(religion_id, religion_type) or '' end
end
local function get_default_zone_name(zone_type)
@ -128,7 +99,7 @@ local function get_location_search_key(zone)
-- for temples and guildhalls, get assigned organization
if language_name_types[building.name.type] == 'Temple' then
table.insert(result, get_religion_string(building.deity_data.Deity or building.deity_data.Religion, building.deity_type))
table.insert(result, get_location_religion(building.deity_data.Deity or building.deity_data.Religion, building.deity_type))
elseif language_name_types[building.name.type] == 'Guildhall' then
-- Broke this up into two locals because table.insert doesn't like it all being inside the second argument for some reason
local profession = df.profession[building.contents.profession]