Module:PowerPlantLister

From Terra Invicta Official Wiki

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

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

--region Dependencies
local RestrictionChecker = require('Module:RestrictionChecker')
local IconModule = require('Module:Icon')
local TVModule = require('Module:TV')
local PowerPlantData = mw.loadData('Module:CSVReader/PowerPlant')
local PowerPlantNames = mw.loadData('Module:ENReader/PowerPlant')
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 PowerPlantLister.ListRestrictedDetailedPowerPlants(frame)
	return PowerPlantLister.ListPowerPlants(true, frame.args)
end
function PowerPlantLister.ListRestrictedBasicPowerPlants(frame)
	return PowerPlantLister.ListPowerPlants(false, frame.args)
end
function PowerPlantLister.ListDetailedPowerPlants()
	return PowerPlantLister.ListPowerPlants(true)
end

function PowerPlantLister.ListBasicPowerPlants()
	return PowerPlantLister.ListPowerPlants(false)
end

---@param detailed boolean whether to show the detailed or basic version.
---@return wiki table of PowerPlants
function PowerPlantLister.ListPowerPlants(detailed, restrictionsTable)
	local returnString = '{| class="wikitable sortable mw-collapsible" style="text-align: center;"'
	returnString = returnString .. '\n|-'
	returnString = returnString .. '\n! rowspan=2|PowerPlant'
	if detailed then
		returnString = returnString .. '\n! rowspan=2|Required Project'
	end
	returnString = returnString .. '\n! rowspan=2|Classification'
	returnString = returnString .. '\n! rowspan=2|Efficiency'
	returnString = returnString .. '\n! rowspan=2|Specific Power<br>(tons/GW)'
	
	if detailed then 
		returnString = returnString .. '\n! rowspan=2|Max Output<br>(GW)'
	end
	
	returnString = returnString .. '\n! rowspan=2|Crew'
	
	if detailed then
		returnString = returnString .. '\n! colspan=7|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={'nobles'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'fissiles'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'antimatter'}})
		returnString = returnString .. '\n!' .. IconModule.Icon({args={'exotics'}})
	else
		returnString = returnString .. '\n! rowspan=2|Resources'
	end
	returnString = returnString .. '\n|-'
	
	for rowID, row in pairs(PowerPlantData) do
		if RestrictionChecker.AllPass(restrictionsTable, row) then
			returnString = returnString .. '\n| ' .. PowerPlantNames['TIPowerPlantTemplate.displayName.' .. rowID]
			
			if detailed then 
				returnString = returnString .. '\n| ' .. ProjectNameBuilder.buildName({args={row['requiredProjectName']}})
			end
		
			returnString = returnString .. '\n| ' .. "[[" .. PowerPlantNames['TIPowerPlantTemplate.PowerPlantRequirement.' .. row['powerPlantClass']] .. " Power Plant|" .. PowerPlantNames['TIPowerPlantTemplate.PowerPlantRequirement.' .. row['powerPlantClass']] .. "]]"
			returnString = returnString .. '\n| ' .. tostring(tonumber(row['efficiency']) * 100) .. '%'
			returnString = returnString .. '\n| ' .. row['specificPower_tGW']
			
			if detailed then
				returnString = returnString .. '\n| ' .. row['maxOutput_GW']
			end
			
			returnString = returnString .. '\n| ' .. row['crew']
			
			local waterCost = (tonumber(row['weightedBuildMaterials/water']) or 0) * 100
			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 fissileCost = (tonumber(row['weightedBuildMaterials/fissiles']) or 0) * 100
			local antimatterCost = (tonumber(row['weightedBuildMaterials/antimatter']) or 0) * 100
			local exoticCost = (tonumber(row['weightedBuildMaterials/exotics']) or 0) * 100
		
			if detailed then
				returnString = returnString .. '\n| ' .. tostring(waterCost) .. '%'
				returnString = returnString .. '\n| ' .. tostring(volatileCost) .. '%'
				returnString = returnString .. '\n| ' .. tostring(metalCost) .. '%'
				returnString = returnString .. '\n| ' .. tostring(nobleCost) .. '%'
				returnString = returnString .. '\n| ' .. tostring(fissileCost) .. '%'
				returnString = returnString .. '\n| ' .. tostring(antimatterCost) .. '%'
				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 nobleCost ~= 0 then
					returnString = returnString .. TVModule.TV({args={'nobles', nobleCost .. '%', 'true'}}) .. ' '
				end
				if fissileCost ~= 0 then
					returnString = returnString .. TVModule.TV({args={'fissiles', fissileCost .. '%', 'true'}}) .. ' '
				end
				if antimatterCost ~= 0 then
					returnString = returnString .. TVModule.TV({args={'antimatter', antimatterCost .. '%', 'true'}}) .. ' '
				end
				if exoticCost ~= 0 then
					returnString = returnString .. TVModule.TV({args={'exotics', exoticCost .. '%', 'true'}}) .. ' '
				end
			end
					
	    	returnString = returnString .. '\n|-'
    	end
	end
	returnString = returnString .. '\n|}'
	
	return returnString
end

--endregion

return PowerPlantLister