Module:Data tables/tanks: Difference between revisions

From Kerbal Space Program 2 Wiki
Jump to navigation Jump to search
start fuel tank table page
 
updated NS ref
 
(6 intermediate revisions by the same user not shown)
Line 5: Line 5:


-- Builds table formatted for fuel tanks
-- Builds table formatted for fuel tanks
function p.podTable(args)
function p.tankTable(args)
local category = args[1]
local category = args[1]
local family = args[2]
local family = args[2]
local json = mw.loadJsonData("Data:Collections/parts")
local json = mw.loadJsonData("GameData:Collections/parts")
local cells = ''
local cells = ''
-- adds command module values
 
local headers = _commonHeaders()
local headers = _commonHeaders()  
if family ~= "methalox" then
headers = headers .. "!".._formatResource(family).." (t) \n"
else
headers = headers .. "!Methane (t)\n" .. "!Oxidizer (t)\n"
end
-- build header and cells per resource in the tank
-- per usual, iterate through each part in the family
for k, v in pairs(json[category][family]) do
for k, v in pairs(json[category][family]) do
local partJson = mw.loadJsonData("Data:"..k)
local partJson = mw.loadJsonData("GameData:"..k)
local tempCell = _commonCells(partJson)
local tempCell = _commonCells(partJson)
-- iterate over each resource in the tank (thanks methalox)
for m, p in pairs(partJson["resources"]) do
for m, p in pairs(partJson["resources"]) do
-- ignore units tab
if m ~= "units" then
if m ~= "units" then
headers = headers.._formatResource(m)
tempCell = _commonCells(partJson) ..
tempCell = _commonCells(partJson) ..
"|".. m .."\n"
"|".. p .."\n"
cells = tempCell .. cells
end
end
cells = tempCell .. cells
end
end

Latest revision as of 05:29, 14 February 2025

Documentation for this module may be created at Module:Data tables/tanks/doc

local p = {}
local _commonCells = require("Module:Data tables/common").commonCells
local _commonHeaders = require("Module:Data tables/common").commonHeaders
local _formatResource = require("Module:Data infobox")._formatResource

-- Builds table formatted for fuel tanks
function p.tankTable(args)
	local category = args[1]
	local family = args[2]
	local json = mw.loadJsonData("GameData:Collections/parts")
	local cells = ''
	

	local headers = _commonHeaders() 
	if family ~= "methalox" then
		headers = headers .. "!".._formatResource(family).." (t) \n"
	else
		headers = headers .. "!Methane (t)\n" .. "!Oxidizer (t)\n"
	end
		
	
	-- build header and cells per resource in the tank
	-- per usual, iterate through each part in the family
	for k, v in pairs(json[category][family]) do
		local partJson = mw.loadJsonData("GameData:"..k)
		local tempCell = _commonCells(partJson)
		
		-- iterate over each resource in the tank (thanks methalox)
		for m, p in pairs(partJson["resources"]) do
			-- ignore units tab
			if m ~= "units" then
				tempCell = _commonCells(partJson) ..
					"|".. p .."\n"
				cells = tempCell .. cells
			end
		end
		
	end

	-- append the cells to the headers and cap off the table wiki text
	local podTab = headers..cells.."|}"
	return podTab
end

return p