Module:BatteryLister
From Terra Invicta Official Wiki
Documentation for this module may be created at Module:BatteryLister/doc
---
---Reads the Battery data files and presents them in readable formats, with additional calculated statistics.
---
---@module BatteryLister
local BatteryLister = {}
--region Dependencies
local IconModule = require('Module:Icon')
local TVModule = require('Module:TV')
local BatteryData = mw.loadData('Module:CSVReader/Battery')
local BatteryNames = mw.loadData('Module:ENReader/Battery')
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 BatteryLister.ListDetailedBatteries()
return BatteryLister.ListBatteries(true)
end
function BatteryLister.ListBasicBatteries()
return BatteryLister.ListBatteries(false)
end
---@param detailed boolean whether to show the detailed or basic version.
---@return wiki table of batteries
function BatteryLister.ListBatteries(detailed)
local returnString = '{| class="wikitable sortable mw-collapsible" style="text-align: center;"'
returnString = returnString .. '\n|-'
returnString = returnString .. '\n! rowspan=2|Battery'
if detailed then
returnString = returnString .. '\n! rowspan=2|Required Project'
end
returnString = returnString .. '\n! rowspan=2|Capacity<br>(GJ)'
returnString = returnString .. '\n! rowspan=2|Recharge Rate<br>(GJ/minute)'
returnString = returnString .. '\n! rowspan=2|Full Charge Time<br>(minutes)'
returnString = returnString .. '\n! rowspan=2|Crew'
if detailed then
returnString = returnString .. '\n! rowspan=2|HP'
end
returnString = returnString .. '\n! rowspan=2|Mass<br>(tons)'
if detailed then
returnString = returnString .. '\n! colspan=5|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={'exotics'}})
else
returnString = returnString .. '\n! rowspan=2|Resources'
end
returnString = returnString .. '\n|-'
for rowID, row in pairs(BatteryData) do
if row['disable'] ~= 'true' then
returnString = returnString .. '\n| ' .. BatteryNames['TIBatteryTemplate.displayName.' .. rowID]
if detailed then
returnString = returnString .. '\n| ' .. ProjectNameBuilder.buildName({args={row['requiredProjectName']}})
end
returnString = returnString .. '\n| ' .. row['energyCapacity_GJ']
local rechargePerMin = tonumber(row['rechargeRate_GJs']) * 60
returnString = returnString .. '\n| ' .. tostring(rechargePerMin)
local fullChargeTime = floor(tonumber(row['energyCapacity_GJ']) / rechargePerMin * 10 + 0.5) / 10
returnString = returnString .. '\n| ' .. tostring(fullChargeTime)
returnString = returnString .. '\n| ' .. row['crew']
if detailed then
returnString = returnString .. '\n| ' .. row['hp']
end
local massWithCrew = tonumber(row['mass_tons']) + tonumber(row['crew']) * 4
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 nobleCost = massTons * (tonumber(row['weightedBuildMaterials/nobleMetals']) 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(nobleCost)
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 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 BatteryLister


