Difference between revisions of "Module:Tables"

From Foundation - Wiki
Jump to navigation Jump to search
Line 33: Line 33:
for k, v in pairs (dataTable) do
for k, v in pairs (dataTable) do
local c = buildingList[v]
local getPreReq = {}
local getPreReq = {}
table.insert(getPreReq, v.building)
table.insert(getPreReq, c.building)
table.insert(getPreReq, v.population)
table.insert(getPreReq, c.population)
if v.splendor then
if c.splendor then
for k, v in pairs(v.splendor) do
for k, v in pairs(v.splendor) do
table.insert(getPreReq, i.icon(k .. ' splendor', v, nil, nil, 'en'))
table.insert(getPreReq, i.icon(k .. ' splendor', v, nil, nil, 'en'))
Line 42: Line 43:
end
end
if v.influence then
if c.influence then
for k, v in pairs(v.influence) do
for k, v in pairs(v.influence) do
table.insert(getPreReq, i.icon(k .. ' influence', v, nil, nil, 'en'))
table.insert(getPreReq, i.icon(k .. ' influence', v, nil, nil, 'en'))
Line 57: Line 58:
local production = {}
local production = {}
if v.requirements then  
if c.requirements then  
local reqs = ''
local reqs = ''
for k, v in pairs(v.requirements) do
for k, v in pairs(c.requirements) do
end
end
Line 67: Line 68:
local newRow = mw.html.create('tr')
local newRow = mw.html.create('tr')
newRow:tag('th')
newRow:tag('th')
:wikitext(k)
:wikitext(v)
:done()
:done()
:tag('td')
:tag('td')

Revision as of 19:00, 17 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 pairs (dataTable) do
		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(v.splendor) do
				table.insert(getPreReq, i.icon(k .. ' splendor', v, nil, nil, 'en'))
			end
		end
		
		if c.influence then
			for k, v in pairs(v.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 
			local reqs = ''
			for k, v in pairs(c.requirements) do
				
			end
		end
				
		
		local newRow = mw.html.create('tr')
		newRow:tag('th')
			:wikitext(v)
			:done()
		:tag('td')
			:wikitext(preReq)
			:done()
			
		buildingTable:node(newRow)
	end
	
	return buildingTable
end

return p