Module:RegionLister/NameBuilder
From Terra Invicta Official Wiki
Documentation for this module may be created at Module:RegionLister/NameBuilder/doc
-- This module builds a full name for a region (possibly with respect to a nation.)
-- Other modules should use this to name regions consistently.
local p = {}
local IconModule = require('Module:Icon')
local RegionData = mw.loadData('Module:CSVReader/Region')
local ClaimData = mw.loadData('Module:CSVReader/Claim')
local MapRegionData = mw.loadData('Module:CSVReader/MapRegion')
local RegionNames = mw.loadData('Module:ENReader/Region')
local ssub = string.sub
function p.buildName( frame )
-- Read parameters
--- [1] is region data name (mandatory)
--- [2] is nation data name (optional)
local regionID = frame.args[1]
local nationID = frame.args[2]
if not regionID or not RegionData[regionID] then
return 'No such Region'
end
local regionString = ''
local openedSpan = false
-- Check whether nationID was given
if nationID and mw.text.trim(nationID) ~= '' then
-- Check whether nation's claim on the region should be hostile.
--- If it does not have a claim, that means it IS hostile.
if not ClaimData[3][nationID][regionID] or ClaimData[3][nationID][regionID]['hostileClaim'] == 'true' then
regionString = '<span style="color:red">'
openedSpan = true
end
end
regionString = regionString .. (RegionNames['TIRegionTemplate.displayName.' .. regionID] or RegionNames['TIRegionTemplate.displayName.' .. ssub(regionID,6)] or regionID)
-- If the nation has a direct claim on the region:
if nationID and ClaimData[3][nationID][regionID] then
-- Check for capital or colony flags
if ClaimData[3][nationID][regionID]['capitalClaim'] == 'true' then
regionString = regionString .. IconModule.Icon({args={'capital', bgcolor='DarkSlateGray'}})
elseif ClaimData[3][nationID][regionID]['initialColony'] == 'true' then
regionString = regionString .. IconModule.Icon({args={'colony', bgcolor='DarkSlateGray'}})
end
end
-- Check for eco/mining/oil flags
if RegionData[regionID]['oilResource'] == 'true' then
regionString = regionString .. IconModule.Icon({args={'oil region'}})
elseif RegionData[regionID]['mining'] == 'true' then
regionString = regionString .. IconModule.Icon({args={'resource region'}})
elseif RegionData[regionID]['coreEco'] == 'true' then
regionString = regionString .. IconModule.Icon({args={'core economic region', bgcolor='DarkSlateGray'}})
end
-- Check for environment flags
if RegionData[regionID]['environment'] == 'Vulnerable' then
regionString = regionString .. IconModule.Icon({args={'ecologically vulnerable region', bgcolor='DarkSlateGray'}})
elseif RegionData[regionID]['environment'] == 'Beneficiary' then
regionString = regionString .. IconModule.Icon({args={'ecologically protected region', bgcolor='DarkSlateGray'}})
end
-- Check for rugged flag
local mapRegionID = RegionData[regionID]['mapRegionName']
if MapRegionData[mapRegionID]['terrain'] == 'Rugged' then
regionString = regionString .. IconModule.Icon({args={'rugged'}})
end
-- Close span if opened.
if openedSpan then
regionString = regionString .. '</span>'
end
return regionString
end
return p


