Difference between revisions of "Module:Tables"

From Foundation - Wiki
Jump to navigation Jump to search
Line 31: Line 31:
:done()
:done()
:done()
:done()
 
for k, v in pairs (dataTable) do
local getPreReq = {}
table.insert(getPreReq, v.building .. '|building')
table.insert(getPreReq, v.population .. '|population')
table.insert(getPreReq, v.splendor .. '|splendor')
table.insert(getPreReq, v.influence .. '|influence')
local preReq = ''
for k, v in ipairs(getPreReq) do
local tag = string.sub(v, string.find(v, '|'))
if tag == 'splendor' or tag == 'influence' then
preReq = preReq i.icon(tag .. ' ' .. k, string.sub(v, string.sub(v, 1,
string.find(v, '|') - 1)), nil, nil, 'en')
else
preReq = preReq .. string.sub(v, string.sub(v, 1,
string.find(v, '|') - 1))
end
 
end
local newRow = mw.html.create('tr')
newRow:tag('th')
:wikitext(k)
:done()
end
end
end
return p

Revision as of 20:27, 14 August 2022

Documentation for this module may be created at Module:Tables/doc

local com = require('Module:Common')
local a = require('Module:Args')
local i = require('Module:Icon')
local p = {}

function p.buildings(frame)
	local buildingList = mw.load('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 pairs (dataTable) do
		local getPreReq = {}
		table.insert(getPreReq, v.building .. '|building')
		table.insert(getPreReq, v.population .. '|population')
		table.insert(getPreReq, v.splendor .. '|splendor')
		table.insert(getPreReq, v.influence .. '|influence')
		local preReq = ''
		for k, v in ipairs(getPreReq) do
			local tag = string.sub(v, string.find(v, '|'))
			if tag == 'splendor' or tag == 'influence' then
				preReq = preReq i.icon(tag .. ' ' .. k, string.sub(v, string.sub(v, 1, 
					string.find(v, '|') - 1)), nil, nil, 'en')
			else
				preReq = preReq .. string.sub(v, string.sub(v, 1, 
					string.find(v, '|') - 1))
			end
			

		end
			
		local newRow = mw.html.create('tr')
		newRow:tag('th')
			:wikitext(k)
			:done()
	end
end

return p