Difference between revisions of "Module:Tables"
Jump to navigation
Jump to search
Line 69: | Line 69: | ||
if c.products then | if c.products then | ||
production = production ..'\'\'\'Produces:\'\'\'<br />' | production = production ..'\'\'\'Produces:\'\'\'<br />' | ||
for k, v in | for k, v in ipairs(c.production) do | ||
production = production .. i.icon(v, nil, nil, v, 'en') .. '<br />' | production = production .. i.icon(v, nil, nil, v, 'en') .. '<br />' | ||
end | end |
Revision as of 18:01, 18 August 2022
Documentation for this module may be created at Module:Tables/doc
local com = require('Module:Common') local a = require('Module:Arguments') local i = require('Module:Icon') local p = {} function p.buildings(frame) local buildingList = mw.loadData('Module:Buildings') local args = a.getArgs(frame) local buildingTable = mw.html.create('table') local dataTable = {} for k, v in pairs(buildingList) do if v.group == args['group'] or not args['group'] then table.insert(dataTable, k) end end table.sort(dataTable) buildingTable:addClass('wikitable sortable') :tag('tr') :tag('th') :wikitext('Name') :done() :tag('th') :wikitext('Prerequisites') :done() :tag('th') :wikitext('Production') :done() :tag('th') :wikitext('Construction Requirements') :done() :done() for k, v in ipairs(dataTable) do local u = string.upper(string.sub(v,1,1)) local buildingName = '[[' .. u .. string.sub(v, 2) .. ']]' local c = buildingList[v] local getPreReq = {} table.insert(getPreReq, c.building) table.insert(getPreReq, c.population) if c.splendor then for k, v in pairs(c.splendor) do table.insert(getPreReq, i.icon(k .. ' splendor', v, nil, nil, 'en')) end end if c.influence then for k, v in pairs(c.influence) do table.insert(getPreReq, i.icon(k .. ' influence', v, nil, nil, 'en')) end end local preReq = '' for k, v in ipairs(getPreReq) do preReq = preReq .. v if k ~= #getPreReq then preReq = preReq .. '<br />' end end local production = '' if c.requirements then production = '\'\'\'Requires:\'\'\'<br />' for k, v in pairs(c.requirements) do production = production .. i.icon(v, nil, nil, v, 'en') .. '<br />' end end if c.products then production = production ..'\'\'\'Produces:\'\'\'<br />' for k, v in ipairs(c.production) do production = production .. i.icon(v, nil, nil, v, 'en') .. '<br />' end end if not production == '' then local l = string.len(production) production = string.sub(production, 1, l - 6) end local newRow = mw.html.create('tr') newRow:tag('th') :wikitext(buildingName) :done() :tag('td') :wikitext(preReq) :done() :tag('td') :wikitext(production) :done() buildingTable:node(newRow) end return buildingTable end return p