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

Module:Data infobox: Difference between revisions

From Kerbal Space Program 2 Wiki
(started module page for infobox helper functions)
 
(Undo revision 1276 by KiwiShark (talk))
Tag: Undo
 
(9 intermediate revisions by the same user not shown)
Line 11: Line 11:
if resource == "hydrogen" then return "Hydrogen" end
if resource == "hydrogen" then return "Hydrogen" end
if resource == "xenon" then return "Xenon" end
if resource == "xenon" then return "Xenon" end
if resource == "uranium" then return "Uranium" end
if resource == "electric_charge" then return "Electric Charge" end
if resource == "electric_charge" then return "Electric Charge" end
end
end
Line 40: Line 41:
mw.logObject(k)
mw.logObject(k)
else
else
propellants = propellants..p._formatResource(k).." ("..mode["units"][k]..")<br>"
propellants = propellants..p._formatResource(k).."<br>"
end
end
end
end
Line 72: Line 73:
mw.logObject(k)
mw.logObject(k)
else
else
propellants = propellants..v.."<br>"
propellants = propellants..v.." <small>"..mode["units"][k].."</small><br>"
end
end
end
end
Line 79: Line 80:


-- Iterate through and provide the resources labels for converter IO's
-- Iterate through and provide the resources labels for converter IO's
function p.getIOLabels(args)
function p.getIOLabels(frame)
-- arg1: part, arg2: alt mode tag, arg3: input or output
-- arg1: part, arg2: inputs or outputs, arg3: alt mode tag
local args = getArgs(frame)
local args = getArgs(frame)
resources = p._getIOLabels(args)
resources = p._getIOLabels(args)
Line 92: Line 93:
-- Engine alt mode handling
-- Engine alt mode handling
if args[2] == "alt" then
if args[3] == "alt" then
mode = dataJson["modules"]["converter"]["alt_mode"][args[3]]
mode = dataJson["modules"]["converter"]["alt_mode"][args[2]]
else
mode = dataJson["modules"]["converter"][args[2]]
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..p._formatResource(k).." ("..mode["units"][k]..")<br>"
end
end
return resources
end
 
-- Iterate through and provide the resource values for converter IO's
function p.getIOValues(frame)
-- arg1: part, arg2: inputs or outputs, arg3: alt mode tag
local args = getArgs(frame)
resources = p._getIOValues(args)
return resources
end
 
function p._getIOValues(args)
local dataJson = mw.loadJsonData("Data:"..args[1])
local resources = ""
local mode = ""
-- Alt mode handling
if args[3] == "alt" then
mode = dataJson["modules"]["converter"]["alt_mode"][args[2]]
else
else
mode = dataJson["modules"]["engine"][args[3]]
mode = dataJson["modules"]["converter"][args[2]]
end
end

Latest revision as of 15:57, 31 December 2024

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 == "uranium" then return "Uranium" 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).."<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.." <small>"..mode["units"][k].."</small><br>"
		end
	end
	return propellants
end

-- Iterate through and provide the resources labels for converter IO's
function p.getIOLabels(frame)
	-- arg1: part, arg2: inputs or outputs, arg3: alt mode tag
	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[3] == "alt" then
		mode = dataJson["modules"]["converter"]["alt_mode"][args[2]]
	else
		mode = dataJson["modules"]["converter"][args[2]]
	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..p._formatResource(k).." ("..mode["units"][k]..")<br>"
		end
	end
	return resources
end

-- Iterate through and provide the resource values for converter IO's
function p.getIOValues(frame)
	-- arg1: part, arg2: inputs or outputs, arg3: alt mode tag
	local args = getArgs(frame)	
	resources = p._getIOValues(args)
	return resources
end

function p._getIOValues(args)
	local dataJson = mw.loadJsonData("Data:"..args[1])
	local resources = ""
	local mode = ""
	
	-- Alt mode handling
	if args[3] == "alt" then
		mode = dataJson["modules"]["converter"]["alt_mode"][args[2]]
	else
		mode = dataJson["modules"]["converter"][args[2]]
	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