Module:RadiatorLister

From Terra Invicta Official Wiki

Documentation for this module may be created at Module:RadiatorLister/doc

---
---Reads the Radiator data files and presents them in readable formats, with additional calculated statistics.
---
---@module RadiatorLister
local RadiatorLister = {}

--region Dependencies
local IconModule = require('Module:Icon')
local TVModule = require('Module:TV')
local RadiatorData = mw.loadData('Module:CSVReader/Radiator')
local RadiatorNames = mw.loadData('Module:ENReader/Radiator')
local ProjectNameBuilder = require('Module:ProjectLister/NameBuilder')
--endregion

--region Private constants
local floor = math.floor
local round = function(num, decimals)
    local mult = 10^(decimals or 0)
    return floor(num * mult + 0.5) / mult
end
--endregion



--region Private member variables
--none
--endregion

--region Private methods


--endregion

--region Public methods
function RadiatorLister.ListDetailedRadiators()
	return RadiatorLister.ListRadiators(true)
end

function RadiatorLister.ListBasicRadiators()
	return RadiatorLister.ListRadiators(false)
end

---@param detailed boolean whether to show the detailed or basic version.
---@return wiki table of Radiators
function RadiatorLister.ListRadiators(detailed)
	local returnString = '{| class="wikitable sortable mw-collapsible" style="text-align: center;"'
	returnString = returnString .. '\n|-'
	returnString = returnString .. '\n! rowspan=2|Radiator'
	if detailed then
		returnString = returnString .. '\n! rowspan=2|Required Project'
	end
	returnString = returnString .. '\n! rowspan=2|Crew'
	if detailed then
		returnString = returnString .. '\n! rowspan=2|Combat Vulnerability'
	end
	returnString = returnString .. '\n! rowspan=2|Mass<br>(tons/GW)'
	
	if detailed then
		returnString = returnString .. '\n! colspan=4|Resources %'
		returnString = returnString .. '\n! colspan=4|Resources/GW'
		returnString = returnString .. '\n|-'
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'volatiles'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'metals'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'nobles'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'exotics'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'volatiles'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'metals'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'nobles'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'exotics'}})
	else
		returnString = returnString .. '\n! rowspan=2|Resources %'
	end
	returnString = returnString .. '\n|-'
	
	for rowID, row in pairs(RadiatorData) do
		returnString = returnString .. '\n| ' .. RadiatorNames['TIRadiatorTemplate.displayName.' .. rowID]
		
		if detailed then 
			returnString = returnString .. '\n| ' .. ProjectNameBuilder.buildName({args={row['requiredProjectName']}})
		end
		
		returnString = returnString .. '\n| ' .. row['crew']
		
		if detailed then 
			returnString = returnString .. '\n| ' .. row['vulnerability'] .. '%'
		end
		
		local massPerGW = 1000 / tonumber(row['specificPower_2s_KWkg'])  
		returnString = returnString .. '\n| ' .. round(massPerGW,2)
		
		local volatileCost = (tonumber(row['weightedBuildMaterials/volatiles']) or 0) * 100
		local metalCost = (tonumber(row['weightedBuildMaterials/metals']) or 0) * 100
		local nobleCost = (tonumber(row['weightedBuildMaterials/nobleMetals']) or 0) * 100
		local exoticCost = (tonumber(row['weightedBuildMaterials/exotics']) or 0) * 100
	
		if detailed then
			returnString = returnString .. '\n| ' .. round(volatileCost,1) .. '%'
			returnString = returnString .. '\n| ' .. round(metalCost,1) .. '%'
			returnString = returnString .. '\n| ' .. round(nobleCost,1) .. '%'
			returnString = returnString .. '\n| ' .. round(exoticCost,1) .. '%'
			returnString = returnString .. '\n| ' .. round(volatileCost / 1000 * massPerGW,2) 
			returnString = returnString .. '\n| ' .. round(metalCost / 1000 * massPerGW,2) 
			returnString = returnString .. '\n| ' .. round(nobleCost / 1000 * massPerGW,2) 
			returnString = returnString .. '\n| ' .. round(exoticCost / 1000 * massPerGW,2) 
		else
			returnString = returnString .. '\n| '
			if volatileCost ~= 0 then
				returnString = returnString .. TVModule.TV({args={'volatiles', volatileCost .. '%', 'true'}}) .. ' '
			end
			if metalCost ~= 0 then
				returnString = returnString .. TVModule.TV({args={'metals', metalCost .. '%', 'true'}}) .. ' '
			end
			if nobleCost ~= 0 then
				returnString = returnString .. TVModule.TV({args={'nobles', nobleCost .. '%', 'true'}}) .. ' '
			end
			if exoticCost ~= 0 then
				returnString = returnString .. TVModule.TV({args={'exotics', exoticCost .. '%', 'true'}}) .. ' '
			end
		end
				
    	returnString = returnString .. '\n|-'
	end
	returnString = returnString .. '\n|}'
	
	return returnString
end

--endregion

return RadiatorLister