Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Data infobox

From Kerbal Space Program 2 Wiki

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

local p = {}
local getArgs = require('Module:Arguments').getArgs

-- Re-format the resource names in part data to be displayed
function p._formatResource(resource)
	if resource == "monopropellant" then return "Monopropellant" end
	if resource == "methane" then return "Methane" end
	if resource == "oxidizer" then return "Oxidizer" end
	if resource == "intake_air" then return "Intake Air" end
	if resource == "solid_fuel" then return "Solid Fuel" end
	if resource == "hydrogen" then return "Hydrogen" end
	if resource == "xenon" then return "Xenon" end
	if resource == "electric_charge" then return "Electric Charge" end
end

-- Iterate through and provide the propellant types of an engine
function p.getFuelLabels(frame)
	local args = getArgs(frame)	
	propellants = p._getFuelLabels(args)
	return propellants
end

function p._getFuelLabels(args)
	-- Load the data from the JSON page, parsed as a table of tables
	local dataJson = mw.loadJsonData("Data:"..args[1])
	local propellants = ""
	local mode = ""
	
	-- Engine alt mode handling
	if args[2] == "alt" then
		mode = dataJson["modules"]["engine"]["alt_mode"]["propellants"]
	else
		mode = dataJson["modules"]["engine"]["propellants"]
	end
	
	-- 	Build the propellants label list
	for k, v in pairs(mode) do
		if k == "units" then
			-- Dummy line
			mw.logObject(k)
		else
			propellants = propellants..p._formatResource(k).." ("..mode["units"][k]..")<br>"
		end
	end
	return propellants
end

-- Iterate through and provide the propellant values of an engine
function p.getFuelValues(frame)
	local args = getArgs(frame)	
	propellants = p._getFuelValues(args)
	return propellants
end

function p._getFuelValues(args)
	-- Load the data from the JSON page, parsed as a table of tables
	local dataJson = mw.loadJsonData("Data:"..args[1])
	local propellants = ""
	local mode = ""
	
	-- Engine alt mode handling
	if args[2] == "alt" then
		mode = dataJson["modules"]["engine"]["alt_mode"]["propellants"]
	else
		mode = dataJson["modules"]["engine"]["propellants"]
	end
	
	-- 	Build the propellants values list
	for k, v in pairs(mode) do
		if k == "units" then
			-- Dummy line
			mw.logObject(k)
		else
			propellants = propellants..v.."<br>"
		end
	end
	return propellants
end

-- Iterate through and provide the resources labels for converter IO's
function p.getIOLabels(args)
	-- arg1: part, arg2: alt mode tag, arg3: input or output
	local args = getArgs(frame)	
	resources = p._getIOLabels(args)
	return resources
end

function p._getIOLabels(args)
	local dataJson = mw.loadJsonData("Data:"..args[1])
	local resources = ""
	local mode = ""
	
		-- Engine alt mode handling
	if args[2] == "alt" then
		mode = dataJson["modules"]["converter"]["alt_mode"][args[3]]
	else
		mode = dataJson["modules"]["engine"][args[3]]
	end
	
	-- 	Build the propellants values list
	for k, v in pairs(mode) do
		if k == "units" then
			-- Dummy line
			mw.logObject(k)
		else
			resources = resources..v.."<br>"
		end
	end
	return resources
end

return p
MediaWiki Appliance - Powered by TurnKey Linux