More actions
No edit summary |
(test) |
||
Line 9: | Line 9: | ||
function p.getData(frame) | function p.getData(frame) | ||
local args = getArgs(frame) | -- Get arguments from the invoke | ||
local args = getArgs(frame) -- E.g., args = {"Example", "modules", "engine", "isp", "vac"} | |||
-- Load the JSON from the Data: page | |||
local dataJson = mw.loadJsonData("Data:"..args[1]) | local dataJson = mw.loadJsonData("Data:"..args[1]) | ||
-- Iterate through the JSON using the remaining args | |||
for i = 2, table.maxn(args) do | for i = 2, table.maxn(args) do | ||
-- Each loop steps into the next level JSON table, | |||
-- leaving the final value at the end | |||
dataJson = dataJson[args[i]] | dataJson = dataJson[args[i]] | ||
end | end | ||
Line 22: | Line 24: | ||
--local dataValue = p._getData(args) | --local dataValue = p._getData(args) | ||
return | return "test" | ||
end | end | ||
function | function _getData(args) | ||
local dataJson = mw.loadJsonData("Data:"..args[1]) | local dataJson = mw.loadJsonData("Data:"..args[1]) | ||
Line 33: | Line 35: | ||
end | end | ||
return dataJson | |||
end | end | ||
Revision as of 16:52, 10 October 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, test
.
{{#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
-- args:
-- subject: The subject entity to get data from.
--- E.g., "Kerbol", "LW-Sw "SWERV""
-- param: 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) -- E.g., args = {"Example", "modules", "engine", "isp", "vac"}
-- Load the JSON from the Data: page
local dataJson = mw.loadJsonData("Data:"..args[1])
-- Iterate through the JSON using the remaining args
for i = 2, table.maxn(args) do
-- Each loop steps into the next level JSON table,
-- leaving the final value at the end
dataJson = dataJson[args[i]]
end
--local dataValue = p._getData(args)
return "test"
end
function _getData(args)
local dataJson = mw.loadJsonData("Data:"..args[1])
-- Run through each additional paramter which should point to a specific element in a part data JSON
for i = 2, table.maxn(args) do
dataJson = dataJson[args[i]]
end
return dataJson
end
function p.test()
local dataJson = mw.loadJsonData("Data:Example")
local temp = dataJson["modules"]["engine"]
return(temp["isp"]["vac"])
end
return p