Difference between revisions of "Module:OTable"
Jump to navigation
Jump to search
m |
m |
||
| Line 48: | Line 48: | ||
local c = buildingList[v] | local c = buildingList[v] | ||
local buildingType = c.type | local buildingType = c.type | ||
local influence = '' | |||
if c.influence then | |||
local influenceKeys = {} | |||
local tierValue = c.influence.tier | |||
for k in pairs(c.influence) do | |||
if k ~= 'perEach splendour' and k ~= 'tier' then -- Exclude 'perEach splendour' and 'tier' | |||
table.insert(influenceKeys, k) | |||
end | |||
end | end | ||
local lastKey = influenceKeys[#influenceKeys] | |||
local itemCount = #influenceKeys | |||
for k, v in pairs(c.influence) do | |||
if k ~= 'perEach splendour' and k ~= 'tier' then | |||
influence = influence .. i.icon(k, v, nil, k, 'en') | |||
if k ~= lastKey and itemCount > 1 then | |||
influence = influence .. '<br />' | |||
end | |||
end | end | ||
end | |||
-- Append the tier in brackets if it exists | |||
if tierValue then | |||
influence = influence .. ' (' .. tierValue .. ')' | |||
end | end | ||
end | end | ||
local unlocks = influence | |||
local production = '' | local production = '' | ||
Revision as of 11:43, 19 April 2025
Documentation for this module may be created at Module:OTable/doc
-- This is adapted from Sakaratte's table located at Module:Tables --
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:BuildingIndex')
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('Type')
: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 titleParts = mw.text.split(v, '%s')
for k2, part in ipairs(titleParts) do
titleParts[k2] = part:upper():sub(1,1) .. part:sub(2)
end
local buildString = '[[%s|%s]]'
local pageTitle = table.concat(titleParts, ' ')
local u = string.upper(string.sub(v,1,1))
local buildingName = buildString:format(pageTitle, u .. string.sub(v, 2))
local c = buildingList[v]
local buildingType = c.type
local influence = ''
if c.influence then
local influenceKeys = {}
local tierValue = c.influence.tier
for k in pairs(c.influence) do
if k ~= 'perEach splendour' and k ~= 'tier' then -- Exclude 'perEach splendour' and 'tier'
table.insert(influenceKeys, k)
end
end
local lastKey = influenceKeys[#influenceKeys]
local itemCount = #influenceKeys
for k, v in pairs(c.influence) do
if k ~= 'perEach splendour' and k ~= 'tier' then
influence = influence .. i.icon(k, v, nil, k, 'en')
if k ~= lastKey and itemCount > 1 then
influence = influence .. '<br />'
end
end
end
-- Append the tier in brackets if it exists
if tierValue then
influence = influence .. ' (' .. tierValue .. ')'
end
end
local unlocks = influence
local production = ''
if c.input then
production = '\'\'\'Consumes:\'\'\'<br />'
for k, v in pairs(c.input) do
production = production .. i.icon(v, nil, nil, v, 'en') .. '<br />'
end
end
if c.output then
production = production ..'\'\'\'Produces:\'\'\'<br />'
for k, v in ipairs(c.output) 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 construction = ''
if c.construction then
for k, v in pairs(c.construction) do
construction = construction .. i.icon(k, v, nil, k, 'en') .. '<br />'
end
local l = string.len(construction)
if l > 0 then
construction = string.sub(construction, 1, l - 6)
end
end
-- adding gold coins back in??
if c.costs and c.costs['gold coins'] then
construction = construction .. '<br />' .. i.icon('gold coins', c.costs['gold coins'], nil, 'gold coins', 'en')
end
local newRow = mw.html.create('tr')
newRow:tag('th')
:wikitext(buildingName)
:done()
:tag('td')
:wikitext(buildingType)
:done()
:tag('td')
:wikitext(unlocks)
:done()
:tag('td')
:wikitext(production)
:done()
:tag('td')
:wikitext(construction)
:done()
buildingTable:node(newRow)
end
return buildingTable
end
return p