Module:Data tables/engines: Difference between revisions

From Kerbal Space Program 2 Wiki
Jump to navigation Jump to search
rename main function for engines
updated NS ref
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local _commonCells = require("Module:Data tables/common cells").commonCells
local _commonCells = require("Module:Data tables/common cells").commonCells
local _commonHeaders = require("Module:Data tables/common").commonHeaders


-- Builds table formatted for engines
-- Builds table formatted for engines
Line 6: Line 7:
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 engine headers
-- adds engine headers
local header =
local headers = _commonHeaders() ..
"!Max Thrust: 1 atm (kN)\n" ..
"!Max Thrust: 1 atm (kN)\n" ..
"!Max Thrust: Vac. (kN)\n" ..
"!Max Thrust: Vac. (kN)\n" ..
Line 18: Line 19:
-- populates common cells and engine cells
-- populates common cells and engine cells
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) ..
"|"..partJson["modules"]["engine"]["max_thrust"]["atm"].."\n" ..
"|"..partJson["modules"]["engine"]["max_thrust"]["atm"].."\n" ..
Line 29: Line 30:


-- append the cells to the headers
-- append the cells to the headers
local engineTab = header..cells
local engineTable = headers..cells.."|}"
return engineTab
return engineTable
end
end


return p
return p

Latest revision as of 05:28, 14 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
local _commonHeaders = require("Module:Data tables/common").commonHeaders

-- Builds table formatted for engines
function p.engineTable(args)
	local category = args[1]
	local family = args[2]
	local json = mw.loadJsonData("GameData:Collections/parts")
	local cells = ''
	
	-- adds engine headers
	local headers = _commonHeaders() ..
		"!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("GameData:"..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 engineTable = headers..cells.."|}"
	return engineTable
end

return p