Module:HeatSinkLister

From Terra Invicta Official Wiki

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

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

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

--region Private constants
local floor = math.floor
--endregion



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

--region Private methods


--endregion

--region Public methods
function HeatSinkLister.ListDetailedHeatSinks()
	return HeatSinkLister.ListHeatSinks(true)
end

function HeatSinkLister.ListBasicHeatSinks()
	return HeatSinkLister.ListHeatSinks(false)
end

---@param detailed boolean whether to show the detailed or basic version.
---@return wiki table of HeatSinks
function HeatSinkLister.ListHeatSinks(detailed)
	local returnString = '{| class="wikitable sortable mw-collapsible" style="text-align: center;"'
	returnString = returnString .. '\n|-'
	returnString = returnString .. '\n! rowspan=2|Heat Sink'
	if detailed then
		returnString = returnString .. '\n! rowspan=2|Required Project'
	end
	returnString = returnString .. '\n! rowspan=2|Capacity<br>(GJ)'
	returnString = returnString .. '\n! rowspan=2|Specific Capacity<br>(GJ/ton)'
	returnString = returnString .. '\n! rowspan=2|Crew'
	returnString = returnString .. '\n! rowspan=2|Mass<br>(tons)'
	if detailed then 
		returnString = returnString .. '\n! colspan=4|Resources'
		returnString = returnString .. '\n|-'
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'water'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'volatiles'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'metals'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'exotics'}})
	else
		returnString = returnString .. '\n! rowspan=2|Resources'
	end
	returnString = returnString .. '\n|-'
	
	for rowID, row in pairs(HeatSinkData) do
		returnString = returnString .. '\n| ' .. HeatSinkNames['TIHeatSinkTemplate.displayName.' .. rowID]
		
		if detailed then 
			returnString = returnString .. '\n| ' .. ProjectNameBuilder.buildName({args={row['requiredProjectName']}})
		end
	
		returnString = returnString .. '\n| ' .. row['heatCapacity_GJ']

		local massWithCrew = tonumber(row['mass_tons']) + tonumber(row['crew']) * 4
		
		local specificCapacity = floor(tonumber(row['heatCapacity_GJ']) / massWithCrew * 1000 + 0.5) / 1000
		returnString = returnString .. '\n| ' .. tostring(specificCapacity)
		
		returnString = returnString .. '\n| ' .. row['crew']

		returnString = returnString .. '\n| ' .. massWithCrew
				
		local massTons = tonumber(row['mass_tons'])
		local waterCost = massTons * (tonumber(row['weightedBuildMaterials/water']) or 0) / 10 + tonumber(row['crew']) / 5
		local volatileCost = massTons * (tonumber(row['weightedBuildMaterials/volatiles']) or 0) / 10 + tonumber(row['crew']) / 5
		local metalCost = massTons * (tonumber(row['weightedBuildMaterials/metals']) or 0) / 10
		local exoticCost = massTons * (tonumber(row['weightedBuildMaterials/exotics']) or 0) / 10
		
		if detailed then 
			returnString = returnString .. '\n| ' .. tostring(waterCost)
			returnString = returnString .. '\n| ' .. tostring(volatileCost)
			returnString = returnString .. '\n| ' .. tostring(metalCost)
			returnString = returnString .. '\n| ' .. tostring(exoticCost)
		else
			returnString = returnString .. '\n| '
			if waterCost ~= 0 then
				returnString = returnString .. TVModule.TV({args={'water', waterCost, 'true'}}) .. ' '
			end
			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 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 HeatSinkLister