More actions
(moved propellants units to data field) |
(changed to build label/data rows rather than return single field to a row) Tag: Reverted |
||
Line 25: | Line 25: | ||
-- Load the data from the JSON page, parsed as a table of tables | -- Load the data from the JSON page, parsed as a table of tables | ||
local dataJson = mw.loadJsonData("Data:"..args[1]) | local dataJson = mw.loadJsonData("Data:"..args[1]) | ||
local i = 1 | |||
local propellants = "" | local propellants = "" | ||
local mode = "" | local mode = "" | ||
Line 41: | Line 42: | ||
mw.logObject(k) | mw.logObject(k) | ||
else | else | ||
propellants = propellants..p._formatResource(k).."<br>" | propellants = propellants.."| label"..tostring(i).."="..p._formatResource(k).."<br>" | ||
i = i + 1 | |||
end | end | ||
end | end | ||
Line 58: | Line 60: | ||
local dataJson = mw.loadJsonData("Data:"..args[1]) | local dataJson = mw.loadJsonData("Data:"..args[1]) | ||
local propellants = "" | local propellants = "" | ||
i = 1 | |||
local mode = "" | local mode = "" | ||
Line 73: | Line 76: | ||
mw.logObject(k) | mw.logObject(k) | ||
else | else | ||
propellants = propellants..v.." <small>"..mode["units"][k].."</small><br>" | propellants = propellants.."| data"..tostring(i).."="..v.." <small>"..mode["units"][k].."</small><br>" | ||
i = i + 1 | |||
end | end | ||
end | end |
Revision as of 15:47, 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 i = 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.."| label"..tostring(i).."="..p._formatResource(k).."<br>"
i = i + 1
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 = ""
i = 1
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.."| data"..tostring(i).."="..v.." <small>"..mode["units"][k].."</small><br>"
i = i + 1
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