From StrategyWiki, the video game walkthrough and strategy guide wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Settlement Survival/Documentation

local getArgs = require('Module:Arguments').getArgs

local p = {}

local args = {}
local root
local buildingData = mw.loadData( 'Module:Settlement Survival/buildingData' )

local function addRow( rowArgs )
	-- Adds a row to the infobox, with either a header cell
	-- or a label/data cell combination.
	if rowArgs.header then
		root
			:tag( 'tr' )
				:addClass( rowArgs.rowclass )
				:tag( 'th' )
					:attr( 'colspan', 2 )
					:css( 'text-align', 'center' )
					:cssText( rowArgs.headerstyle )
					:wikitext( rowArgs.header )
	elseif rowArgs.data then
		local row = root:tag( 'tr' ):addClass( rowArgs.rowclass )

		if rowArgs.label then
			row
				:tag( 'th' )
					:cssText( rowArgs.labelstyle )
					:wikitext( rowArgs.label )
					:done()
		end

		local dataCell = row:tag( 'td' )
		if not rowArgs.label then
			dataCell
				:attr( 'colspan', 2 )
				:cssText( rowArgs.rowstyles or 'text-align: center;' )
		end
		dataCell
			:wikitext( rowArgs.data )
	end
end

local function renderTitle( entry )
	if buildingData[entry]["Name"] then
		root
			:tag( 'tr' )
				:tag( 'th' )
					:attr( 'colspan', 2 )
					:addClass( 'infobox_heading' )
					:wikitext( buildingData[entry]["Name"] )
	end
end

local function renderImage( entry )
	if buildingData[entry]["Icon"] then
		local data = mw.html.create():wikitext( '[[File:SetSur ' .. buildingData[entry]["Icon"] .. '.png|200px|' .. buildingData[entry]["Name"] .. ']]' )
		addRow( { data = tostring( data ) } )
	end
end

local function renderRows( entry )
	addRow( {label = 'ID', data = buildingData[entry]["ID"] } )
	addRow( {label = 'Max Workers', data = buildingData[entry]["WorkerRange"]["Upper"] } )
end

local function _building( entry )
	root = mw.html.create( 'table' )

	root
		:addClass( 'infobox' )
		:addClass( 'bordered' )

	renderTitle( entry )
	renderImage( entry )
	renderRows( entry )

	return tostring( root ) .. buildingData[entry]["Des"]
end

function p.building( frame )
	args = getArgs( frame )

	return _building( args[1] )
end

return p