More actions
Tag: Undo |
(new line test, no cells) |
||
Line 23: | Line 23: | ||
local mass = "" | local mass = "" | ||
local max_temp = "" | local max_temp = "" | ||
local header = "{| class=\"wikitable\"" .. | local header = "{| class=\"wikitable\"\n" .. | ||
"|+ style=\"caption-side: bottom\" | <sup>1</sup> The CR-7 R.A.P.I.E.R.'s air-breathing mode specs can be found in the jet engines table." .. | "|+ style=\"caption-side: bottom\" | <sup>1</sup> The CR-7 R.A.P.I.E.R.'s air-breathing mode specs can be found in the jet engines table.\n" .. | ||
"!Image" .. | "!Image\n" .. | ||
"!Name" .. | "!Name\n" .. | ||
"!Mass (t)" .. | "!Mass (t)\n" .. | ||
"!Max Thrust: 1 atm (kN)" .. | "!Max Thrust: 1 atm (kN)\n" .. | ||
"!Max Thrust: Vac. (kN)" .. | "!Max Thrust: Vac. (kN)\n" .. | ||
"!ISP: 1 atm (s)" .. | "!ISP: 1 atm (s)\n" .. | ||
"!ISP: Vac. (s)" .. | "!ISP: Vac. (s)\n" .. | ||
"!Max Temp (K)" .. | "!Max Temp (K)\n" .. | ||
"!Size" | "!Size\n" | ||
local cell = "" | local cell = "" | ||
Line 51: | Line 51: | ||
"|".."{{Size|Size="..partJson["size"].."}}" | "|".."{{Size|Size="..partJson["size"].."}}" | ||
end | end | ||
tempTable = header | tempTable = header.."|}" | ||
return tempTable | return tempTable | ||
end | end |
Revision as of 21:58, 24 November 2024
Documentation for this module may be created at Module:Data tables/doc
local p = {}
local getArgs = require('Module:Arguments').getArgs
function p.buildPartsTable(frame)
local args = getArgs(frame)
local category = args[1]
local family = args[2]
local newTable = ""
if category == "command_modules" and family == "pods" then
newTable = p._podTable(args)
elseif category == "engines" then
newTable = p._engineTable(args)
end
return frame:preprocess(newTable)
end
function p._engineTable(args)
local category = args[1]
local family = args[2]
local tempTable = ""
local name = ""
local mass = ""
local max_temp = ""
local header = "{| class=\"wikitable\"\n" ..
"|+ style=\"caption-side: bottom\" | <sup>1</sup> The CR-7 R.A.P.I.E.R.'s air-breathing mode specs can be found in the jet engines table.\n" ..
"!Image\n" ..
"!Name\n" ..
"!Mass (t)\n" ..
"!Max Thrust: 1 atm (kN)\n" ..
"!Max Thrust: Vac. (kN)\n" ..
"!ISP: 1 atm (s)\n" ..
"!ISP: Vac. (s)\n" ..
"!Max Temp (K)\n" ..
"!Size\n"
local cell = ""
json = mw.loadJsonData("Data:Collections/parts")
for k, v in pairs(json[category][family]) do
local partJson = mw.loadJsonData("Data:"..k)
cell = "|-" ..
"|".."[[File:"..partJson["file"].."|80px|center]]" ..
"|"..partJson["name"] ..
"|"..partJson["mass"] ..
"|"..partJson["modules"]["engine"]["max_thrust"]["atm"] ..
"|"..partJson["modules"]["engine"]["max_thrust"]["vac"] ..
"|"..partJson["modules"]["engine"]["isp"]["atm"] ..
"|"..partJson["modules"]["engine"]["isp"]["vac"] ..
"|"..partJson["max_temp"] ..
"|".."{{Size|Size="..partJson["size"].."}}"
end
tempTable = header.."|}"
return tempTable
end
function p._podTable(args)
local category = args[1]
local family = args[2]
local tempTable = ""
json = mw.loadJsonData("Data:Collections/parts")
for k, v in pairs(json[category][family]) do
local partJson = mw.loadJsonData("Data:"..k)
local name = partJson["name"]
local mass = partJson["mass"]
local max_temp = partJson["max_temp"]
end
tempTable = name.." "..mass.." "..max_temp
return tempTable
end
-- args:
-- tablePage: Name of the tables subpage "Template:Data tables/<tablePage>". Ex: "parts", "tech tree"
-- tableName: Name of the table after the "#". Ex: "command-pods", "ground-landing-legs", "tier1"
function p.getTable(frame)
local args = getArgs(frame)
local tablePage = args[1]
local tableName = escapeTableName(args[2])
local tableContent = p._getTable(tablePage, tableName)
return frame:preprocess(tableContent)
-- return table.concat{frame:preprocess(partTable), "[[Category:Parts]]"}
end
function p._getTable(tablePage, TableName)
local tablePageContent = mw.title.new("Template:Data tables/"..tablePage):getContent()
local regex = '#'..TableName..'.-{|.-|}'
local tableWithTag = tablePageContent:match(regex)
local tableContent = tableWithTag:match('{|.-|}')
return tableContent
end
function escapeTableName(name)
return name:gsub("-","--")
end
function p.tableToObjects(inputTable)
local result = {}
local columns = {}
local header = inputTable:match("\n!(.-)\n|")
local body = inputTable:match("\n|%-(.-)\n|}")
columns = split(header, "\n!")
rows = split(body, "\n|-")
for i, row in ipairs(rows) do
local object = {}
local cells = split(row, "\n|")
cells = {unpack(cells, 2, #cells)}
for i, cell in ipairs(cells) do
local column = columns[i]
column = column:gsub("^%s*(.-)%s*$", "%1")
if (column == null) then
column = "missing"
end
object[column] = cell
end
table.insert(result, object)
end
return result
end
return p