Module:Data tables/engines: Difference between revisions

From Kerbal Space Program 2 Wiki
Jump to navigation Jump to search
start page for engine tables
 
rename main function for engines
Line 3: Line 3:


-- Builds table formatted for engines
-- Builds table formatted for engines
function p.podTable(args)
function p.engineTable(args)
local category = args[1]
local category = args[1]
local family = args[2]
local family = args[2]

Revision as of 06:06, 1 February 2025

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

local p = {}
local _commonCells = require("Module:Data tables/common cells").commonCells

-- Builds table formatted for engines
function p.engineTable(args)
	local category = args[1]
	local family = args[2]
	local json = mw.loadJsonData("Data:Collections/parts")
	local cells = ''
	
	-- adds engine headers
	local header =
		"!Max Thrust: 1 atm (kN)\n" ..
		"!Max Thrust: Vac. (kN)\n" ..
		"!ISP: 1 atm (s)\n" ..
		"!ISP: Vac. (s)\n"
	
	-- populates common cells and engine cells
	for k, v in pairs(json[category][family]) do
		local partJson = mw.loadJsonData("Data:"..k)
		local tempCell = _commonCells(partJson) ..
			"|"..partJson["modules"]["engine"]["max_thrust"]["atm"].."\n" ..
			"|"..partJson["modules"]["engine"]["max_thrust"]["vac"].."\n" ..
			"|"..partJson["modules"]["engine"]["isp"]["atm"].."\n" ..
			"|"..partJson["modules"]["engine"]["isp"]["vac"].."\n"

		cells = tempCell..cells
	end

	-- append the cells to the headers
	local engineTab = header..cells
	return engineTab
end

return p