More actions
(see args with frameonly) |
(re-eval of args for frameonly) |
||
Line 11: | Line 11: | ||
local args = getArgs(frame, {frameOnly = true}) -- E.g., args = {"Example", "modules", "engine", "isp", "vac"} | local args = getArgs(frame, {frameOnly = true}) -- E.g., args = {"Example", "modules", "engine", "isp", "vac"} | ||
-- Pass arguments to the helper function | -- Pass arguments to the helper function | ||
dataJson = p._getData(args) | |||
return dataJson--[args[2]]["engine"]["isp"]["vac"] | return dataJson--[args[2]]["engine"]["isp"]["vac"] | ||
end | end | ||
Line 22: | Line 21: | ||
-- Iterate through dataJson using the args values as keys to | -- Iterate through dataJson using the args values as keys to | ||
-- step down into the table per argument | -- step down into the table per argument | ||
--for k, v in pairs(args) do | |||
-- if k > 1 then | |||
-- dataJson = dataJson[v] | |||
-- end | |||
--end | |||
local temp = "START:" | |||
for k, v in pairs(args) do | for k, v in pairs(args) do | ||
temp = temp.." "..k | |||
end | end | ||
dataJson = temp | dataJson = temp | ||
-- Send the final, requested value back to the main function | -- Send the final, requested value back to the main function |
Revision as of 18:56, 25 November 2024
The Data module exists to translate information from Data: pages to templates/articles.
Arguments
<1>
(Entity): This argument is taken as the title of the intended Data: page to search through.
E.g.: "Kerbol", "LW-Sw "SWERV""
<2+>
(Parameter chain): Arguments 2 and beyond define the parameter chain to search on the data page.
E.g.: "mass", "max_temp", "modules|engine|isp_vac", "modules|generator|outputs|units"
Functions
getData
: The primary function of the module. Accepts the full argument set to determine the parameter to return from the subject.
getFuelLabels
: Used for engine infobox construction. Accepts a part name (only works for engines) for <1>
and optionally "alt" for <2>
. Returns a line-break separated list of the propellant names used by an engine mode. Should probably be moved to a different Module.
getFuelValues
: Used for engine infobox construction. Accepts a part name (only works for engines) for <1>
and optionally "alt" for <2>
. Returns a line-break separated list of the propellant use rates of an engine mode. Should probably be moved to a different Module.
Examples
A list of example JSON sets can be found at Data:Example.
{{#invoke:Data|getData|LV-SW "SWERV"|mass}}
- Returns the mass of the "SWERV" in tons, START: 1 2
.
{{#invoke:Data|getData|LV-3000 "Tuba"|modules|engine|thrust|vac}}
- Returns the vacuum thrust of the "Tuba" in kilonewtons, 510.0
.
local p = {}
local getArgs = require('Module:Arguments').getArgs
-- subject: The subject entity to get data from.
--- E.g., "Kerbol", "LW-Sw "SWERV""
-- args: The parameter / parameter chain to access from the data page.
--- E.g., "mass", "max_temp", "modules|engine|isp_vac", "modules|generator|outputs|units"
function p.getData(frame)
-- Get arguments from the invoke
local args = getArgs(frame, {frameOnly = true}) -- E.g., args = {"Example", "modules", "engine", "isp", "vac"}
-- Pass arguments to the helper function
dataJson = p._getData(args)
return dataJson--[args[2]]["engine"]["isp"]["vac"]
end
function p._getData(args)
-- Load the data from the JSON page, parsed as a table of tables
local dataJson = mw.loadJsonData("Data:"..args[1])
-- Iterate through dataJson using the args values as keys to
-- step down into the table per argument
--for k, v in pairs(args) do
-- if k > 1 then
-- dataJson = dataJson[v]
-- end
--end
local temp = "START:"
for k, v in pairs(args) do
temp = temp.." "..k
end
dataJson = temp
-- Send the final, requested value back to the main function
return dataJson
end
function p.getEngineFuel(frame)
local args = getArgs(frame)
fuelType = p._getEngineFuel(args)
return fuelType
end
function p._getEngineFuel(args)
-- Load the data from the JSON page, parsed as a table of tables
local dataJson = mw.loadJsonData("Data:"..args[1])
local fuelType = ""
for k, v in pairs(dataJson["modules"]["engine"]["propellants"]) do
mw.logObject(k)
if k == "oxidizer" then
fuelType = "Methalox"
end
end
return fuelType
end
return p